User:Sohom Datta/Redirectify.js

//Copied from User:DannyS712/Redirectify.js // Originally from User:FR30799386/redirectify.js? // var Redirectify_config = { name: 'Redirectify', version: 1.2, debug: false }; var Redirectify_ending = ' (' + Redirectify_config.name + ' v.' + Redirectify_config.version + ')'; function loadredirectify { if($('#mw-indicator-featured-star').length || $('#mw-indicator-good-star').length) { $('#mw-content-text').prepend(' Redirectify should not be used to redirect a Good article or a featured article. '		 +'Seek consensus on the article talk page if you plan to redirect this page. '); return; }   if( mw.config.get( 'wgTitle' ) === 'Main Page' ) { console.log('huh? wut? Why?') return; }   mw.loader.using( [ 'mediawiki.widgets', 'oojs-ui-core', 'oojs-ui-widgets', 'ext.gadget.morebits' ], function {        $('.redirectify-ui').remove;        var api = new mw.Api;        //Portion copied from User:EnterpriseyBot/AFCHRS.js starts        var Rcat = [{            label: 'R from related topic',            data: 'R from related topic'        },        {            label: 'R to related topic',            data: 'R to related topic'        },        {            label: 'R from alternative language',            data: 'R from alternative language'        }, {            label: 'R from alternative name',            data: 'R from alternative name'        }, {            label: 'R from modification',            data: 'R from modification'        }, {            label: 'R to section',            data: 'R to section'        }, {            label: 'R from diacritic',            data: 'R from diacritic' }, {           label: 'R to diacritic', data: 'R to diacritic' }, {           label: 'R from acronym', data: 'R from acronym' }, {           label: 'R from initialism', data: 'R from initialism' }, {           label: 'R from CamelCase', data: 'R from CamelCase' }, {           label: 'R from miscapitalisation', data: 'R from miscapitalisation' }, {           label: 'R from other capitalisation', data: 'R from other capitalisation' }, {           label: 'R from modification', data: 'R from modification' }, {           label: 'R from plural', data: 'R from plural' }, {           label: 'R from adjective', data: 'R from adjective' }, {           label: 'R from adverb', data: 'R from adverb' }, {           label: 'R from common noun', data: 'R from common noun' }, {           label: 'R from gerund', data: 'R from gerund' }, {           label: 'R from proper noun', data: 'R from proper noun' }, {           label: 'R from verb', data: 'R from verb' }, {           label: 'R from alternative spelling', data: 'R from alternative spelling' }, {           label: 'R from misspelling', data: 'R from misspelling' }, {           label: 'R from American English', data: 'R from American English' }, {           label: 'R from British English', data: 'R from British English' }, {           label: 'R from ASCII-only', data: 'R from ASCII-only' }, {           label: 'R from diacritic', data: 'R from diacritic' }, {           label: 'R from ligature', data: 'R from ligature' }, {           label: 'R from stylization', data: 'R from stylization' }, {           label: 'R from alternative transliteration', data: 'R from alternative transliteration' }, {           label: 'R from Wade–Giles romanization', data: 'R from Wade–Giles romanization' }, {           label: 'From alternative names, general', data: 'From alternative names, general', disabled: true }, {           label: 'R from alternative language', data: 'R from alternative language' }, {           label: 'R from alternative name', data: 'R from alternative name' }, {           label: 'R from former name', data: 'R from former name' }, {           label: 'R from historic name', data: 'R from historic name' }, {           label: 'R from incomplete name', data: 'R from incomplete name' }, {           label: 'R from incorrect name', data: 'R from incorrect name' }, {           label: 'R from letter–word combination', data: 'R from letter–word combination' }, {           label: 'R from long name', data: 'R from long name' }, {           label: 'R from portmanteau', data: 'R from portmanteau' }, {           label: 'R from predecessor company name', data: 'R from predecessor company name' }, {           label: 'R from short name', data: 'R from short name' }, {           label: 'R from sort name', data: 'R from sort name' }, {           label: 'R from less specific name', data: 'R from less specific name' }, {           label: 'R from more specific name', data: 'R from more specific name' }, {           label: 'R from antonym', data: 'R from antonym' }, {           label: 'R from eponym', data: 'R from eponym' }, {           label: 'R from synonym', data: 'R from synonym' }, {           label: 'R from Roman numerals', data: 'R from Roman numerals' }, {           label: 'From alternative names, geography', data: 'From alternative names, geography', disabled: true }, {           label: 'R from Canadian settlement name', data: 'R from Canadian settlement name' }, {           label: 'R from name and country', data: 'R from name and country' }, {           label: 'R from city and state', data: 'R from city and state' }, {           label: 'R from city and province', data: 'R from city and province' }, {           label: 'R from more specific geographic name', data: 'R from more specific geographic name' }, {           label: 'R from postal abbreviation', data: 'R from postal abbreviation' }, {           label: 'R from postal code', data: 'R from postal code' }, {           label: 'R from US postal abbreviation', data: 'R from US postal abbreviation' }, {           label: 'From alternative names, organisms', data: 'From alternative names, organisms', disabled: true }, {           label: 'R from scientific abbreviation', data: 'R from scientific abbreviation' }, {           label: 'R from scientific name', data: 'R from scientific name' }, {           label: 'R from alternative scientific name', data: 'R from alternative scientific name' }, {           label: 'R from monotypic taxon', data: 'R from monotypic taxon' }, {           label: 'From alternative names, people', data: 'From alternative names, people', disabled: true }, {           label: 'R from birth name', data: 'R from birth name' }, {           label: 'R from given name', data: 'R from given name' }, {           label: 'R from married name', data: 'R from married name' }, {           label: 'R from name with title', data: 'R from name with title' }, {           label: 'R from non-neutral name', data: 'R from non-neutral name' }, {           label: 'R from personal name', data: 'R from personal name' }, {           label: 'R from pseudonym', data: 'R from pseudonym' }, {           label: 'R from relative', data: 'R from relative' }, {           label: 'R from spouse', data: 'R from spouse' }, {           label: 'R from surname', data: 'R from surname' }, {           label: 'R from Bluebook abbreviation', data: 'R from Bluebook abbreviation' }, {           label: 'R from brand name', data: 'R from brand name' }, {           label: 'R from drug trade name', data: 'R from drug trade name' }, {           label: 'R from file name', data: 'R from file name' }, {           label: 'R from Java package name', data: 'R from Java package name' }, {           label: 'R from MathSciNet abbreviation', data: 'R from MathSciNet abbreviation' }, {           label: 'R from molecular formula', data: 'R from molecular formula' }, {           label: 'R from NLM abbreviation', data: 'R from NLM abbreviation' }, {           label: 'R from product name', data: 'R from product name' }, {           label: 'R from slogan', data: 'R from slogan' }, {           label: 'R from symbol', data: 'R from symbol' }, {           label: 'R from systematic abbreviations', data: 'R from systematic abbreviations' }, {           label: 'R from technical name', data: 'R from technical name' }, {           label: 'R from trademark', data: 'R from trademark' }, {           label: 'R from file metadata link', data: 'R from file metadata link' }, {           label: 'R mentioned in hatnote', data: 'R mentioned in hatnote' }, {           label: 'R from shortcut', data: 'R from shortcut' }, {           label: 'R from template shortcut', data: 'R from template shortcut' }, {           label: 'From disambiguations', data: 'From disambiguations', disabled: true }, {           label: 'R from ambiguous term', data: 'R from ambiguous term' }, {           label: 'R from incomplete disambiguation', data: 'R from incomplete disambiguation' }, {           label: 'R from incorrect disambiguation', data: 'R from incorrect disambiguation' }, {           label: 'R from other disambiguation', data: 'R from other disambiguation' }, {           label: 'R from predictable disambiguation', data: 'R from predictable disambiguation' }, {           label: 'R from unnecessary disambiguation', data: 'R from unnecessary disambiguation' }, {           label: 'From mergers, duplicates, and moves', data: 'From mergers, duplicates, and moves', disabled: true }, {           label: 'R from duplicated article', data: 'R from duplicated article' }, {           label: 'R with history', data: 'R with history' }, {           label: 'R from merge', data: 'R from merge' }, {           label: 'R from move', data: 'R from move' }, {           label: 'R with old history', data: 'R with old history' }, {           label: 'R from fictional character', data: 'R from fictional character' }, {           label: 'R from fictional element', data: 'R from fictional element' }, {           label: 'R from fictional location', data: 'R from fictional location' }, {           label: 'From related info', data: 'From related info', disabled: true }, {           label: 'R from album', data: 'R from album' }, {           label: 'R from animal', data: 'R from animal' }, {           label: 'R from book', data: 'R from book' }, {           label: 'R from catchphrase', data: 'R from catchphrase' }, {           label: 'R from domain name', data: 'R from domain name' }, {           label: 'R from top-level domain', data: 'R from top-level domain' }, {           label: 'R from film', data: 'R from film' }, {           label: 'R from gender', data: 'R from gender' }, {           label: 'R from legislation', data: 'R from legislation' }, {           label: 'R from list topic', data: 'R from list topic' }, {           label: 'R from member', data: 'R from member' }, {           label: 'R from person', data: 'R from person' }, {           label: 'R from phrase', data: 'R from phrase' }, {           label: 'R from quotation', data: 'R from quotation' }, {           label: 'R from related word', data: 'R from related word' }, {           label: 'R from school', data: 'R from school' }, {           label: 'R from song', data: 'R from song' }, {           label: 'R from subtopic', data: 'R from subtopic' }, {           label: 'R from team', data: 'R from team' }, {           label: 'R from work', data: 'R from work' }, {           label: 'R from writer', data: 'R from writer' }, {           label: 'R from Unicode', data: 'R from Unicode' }, {           label: 'R to acronym', data: 'R to acronym' }, {           label: 'R to initialism', data: 'R to initialism' }, {           label: 'R to ASCII-only title', data: 'R to ASCII-only title' }, {           label: 'R to diacritic', data: 'R to diacritic' }, {           label: 'R to ligature', data: 'R to ligature' }, {           label: 'R to plural', data: 'R to plural' }, {           label: 'To alternative names', data: 'To alternative names', disabled: true }, {           label: 'R to former name', data: 'R to former name' }, {           label: 'R to historic name', data: 'R to historic name' }, {           label: 'R to joint biography', data: 'R to joint biography' }, {           label: 'R to name with title', data: 'R to name with title' }, {           label: 'R to monotypic taxon', data: 'R to scientific name' }, {           label: 'R to scientific name', data: 'R to scientific name' }, {           label: 'R to systematic name', data: 'R to systematic name' }, {           label: 'R to technical name', data: 'R to technical name' }, {           label: 'To – navigation and disambiguation', data: 'To – navigation and disambiguation', disabled: true }, {           label: 'R to anchor', data: 'R to anchor' }, {           label: 'R to anthroponymy page', data: 'R to anthroponymy page' }, {           label: 'R to disambiguation page', data: 'R to disambiguation page' }, {           label: 'R to list entry', data: 'R to list entry' }, {           label: 'R to section', data: 'R to section' }, {           label: 'To miscellaneous', data: 'To miscellaneous', disabled: true }, {           label: 'R to decade', data: 'R to decade' }, {           label: 'R to related topic', data: 'R to related topic' }, {           label: 'R to subpage', data: 'R to subpage' }, {           label: 'R to subtopic', data: 'R to subtopic' }, {           label: 'R to TV episode list entry', data: 'R to TV episode list entry' } ];       function generateSelect(title, options, onchange) { const multiselect = new OO.ui.MenuTagMultiselectWidget( {               inputPosition: 'outline',                allowArbitrary: true,                verticalPosition: 'below',                title,                options: options            }); return multiselect; }       //Section copied ends here var morebits = new Morebits.wiki.page(mw.config.get('wgPageName')); var wikitext = '#REDIRECT $1\n'; var summaryredirect = 'Redirecting page to $1'; var summaryalert = 'Notification of a page being redirected' + Redirectify_ending; var title = (mw.config.get('wgPageName')).replace('_', ' '); var messagetouser = window.messagetouser || '==Redirecting page: ' + title + '==\nA page you created, ' + title + ', does not seem to have enough reliable third party sources to merit inclusion in the encyclopedia in itself. It has been redirected to $1 which is related to the subject of the article. ~';       var titleinput = new mw.widgets.TitleInputWidget({            required: true        }); $('#mw-content-text').prepend(' Redirectify Target :  '); var $redirectify = $('.r-action-ui'); if( $( '.redirectText' ).length ) { titleinput.setValue( $( '.redirectText a' )[0].innerText ); }       $redirectify.append(titleinput.$element); const redirectifyMultiselect = generateSelect('r-rcat', Rcat); $redirectify.append(' Redirect categorization : \n ' ); $redirectify.append(redirectifyMultiselect.$element); $redirectify.append(' Summary of action :   '); const $redirectifyMsgElem = $( '.r-message-element' ) const userMsg = new OO.ui.MultilineTextInputWidget( {           autosize: true,            value: messagetouser        } ); morebits.lookupCreation(function {       	if ( $( '.redirectMsg' ).length ) return;            $redirectifyMsgElem.append(' Message : (Remove current text to prevent message for being sent) \n');            $redirectifyMsgElem.append(userMsg.$element);            $redirectifyMsgElem.append(' Note :$1 denotes target page ');        }); $('.r-action-ui').append('Redirect '       +' Cancel '); $('.r-cancel').click(function{       $('.redirectify-ui').remove;        }); $('.r-submit').click(function(e) {           e.preventDefault;            var reason = ($('#r-summary').val) ? (': ' + $('#r-summary').val ) : '';            var target = titleinput.getQueryValue;            console.log(target);            if (target) {                api.get({ action: "query", titles: target, }).then(function(ret) { $.each(ret.query.pages, function {                       if (this.missing !== "") {                            wikitext = wikitext.replace('$1', target);                            const redirectTags = redirectifyMultiselect.getValue;                            let redirectTagText = ;                            for (let i = 0; i < redirectTags.length;i++) {                                redirectTagText += ``;                            }                            if (redirectTagText !== ) {                                wikitext = wikitext.replace('$2', redirectTagText);                            } else {                                wikitext = wikitext.replace(, );                            }                            summaryredirect = summaryredirect.replace('$1', target);                            messagetouser = ($('#r-message').val || '').replace('$1', target); $redirectify.empty; api.postWithToken('csrf', {                               action: 'edit',                                title: mw.config.get('wgPageName'),                                text: wikitext,                                summary: summaryredirect + reason + Redirectify_ending                            }).done(function(response) {                                if (response.edit.result === 'Success')                                    $redirectify.append('Redirected page !');                                console.log(response);                            }).fail(function(status) {                                $redirectify.append(' Could not redirect page ! ');                               console.log(status);                            }); if (messagetouser !== '') { morebits.lookupCreation(function {                               	if ( $( '.redirectMsg' ).length ) return;                                    var guy = morebits.getCreator;                                    var guyedit = new Morebits.wiki.page('User talk:' + guy);                                    guyedit.setEditSummary(summaryalert);                                    guyedit.setAppendText('\n' + messagetouser);                                    guyedit.append(function { $redirectify.append('Messaged user !'); }, function { $redirectify.append('Could not message user !'); });                               });                            }                            $('#r-error').html(""); $('.r-action-ui').html('Reload '); $('.r-reload').click(function {                               location.href = '/wiki/' + mw.config.get('wgPageName') + '?redirect=no';                            }); } else { createerror; }                   });                }, function(error) {                    console.error(error);                    createerror;                }); } else { createerror; }       });    });    function createerror{ $('#r-error').html('The page specified in the target parameter does not exist. Redirecting this page to the target will result in the creation of a broken redirect.'); } } $.when(mw.loader.using('mediawiki.util'), $.ready).then(function {	if( mw.config.get( "wgNamespaceNumber" ) < 0 ) return;	if (mw.config.get('wgUserGroups').indexOf('extendedconfirmed') === -1 ) {       console.log("[Redirectify] User isn't extendedconfirmed, and so shouldn't use this script.");        return;    }    var portlet = mw.util.addPortletLink('p-cactions', 'javascript:void(0)', 'Redirect page', 'ca-redirectify', 'Make page a redirect', 'r', '');    $('#ca-redirectify').click(function { loadredirectify; }); }); //