-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpagemods.js
360 lines (295 loc) · 14.5 KB
/
pagemods.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
// Overflow of most of the functions here inspired by [[User:Equazcion/CatListMainTalkLinks.js]]
// Quick delete and cleanup functions
$(function () {
if ((mw.util.getParamValue('geight') === 'yes') || (mw.util.getParamValue('gthirteen') === 'yes')) {
var gSumm;
var gName;
var gWhich;
if (mw.util.getParamValue('geight') === 'yes') {
gSumm = '[[WP:CSD#G8|G8]]: Dependent on a nonexistant page';
gName = 'G8';
gWhich = 'geight';
} else if (mw.util.getParamValue('gthirteen') === 'yes') {
gSumm = '[[WP:CSD#G13|G13]]: Abandoned [[WP:AFC|Article for creation]] — to retrieve it, see [[WP:REFUND/G13]]';
gName = 'G13';
gWhich = 'gthirteen';
}
if (mw.config.get('wgAction') === 'delete') {
var wpReason = $('#wpReason > input');
wpReason.attr('value', gSumm);
document.getElementById('deleteconfirm').submit();
} else if (mw.config.get('wgAction') === 'view') {
mw.util.addPortletLink('p-cactions', '//en.wikipedia.org/wiki/' + mw.config.get('wgPageName') + '?action=delete&' + gWhich + '=yes', gName, gName, 'Delete under CSD ' + gName);
}
} else if (mw.util.getParamValue('magicword') === 'yes' && mw.config.get('wgAction') === 'edit') {
var txt = document.editform.wpTextbox1;
txt.value = txt.value.replace(/{{basepagename[:|]/gi, '{{BASEPAGENAME:');
txt.value = txt.value.replace(/{{defaultsort[:|]/gi, '{{DEFAULTSORT:');
txt.value = txt.value.replace(/{{display ?title[:|]/gi, '{{DISPLAYTITLE:');
txt.value = txt.value.replace(/{{fullpagename[:|]/gi, '{{FULLPAGENAME:');
txt.value = txt.value.replace(/{{namespace[:|]/gi, '{{NAMESPACE:');
txt.value = txt.value.replace(/{{numberofarticles[:|]/gi, '{{NUMBEROFARTICLES:');
txt.value = txt.value.replace(/{{padleft[:|]/gi, '{{PADLEFT:');
txt.value = txt.value.replace(/{{pagename[:|]/gi, '{{PAGENAME:');
txt.value = txt.value.replace(/{{protectionlevel[:|]/gi, '{{PROTECTIONLEVEL:');
txt.value = txt.value.replace(/{{pagesize[:|]/gi, '{{PAGESIZE:');
txt.value = txt.value.replace(/{{shortdesc[:|]/gi, '{{SHORTDESC:');
txt.value = txt.value.replace(/{{subpagename[:|]/gi, '{{SUBPAGENAME:');
document.editform.wpSummary.value = 'Use magic word in place of template';
document.getElementById('wpMinoredit').checked = true;
document.getElementById('wpWatchthis').checked = false;
document.getElementById('wpDiff').click();
} else if (mw.util.getParamValue('copyrev') === 'yes' && mw.config.get('wgAction') === 'edit') {
var ctxt = document.editform.wpTextbox1;
ctxt.value = ctxt.value.replace(/\{\{(copy(vio|right)-)?(revdel|histpurge)(-copyvio)?(\n?\|.*)*\n?}}\n?/i, '');
document.editform.wpSummary.value = 'Revision delete done, removing copyvio template';
document.getElementById('wpMinoredit').checked = false;
document.getElementById('wpWatchthis').checked = true;
}
});
// Page-specific functions
// Make clearing [[Wikipedia:Database reports/Orphaned talk pages]] easier
if (mw.config.get('wgPageName') === 'Wikipedia:Database_reports/Orphaned_talk_pages') {
// Grab page list elements
var orPages = $('.wikitable a');
$.each(orPages, function(k, page) { // Iterate through list elements; each step below runs on each list element
// Work with the link within each list element from now on
page = $(page);
// Clone the link
var pageClone = page.clone(true);
// Fix for redirects
if (pageClone.attr('class') === 'external text') {
pageClone.attr('href', pageClone.attr('href').replace(/.*=(.*_?)([Tt]alk)(.*)&redirect=no/gi, '/wiki/$1$2$3'));
pageClone.attr('title', pageClone.attr('href').replace(/\/wiki\//gi, ''));
}
// Save talk title
var talkTitle = pageClone.attr('title');
// talkTitle = encodeURIComponent(talkTitle);
// Set main page link text
pageClone.text('main');
// Do a dumb replace of the original URL and tooltip
pageClone.attr('title', pageClone.attr('title').replace('Talk:', ''));
pageClone.attr('title', pageClone.attr('title').replace('Wikipedia talk:', 'Wikipedia:'));
pageClone.attr('title', pageClone.attr('title').replace('User talk:', 'User:'));
pageClone.attr('title', pageClone.attr('title').replace('Template talk:', 'Template:'));
pageClone.attr('title', pageClone.attr('title').replace('Portal talk:', 'Portal:'));
pageClone.attr('title', pageClone.attr('title').replace('Category talk:', 'Category:'));
pageClone.attr('title', pageClone.attr('title').replace('MediaWiki talk:', 'MediaWiki:'));
pageClone.attr('title', pageClone.attr('title').replace('Help talk:', 'Help:'));
pageClone.attr('title', pageClone.attr('title').replace('Book talk:', 'Book:'));
pageClone.attr('title', pageClone.attr('title').replace('Draft talk:', 'Draft:'));
pageClone.attr('title', pageClone.attr('title').replace('Module talk:', 'Module:'));
pageClone.attr('title', pageClone.attr('title').replace('TimedText talk:', 'TimedText:'));
pageClone.attr('title', pageClone.attr('title').replace('Education Program talk:', 'Education Program:'));
pageClone.attr('href', pageClone.attr('href').replace('Talk:', ''));
pageClone.attr('href', pageClone.attr('href').replace('Wikipedia_talk:', 'Wikipedia:'));
pageClone.attr('href', pageClone.attr('href').replace('User_talk:', 'User:'));
pageClone.attr('href', pageClone.attr('href').replace('Template_talk:', 'Template:'));
pageClone.attr('href', pageClone.attr('href').replace('Portal_talk:', 'Portal:'));
pageClone.attr('href', pageClone.attr('href').replace('Category_talk:', 'Category:'));
pageClone.attr('href', pageClone.attr('href').replace('MediaWiki_talk:', 'MediaWiki:'));
pageClone.attr('href', pageClone.attr('href').replace('Help_talk:', 'Help:'));
pageClone.attr('href', pageClone.attr('href').replace('Book_talk:', 'Book:'));
pageClone.attr('href', pageClone.attr('href').replace('Draft_talk:', 'Draft:'));
pageClone.attr('href', pageClone.attr('href').replace('Module_talk:', 'Module:'));
pageClone.attr('href', pageClone.attr('href').replace('TimedText_talk:', 'TimedText:'));
pageClone.attr('href', pageClone.attr('href').replace('Education_Program_talk:', 'Education_Program:'));
// Remove database report link
pageClone.attr('href', pageClone.attr('href').replace(' (page does not exist)', ''));
pageClone.attr('title', pageClone.attr('title').replace(' (page does not exist)', ''));
// Link is done, just need to check if the target exists so we can turn it red if not.
// Grab link tooltip (as it now conveniently contains the page title alone, which we need for the Ajax query)
var cloneTitle = pageClone.attr('title');
cloneTitle = encodeURIComponent(cloneTitle);
// Perform Ajax query (using jQuery's awesomely-simple Ajax function) to get target's "title" data from MediaWiki API
$.ajax({
url: mw.util.wikiScript('api') + '?action=query&titles=' + cloneTitle + '&format=xml',
dataType: 'xml',
type: 'GET',
success: parseIt
});
var logLink = $(pageClone).clone(true);
logLink.text('log');
logLink.attr('class', 'external text');
logLink.attr('href', '/w/index.php?title=Special:Log&page=' + cloneTitle);
var histLink = $(page).clone(true);
histLink.text('hist');
histLink.attr('class', 'external text');
histLink.attr('href', '/w/index.php?title=' + encodeURIComponent(talkTitle) + '&action=history');
var delLink = $(page).clone(true);
delLink.text('G8');
// Try with API
var api = new mw.Api();
delLink.attr('href', '#');
$(delLink).on('click', function() {
geight(talkTitle);
return false;
});
function geight(page_title) {
api.postWithEditToken({
action: 'delete',
reason: '[[WP:CSD#G8|G8]]: Dependent on a nonexistant page',
title: page_title
});
}
// If Ajax result shows the target doesn't exist, add "new" class to the link to turn it red
function parseIt (xml) {
var missing = $(xml).find('page').attr('missing'); // Grab the "missing" attribute from the "page" xml tag that's included in "title" data
if (typeof missing !== 'undefined') {
pageClone.addClass('new');
} // The "missing" field is only defined (as empty string) in the API when the page doesn't exist,
} // ...so if "missing" is NOT undefined, the target IS missing. Turn the link red.
if (pageClone.attr('class') === 'external text') {
page.attr('href', page.attr('href') + '&geight=yes');
} else {
page.attr('href', page.attr('href') + '?geight=yes');
}
// Insert the constructed link after the existing one, along with space and parenthesis
delLink.insertAfter(page).before('| ').after(')');
logLink.insertAfter(page).before('| ').after(' ');
pageClone.insertAfter(page).before('| ').after(' ');
histLink.insertAfter(page).before(' (').after(' ');
});
} else if (mw.config.get('wgCanonicalSpecialPageName') === 'BrokenRedirects') {
// Make cleaning [[Special:BrokenRedirects]] easier
// Grab page list elements
var brPages = $('.special li');
$.each(brPages, function(k, page) { // Iterate through list elements; each step below runs on each list element
var mLink = $(page).find('a')[0];
var delLink = $(mLink).clone(true);
delLink.text('G8');
// Try with API
var api = new mw.Api();
delLink.attr('href', '#');
var histLink = $(mLink).clone(true);
histLink.text('hist');
histLink.attr('class', 'external text');
histLink.attr('href', '/w/index.php?title=' + encodeURIComponent(mLink.text) + '&action=history');
$(delLink).on('click', function() {
geight(mLink.text);
return false;
});
function geight(page_title) {
api.postWithEditToken({
action: 'delete',
reason: '[[WP:CSD#G8|G8]]: Dependent on a nonexistant page',
title: page_title
});
}
// Work with the link within each list element from now on
mLink.href += '?geight=yes'; // The main link
page = $(page).find('a')[2]; // The delete link
if (page) {
page.href += '&geight=yes';
}
histLink.insertBefore(page).before('').after(' | ');
delLink.insertAfter(page).before(' | ').after('');
});
} else if (mw.config.get('wgPageName') === 'User:AnomieBOT_III/Broken_redirects') {
// Make cleaning [[User:AnomieBOT III/Broken redirects]] easier
// Grab page list elements
var abPages = $('.plainlinks a');
$.each(abPages, function(k, page) { // Iterate through list elements; each step below runs on each list element
page = $(page);
var delLink = page.clone(true);
delLink.text('G8');
// Try with API
var api = new mw.Api();
delLink.attr('href', '#');
var histLink = page.clone(true);
histLink.text('hist');
histLink.attr('class', 'external text');
histLink.attr('href', '/w/index.php?title=' + encodeURIComponent(page.text()) + '&action=history');
$(delLink).on('click', function() {
geight(page.text());
return false;
});
function geight(page_title) {
api.postWithEditToken({
action: 'delete',
reason: '[[WP:CSD#G8|G8]]: Dependent on a nonexistant page',
title: page_title
});
}
// Work with the link within each list element from now on
page.attr('href', page.attr('href') + '?geight=yes'); // The main link
delLink.insertAfter(page).before('| ').after(')');
histLink.insertAfter(page).before(' (').after(' ');
});
} else if (mw.config.get('wgPageName') === 'Category:Pages_which_use_a_template_in_place_of_a_magic_word') {
// Make fixing [[:Category:Pages which use a template in place of a magic word]] easier
// Grab page list elements
var maPages = $('#mw-pages li');
$.each(maPages, function(k, page) { // Iterate through list elements; each step below runs on each list element
// Work with the link within each list element from now on
page = $(page).find('a')[0];
page.href += '?action=edit&magicword=yes';
});
} else if (mw.config.get('wgPageName') === 'Category:Candidates_for_speedy_deletion_as_abandoned_drafts_or_AfC_submissions') {
// Make cleaning [[:Category:Candidates_for_speedy_deletion_as_abandoned_drafts_or_AfC_submissions]] easier
// Grab page list elements
var drPages = $('#mw-pages li');
$.each(drPages, function(k, page) { // Iterate through list elements; each step below runs on each list element
// Work with the link within each list element from now on
page = $(page).find('a')[0];
page.href += '?gthirteen=yes';
});
} else if (mw.config.get('wgPageName') === 'Wikipedia:Database_reports/Stale_drafts') {
// Make tidying [[:Wikipedia:Database_reports/Stale_drafts]] easier
// Grab page list elements
var stPages = $('.wikitable tr');
$.each(stPages, function(k, page) { // Iterate through list elements; each step below runs on each list element
page = $(page.firstElementChild.firstElementChild);
if (typeof page === 'undefined') {
return true;
}
var delLink = page.clone(true);
delLink.text('G13');
// Try with API
var api = new mw.Api();
delLink.attr('href', '#');
var histLink = page.clone(true);
histLink.text('hist');
histLink.attr('class', 'external text');
histLink.attr('href', '/w/index.php?title=' + encodeURIComponent(page.text()) + '&action=history');
$(delLink).on('click', function() {
gthirteen(page.text());
return false;
});
function gthirteen(page_title) {
api.postWithEditToken({
action: 'delete',
reason: '[[WP:CSD#G13|G13]]: Abandoned [[WP:AFC|Article for creation]] — to retrieve it, see [[WP:REFUND/G13]]',
title: page_title
});
}
// Work with the link within each list element from now on
page.attr('href', page.attr('href') + '?gthirteen=yes'); // The main link
delLink.insertAfter(page).before('| ').after(')');
histLink.insertAfter(page).before(' (').after(' ');
});
} else if (mw.config.get('wgCanonicalSpecialPageName') === 'Undelete') {
// Make processing page creation logs easier
// Grab page list elements
var unPages = $('.mw-usertoollinks');
$.each(unPages, function(k, page) { // Iterate through list elements; each step below runs on each list element
page = page.getElementsByTagName('a');
page = $(page);
var mLink = page[page.length - 1];
var user = mLink.title.replace(/Special:Block\//, '');
var histLink = $(mLink).clone(true);
histLink.text('log');
histLink.attr('class', 'external text');
histLink.attr('href', '/w/index.php?title=Special:Log&user=' + user);
histLink.insertBefore(page[2]).before('').after(' | ');
});
} else if (mw.config.get('wgPageName') === 'Category:Requested_RD1_redactions') {
// Make processing [[:Category:Requested_RD1_redactions]] easier
// Grab page list elements
var rdPages = $('#mw-pages li');
$.each(rdPages, function(k, page) { // Iterate through list elements; each step below runs on each list element
// Work with the link within each list element from now on
page = $(page).find('a')[0];
page.href += '?copyrev=yes&action=edit§ion=0';
});
}