MediaWiki:Gadget-MoveUtil.js: Difference between revisions

From Elwiki
mNo edit summary
mNo edit summary
Line 6: Line 6:
         /* Bind to Submit Event */
         /* Bind to Submit Event */
         $('form#movepage').submit(function(){
         $('form#movepage').submit(function(){
             var from, ns, to, wiki, edittoken = '', new_wiki;
             var from, ns, to, wiki, api, new_wiki;
             from = $('#mw-movepage-table strong').first().text();
             from = $('#mw-movepage-table strong').first().text();
             ns = mw.config.get('wgNamespaceIds', wgNamespaceIds);
             ns = mw.config.get('wgNamespaceIds', wgNamespaceIds);
Line 14: Line 14:
             to = $('#wpNewTitleMain').val();
             to = $('#wpNewTitleMain').val();


             /* Get Wiki Content From User:Boxsnake/MoveList */
             api = new mw.Api();
            $.get('/wiki/api.php?action=query&titles=User:Boxsnake/MoveList&prop=revisions&rvprop=content&format=json', function(data){
                try{
                    data = data.query.pages;
                    wiki = data[Object.keys(data)[0]].revisions[0]['*'];
                }
                catch(err){
                    wiki = '';
                }
            }, '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 */
             /* Add Line in MoveList */
             $.post('/wiki/api.php?minor&recreate&bot', {
             api.postWithToken('edit', {
                'minor': '',
                'recreate': '',
                'bot': '',
                 'action': 'edit',
                 'action': 'edit',
                 'title': 'User:Boxsnake/MoveList',
                 'title': 'User:Boxsnake/MoveList',
                 'summary': 'Bot Adding From Page Move. --[[Special:Gadgets|Move Util]]',
                 'summary': 'Bot Adding From Page Move. --[[Special:Gadgets|Move Util]]',
                 'token': edittoken,
                 'contentmodel': 'wikitext',
                 'text': new_wiki
                 'appendtext': from + ' -> ' + (ns == '' ? '' : ns + ':') + to
            }).done(function(){
                $('form#movepage').submit();
             });
             });
         });
         });
     }
     }
}
}

Revision as of 08:35, 7 May 2015

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, api, 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();

            api = new mw.Api();
            /* Add Line in MoveList */
            api.postWithToken('edit', {
                'minor': '',
                'recreate': '',
                'bot': '',
                'action': 'edit',
                'title': 'User:Boxsnake/MoveList',
                'summary': 'Bot Adding From Page Move. --[[Special:Gadgets|Move Util]]',
                'contentmodel': 'wikitext',
                'appendtext': from + ' -> ' + (ns == '' ? '' : ns + ':') + to
            }).done(function(){
                $('form#movepage').submit();
            });
        });
    }
}