MediaWiki:Gadget-autotags.js
Jump to navigation
Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes.
- Internet Explorer: hold down the Ctrl key and click the Refresh or Reload button, or press Ctrl+F5.
- Firefox: hold down the Shift key while clicking Reload; alternatively press Ctrl+F5 or Ctrl-Shift-R.
- Opera, Konqueror and Safari users can just click the Reload button.
- Chrome: press Ctrl+F5 or Shift+F5
/**
* autotags: Allows automatic tagging of pages (e.g. for improvement/deletion)
* with one click. Similar to some parts of Twinkle.
* Works best on Vector (links are inside a dropdown), Cologne Blue and Timeless
* (links in the sidebar). On Monobook the links stretch way off to the right,
* and on Modern they're cut off. Doesn't work at all on Minerva/mobile.
*
* Depends on Sparkle ([[MediaWiki:Gadget-sparkle.js]]).
*/
// <nowiki> Kept here to prevent tilde sequences from expanding
// Create empty "tags" object, which we will add various items to
tags = {};
// Suffix for identifying gadget
tags.suffix = " ([[MediaWiki:Gadget-autotags.js|autotags]])";
// Portlet to use with Sparkle functions
switch (mw.config.get('skin')) {
case 'vector':
tags.portletArea = 'right-navigation';
tags.portletId = 'p-tags';
tags.portletName = 'Tags';
tags.portletType = 'menu';
tags.portletNext = 'p-search';
break;
case 'timeless':
tags.portletArea = '#page-tools .sidebar-inner';
tags.portletId = 'p-tags';
tags.portletName = 'Tags';
tags.portletType = null;
tags.portletNext = 'p-userpagetools';
break;
default:
tags.portletArea = null;
tags.portletId = 'p-cactions';
tags.portletName = null;
tags.portletType = null;
tags.portletNext = null;
}
// Create lists of tags and add links to the top of the page
tags.addtag = function() {
if( !(document.getElementById( 'ca-history' )
&& document.getElementById( 'ca-edit' ))) {
return;
}
// Add a dropdown to the right navigation, between "More" and "Search"
Sparkle.addPortlet(tags.portletArea, tags.portletId, tags.portletName, tags.portletType, tags.portletNext);
// Create lists of tags and add them to the new dropdown
if (mw.config.get("wgCanonicalNamespace") == "Project") {
Sparkle.addPortletLink(tags.portletId, tags.go, "Tag", "ca-tag",
'Add a custom template or text to the top of this page', 'tag');
if (mw.config.get("wgPageName") == "Uncyclopedia:Ban_Patrol"
&& document.getElementById( 'ca-delete' )) {
var tagBox = [];
tagBox[0] = [tags.go, 'BPC', '',
'Mark Ban Patrol as checked', 'bpc'];
tagBox[1] = [vfd.go, 'VFD', '', 'Nominate this page for deletion'];
tagBox[2] = [tags.go, 'Other', '',
'Add a custom template or text to the bottom of this page', 'other'];
} else if (mw.config.get("wgPageName") == "Uncyclopedia:QuickVFD"
&& document.getElementById( 'ca-delete' )) {
var tagBox = [];
tagBox[0] = [tags.go, 'QVFDc', '',
'Mark QVFD as checked (only do this if it needs to be marked', 'qvfdc'];
tagBox[1] = [vfd.go, 'VFD', '', 'Nominate this page for deletion'];
tagBox[2] = [tags.go, 'Other', '',
'Add a custom template or text to the bottom of this page', 'other'];
}
else {
var tagBox = [];
tagBox[0] = [vfd.go, 'VFD', '', 'Nominate this page for deletion'];
tagBox[1] = [tags.go, 'Other', '',
'Add a custom template or text to the bottom of this page', 'other'];
}
Sparkle.addPortletLinks(tags.portletId, tagBox);
}
else if (mw.config.get("wgCanonicalNamespace") == "UnNews") {
Sparkle.addPortletLink(tags.portletId, tags.go, 'Tag',
'ca-tag', 'Add a custom template or text to the top of this page', 'tag');
var tagBox = [];
tagBox[0] = [tags.go, 'Original', '',
'Add the \'Original Newscasting\' template to this page', 'original'];
tagBox[1] = [tags.go, 'News header', '',
'Add the UnNews and date templates to this page', 'news'];
tagBox[2] = [vfd.go, 'VFD', '', 'Nominate this page for deletion'];
tagBox[3] = [tags.go, 'Other', '',
'Add a custom template or text to the bottom of this page', 'other'];
Sparkle.addPortletLinks(tags.portletId, tagBox);
}
else if (mw.config.get("wgCanonicalNamespace") === ""
|| mw.config.get("wgCanonicalNamespace") === "UnTunes"
|| mw.config.get("wgCanonicalNamespace") === "HowTo"
|| mw.config.get("wgCanonicalNamespace") === "Why?"
|| mw.config.get("wgCanonicalNamespace") === "UnBooks"
|| mw.config.get("wgCanonicalNamespace") === "UnScripts"
|| mw.config.get("wgCanonicalNamespace") === "UnPoetia"
|| mw.config.get("wgCanonicalNamespace") === "Unquotable"
|| mw.config.get("wgCanonicalNamespace") === "UnDebate"
|| mw.config.get("wgCanonicalNamespace") === "UnReviews"
|| mw.config.get("wgCanonicalNamespace") === "Uncycloversity") {
var tagBox = [];
var icuBox = [];
var fixBox = [];
var formatBox = [];
var writingBox = [];
var unfunnyBox = [];
var mergeBox = [];
icuBox[0] = [tags.go, 'ICU', '',
'Add an ICU with a custom fix message', 'icu', 0];
icuBox[1] = [tags.go, 'Not funny', '',
'Add an ICU: \'This page seems to be lacking in humor or satire.\'', 'icu', 'notfunny'];
icuBox[2] = [tags.go, 'Random', '',
'Add an ICU: \'Truth is funnier than outright Lies or Plain Nonsense.\'', 'icu', 'random'];
icuBox[3] = [tags.go, 'Encyclopedic',
'', 'Add an ICU: \'Uncyclopedia is a parody of a Wikipedia-style Encyclopedia '
+ 'and should be written accordingly.\'', 'icu', 'encyclopedic'];
icuBox[4] = [tags.go, 'Format', '',
'Add an ICU: \'This page needs some formatting help.\'', 'icu', 'format'];
icuBox[5] = [tags.go, 'Short', '',
'Add an ICU: \'This page needs some content!\'', 'icu', 'short'];
icuBox[6] = [tags.go, 'List', '',
'Add an ICU: \'This List needs some content!\'', 'icu', 'list'];
icuBox[7] = [tags.go, 'Original', '',
'Add an ICU: \'This article appears to have no redeeming value and is '
+ 'hence a candidate for speedy deletion.\' Only use this one if someone '
+ 'has already removed an ICU without permission.', 'icu', 'original'];
Sparkle.addPortletLinks(tags.portletId, icuBox);
fixBox[0] = [tags.go, 'Fix', '',
'Tag this article as needing to be fixed - default use', 'fix', 0];
fixBox[1] = [tags.go, 'Vanity', '',
'Add a fix tag: This appears to be vanity.', 'fix', 'vanity'];
fixBox[2] = [tags.go, 'Qua?', '',
'Add a fix tag: This text does not appear to be entirely English.', 'fix', 'qua?'];
fixBox[3] = [tags.go, 'Multiple issues', '',
'Add a fix tag: This article has multiple issues.', 'fix', 1];
Sparkle.addPortletLinks(tags.portletId, fixBox);
formatBox[0] = [tags.go, 'Format', '',
'Add a fix tag: This article needs formatting help.', 'fix', 'format'];
formatBox[1] = [tags.go, 'Listiness', '',
'Add a fix tag: This article has too much listiness.', 'fix', 'list'];
formatBox[2] = [tags.go, 'Red links', '',
'Add a fix tag: This article is full of links that don\'t go anywhere.', 'fix', 'redlink'];
formatBox[3] = [tags.go, 'Blue links', '',
'Add a fix tag: This article has too many blue links.', 'fix', 'bluelink'];
formatBox[4] = [tags.go, 'No links', '',
'Add a fix tag: This article is a Dead End.', 'fix', 'deadend'];
formatBox[5] = [tags.go, 'Excess images', '',
'Add a fix tag: This article has too many images.', 'fix', 'images'];
Sparkle.addPortletLinks(tags.portletId, formatBox);
writingBox[0] = [tags.go, 'Bad writing', '',
'Add a fix tag: This is just plain bad writing.', 'fix', 'badwriting'];
writingBox[1] = [tags.go, 'Proofread', '',
'Add a fix tag: This article needs a proofreading.', 'fix', 'proofread'];
writingBox[2] = [tags.go, 'Too long', '',
'Add a fix tag: This article is quite drawn-out in spots.', 'fix', 'long'];
writingBox[3] = [tags.go, 'Unencyclopedic', '',
'Add a fix tag: This article does not resemble an encyclopedia entry.', 'fix', 'unencyclopedic'];
Sparkle.addPortletLinks(tags.portletId, writingBox);
unfunnyBox[0] = [tags.go, 'Not funny', '',
'Add a fix tag: This article just isn\'t funny.', 'fix', 'notfunny'];
unfunnyBox[1] = [tags.go, 'Random', '',
'Add a fix tag: This article is terribly random.', 'fix', 'random'];
unfunnyBox[2] = [tags.go, 'No concept',
'', 'Add a fix tag: This article appears to lack a unifying concept or idea.', 'fix', 'noconcept'];
unfunnyBox[3] = [tags.go, 'Stupid', '',
'Add a fix tag: This article relies heavily on stupid humor.', 'fix', 'stupid'];
Sparkle.addPortletLinks(tags.portletId, unfunnyBox);
mergeBox[0] = [tags.go, 'Merge', '',
'Mark this to be merged into another article', 'merge'];
mergeBox[1] = [tags.go, 'Mergeinto', '',
'Mark this article to have content from another merged into it', 'mergeinto'];
Sparkle.addPortletLinks(tags.portletId, mergeBox);
Sparkle.addPortletLink(tags.portletId, tags.go, 'Tag',
'ca-tag', 'Add a custom template or text to the top of this page', 'tag');
tagBox[0] = [tags.go, 'Expand', '',
'Tag this article for expansion', 'expansion'];
tagBox[1] = [tags.go, 'AAP', '',
'Mark this article as a candidate for receiving some pictures', 'aap'];
tagBox[2] = [vfd.go, 'VFD', '',
'Nominate this page for deletion'];
tagBox[3] = [tags.go, 'Other', '',
'Add a custom template or text to the bottom of this page', 'other'];
Sparkle.addPortletLinks(tags.portletId, tagBox);
}
else if (mw.config.get("wgCanonicalNamespace") == "Category") {
var tagBox = [];
Sparkle.addPortletLink(tags.portletId, tags.go, 'Tag',
'ca-tag', 'Add a custom template or text to the top of this page', 'tag');
tagBox[0] = [tags.go, 'CatBrowser', '',
'Add a CatBrowser to this category page', 'catbrowser'];
tagBox[1] = [tags.go, 'Diffuse', '',
'Mark this category as having too many subpages', 'diffuse'];
tagBox[2] = [vfd.go, 'VFD', '', 'Nominate this page for deletion'];
tagBox[3] = [tags.go, 'Other', '',
'Add a custom template or text to the bottom of this page', 'other'];
Sparkle.addPortletLinks(tags.portletId, tagBox);
}
else if ( mw.config.get("wgCanonicalNamespace") == "Template"
|| mw.config.get("wgCanonicalNamespace") == "Game" ) {
var tagBox = [];
Sparkle.addPortletLink(tags.portletId, tags.go, 'Tag',
'ca-tag', 'Add a custom template or text to the top of this page', 'tag');
tagBox[0] = [tags.go, 'Other', '',
'Add a custom template or text to the bottom of this page', 'other'];
tagBox[1] = [vfd.go, 'VFD', '', 'Nominate this page for deletion'];
Sparkle.addPortletLinks(tags.portletId, tagBox);
}
else if (mw.config.get("wgNamespaceNumber") > 0) {
var tagBox = [];
Sparkle.addPortletLink(tags.portletId, tags.go, 'Tag',
'ca-tag', 'Add a custom template or text to the top of this page', 'tag');
tagBox[0] = [tags.go, 'Other', '',
'Add a custom template or text to the bottom of this page', 'other'];
Sparkle.addPortletLinks(tags.portletId, tagBox);
}
};
// Add tag text to the page
tags.go = function(type, moo) {
if (type == 'aap') {
tags.tag = '{{AAP}}';
} else if (type == 'bpc') {
tags.tag = '{{BPC|' + mw.config.get("wgUserName") + '}}';
} else if (type == 'catbrowser') {
tags.tag = '{{CatBrowser}}';
} else if (type == 'diffuse') {
tags.tag = '{{Category diffuse}}';
} else if ( type == 'fix' ) {
if (moo == 0) {
tags.tag = '{{fix}}';
} else if (moo == 1) {
tags.tag = '{{fix|' + prompt( 'Fix tags (separated by \'|\'):', '' ) + '}}';
if ( tags.tag == '{{fix|}}' || tags.tag == '{{fix|}}' ) {
return;
}
} else {
tags.tag = '{{fix|' + moo + '}}';
}
} else if ( type == 'icu' ) {
if (moo == 0) {
tags.tag = '{{ICU|~~~~~|fix=' + prompt( 'ICU fix comment:', '' ) + '}}';
if (tags.tag == '{{ICU|~~~~~|fix=null}}' || tags.tag == '{{ICU|~~~~~|fix=}}' ) {
return;
}
} else {
tags.tag = '{{ICU|~~~~~|sub=' + moo + '}}';
}
} else if ( type == 'merge' || type == 'mergeinto' ) {
if ( type == 'merge' ) {
tags.other = prompt( 'Article to merge into:', '' );
} else {
tags.other = prompt( 'Article to merge into this:', '' );
}
if ( tags.other == 'null' || tags.other == '' ) {
return;
}
tags.tag = '{{' + type + '|' + tags.other + '}}';
} else if (type == 'news'){
tags.tag = prompt( 'Date:', '' );
if ( tags.tag == null || tags.tag == '' ) {
tags.tag = '{{news|{{subst:CURRENTDAY}} {{subst:CURRENTMONTHNAME}} '
+ '{{subst:CURRENTYEAR}}}}\n{{date|{{subst:CURRENTDAY}} '
+ '{{subst:CURRENTMONTHNAME}} {{subst:CURRENTYEAR}}}}';
} else {
tags.tag = '{{news|' + tags.tag + '}}\n{{date|' + tags.tag + '}}';
}
} else if (type == 'other'){
tags.tag = prompt( 'Text or tag to append to page:', '' );
if ( tags.tag == null || tags.tag == '' ) {
return;
}
} else if (type == 'qvfdc'){
tags.tag = '{{QVFD checked}} ';
} else if (type == 'tag'){
tags.tag = prompt( 'Text or tag to prepend to page:', '' );
if ( tags.tag == null || tags.tag == '' ) {
return;
}
} else {
tags.tag = '{{' + type + '}}';
}
if (type == 'merge' || type == 'mergeinto') {
tags.type = 'merge';
} else {
tags.type = type;
}
tags.page = mw.config.get("wgPageName").replace(/_/g,' ');
mw.notify("tagging, please wait...");
mw.notify("Loading page...");
var api = new mw.Api();
api.get({
action: 'query',
indexpageids: 1,
titles: mw.config.get("wgPageName"),
prop: 'revisions|info|links',
pllimit: 500,
rvprop: 'content',
rvlimit: 1,
rvsection: 0,
rvslots: "main"
}).done(function(o) {
mw.notify("Adding tag...");
try {
var id = o.query.pageids[0];
var sectionText = o.query.pages[id].revisions[0].slots.main["*"];
if (tags.type == 'bpc' || tags.type == 'qvfdc') {
var lines = sectionText.split( '\n' );
lines.splice( 1, 0, tags.tag );
sectionText = lines.join( '\n' );
} else if (mw.config.get("wgCanonicalNamespace") == 'Template') {
if (tags.type == 'other') {
sectionText = sectionText + '<noinclude>\n' + tags.tag + '\n</noinclude>';
} else {
sectionText = '<noinclude>' + tags.tag + '\n</noinclude>' + sectionText;
}
}
else {
if (tags.type == "icu" || tags.type == "original" ) {
sectionText = sectionText + '\n\n' + tags.tag;
} else if (tags.type == 'other') {
sectionText = sectionText + '\n' + tags.tag;
} else {
sectionText = tags.tag + '\n' + sectionText;
}
}
} catch(e) {
mw.notify("Could not add text to the page.");
return;
}
mw.notify("Saving page...");
// Edit summaries
if (tags.type == 'icu') {
tags.type = '+ICU: This new page should be improved '
+ 'or it will become a candidate for deletion in seven days.';
} else if (tags.type == 'fix') {
tags.type = '+Fix: This page may need one or '
+ 'more assorted fixes.';
} else if (tags.type == 'expansion') {
tags.type = '+Expansion: This short page '
+ 'should be expanded into a full article.';
} else if (tags.type == 'aap') {
tags.type = '+AAP: This page needs some images.';
} else if (tags.type == 'catbrowser') {
tags.type = '+CatBrowser';
} else if (tags.type == 'original') {
tags.type = '+Original content notice';
} else if (tags.type == 'news') {
tags.type = '+Presumably proper news header';
} else if (tags.type == 'bpc') {
tags.type = 'BPC';
} else if (tags.type == 'qvfdc') {
tags.type = 'QVFDc';
} else if (tags.type == 'diffuse') {
tags.type = '+Diffuse: Pages in this category '
+ 'should be moved to subcategories';
} else if (tags.type == 'merge') {
tags.type = '+Merge: This page should be merged '
+ 'with [[' + tags.other + ']].';
} else if (tags.type == 'other' || tags.type == 'tag') {
tags.type = 'Vigilance.';
}
var api = new mw.Api();
api.post({
action: "edit",
section: 0,
summary: tags.type + tags.suffix,
text: unescape(sectionText),
title: mw.config.get("wgPageName"),
token: mw.user.tokens.get("csrfToken")
}).done(function(o) {
try {
result = (o.edit.result == 'Success') ? 1 : 0;
} catch(e) {
result = 0;
}
if (result) {
mw.notify("Saved!");
if (mw.config.get("wgIsArticle")) {
window.location = '/wiki/' + mw.config.get("wgPageName");
}
} else {
mw.notify( $( "Error: "
+ getAttribute('code') + ' - ' + getAttribute('info')
+ "<br /><a href=\"/wiki/" + mw.config.get("wgPageName")
+ "?action=edit\">Add manually</a>" ), { title: "Saving failed :(" } );
}
}).fail(function(o) {
mw.notify("Connection failed.");
});
}).fail(function() {
mw.notify("Couldn\'t connect to page.");
});
};
// Add VFD tag to a page and add it to Votes for Deletion
/* This should really be merged into the above, but ugh, do I ever not want to. */
vfd = {};
vfd.go = function() {
vfd.comment = prompt( 'Reason:', '' );
if ( vfd.comment == null ) {
return;
}
vfd.page = mw.config.get("wgPageName").replace(/_/g,' ');
mw.notify("VFDing, please wait...");
vfd.output = '';
mw.notify("Loading VFD page...");
var api = new mw.Api();
api.get({
action: "query",
indexpageids: 1,
titles: "Uncyclopedia:Votes_for_deletion",
prop: "revisions|info|links",
pllimit: 500,
rvprop: "content",
rvlimit: 1,
rvslots: "main"
}).done(function(o) {
mw.notify("Checking VFD for selected page...");
var id = o.query.pageids[0];
var titles = o.query.pages[id].links;
for (var lk in titles) {
try {
if (titles[lk].getAttribute('title') == vfd.page) {
mw.notify("Page already on VFD!");
return;
}
} catch(e) {};
}
try {
var sectionText = '{{VFDt|'
+ 'time=~~~~~\n|delnumber=1\n|delete=\n#' + vfd.comment + ' ~~~\n|'
+ 'keepnumber=0\n|keep=\n|comments=\n}}\n\n';
} catch(e) {
mw.notify("Could not add text to the page!");
return;
}
mw.notify("Saving page...");
var api = new mw.Api();
api.post({
action: "edit",
title: "Uncyclopedia:Votes_for_deletion",
section: "new",
sectiontitle: '{{VFDn|' + vfd.page +'}}',
token: mw.user.tokens.get("csrfToken"),
summary: '+[[' + vfd.page + ']]' + tags.suffix,
text: unescape(sectionText)
}).done(function(o) {
try {
result = (o.edit.result == 'Success') ? 1 : 0;
} catch(e) {
result = 0;
}
if (result) {
mw.notify("Saved!");
var api = new mw.Api();
api.get({
action: "query",
indexpageids: 1,
pllimit: 500,
prop: "revisions|info|links",
rvprop: "content",
rvlimit: 1,
rvsection: 0,
rvslots: "main",
titles: mw.config.get("wgPageName")
}).done(function(o) {
mw.notify("Adding tag...");
try {
var id = o.query.pageids[0];
var sectionText = o.query.pages[id].revisions[0].slots.main["*"];
if (mw.config.get("wgCanonicalNamespace") == 'Template') {
sectionText = '<noinclude>{{VFD}}\n</noinclude>' + sectionText;
} else {
sectionText = '{{VFD}}\n' + sectionText;
}
} catch(e) {
mw.notify("Could not add text to the page.");
return;
}
mw.notify("Saving page...");
var api = new mw.Api();
api.post({
action: "edit",
section: 0,
summary: "+VFD" + tags.suffix,
text: unescape(sectionText),
title: mw.config.get("wgPageName"),
token: mw.user.tokens.get("csrfToken")
}).done(function(o) {
try {
result = (o.edit.result == 'Success') ? 1 : 0;
} catch(e) {
result = 0;
}
if (result) {
mw.notify( $( "<a href=\"/wiki/Uncyclopedia:"
+ "Votes_for_deletion\">Go to VFD</a> or <br />"
+ "<a href=\"#\">close</a>" ), { title: "Saved!" } );
if (mw.config.get("wgIsArticle")) {
window.location = "/wiki/" + mw.config.get("wgPageName");
}
} else {
mw.notify( $( "Error: "
+ getAttribute('code') + ' - ' + getAttribute('info')
+ '<br /><a href="' + "/wiki/" + mw.config.get("wgPageName")
+ '?action=edit">Add manually</a> '
+ 'or <br /><a href="#">close</a>' ), { title: "Saving failed :(" } );
}
}).fail(function(o) {
mw.notify("Connection failed.");
});
}).fail(function() {
mw.notify("Couldn\'t connect to page.");
});
} else {
mw.notify( $( "Error: "
+ getAttribute('code') + ' - ' + getAttribute('info')
+ '<br /><a href="/wiki/Uncyclopedia:Votes_for_deletion">Add manually</a> '
+ 'or <br /><a href="#">close</a>' ), { title: "Saving failed :(" } );
}
}).fail(function(o) {
mw.notify( $( '<a href="/wiki/'
+ 'Uncyclopedia:Votes_for_deletion">Go to VFD</a> or <br />'
+ '<a href="#">close</a>' ), { title: "Connection failed :(" } );
});
}).fail(function() {
mw.notify("Couldn\'t connect to VFD page!");
});
};
$(tags.addtag);
// </nowiki>