User:FR30799386/redirectify.js

// function loadredirectify { if($('.assess-ga-text').length || $('.assess-fa-text').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; }   mw.loader.using('mediawiki.widgets', function {        if (window.Morebits === null) {            importScript('MediaWiki:Gadget-morebits.js');        }        $('.redirectify-ui').remove;        var api = new mw.Api;        //Portion copied from User:EnterpriseyBot/AFCHRS.js starts        var Rcat = [{            label: 'None',            selected: true,            value: '#'        }, {            label: 'Frequently used',            value: 'Frequently used',            disabled: true        }, {            label: 'R from alternative language',            value: 'R from alternative language'        }, {            label: 'R from alternative name',            value: 'R from alternative name'        }, {            label: 'R from modification',            value: 'R from modification'        }, {            label: 'R to section',            value: 'R to section'        }, { label: 'R from diacritic', value: 'R from diacritic' }, {           label: 'R to diacritic', value: 'R to diacritic' }, {           label: 'From – abbreviation, capitalisation, and grammar', value: 'From – abbreviation, capitalisation, and grammar', disabled: true }, {           label: 'R from acronym', value: 'R from acronym' }, {           label: 'R from initialism', value: 'R from initialism' }, {           label: 'R from CamelCase', value: 'R from CamelCase' }, {           label: 'R from miscapitalisation', value: 'R from miscapitalisation' }, {           label: 'R from other capitalisation', value: 'R from other capitalisation' }, {           label: 'R from modification', value: 'R from modification' }, {           label: 'R from plural', value: 'R from plural' }, {           label: 'From parts of speach', value: 'From parts of speach', disabled: true }, {           label: 'R from adjective', value: 'R from adjective' }, {           label: 'R from adverb', value: 'R from adverb' }, {           label: 'R from common noun', value: 'R from common noun' }, {           label: 'R from gerund', value: 'R from gerund' }, {           label: 'R from proper noun', value: 'R from proper noun' }, {           label: 'R from verb', value: 'R from verb' }, {           label: 'From – spelling', value: 'From – spelling', disabled: true }, {           label: 'R from alternative spelling', value: 'R from alternative spelling' }, {           label: 'R from misspelling', value: 'R from misspelling' }, {           label: 'R from American English', value: 'R from American English' }, {           label: 'R from British English', value: 'R from British English' }, {           label: 'R from ASCII-only', value: 'R from ASCII-only' }, {           label: 'R from diacritic', value: 'R from diacritic' }, {           label: 'R from ligature', value: 'R from ligature' }, {           label: 'R from stylization', value: 'R from stylization' }, {           label: 'R from alternative transliteration', value: 'R from alternative transliteration' }, {           label: 'R from Wade–Giles romanization', value: 'R from Wade–Giles romanization' }, {           label: 'From alternative names, general', value: 'From alternative names, general', disabled: true }, {           label: 'R from alternative language', value: 'R from alternative language' }, {           label: 'R from alternative name', value: 'R from alternative name' }, {           label: 'R from former name', value: 'R from former name' }, {           label: 'R from historic name', value: 'R from historic name' }, {           label: 'R from incomplete name', value: 'R from incomplete name' }, {           label: 'R from incorrect name', value: 'R from incorrect name' }, {           label: 'R from letter–word combination', value: 'R from letter–word combination' }, {           label: 'R from long name', value: 'R from long name' }, {           label: 'R from portmanteau', value: 'R from portmanteau' }, {           label: 'R from predecessor company name', value: 'R from predecessor company name' }, {           label: 'R from short name', value: 'R from short name' }, {           label: 'R from sort name', value: 'R from sort name' }, {           label: 'R from less specific name', value: 'R from less specific name' }, {           label: 'R from more specific name', value: 'R from more specific name' }, {           label: 'R from antonym', value: 'R from antonym' }, {           label: 'R from eponym', value: 'R from eponym' }, {           label: 'R from synonym', value: 'R from synonym' }, {           label: 'R from Roman numerals', value: 'R from Roman numerals' }, {           label: 'From alternative names, geography', value: 'From alternative names, geography', disabled: true }, {           label: 'R from Canadian settlement name', value: 'R from Canadian settlement name' }, {           label: 'R from name and country', value: 'R from name and country' }, {           label: 'R from city and state', value: 'R from city and state' }, {           label: 'R from city and province', value: 'R from city and province' }, {           label: 'R from more specific geographic name', value: 'R from more specific geographic name' }, {           label: 'R from postal abbreviation', value: 'R from postal abbreviation' }, {           label: 'R from postal code', value: 'R from postal code' }, {           label: 'R from US postal abbreviation', value: 'R from US postal abbreviation' }, {           label: 'From alternative names, organisms', value: 'From alternative names, organisms', disabled: true }, {           label: 'R from scientific abbreviation', value: 'R from scientific abbreviation' }, {           label: 'R from scientific name', value: 'R from scientific name' }, {           label: 'R from alternative scientific name', value: 'R from alternative scientific name' }, {           label: 'R from monotypic taxon', value: 'R from monotypic taxon' }, {           label: 'From alternative names, people', value: 'From alternative names, people', disabled: true }, {           label: 'R from birth name', value: 'R from birth name' }, {           label: 'R from given name', value: 'R from given name' }, {           label: 'R from married name', value: 'R from married name' }, {           label: 'R from name with title', value: 'R from name with title' }, {           label: 'R from non-neutral name', value: 'R from non-neutral name' }, {           label: 'R from personal name', value: 'R from personal name' }, {           label: 'R from pseudonym', value: 'R from pseudonym' }, {           label: 'R from relative', value: 'R from relative' }, {           label: 'R from spouse', value: 'R from spouse' }, {           label: 'R from surname', value: 'R from surname' }, {           label: 'From alternative names, technical', value: 'From alternative names, technical', disabled: true }, {           label: 'R from Bluebook abbreviation', value: 'R from Bluebook abbreviation' }, {           label: 'R from brand name', value: 'R from brand name' }, {           label: 'R from drug trade name', value: 'R from drug trade name' }, {           label: 'R from file name', value: 'R from file name' }, {           label: 'R from Java package name', value: 'R from Java package name' }, {           label: 'R from MathSciNet abbreviation', value: 'R from MathSciNet abbreviation' }, {           label: 'R from molecular formula', value: 'R from molecular formula' }, {           label: 'R from NLM abbreviation', value: 'R from NLM abbreviation' }, {           label: 'R from product name', value: 'R from product name' }, {           label: 'R from slogan', value: 'R from slogan' }, {           label: 'R from symbol', value: 'R from symbol' }, {           label: 'R from systematic abbreviations', value: 'R from systematic abbreviations' }, {           label: 'R from technical name', value: 'R from technical name' }, {           label: 'R from trademark', value: 'R from trademark' }, {           label: 'From – navigation', value: 'From – navigation', disabled: true }, {           label: 'R from file metadata link', value: 'R from file metadata link' }, {           label: 'R mentioned in hatnote', value: 'R mentioned in hatnote' }, {           label: 'R from shortcut', value: 'R from shortcut' }, {           label: 'R from template shortcut', value: 'R from template shortcut' }, {           label: 'From disambiguations', value: 'From disambiguations', disabled: true }, {           label: 'R from ambiguous term', value: 'R from ambiguous term' }, {           label: 'R from incomplete disambiguation', value: 'R from incomplete disambiguation' }, {           label: 'R from incorrect disambiguation', value: 'R from incorrect disambiguation' }, {           label: 'R from other disambiguation', value: 'R from other disambiguation' }, {           label: 'R from predictable disambiguation', value: 'R from predictable disambiguation' }, {           label: 'R from unnecessary disambiguation', value: 'R from unnecessary disambiguation' }, {           label: 'From mergers, duplicates, and moves', value: 'From mergers, duplicates, and moves', disabled: true }, {           label: 'R from duplicated article', value: 'R from duplicated article' }, {           label: 'R with history', value: 'R with history' }, {           label: 'R from merge', value: 'R from merge' }, {           label: 'R from move', value: 'R from move' }, {           label: 'R with old history', value: 'R with old history' }, {           label: 'From fiction', value: 'From fiction', disabled: true }, {           label: 'R from fictional character', value: 'R from fictional character' }, {           label: 'R from fictional element', value: 'R from fictional element' }, {           label: 'R from fictional location', value: 'R from fictional location' }, {           label: 'From related info', value: 'From related info', disabled: true }, {           label: 'R from album', value: 'R from album' }, {           label: 'R from animal', value: 'R from animal' }, {           label: 'R from book', value: 'R from book' }, {           label: 'R from catchphrase', value: 'R from catchphrase' }, {           label: 'R from domain name', value: 'R from domain name' }, {           label: 'R from top-level domain', value: 'R from top-level domain' }, {           label: 'R from film', value: 'R from film' }, {           label: 'R from gender', value: 'R from gender' }, {           label: 'R from legislation', value: 'R from legislation' }, {           label: 'R from list topic', value: 'R from list topic' }, {           label: 'R from member', value: 'R from member' }, {           label: 'R from person', value: 'R from person' }, {           label: 'R from phrase', value: 'R from phrase' }, {           label: 'R from quotation', value: 'R from quotation' }, {           label: 'R from related word', value: 'R from related word' }, {           label: 'R from school', value: 'R from school' }, {           label: 'R from song', value: 'R from song' }, {           label: 'R from subtopic', value: 'R from subtopic' }, {           label: 'R from team', value: 'R from team' }, {           label: 'R from work', value: 'R from work' }, {           label: 'R from writer', value: 'R from writer' }, {           label: 'R from Unicode', value: 'R from Unicode' }, {           label: 'To – grammar, punctuation, and spelling', value: 'To – grammar, punctuation, and spelling', disabled: true }, {           label: 'R to acronym', value: 'R to acronym' }, {           label: 'R to initialism', value: 'R to initialism' }, {           label: 'R to ASCII-only title', value: 'R to ASCII-only title' }, {           label: 'R to diacritic', value: 'R to diacritic' }, {           label: 'R to ligature', value: 'R to ligature' }, {           label: 'R to plural', value: 'R to plural' }, {           label: 'To alternative names', value: 'To alternative names', disabled: true }, {           label: 'R to former name', value: 'R to former name' }, {           label: 'R to historic name', value: 'R to historic name' }, {           label: 'R to joint biography', value: 'R to joint biography' }, {           label: 'R to name with title', value: 'R to name with title' }, {           label: 'R to monotypic taxon', value: 'R to scientific name' }, {           label: 'R to scientific name', value: 'R to scientific name' }, {           label: 'R to systematic name', value: 'R to systematic name' }, {           label: 'R to technical name', value: 'R to technical name' }, {           label: 'To – navigation and disambiguation', value: 'To – navigation and disambiguation', disabled: true }, {           label: 'R to anchor', value: 'R to anchor' }, {           label: 'R to anthroponymy page', value: 'R to anthroponymy page' }, {           label: 'R to disambiguation page', value: 'R to disambiguation page' }, {           label: 'R to list entry', value: 'R to list entry' }, {           label: 'R to section', value: 'R to section' }, {           label: 'To miscellaneous', value: 'To miscellaneous', disabled: true }, {           label: 'R to decade', value: 'R to decade' }, {           label: 'R to related topic', value: 'R to related topic' }, {           label: 'R to subpage', value: 'R to subpage' }, {           label: 'R to subtopic', value: 'R to subtopic' }, {           label: 'R to TV episode list entry', value: 'R to TV episode list entry' }, {       	label:'Custom - prompt me', value: 'Custom' }       ];        function generateSelect(title, options, onchange) { var text = ''; for (var i = 0; i < options.length; i++) { var o = options[i]; text += '' + o.label + ' '; }           text += " "; return text; }       //Section copied ends here var morebits = new Morebits.wiki.page(mw.config.get('wgPageName')); var wikitext = '#REDIRECT $1\n$2'; var summaryredirect; if($('.redirectMsg').length) summaryredirect = "Managing redirects by"; else summaryredirect = 'Redirecting page to $1'; var summaryalert = 'Notification of article being redirected'; 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        }); if($('.redirectMsg').length) {       	titleinput.setValue($('.redirectMsg a').text); }       $('#mw-content-text').prepend(' Redirectify Target :   '); var $redirectify = $('.redirectify'); $redirectify.append(titleinput.$element); $redirectify.append(' Redirect categorization : ' + generateSelect('r-rcat', Rcat)+'  '); $('#r-rcat-custom').hide; $('#r-rcat').change(function{       	if($(this).val === 'Custom')        	{        		$('#r-rcat-custom').fadeIn;        	}        	else        	$('#r-rcat-custom').fadeOut;        }); $redirectify.append(' Summary of action :  '); morebits.lookupCreator(function {           if (!$('.redirectMsg').length) {                $redirectify.append(' Message : (Remove current text to prevent message for being sent) \n' + messagetouser + ' \n 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||'';            var target = titleinput.value;            if (target) {                api.get({ action: "query", titles: target, }).then(function(ret) { $.each(ret.query.pages, function {                       if (this.missing !== "") {                            wikitext = wikitext.replace('$1', target);                            if ($('#r-rcat').val !== '#') {                            	if($('#r-rcat-custom:visible').length){                            		wikitext = wikitext.replace('$2', );                            	}else{                                wikitext = wikitext.replace('$2', );                            	}                            }else {                                wikitext = wikitext.replace('$2', );                            }                            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)' }).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.lookupCreator(function { 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('<button class="mw-ui-button r-reload">Reload ');                            $('.r-reload').click(function { location.href = '/wiki/' + mw.config.get('wgPageName') + '?redirect=no'; });                       } else {                            createerror;                        }                    }); }, function(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 (-1 === $.inArray('extendedconfirmed', mw.config.get('wgUserGroups'))) { console.log("[Redirectify] User isn't extendedconfirmed. Due to the sensitive nature of the script we cannot allow non-confirmed users to use it."); 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;    }); }); //