MediaWiki:Gadget-MoveUtil.js

From Elwiki
Revision as of 02:44, 7 May 2015 by Boxsnake (talk | contribs)

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
if(wgNamespaceNumber == -1 && /MovePage(\/.+)?/.test(wgTitle)){
    if($('#mw-movepage-table').length){
        $('#wpMovetalk').attr('checked', 'checked');
        $('#wpLeaveRedirect').removeAttr('checked');
        $('#wpMovesubpages').attr('checked', 'checked');
        /* Bind to Submit Event */
        $('$('form#movepage').submit(function(){
            var from, ns, to, wiki, edittoken = '', new_wiki;
            from = $('#mw-movepage-table strong').first().text();
            ns = mw.config.get('wgNamespaceIds', wgNamespaceIds);
            ns = ns.map(function(e){
                return e.name;
            }).indexOf($('#wpNewTitleNs').val());
            to = $('#wpNewTitleMain').val();

            /* Get Wiki Content From User:Boxsnake/MoveList */
            $.get('/wiki/api.php?action=query&titles=User:Boxsnake/MoveList&prop=revisions&rvprop=content&format=json', function(data){
                if(data.query.pages['-1']){
                    wiki = '';
                }
                else{
                    data = data.query.pages;
                    wiki = data[Object.keys(data)[0]].revisions[0]['*'];
                }
            }, 'json');

            /* Get Edit Token and Add a Line in MoveList */
            edittoken = $('input[name=wpEditToken]').val();

            /* Compose New Wikitext */
            new_wiki = wiki + '\n' + from + ' -> ' + (ns == '' ? ns : ns + ':') + to;
            /* Add Line in MoveList */
            $.post('/wiki/api.php?minor&recreate&bot', {
                'action': 'edit',
                'title': 'User:Boxsnake/MoveList',
                'summary': 'Bot Adding From Page Move. --[[Special:Gadgets|Move Util]]',
                'token': edittoken,
                'text': new_wiki
            });
        });
    }
}