From Wikipedia, the free encyclopedia
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.

'edit', 'submit'].includes(mw.config.get('wgAction')) &&

$.when(

	$.ajax(

		'//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js',

		{ dataType: 'script', cache: true }

	),

	mw.loader.using(['mediawiki.api', 'mediawiki.Title'])

).then(function unpipe() {

	let replace = data => {

		Object.entries(data.tokens).forEach(([source, ts]) => {

			if (!ts.some(t => data.redirst.pn])) return;

			let links = ts.map(t => {

				let r = data.redirst.pn || {};

				return r.to || t.pn, t.fragment || r.tofragment].join('#');

			});

			if (links0 !== links1]) return;

			data.repl = data.repl.split(source).join(source.replace(/^[^|]+\|/, '[['));

		});

		if (data.repl === data.orig) {

			mw.notify('No change.');

			return;

		}

		data.editor

			.set(data.repl)

			.appendEditSummary('unpiped links using [[User:Nardog/Unpipe|script]]')

			.options({ minor: true })

			.clickDiff();

	};

	let query = (titles, data) => {

		if (!titles.length) {

			replace(data);

			return;

		}

		new mw.Api().post({

			action: 'query',

			titles: titles.slice(0, 50),

			redirects: 1,

			formatversion: 2

		}).then(response => {

			(response.query.redirects || []).forEach(r => {

				data.redirsr.from = r;

			});

			query(titles.slice(50), data);

		});

	};

	window.pathoschild.TemplateScript.add([{

		name: 'Unpipe links',

		script: editor => {

			let orig = editor.get(), repl = orig, tokens = {};

			let titles = new Set();

			let match, re = /\[\[([^|\]]+)\|([^\]]+)\]\]/g;

			while ((match = re.exec(orig))) {

				if (tokensmatch0]]) continue;

				let ts = match.slice(1).map(s => mw.Title.newFromText(s));

				if (ts.some(t => !t || t.namespace)) continue;

				let pns = ts.map(t => t.toText());

				if (pns0].endsWith(' (disambiguation)')) continue;

				if (pns0 === pns1 && ts0].fragment === ts1].fragment) {

					repl = repl.split(match0]).join(`[[${match2}]]`);

					continue;

				}

				tokensmatch0]] = pns.map((pn, i) => {

					titles.add(pn);

					return { pn, fragment: tsi].fragment };

				});

			}

			query([...titles], { editor, orig, repl, tokens, redirs: {} });

		}

	}]);

});
From Wikipedia, the free encyclopedia
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.

'edit', 'submit'].includes(mw.config.get('wgAction')) &&

$.when(

	$.ajax(

		'//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js',

		{ dataType: 'script', cache: true }

	),

	mw.loader.using(['mediawiki.api', 'mediawiki.Title'])

).then(function unpipe() {

	let replace = data => {

		Object.entries(data.tokens).forEach(([source, ts]) => {

			if (!ts.some(t => data.redirst.pn])) return;

			let links = ts.map(t => {

				let r = data.redirst.pn || {};

				return r.to || t.pn, t.fragment || r.tofragment].join('#');

			});

			if (links0 !== links1]) return;

			data.repl = data.repl.split(source).join(source.replace(/^[^|]+\|/, '[['));

		});

		if (data.repl === data.orig) {

			mw.notify('No change.');

			return;

		}

		data.editor

			.set(data.repl)

			.appendEditSummary('unpiped links using [[User:Nardog/Unpipe|script]]')

			.options({ minor: true })

			.clickDiff();

	};

	let query = (titles, data) => {

		if (!titles.length) {

			replace(data);

			return;

		}

		new mw.Api().post({

			action: 'query',

			titles: titles.slice(0, 50),

			redirects: 1,

			formatversion: 2

		}).then(response => {

			(response.query.redirects || []).forEach(r => {

				data.redirsr.from = r;

			});

			query(titles.slice(50), data);

		});

	};

	window.pathoschild.TemplateScript.add([{

		name: 'Unpipe links',

		script: editor => {

			let orig = editor.get(), repl = orig, tokens = {};

			let titles = new Set();

			let match, re = /\[\[([^|\]]+)\|([^\]]+)\]\]/g;

			while ((match = re.exec(orig))) {

				if (tokensmatch0]]) continue;

				let ts = match.slice(1).map(s => mw.Title.newFromText(s));

				if (ts.some(t => !t || t.namespace)) continue;

				let pns = ts.map(t => t.toText());

				if (pns0].endsWith(' (disambiguation)')) continue;

				if (pns0 === pns1 && ts0].fragment === ts1].fragment) {

					repl = repl.split(match0]).join(`[[${match2}]]`);

					continue;

				}

				tokensmatch0]] = pns.map((pn, i) => {

					titles.add(pn);

					return { pn, fragment: tsi].fragment };

				});

			}

			query([...titles], { editor, orig, repl, tokens, redirs: {} });

		}

	}]);

});

Videos

Youtube | Vimeo | Bing

Websites

Google | Yahoo | Bing

Encyclopedia

Google | Yahoo | Bing

Facebook