MediaWiki:Gadget-dyktool.js
外观
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
/**
* DYK Tool
* Developer & maintainer: [[User:PhiLiP]]
*/
jQuery( document ).ready( function() {
var DYKCtitle = 'Wikipedia:新条目推荐/候选';
if (
mw.config.get('wgPageName') != DYKCtitle
|| mw.config.get('wgUserGroups').indexOf( 'sysop' ) == -1
|| !!mw.util.getParamValue("diff")
|| !!mw.util.getParamValue("oldid")
) return false;
if("function"!=typeof DYKCtitle.trim) String.prototype.trim=function(){
return this.replace(/^\s+/, "").replace(/\s+$/, "");
};
var $=jQuery, maxErrTime=3, nullFunc=function(){}, nullAry=[];
var genhash=function SHA1(msg) {
function rotate_left(n,s) {
var t4 = ( n<<s ) | (n>>>(32-s));
return t4;
};
function lsb_hex(val) {
var str="";
var i;
var vh;
var vl;
for( i=0; i<=6; i+=2 ) {
vh = (val>>>(i*4+4))&0x0f;
vl = (val>>>(i*4))&0x0f;
str += vh.toString(16) + vl.toString(16);
}
return str;
};
function cvt_hex(val) {
var str="";
var i;
var v;
for( i=7; i>=0; i-- ) {
v = (val>>>(i*4))&0x0f;
str += v.toString(16);
}
return str;
};
function Utf8Encode(string) {
string = string.replace(/\r\n/g,"\n");
var utftext = "";
for (var n = 0; n < string.length; n++) {
var c = string.charCodeAt(n);
if (c < 128) {
utftext += String.fromCharCode(c);
}
else if((c > 127) && (c < 2048)) {
utftext += String.fromCharCode((c >> 6) | 192);
utftext += String.fromCharCode((c & 63) | 128);
}
else {
utftext += String.fromCharCode((c >> 12) | 224);
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
utftext += String.fromCharCode((c & 63) | 128);
}
}
return utftext;
};
var blockstart;
var i, j;
var W = new Array(80);
var H0 = 0x67452301;
var H1 = 0xEFCDAB89;
var H2 = 0x98BADCFE;
var H3 = 0x10325476;
var H4 = 0xC3D2E1F0;
var A, B, C, D, E;
var temp;
msg = Utf8Encode(msg);
var msg_len = msg.length;
var word_array = new Array();
for( i=0; i<msg_len-3; i+=4 ) {
j = msg.charCodeAt(i)<<24 | msg.charCodeAt(i+1)<<16 |
msg.charCodeAt(i+2)<<8 | msg.charCodeAt(i+3);
word_array.push( j );
}
switch( msg_len % 4 ) {
case 0:
i = 0x080000000;
break;
case 1:
i = msg.charCodeAt(msg_len-1)<<24 | 0x0800000;
break;
case 2:
i = msg.charCodeAt(msg_len-2)<<24 | msg.charCodeAt(msg_len-1)<<16 | 0x08000;
break;
case 3:
i = msg.charCodeAt(msg_len-3)<<24 | msg.charCodeAt(msg_len-2)<<16 | msg.charCodeAt(msg_len-1)<<8 | 0x80;
break;
}
word_array.push( i );
while( (word_array.length % 16) != 14 ) word_array.push( 0 );
word_array.push( msg_len>>>29 );
word_array.push( (msg_len<<3)&0x0ffffffff );
for ( blockstart=0; blockstart<word_array.length; blockstart+=16 ) {
for( i=0; i<16; i++ ) W[i] = word_array[blockstart+i];
for( i=16; i<=79; i++ ) W[i] = rotate_left(W[i-3] ^ W[i-8] ^ W[i-14] ^ W[i-16], 1);
A = H0;
B = H1;
C = H2;
D = H3;
E = H4;
for( i= 0; i<=19; i++ ) {
temp = (rotate_left(A,5) + ((B&C) | (~B&D)) + E + W[i] + 0x5A827999) & 0x0ffffffff;
E = D;
D = C;
C = rotate_left(B,30);
B = A;
A = temp;
}
for( i=20; i<=39; i++ ) {
temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0x6ED9EBA1) & 0x0ffffffff;
E = D;
D = C;
C = rotate_left(B,30);
B = A;
A = temp;
}
for( i=40; i<=59; i++ ) {
temp = (rotate_left(A,5) + ((B&C) | (B&D) | (C&D)) + E + W[i] + 0x8F1BBCDC) & 0x0ffffffff;
E = D;
D = C;
C = rotate_left(B,30);
B = A;
A = temp;
}
for( i=60; i<=79; i++ ) {
temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0xCA62C1D6) & 0x0ffffffff;
E = D;
D = C;
C = rotate_left(B,30);
B = A;
A = temp;
}
H0 = (H0 + A) & 0x0ffffffff;
H1 = (H1 + B) & 0x0ffffffff;
H2 = (H2 + C) & 0x0ffffffff;
H3 = (H3 + D) & 0x0ffffffff;
H4 = (H4 + E) & 0x0ffffffff;
}
var temp = cvt_hex(H0) + cvt_hex(H1) + cvt_hex(H2) + cvt_hex(H3) + cvt_hex(H4);
return temp.toLowerCase();
};
var editPage=function(argobj){
var titles,
errcount=maxErrTime*1,
editFunc,
doneFunc,
failFunc,
beforeRetryFunc;
if("object"==typeof argobj) for(var p in argobj) eval(p+"=argobj[p]");
var retryFunc=function(){
if(errcount>0){
setTimeout(
function(){
if("function"==typeof beforeRetryFunc) if(false===beforeRetryFunc()) return;
editPage({
titles :titles ,
errcount:errcount-1,
editFunc:editFunc,
doneFunc:doneFunc,
failFunc:failFunc,
beforeRetryFunc:beforeRetryFunc,
});
}
, 1000*15
);
}else{
if("function"==typeof failFunc) failFunc();
}
};
$.post(
'/w/api.php',
{
action : 'query',
prop : 'revisions',
format : 'json',
titles : titles,
rvprop : 'content|timestamp',
rvslots: 'main',
},
null,
'json'
).fail(
retryFunc
).done(
function(data){
var contentstr = '',
timestamp = '',
pageid = '';
for ( pageid in data.query.pages ) {
if(pageid<0){
timestamp = Math.floor(Date.now()/1000);
}else{
timestamp = data.query.pages[pageid].revisions[0].timestamp;
contentstr = data.query.pages[pageid].revisions[0].slots.main['*'];
}
break;
}
var content={
value : ""+contentstr,
toString : function(){ return this.value },
summary : "",
};
if(editFunc==nullFunc || "function"!=typeof editFunc){
if("function"==typeof doneFunc){
doneFunc({
content:content,
data:nullFunc(),
});
}
}else{
if( editFunc({content:content})===false ) return false;
if( contentstr.trim()==(""+content).trim() ){
;
if("function"==typeof doneFunc) doneFunc({content:content,data:nullFunc()});
}else{
$.post(
'/w/api.php',
{
action : 'query',
prop : 'info',
titles : titles,
meta : 'tokens',
format : 'json',
},
null,
'json'
).fail(
retryFunc
).done(
function(data){
var startts = (pageid<0)?Math.floor(Date.now()/1000):data.query.pages[pageid].starttimestamp;
var edittoken = data.query.tokens.csrftoken;
content.lastrevid=data.query.pages[pageid].lastrevid;
content.isCreate=(pageid<0);
$.post (
'/w/api.php',
{
action : 'edit',
title : titles,
text : ""+content,
token : edittoken,
summary : content.summary,
format : 'json',
basetimestamp : timestamp,
starttimestamp : startts,
},
null,
'json'
).fail(
retryFunc
).done(
function( data ){
if(!!data) if(!!data.edit) if( "success"== (""+data.edit.result).toLowerCase() ){
doneFunc({content:content,data:data});
return;
}
retryFunc();
}
);
}
);
}
}
}
);
}
$( 'dl.dykentry' ).each( function() {
var $hashobj = $(this).find( '.dykentry_hash');
if($hashobj.length!=1) return;
var hash = $hashobj.text();
var img = $( 'dd:first img', this );
$( '<a class="dykentry_accept" href="#">' + wgUVS( '通过', '通過' ) + '</a> \
<a class="dykentry_deny" href="#">' + wgUVS( '拒绝', '拒絕' ) + '</a>' ).insertAfter( $hashobj );
$(this).find( 'a[class^=dykentry_]' ).click( function() {
var $this = $(this);
var classname = $this.attr( 'class' );
var reason = '';
if ( classname == 'dykentry_deny' || classname == 'dykentry_remove' ) {
var defaultreason = '7天仍不足4票支持';
reason = window.prompt( wgUVS( '拒绝原因', '拒絕原因' ) , defaultreason );
if ( reason==null ) return false;
if ( reason==defaultreason ) reason='';
}
var hash = $this.parent().find( '.dykentry_hash' ).text();
var dd = $( 'dd:first', $this.parentsUntil( 'li' ) );
var loading = $( '<img src="data:image/gif;base64,R0lGODlhEAAQAPcAAF9gYGhpam9wcHh6e4aHiIaIiYeJiomLjI2Oj5GTlJKUlZWXmJyen5+hoqCio6Omp6Smp6iqrKqsra2vsbCztLS2uLa5uri7vbu+v7y+wL7Bw8LFxsTHyMTHycjLzcvOz8zP0c3Q0tLV1tPW2NTX2dXZ2tfa3Njb3dnc3t3h4+Dk5uPn6eXp6+fr7ejr7ert7+ru8Ovv8e3x8+7y9PH19/L2+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FlA/EryDhgiREk9b4BGJ8I4FNGhIDBSBJg/BGnDqNBp4ZwGXHi24NophhgAaPAIhdEmFBYEFFCjckMkVRwEbgXjwrgHghEGYOl5wBciSiyAWAQwChAkTwEyPowjpftLMuYWFLAkJ4pKcMCAAIfkEAQoAAAAsAAAAABAAEAAACL0AAQgcCGBRC4IIATRatAXAExIAZJxolLCRplUOnwBooqEhQYqMRsh48qSFkUQRPbZaJaNRohYyZKQIsYVOhSYCG7XS1aKRjYFbOpwCIeNj0Y8nDgrUUKDpiISLNBgxckKDgasQEUY1MujEwBEWPOYMkYKgIgZ8ELigKDBGoARGWgmU0EdDqwWDUqToEEFGEyAdBDJiBKBQDhMQAKUw8CHi0bY7AAFw4ABAhQQxEsagUGVyZUYaHicEAALE6IAAIfkEAQoAAAAsAAAAABAAEAAACMEAAQgcCCAGFoIIBcZoBCBRIgCuEjFE2GjFwURRAEDBRIMglhYAstyh4TAGrhUAaHQEAKHLJFctsrhytcJJo0SVNAm8s4DLoywDbdDANMmQK4KGiKwU2CjKQYEbfPhI8CRhC1wcOESJOrUqwqtZMwo0QWkpABtO7hDk9SDAAiwTbWTB0GBDDIEUBmzIUvdOoiVEXD2J8EHh3UuOoAyxdUfBEohHB8Z4ZAuArQgAKO0CijBLEZCXAWDBFTmhQEOPEwYEACH5BAEKAAAALAAAAAAQABAAAAi/AAEIHAjAlSuCCAEwgvALQIsWAGiAapSQkagFDiH+OkFxICNGACzckMOohSsSjBrR6CihjyoYX4iobGGnEagPdQR+YsAHASgaAm00KpEExcGBIywAJfgLxsAkYcKIQZEQxhJMmH7BiTrmRMWrWQfScdMxKApQBFtIGNULRllXHU59yCXQAik4uYLA+fRrBAZXdASJEJjL6RI/viyk+WSqRMGlAl2VIgKACOU2QY4SzKUKomUAMDBpTgighOOEAQEAOw=="/>' ).prependTo( dd );
var resultflag = (function(classname){
switch(classname){
case 'dykentry_accept':
return '+';
case 'dykentry_deny':
return '-';
}
})(classname);
var resulthash = resultflag + '\|' + genhash(resultflag+hash+resultflag);
var comment=resulthash + '\|' + ( (classname=='dykentry_holdon') ? '0' : ('\{\{subst' + ':#time:U\}\}') );
$( 'a[class^=dykentry_]' ).css("visibility", "hidden");
editPage({
titles : DYKCtitle,
errcount : maxErrTime*1,
editFunc : function(argobj){
var content;
if("object"==typeof argobj) for(var p in argobj) eval(p+"=argobj[p]");
var article,
result,
newcontent=(""+content),
parts = newcontent.split( /\{\{\s*DYKEntry/i );
for ( var i = 0; i < parts.length; i ++ ) {
if ( parts[i].indexOf( hash ) != -1 ) {
article = parts[i].replace( /(?:\n|.)*\|\s*article\s*\= *([\S ]*)(?:\n|.)*/m , '$1');
parts[i] = "/close"+parts[i].replace(/\{\{\s*DYKvote[HF]\s*(?:\|[^\}]*?)?\}\}\n*/g, "");
parts[i] = parts[i]
.replace( /\s*?\|\s*x\-approved\-by\s*\=.*?\n/, "\n")
.replace( /(\|\s*result\s*\=).*\n/, '$1 ' + comment + '\n');
if( reason.length>0 ) parts[i] = parts[i].replace( /\s*((\={4} *\={4}\s*\{\{\s*DYKCsplit\s*\}\}\s*)*(\={3} *\d{1,2}月\d{1,2}日 *\={3}\s*)?(\={4} *\={4}\s*)?)?$/ , '\n*:\{\{已取消\}\},' + reason + ( reason.charAt(reason.length-1)=='。'?'':'。' ) + '--~~\~~\n\n$1' );
parts[i] = parts[i].replace( /\s*((\={4} *\={4}\s*\{\{\s*DYKCsplit\s*\}\}\s*)*(\={3} *\d{1,2}月\d{1,2}日 *\={3}\s*)?(\={4} *\={4}\s*)?)?$/ , '\n\{\{DYKvoteF\}\}\n\n$1' );
break;
}
}
newcontent = parts.join( '\{\{ DYKEntry' ).replace(/(DYKEntry\/close)/g, "subst\:$1" );
content.value = newcontent;
content.summary = resulthash + " /" + "*" + article + "*"+ "/ (dyktool)" ;
},
doneFunc : function(argobj){
var content,
data=nullAry;
if("object"==typeof argobj) for(var p in argobj) eval(p+"=argobj[p]");
loading.remove();
$( 'a[class^=dykentry_]' ).css("visibility", "");
if ( classname == 'dykentry_accept' || classname == 'dykentry_quickpass' ) {
dd.prepend( $( '<a href="/wiki/File:Yes_check.svg" class="image" title="是"><img alt="是" src="//upload.wikimedia.org/wikipedia/commons/thumb/f/fb/Yes_check.svg/15px-Yes_check.svg.png" height="15" width="15"></a>' ) );
} else {
dd.prepend( $( '<a href="/wiki/File:X_mark.svg" class="image" title="否"><img alt="否" src="//upload.wikimedia.org/wikipedia/commons/thumb/a/a2/X_mark.svg/15px-X_mark.svg.png" height="17" width="15"></a>' ) );
}
},
});
return false;
});
});
});