User:Rillke/Code
Jump to navigation
Jump to search
Snippets[edit]
OTRS[edit]
// Extract HTML links for OTRS purpose from File-LOG
var wd= "";
var i = 1;
$('a[href^="/wiki/File:"]').each(function(x, v) {
wd+= i + '. http://commons.wikimedia.org' + $(v).attr('href') + '\n\n'
i++;
});
console.log(wd);
Remove red links and Deletion Requests from watchlist[edit]
You can delete the line which drops out the DRs. You'll have to go to Special:Watchlist/edit and run this from your console.
$('.mw-htmlform-flatlist-item').each(function(x, v) {
var $v = $(v),
ch = $v.children('input')[0],
lb = $v.children('label').children('a').eq(0);
// Remove redlinks
if ( "new" === lb.attr('class') )
ch.checked = true;
// Preserve user pages
if ( /User:/.test(lb.attr('title')) )
ch.checked = false;
// Remove deletion requests
if ( /^\/wiki\/Commons:Deletion_requests\/.+/.test(lb.attr('href')) )
ch.checked = true;
// Preserve redirects
if ( $v.children('label').children('span.watchlistredir').length > 0 )
ch.checked = false;
});
void(0)
Enumerate all broken Redirects redirs in User Namespace[edit]
See also: User:RillkeBot/AjaxSoftRedirects.js.
var linklist = "[ ";
$('.mw-spcontent > ol > li').each(function(x, v) {
try {
linklist += '"' + decodeURI($(v).children('del').children('a').eq(0).attr('href')).match(/(User.*:.+)/)[1].replace(/_/g, " ") + '", \n';
} catch (ex) {}
});
$('#bodyContent').append($('<pre>').append(linklist + " ]"));
escape to unicode[edit]
var unsaveCharC = [173, 1807, 6068, 6069, 65279];
for (var i = 0; i < 32; i++) unsaveCharC.push(i);
for (var i = 127; i < 160; i++) unsaveCharC.push(i);
for (var i = 1536; i < 1541; i++) unsaveCharC.push(i);
for (var i = 8204; i < 8208; i++) unsaveCharC.push(i);
for (var i = 8232; i < 8240; i++) unsaveCharC.push(i);
for (var i = 8288; i < 8304; i++) unsaveCharC.push(i);
for (var i = 65520; i < 65536; i++) unsaveCharC.push(i);
function esc(str) {
var code, pref = {1: '\\x0', 2: '\\x', 3: '\\u0', 4: '\\u'};
var escaped = str.replace(/\W/g, function(c) {
return (pref[(code = c.charCodeAt(0).toString(16)).length] + code);
});
return escaped.replace(/\\x20/g," ");
};
var st = 'انتخاب'
var st2 = '';
var tmp = '';
for (i=0 ; i<st.length; i++) {
if (-1 === $.inArray(st.charCodeAt(i), unsaveCharC)) {
st2 += st.charAt(i);
} else {
st2 += esc(st.charAt(i));
}
}
console.log('\'' + st2 + '\'');
Manually publish an upload if upload wizard crashed[edit]
$.post(mw.util.wikiScript( 'api' ), {
action: 'upload',
format: 'json',
filekey: 'xxxxxxxxxxxx.xxxxxx.ddddd.png',
filename:'targetname.png',
summary: 'User created page with UploadWizard (alpha)',
text: 'text here',
token: mw.user.tokens.get('csrfToken')
});
Info: You find the filekey in Special:UploadStash.