Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// This script used to populate the Persondata template with fields from
// infoboxes. However, it is now deprecated, and should no longer be used.
// See [[Wikipedia:Persondata]] for more details.

mw.loader.using( [
	'mediawiki.jqueryMsg',
	'mediawiki.util',
], function () {
	var label, tooltip, portletLink;

	// Find the label and tooltip the same way as the old script did.
	if ( !document.forms.editform && $( '#persondata' ).length ) {
		label = 'show/hide persondata';
		tooltip = 'Show/hide persondata metadata';
	} else if (
			mw.config.get( 'wgNamespaceNumber' ) === 0  &&
			$( '#wpTextbox1' ).length &&
			!$( '#wpTextbox1' ).text().match( /persondata/i )
	) {
		label = 'add persondata';
		tooltip = 'Add persondata metadata';
	}

	// Add the portlet link. When clicked, this pops up a notification saying
	// that the script is deprecated.
	if ( label && tooltip ) {
		portletLink = mw.util.addPortletLink(
			'p-cactions',
			'#',
			label,
			'ca-pdata',
			tooltip
		);
		mw.messages.set( {
			'pdata-deprecated': "[[User:Dr pda/persondata.js]] is " +
				"[[Wikipedia:Persondata|deprecated]]. Please remove it " +
				"from your [[Wikipedia:User scripts|user script]] page."
		} );
		$( portletLink ).click( function ( e ) {
			e.preventDefault();
			mw.notify(
				mw.message( 'pdata-deprecated' ),
				{ title: 'Script deprecated' }
			);
		} );
	}
});