Template documentation


Usage

{{bot policy|ie.wikipedia}}

Returns information about the implementation of the standard bot policy on a given wiki as one of the following strings. This template is intended to be used in other templates, particularly {{sr-request}}.

Please update Bot policy/Implementation#Where it is policy instead of this template, which is updated using a script.

aaa,gb allows both automatic approval and global bots.
aaa allows automatic approval, but not global bots.
gb allows global bots, but not automatic approval.
does not use the bot policy.

Updating this template

This template is semi-automatically updated using the following JavaScript. You can run it on any Meta page (e.g., by pasting it into your browser's console window). This will parse the latest data from Bot policy/Implementation, and output the results and instructions on what to do at the top of the page.

if (!window.pathoschild) {
	var pathoschild = {};
}

/**
 * This is a specialized wiki script. It queries the content of [[m:Bot policy/Implementation]], and generates an
 * updated {{#switch}} statement used in [[m:Template:Bot policy]].
 * @author Pathoschild; http://meta.wikimedia.org/wiki/User_talk:Pathoschild
 * @version 0.2
 */
pathoschild.UpdateBotPolicyTemplate = {
	/*########
	## Properties
	########*/
	/**
	 * @field {string} The URL to the page containing the bot policy implementation details to extract.
	 * @private
	 */
	_url: '//meta.wikimedia.org/wiki/Bot_policy/Implementation?action=render',

	/**
	 * The unique ID associated with the log element.
	 * @private
	 */
	_logID: 'pathoschild-update-bot-policy-template-result',

	/**
	 * The element to which output is written.
	 * @private
	 */
	_$log: null,


	/*########
	## Internal methods
	########*/
	/**
	 * Get an element to which output can be written for the user.
	 * @return {Element} The DOM element to which output can be written.
	 * @private
	 */
	_GetLog: function () {
		/* already created */
		var log = $('#' + this._logID).first();
		if (log.length) {
			return log.empty();
		}

		/* create */
		log = $(document.createElement('pre'))
			.attr('id', this._logID)
			.css({ 'font-size': '0.8em' });
		$('#wpTextbox1, #bodyContent').first().before(log);
		return log;
	},

	/**
	 * Append a message to the output log.
	 * @param {string} message The message to append.
	 * @private
	 */
	_Log: function (message) {
		this._LogRaw(
			$(document.createElement('div')).text(message)
		);
	},

	_LogRaw: function (message) {
		if (!this._$log) {
			this._$log = this._GetLog();
		}
		this._$log.append(message);
	},


	/*########
	## Public methods
	########*/
	/**
	 * Execute the update script.
	 * @param $ {jQuery} The jQuery instance used for AJAX and DOM manipulation.
	 */
	Execute: function ($) {
		var _this = this;
		_this._LogRaw('Fetching details from <a href="' + this._url + '" title="Bot policy/Implementation">the implementation table</a>...');

		$.ajax({
			url: this._url,
			error: function (xhr, status, error) {
				_this._Log('Could not retrieve implementation page: ' + status + ': ' + error);
			},
			success: function (data) {
				data = $(data);

				/* extract implementation details */
				var aa = [];
				var gb = [];
				var aagb = [];
				var wikiset = [];
				data.find('.is-wiki-row').each(function (i, item) {
					item = $(item);
					var subdomain = item.find('.is-data-subdomain').first().text();
					var domain = item.find('.is-data-domain').first().text();
					var allowsApproval = item.hasClass('is-aa-1');
					var allowsGlobal = item.hasClass('is-gb-1');

					/* save the wikiset ID (eg, "enwiki") */
					if (allowsGlobal) {
						var wikisetID = subdomain.replace(/-/g, '_');
						switch (domain) {
							case 'meta':
								wikisetID = 'metawiki';
								break;

							case 'wikipedia':
								wikisetID += 'wiki';
								break;

							default:
								wikisetID += domain;
						}
						wikiset.push(wikisetID);
					}

					/* save the template ID (eg, "en.wikipedia") */
					var templateID = subdomain + '.' + domain;
					if (templateID == '.meta') {
						templateID = 'meta.wikimedia';
					}

					if (allowsApproval && allowsGlobal) {
						aagb.push(templateID);
					}
					else if (allowsApproval) {
						aa.push(templateID);
					}
					else if (allowsGlobal) {
						gb.push(templateID);
					}
					else {
						_this._Log('Cannot determine implementation status for wiki "' + templateID + '".');
					}
				});
				aa.sort();
				gb.sort();
				aagb.sort();
				wikiset.sort();

				/* output template */
				_this._LogRaw('Done! I suggest the following code. If this looks fine, just replace the {{#switch}} statement in <a href="//meta.wikimedia.org/wiki/Template:Bot_policy" title="Template:Bot policy">the template text</a> with this one.');
				_this._LogRaw(
					$(document.createElement('pre'))
						.css({ 'height': '20em', 'overflow': 'auto' })
						.text(
							'{{#switch:{{{1}}}\n'
							+ '<!-- automatic-approval *and* global bot wikis -->\n'
							+ ' |' + aagb.join('\n |') + ' = aa,gb\n\n'
							+ '<!-- automatic-approval only wikis -->\n'
							+ ' |' + aa.join('\n |') + ' = aaa\n\n'
							+ '<!-- global bot only wikis -->\n'
							+ ' |' + gb.join('\n |') + ' = gb\n'
							+ '}}'
						)
				);

				/* output wikiset */
				_this._LogRaw('<div>I suggest these wikis for the wikiset. If this look fine, just replace the list on <a href="//meta.wikimedia.org/wiki/Special:Wikisets/2" title="Edit global bot list">Special:EditWikiset/2</a>. (You might also want to <a href="https://quickdiff.net/" title="Quick Diff Online Tool">compare the differences</a> in case a wiki wasn\'t added to the table.)</div>');
				_this._LogRaw(
					$(document.createElement('pre'))
						.css({ 'height': '20em', 'overflow': 'auto' })
						.text(wikiset.join('\n'))
				);
			}
		});
	}
};

pathoschild.UpdateBotPolicyTemplate.Execute(jQuery);