User:Zhuyifei1999/common.js: Difference between revisions

From WikiIndex
Jump to navigation Jump to search
(Created page with "/* easyblock.js - Script to quickly block spambots By Legoktm, with assistance from Ori.livneh and MZMcBride Adds two tabs, "OP: Spambot block" and "...")
 
No edit summary
 
(17 intermediate revisions by the same user not shown)
Line 1: Line 1:
/*
//$("#wpTextbox1").val("*[[User:" + $("#wpTextbox1").val().match(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/g).sort().join("]]\n*[[User:") + "]]");
        easyblock.js - Script to quickly block spambots
 
        By Legoktm, with assistance from Ori.livneh and MZMcBride
/**
* Add a toolbox link to enable/disable my scripts
        Adds two tabs, "OP: Spambot block" and "Spambot block".
  *
        OP will block for 6 months, and regular will do 3.
* @source: http://www.mediawiki.org/wiki/Snippets/Toggle_user_scripts
        If the user is an account, it will be indefinite.
  * @rev: 1
        The script will forward you to Special:Nuke once done.
*/
 
        This script very likely may contain bugs, use at your
if (mw.config.get("wgAction") == "delete") {
        own risk.
    $("#wpReason").val("")
   
        Released under the MIT License, see README.txt for details.
   
*/
if ( mw.config.get('wgPageName').indexOf('Special:Contributions') >= 0 ) {
        var opblock = mw.util.addPortletLink( 'p-cactions', '#',
                'OP: Spambot block', 'ca-easy-block', 'Open proxy spambot block - 6 months'
        );
        var spambot = mw.util.addPortletLink( 'p-cactions', '#',
                'Spambot block', 'ca-easy-block', 'Spambot block - 3 months'
        );
}
}
/**
* withJS
*
* Allow to load custom scripts from the MediaWiki namespace without
* editing [[Special:Mypage/common.js]]
*
* Attribution: [[commons:User:Platonides]], [[commons:User:Lupo]]
*/
var extraJS = mw.util.getParamValue('withJS');
// Leave here for backwards compatibility
(function (extraJS) {
if (!extraJS) {
  return;
}
if (extraJS.match(/^MediaWiki:[^&<>=%#]*\.js$/)) {
  // Disallow some characters in file name
  importScript(extraJS);
} else {
  // Dont use alert but the jsMsg system. Run jsMsg only once the DOM is ready.
  $(function () {
  jsMsgAppend(extraJS + ' javascript not allowed to be loaded.', 'error');
  });
}
})(extraJS);
   
   
// Bind click handler
$( opblock ).click( function () {
        block( true );
        // doSomeStuff();
        //alert( 'It works!' );
});
$( spambot ).click( function () {
        block( false );
        // doSomeStuff();
        //alert( 'It works!' );
});
function block( isproxy ) {
        var api = new mw.Api();
        // lets figure out the username
        var username = mw.util.getParamValue('target') || mw.config.get('wgTitle').substr(14);
        //action=query&list=users&ususers=127.0.0.1
        //action=query&prop=info&intoken=block&titles=User:Bob&format=jsonfm
        api.get( {
                action: 'query',
                list: 'users',
                ususers: username
        }).done(
                function( data ) {
                        var obj = data.query.users[0];
                        console.log(obj);
                        var exp;
                        if ( obj.invalid !== undefined ) {
                                exp = isproxy ? '6 months' : '3 months';
                        } else {
                                exp = 'indefinite';
                        }
                        api.get( {
                                action: 'query',
                                prop: 'info',
                                intoken: 'block',
                                titles: 'aksjdhfksdjhfskdfhsjdhfgsjhdfg', //apparently this works
                                format: 'json'
                        } ).done(
                                function( data ) {
                                        var blocktoken = data.query.pages['-1'].blocktoken;
                                        console.log(blocktoken);
                                        api.post( {
                                                action: 'block',
                                                user: username,
                                                expiry: exp,
                                                reason: isproxy ? '{{blocked proxy}}: Spambot' : 'Spambot',
                                                nocreate: '1',
                                                anononly: '1',
                                                token: blocktoken
                                        }).done(
                                                function( data ) {
                                                        window.location = '/wiki/Special:Nuke/' + username;
                                                }
                                        );
                                }
                        );
                }
        );
   
   
/**
* withCSS
*
* Allow to load custom styles from the MediaWiki namespace without
* editing [[Special:Mypage/common.css]]
*
* Attribution: [[commons:User:Krinkle]]
*/
var extraCSS = mw.util.getParamValue('withCSS');
if ( extraCSS ) {
  // Disallow some characters in file name
  if (extraCSS.match(/^MediaWiki:[^&<>=%#]*\.css$/)) {
    importStylesheet(extraCSS);
  // Dont use alert but the jsMsg system. Run jsMsg only once the DOM is ready.
  } else {
    $(function() {
      jsMsgAppend(extraCSS + ' stylesheet not allowed to be loaded.', 'error');
    });
  }
}
}

Latest revision as of 09:50, 29 January 2014

//$("#wpTextbox1").val("*[[User:" + $("#wpTextbox1").val().match(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/g).sort().join("]]\n*[[User:") + "]]");

/**
 * Add a toolbox link to enable/disable my scripts
 *
 * @source: http://www.mediawiki.org/wiki/Snippets/Toggle_user_scripts
 * @rev: 1
 */

if (mw.config.get("wgAction") == "delete") {
    $("#wpReason").val("")
}

/**
 * withJS
 *
 * Allow to load custom scripts from the MediaWiki namespace without
 * editing [[Special:Mypage/common.js]]
 *
 * Attribution: [[commons:User:Platonides]], [[commons:User:Lupo]]
 */
var extraJS = mw.util.getParamValue('withJS');
// Leave here for backwards compatibility
(function (extraJS) {
 if (!extraJS) {
  return;
 }
 if (extraJS.match(/^MediaWiki:[^&<>=%#]*\.js$/)) {
  // Disallow some characters in file name
  importScript(extraJS);
 } else {
  // Dont use alert but the jsMsg system. Run jsMsg only once the DOM is ready.
  $(function () {
   jsMsgAppend(extraJS + ' javascript not allowed to be loaded.', 'error');
  });
 }
})(extraJS);
 
 
/**
 * withCSS
 *
 * Allow to load custom styles from the MediaWiki namespace without
 * editing [[Special:Mypage/common.css]]
 *
 * Attribution: [[commons:User:Krinkle]]
 */
var extraCSS = mw.util.getParamValue('withCSS');
if ( extraCSS ) {
  // Disallow some characters in file name
  if (extraCSS.match(/^MediaWiki:[^&<>=%#]*\.css$/)) {
    importStylesheet(extraCSS);
  // Dont use alert but the jsMsg system. Run jsMsg only once the DOM is ready.
  } else {
    $(function() {
      jsMsgAppend(extraCSS + ' stylesheet not allowed to be loaded.', 'error');
    });
  }
}