میڈیاویکی:Gadget-autodel.js
Appearance
یاددہانی: محفوظ کرنے کے بعد، تبدیلیاں دیکھنے کے لیے آپ کو اپنے متصفح (browser) کے ابطن (cache) کو خالی کرنا ہوگا۔
- فائرفاکس/ سفاری: جب Reload طق کریں تو Shift دباکر رکھیں، یا Ctrl-F5 یا Ctrl-R دبائیں (Mac پر R-⌘)
- گوگل کروم: Ctrl-Shift-R دبائیں (Mac پر Shift-R-⌘)
- انٹرنیٹ ایکسپلورر: جب Refresh طق کریں تو Ctrl یا Ctrl-F5 دبائیں
- اوپیرا: Tools → Preferences میں ابطن (cache) صاف کریں
// Outline for an automatic delete link generator.
// Not highly tested. Started by Splarka @ test.wikipedia
// Written for & maintained by Mike_lifeguard @ en.wikibooks
// Rewritten by [[m:User:Hoo man]]
// https://meta.wikimedia.org/wiki/MediaWiki:Gadget-autodel.js
mw.loader.using( ['mediawiki.util', 'mediawiki.cookie'], function() {
function portletOnClick() {
var reason = prompt( 'Enter default delete reason', 'per [[WB:SPEEDY]]' );
if( !reason ) {
return false;
}
var links = document.getElementById( 'bodyContent' ).getElementsByTagName( 'a' );
var arp = mw.config.get( 'wgServer' ) + mw.config.get( 'wgArticlePath' ).replace( '$1', '' );
if( links.length === 0 ) {
return false;
}
// random token, to prevent CSRF deletions
// https://bugzilla.wikimedia.org/show_bug.cgi?id=40743
var autoDeleteToken = ( Math.ceil( Math.random() * 20000000000 ) );
// expire after 45 min
var date = new Date();
date.setTime( date.getTime() + ( 45 * 60 * 1000 ) );
// save to cookie
mw.cookie.set( 'autoDeleteToken', autoDeleteToken, { expires: date, path: '/' } );
for( var i=0; i<links.length; i++ ) {
if( links[i].href.indexOf( arp ) === 0 && links[i].href.indexOf( 'action=delete' ) === -1 &&
links[i].href.indexOf( '/' + mw.config.get( 'wgFormattedNamespaces' )[-1] + ':' ) === -1
) {
links[i].href += '?action=delete&submitdelete=' + autoDeleteToken + '&deletetalkalso=true&wpReason=' + encodeURIComponent( reason );
links[i].innerHTML += ' (delete)';
}
}
return false;
}
// Auto delete
if( mw.util.getParamValue( 'submitdelete' ) ) {
if( mw.util.getParamValue( 'submitdelete' ) === mw.cookie.get( 'autoDeleteToken' ) && !mw.util.getParamValue( 'deletetalk' ) ) {
$( document ).ready( function() {
if( document.getElementById( 'ca-talk' ).className.indexOf( 'new' ) === -1 &&
mw.util.getParamValue( 'deletetalkalso' ) === 'true' &&
( mw.config.get( 'wgNamespaceNumber' ) % 2 === 0 )
) {
// if the talk tab isn't redlinked and this is the first time AND this is not a talk page then
// add the parameters necessary to delete the talk page
document.getElementById( 'deleteconfirm' ).action += '&deletetalk=true&submitdelete=' + mw.cookie.get( 'autoDeleteToken' );
document.getElementById( 'deleteconfirm' ).action += 'wpReason=' + encodeURIComponent( mw.util.getParamValue( 'wpReason' ) );
}
// set the delete reason and auto delete
$( '#wpReason' ).attr( 'value', mw.util.getParamValue( 'wpReason' ) );
var sub = ( document.getElementById( 'wpConfirmB' ) ) ? document.getElementById( 'wpConfirmB' ) : document.getElementById( 'mw-filedelete-submit' );
sub.click();
} );
}else if( mw.util.getParamValue( 'submitdelete' ) && mw.util.getParamValue( 'submitdelete' ) !== mw.cookie.get( 'autoDeleteToken' ) ) {
// Invalid token
alert( 'Invalid autoDeleteToken, please recreate the auto delete links!' );
return;
}
// The "main" page has already been deleted, go on with the talk
if(mw.config.get( 'wgAction' ) === 'delete' && mw.util.getParamValue( 'deletetalk' ) === 'true' && mw.util.getParamValue( 'submitdelete' ) === mw.cookie.get( 'autoDeleteToken' ) ) {
$( document ).ready( function() {
var url = document.getElementById( 'ca-talk' ).getElementsByTagName( 'a' )[0].href;
url += '?action=delete&submitdelete=' + mw.cookie.get( 'autoDeleteToken' ) + '&wpReason=' + encodeURIComponent( mw.util.getParamValue( 'wpReason' ) );
document.location.href = url;
} );
}else if( mw.util.getParamValue( 'submitdelete' ) && mw.util.getParamValue( 'submitdelete' ) !== mw.cookie.get( 'autoDeleteToken' ) ) {
// Invalid token
alert( 'Invalid autoDeleteToken, please recreate the auto delete links!' );
return;
}
}
// Init portlet IF contribs or log or newpages or [article AND (submit|view|purge)]
if( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Contributions' || mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Whatlinkshere' ||
mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Log' || mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Prefixindex' ||
mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Newpages' ||
( mw.config.get( 'wgIsArticle' ) && ( mw.config.get( 'wgAction' ) === 'submit' || mw.config.get( 'wgAction' ) === 'view' || mw.config.get( 'wgAction' ) === 'purge' ) )
) {
$( document ).ready( function() {
// portlet link with onClick
$(
mw.util.addPortletLink( 'p-cactions', '#', 'خودکار حذف شدگی', 'ca-dellink', 'generate deletion links' )
).on( 'click', portletOnClick );
} );
}
} );
// [[Category:Gadgets|Autodel.js]]