維基百科 ganwiki https://gan.wikipedia.org/wiki/%E5%B0%81%E9%9D%A2 MediaWiki 1.39.0-wmf.26 first-letter 媒體 特別 談詑 用戶 用戶・談詑 Wikipedia Wikipedia・談詑 文檔 文檔・談詑 MediaWiki MediaWiki・談詑 模板 模板・談詑 幫助 幫助・談詑 分類 分類・談詑 TimedText TimedText talk 模組 模組討論 Gadget Gadget talk Gadget definition Gadget definition talk 用戶:Lt2818/vector-2022.js 2 35844 396484 2022-08-29T01:03:06Z Lt2818 18630 新頁: /* This is userscirpt is usefull for Mass pages Move. @Author [[User:Jayprakash12345]] @Author from [[User:Legoktm/massrename.js]] @OwnBy [[meta:Indic-TechCom]] */ $( document ).ready( function() { function init() { $('#mw-content-text > p').remove(); $('#firstHeading').text('MassMover'); var listofPages = new OO.ui.MultilineTextInputWidget( { placeholder: 'List of Pages', autosize: true, rows:… javascript text/javascript /* This is userscirpt is usefull for Mass pages Move. @Author [[User:Jayprakash12345]] @Author from [[User:Legoktm/massrename.js]] @OwnBy [[meta:Indic-TechCom]] */ $( document ).ready( function() { function init() { $('#mw-content-text > p').remove(); $('#firstHeading').text('MassMover'); var listofPages = new OO.ui.MultilineTextInputWidget( { placeholder: 'List of Pages', autosize: true, rows: 10 } ), findInput = new OO.ui.TextInputWidget( { placeholder: 'Find' } ); replaceInput = new OO.ui.TextInputWidget( { placeholder: 'Replace' } ), reasonInput = new OO.ui.TextInputWidget( { placeholder: 'Reason' } ), treatAsRegex = new OO.ui.FieldLayout( treatAsRegexInside = new OO.ui.CheckboxInputWidget( { selected: false } ), { label: 'Treat search string as a regular expression', align: 'inline' } ), notleaveRedirect = '', moveStart = new OO.ui.ButtonWidget( { label: 'Start Moving', icon: 'alert', flags: [ 'primary', 'progressive' ] } ), cancelBtn = new OO.ui.ButtonWidget( { label: 'Cancel', flags: [ 'primary', 'destructive' ], href: 'https:' + mw.config.get( 'wgServer' ) } ), moveLogHeading = $("<div>").hide(); label1 = $('<p>').text('List of Pages:').css('font-weight','bold' ); label2 = $('<p>').text('Find:').css('font-weight','bold' ); label3 = $('<p>').text('Replace:').css('font-weight','bold' ); label4 = $('<p>').text('Reason:').css('font-weight','bold' ); if ( $.inArray( 'sysop', mw.config.get('wgUserGroups') ) !== -1 ) { notleaveRedirect = new OO.ui.FieldLayout( notleaveRedirectInside = new OO.ui.CheckboxInputWidget( { selected: false } ), { label: 'Don\'t leave the redirect behind (Be careful)', align: 'inline' } ); } $( '#mw-content-text' ).append( label1, listofPages.$element, label2, findInput.$element, label3, replaceInput.$element, label4, reasonInput.$element, treatAsRegex.$element, notleaveRedirect.$element, '<br/>', moveStart.$element, cancelBtn.$element, '<br/>', moveLogHeading ); // Thanks [[User:Legoktm]], Stolen from [[User:Legoktm/massrename.js]] function rename_file( old, newname, reason, noRedirect, callback ) { ( new mw.Api() ).postWithToken ( 'csrf', { action: 'move', from: old, to: newname, reason: reason, movetalk: 1, noredirect: noRedirect }, { async: false // Don't run parallel requests, be nice to sever kittens! }) .done( callback ) .fail( callback ); } function escapeRegExp(str) { // From MDN return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"); } function missingAlertMsg ( str ) { return alert( "Did not find " + str + " :(" ); } function responeHanddler( data ) { var orderedList = $("<ul>").appendTo( moveLogHeading ); /* // If source page is not exist if ( data === "missingtitle") { orderedList.append( "<li> Page <b>" + pageToMoveByMassMover + "</b> not found. </li>" ); } // If old name and new name are same if ( data === "selfmove") { orderedList.append( "<li><b>" + pageToMoveByMassMover + "</b> no changes made. </li>" ); } */ if( data.move ) { orderedList.append( "<li><b>" + data.move.from + "</b> moved to <b>" + data.move.to + "</b>.</li>" ); } } moveStart.on( 'click', function() { pagesList = listofPages.getValue().replace(/^\s*[\r\n]/gm, '').split("\n"); var find = findInput.getValue().trim(); var replace = replaceInput.getValue().trim(); var reason = reasonInput.getValue().trim() + " (By [[meta:Indic-TechCom/Tools|MassMover]])"; var noRedirect = false; var AsRegex = treatAsRegexInside.isSelected(); if( pagesList[0].trim() !== "" && find !== "" && replace !== "" ) { moveLogHeading.empty(); $("<h1>").wrapInner( "<span class='mw-headline'>Move Log</span>").appendTo( moveLogHeading ); moveLogHeading.show(); } else { missingAlertMsg( "any source page" ); return; } if ( find === "" ) { missingAlertMsg( "\'find\' string" ); return; } if ( replace === "" ) { missingAlertMsg( "replace string" ); return; } if ( $.inArray( 'sysop', mw.config.get('wgUserGroups') ) !== -1 ) { noRedirect = notleaveRedirectInside.isSelected(); } pagesList.forEach( function(page){ // Lengthy name to aviod override in the global variable window.pageToMoveByMassMover = page.trim(); // Simple find/replace without Regex if ( !AsRegex ) { find = escapeRegExp(find); newPagename = pageToMoveByMassMover.replace( find, replace ); rename_file( pageToMoveByMassMover, newPagename, reason, noRedirect, responeHanddler ); } // Find/replace with Regex else { // Check whether the Regex is correct or not try { find = new RegExp( find, 'gi' ); } catch (e) { alert( "Regex Error: " + e ); // Hack to break the loop pagesList.length = 0; return; } newPagename = pageToMoveByMassMover.replace( find, replace ); rename_file( pageToMoveByMassMover, newPagename, reason, noRedirect, responeHanddler); } }); }); } // On every page $.when(mw.loader.using('mediawiki.util'), $.ready).then(function () { mw.util.addPortletLink( 'p-tb', mw.util.getUrl('Special:BlankPage/MassMover'), 'MassMover' ); }); if ( mw.config.get('wgCanonicalSpecialPageName') === 'Blankpage' && mw.config.get('wgTitle').split('/', 2)[1] === 'MassMover' ) { $.when(mw.loader.using('oojs-ui-core'), $.ready).then(function () { init(); }); } }); rvcivjj7rzg0s2g3yre5jf1aqsibc5s 396485 396484 2022-08-29T01:13:27Z Lt2818 18630 javascript text/javascript /* This is userscirpt is usefull for Mass pages Move. @Author [[User:Jayprakash12345]] @Author from [[User:Legoktm/massrename.js]] @OwnBy [[meta:Indic-TechCom]] */ $( document ).ready( function() { function init() { $('#mw-content-text > p').remove(); $('#firstHeading').text('MassMover'); var listofPages = new OO.ui.MultilineTextInputWidget( { placeholder: 'List of Pages', autosize: true, rows: 10 } ), findInput = new OO.ui.TextInputWidget( { placeholder: 'Find' } ); replaceInput = new OO.ui.TextInputWidget( { placeholder: 'Replace' } ), reasonInput = new OO.ui.TextInputWidget( { placeholder: 'Reason' } ), treatAsRegex = new OO.ui.FieldLayout( treatAsRegexInside = new OO.ui.CheckboxInputWidget( { selected: false } ), { label: 'Treat search string as a regular expression', align: 'inline' } ), notleaveRedirect = '', moveStart = new OO.ui.ButtonWidget( { label: 'Start Moving', icon: 'alert', flags: [ 'primary', 'progressive' ] } ), cancelBtn = new OO.ui.ButtonWidget( { label: 'Cancel', flags: [ 'primary', 'destructive' ], href: 'https:' + mw.config.get( 'wgServer' ) } ), moveLogHeading = $("<div>").hide(); label1 = $('<p>').text('List of Pages:').css('font-weight','bold' ); label2 = $('<p>').text('Find:').css('font-weight','bold' ); label3 = $('<p>').text('Replace:').css('font-weight','bold' ); label4 = $('<p>').text('Reason:').css('font-weight','bold' ); if ( $.inArray( 'sysop', mw.config.get('wgUserGroups') ) !== -1 ) { notleaveRedirect = new OO.ui.FieldLayout( notleaveRedirectInside = new OO.ui.CheckboxInputWidget( { selected: false } ), { label: 'Don\'t leave the redirect behind (Be careful)', align: 'inline' } ); } $( '#mw-content-text' ).append( label1, listofPages.$element, label2, findInput.$element, label3, replaceInput.$element, label4, reasonInput.$element, treatAsRegex.$element, notleaveRedirect.$element, '<br/>', moveStart.$element, cancelBtn.$element, '<br/>', moveLogHeading ); // Thanks [[User:Legoktm]], Stolen from [[User:Legoktm/massrename.js]] function rename_file( old, newname, reason, noRedirect, callback ) { ( new mw.Api() ).postWithToken ( 'csrf', { action: 'move', from: old, to: newname, reason: reason, movetalk: 1, noredirect: noRedirect }, { async: false // Don't run parallel requests, be nice to sever kittens! }) .done( callback ) .fail( callback ); } function escapeRegExp(str) { // From MDN return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"); } function missingAlertMsg ( str ) { return alert( "Did not find " + str + " :(" ); } function responeHanddler( data ) { var orderedList = $("<ul>").appendTo( moveLogHeading ); /* // If source page is not exist if ( data === "missingtitle") { orderedList.append( "<li> Page <b>" + pageToMoveByMassMover + "</b> not found. </li>" ); } // If old name and new name are same if ( data === "selfmove") { orderedList.append( "<li><b>" + pageToMoveByMassMover + "</b> no changes made. </li>" ); } */ if( data.move ) { orderedList.append( "<li><b>" + data.move.from + "</b> moved to <b>" + data.move.to + "</b>.</li>" ); } } moveStart.on( 'click', function() { pagesList = listofPages.getValue().replace(/^\s*[\r\n]/gm, '').split("\n"); var find = findInput.getValue().trim(); var replace = replaceInput.getValue().trim(); var reason = reasonInput.getValue().trim() + " (By [[meta:Indic-TechCom/Tools|MassMover]])"; var noRedirect = false; var AsRegex = treatAsRegexInside.isSelected(); if( pagesList[0].trim() !== "" && find !== "" && replace !== "" ) { moveLogHeading.empty(); $("<h1>").wrapInner( "<span class='mw-headline'>Move Log</span>").appendTo( moveLogHeading ); moveLogHeading.show(); } else { missingAlertMsg( "any source page" ); return; } if ( find === "" ) { missingAlertMsg( "\'find\' string" ); return; } if ( replace === "" ) { missingAlertMsg( "replace string" ); return; } if ( $.inArray( 'sysop', mw.config.get('wgUserGroups') ) !== -1 ) { noRedirect = notleaveRedirectInside.isSelected(); } var getParams = function (bltitle) { return { action: 'query', format: 'json', list: 'backlinks', bltitle: bltitle }; }, api = new mw.Api(); pagesList.forEach( function(page){ api.get( getParams(page) ).done( function ( data1 ) { api.get( getParams('Talk:' + page) ).done( function ( data2 ) { console.log( data1.query.backlinks, data2.query.backlinks ); } ); } ); // Lengthy name to aviod override in the global variable window.pageToMoveByMassMover = page.trim(); // Simple find/replace without Regex if ( !AsRegex ) { find = escapeRegExp(find); newPagename = pageToMoveByMassMover.replace( find, replace ); rename_file( pageToMoveByMassMover, newPagename, reason, noRedirect, responeHanddler ); } // Find/replace with Regex else { // Check whether the Regex is correct or not try { find = new RegExp( find, 'gi' ); } catch (e) { alert( "Regex Error: " + e ); // Hack to break the loop pagesList.length = 0; return; } newPagename = pageToMoveByMassMover.replace( find, replace ); rename_file( pageToMoveByMassMover, newPagename, reason, noRedirect, responeHanddler); } }); }); } // On every page $.when(mw.loader.using('mediawiki.util'), $.ready).then(function () { mw.util.addPortletLink( 'p-tb', mw.util.getUrl('Special:BlankPage/MassMover'), 'MassMover' ); }); if ( mw.config.get('wgCanonicalSpecialPageName') === 'Blankpage' && mw.config.get('wgTitle').split('/', 2)[1] === 'MassMover' ) { $.when(mw.loader.using('oojs-ui-core'), $.ready).then(function () { init(); }); } }); 156mu5o9i3tvjiraietaunvw0zhvwdp 396486 396485 2022-08-29T01:36:57Z Lt2818 18630 javascript text/javascript /* This is userscirpt is usefull for Mass pages Move. @Author [[User:Jayprakash12345]] @Author from [[User:Legoktm/massrename.js]] @OwnBy [[meta:Indic-TechCom]] */ $( document ).ready( function() { function init() { $('#mw-content-text > p').remove(); $('#firstHeading').text('MassMover'); var listofPages = new OO.ui.MultilineTextInputWidget( { placeholder: 'List of Pages', autosize: true, rows: 10 } ), findInput = new OO.ui.TextInputWidget( { placeholder: 'Find' } ); replaceInput = new OO.ui.TextInputWidget( { placeholder: 'Replace' } ), reasonInput = new OO.ui.TextInputWidget( { placeholder: 'Reason' } ), treatAsRegex = new OO.ui.FieldLayout( treatAsRegexInside = new OO.ui.CheckboxInputWidget( { selected: false } ), { label: 'Treat search string as a regular expression', align: 'inline' } ), notleaveRedirect = '', moveStart = new OO.ui.ButtonWidget( { label: 'Start Moving', icon: 'alert', flags: [ 'primary', 'progressive' ] } ), cancelBtn = new OO.ui.ButtonWidget( { label: 'Cancel', flags: [ 'primary', 'destructive' ], href: 'https:' + mw.config.get( 'wgServer' ) } ), moveLogHeading = $("<div>").hide(); label1 = $('<p>').text('List of Pages:').css('font-weight','bold' ); label2 = $('<p>').text('Find:').css('font-weight','bold' ); label3 = $('<p>').text('Replace:').css('font-weight','bold' ); label4 = $('<p>').text('Reason:').css('font-weight','bold' ); if ( $.inArray( 'sysop', mw.config.get('wgUserGroups') ) !== -1 ) { notleaveRedirect = new OO.ui.FieldLayout( notleaveRedirectInside = new OO.ui.CheckboxInputWidget( { selected: false } ), { label: 'Don\'t leave the redirect behind (Be careful)', align: 'inline' } ); } $( '#mw-content-text' ).append( label1, listofPages.$element, label2, findInput.$element, label3, replaceInput.$element, label4, reasonInput.$element, treatAsRegex.$element, notleaveRedirect.$element, '<br/>', moveStart.$element, cancelBtn.$element, '<br/>', moveLogHeading ); // Thanks [[User:Legoktm]], Stolen from [[User:Legoktm/massrename.js]] function rename_file( old, newname, reason, noRedirect, callback ) { ( new mw.Api() ).postWithToken ( 'csrf', { action: 'move', from: old, to: newname, reason: reason, movetalk: 1, noredirect: noRedirect }, { async: false // Don't run parallel requests, be nice to sever kittens! }) .done( callback ) .fail( callback ); } function escapeRegExp(str) { // From MDN return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"); } function missingAlertMsg ( str ) { return alert( "Did not find " + str + " :(" ); } function responeHanddler( data ) { var orderedList = $("<ul>").appendTo( moveLogHeading ); /* // If source page is not exist if ( data === "missingtitle") { orderedList.append( "<li> Page <b>" + pageToMoveByMassMover + "</b> not found. </li>" ); } // If old name and new name are same if ( data === "selfmove") { orderedList.append( "<li><b>" + pageToMoveByMassMover + "</b> no changes made. </li>" ); } */ if( data.move ) { orderedList.append( "<li><b>" + data.move.from + "</b> moved to <b>" + data.move.to + "</b>.</li>" ); } } moveStart.on( 'click', function() { pagesList = listofPages.getValue().replace(/^\s*[\r\n]/gm, '').split("\n"); var find = findInput.getValue().trim(); var replace = replaceInput.getValue().trim(); var reason = reasonInput.getValue().trim() + " (By [[meta:Indic-TechCom/Tools|MassMover]])"; var noRedirect = false; var AsRegex = treatAsRegexInside.isSelected(); if( pagesList[0].trim() !== "" && find !== "" && replace !== "" ) { moveLogHeading.empty(); $("<h1>").wrapInner( "<span class='mw-headline'>Move Log</span>").appendTo( moveLogHeading ); moveLogHeading.show(); } else { missingAlertMsg( "any source page" ); return; } if ( find === "" ) { missingAlertMsg( "\'find\' string" ); return; } if ( replace === "" ) { missingAlertMsg( "replace string" ); return; } if ( $.inArray( 'sysop', mw.config.get('wgUserGroups') ) !== -1 ) { noRedirect = notleaveRedirectInside.isSelected(); } var getParams = function (bltitle) { return { action: 'query', format: 'json', list: 'backlinks', bltitle: bltitle }; }, api = new mw.Api(); pagesList.forEach( function(page){ var p1 = api.get(getParams(page)), p2 = api.get(getParams('Talk:' + page)); Promise.all([p1, p2]).then( function ( data ) { console.log( data[0].query.backlinks.length, data[1].query.backlinks.length ); } ); // Lengthy name to aviod override in the global variable window.pageToMoveByMassMover = page.trim(); // Simple find/replace without Regex if ( !AsRegex ) { find = escapeRegExp(find); newPagename = pageToMoveByMassMover.replace( find, replace ); rename_file( pageToMoveByMassMover, newPagename, reason, noRedirect, responeHanddler ); } // Find/replace with Regex else { // Check whether the Regex is correct or not try { find = new RegExp( find, 'gi' ); } catch (e) { alert( "Regex Error: " + e ); // Hack to break the loop pagesList.length = 0; return; } newPagename = pageToMoveByMassMover.replace( find, replace ); rename_file( pageToMoveByMassMover, newPagename, reason, noRedirect, responeHanddler); } }); }); } // On every page $.when(mw.loader.using('mediawiki.util'), $.ready).then(function () { mw.util.addPortletLink( 'p-tb', mw.util.getUrl('Special:BlankPage/MassMover'), 'MassMover' ); }); if ( mw.config.get('wgCanonicalSpecialPageName') === 'Blankpage' && mw.config.get('wgTitle').split('/', 2)[1] === 'MassMover' ) { $.when(mw.loader.using('oojs-ui-core'), $.ready).then(function () { init(); }); } }); tdbvfsmiqeat54mdgmkf69dbtjahnfz 396487 396486 2022-08-29T01:43:51Z Lt2818 18630 javascript text/javascript /* This is userscirpt is usefull for Mass pages Move. @Author [[User:Jayprakash12345]] @Author from [[User:Legoktm/massrename.js]] @OwnBy [[meta:Indic-TechCom]] */ $( document ).ready( function() { function init() { $('#mw-content-text > p').remove(); $('#firstHeading').text('MassMover'); var listofPages = new OO.ui.MultilineTextInputWidget( { placeholder: 'List of Pages', autosize: true, rows: 10 } ), findInput = new OO.ui.TextInputWidget( { placeholder: 'Find' } ); replaceInput = new OO.ui.TextInputWidget( { placeholder: 'Replace' } ), reasonInput = new OO.ui.TextInputWidget( { placeholder: 'Reason' } ), treatAsRegex = new OO.ui.FieldLayout( treatAsRegexInside = new OO.ui.CheckboxInputWidget( { selected: false } ), { label: 'Treat search string as a regular expression', align: 'inline' } ), moveStart = new OO.ui.ButtonWidget( { label: 'Start Moving', icon: 'alert', flags: [ 'primary', 'progressive' ] } ), cancelBtn = new OO.ui.ButtonWidget( { label: 'Cancel', flags: [ 'primary', 'destructive' ], href: 'https:' + mw.config.get( 'wgServer' ) } ), moveLogHeading = $("<div>").hide(); label1 = $('<p>').text('List of Pages:').css('font-weight','bold' ); label2 = $('<p>').text('Find:').css('font-weight','bold' ); label3 = $('<p>').text('Replace:').css('font-weight','bold' ); label4 = $('<p>').text('Reason:').css('font-weight','bold' ); $( '#mw-content-text' ).append( label1, listofPages.$element, label2, findInput.$element, label3, replaceInput.$element, label4, reasonInput.$element, treatAsRegex.$element, '<br/>', moveStart.$element, cancelBtn.$element, '<br/>', moveLogHeading ); // Thanks [[User:Legoktm]], Stolen from [[User:Legoktm/massrename.js]] function rename_file( old, newname, reason, noRedirect, callback ) { ( new mw.Api() ).postWithToken ( 'csrf', { action: 'move', from: old, to: newname, reason: reason, movetalk: 1, noredirect: noRedirect }, { async: false // Don't run parallel requests, be nice to sever kittens! }) .done( callback ) .fail( callback ); } function escapeRegExp(str) { // From MDN return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"); } function missingAlertMsg ( str ) { return alert( "Did not find " + str + " :(" ); } function responeHanddler( data ) { var orderedList = $("<ul>").appendTo( moveLogHeading ); /* // If source page is not exist if ( data === "missingtitle") { orderedList.append( "<li> Page <b>" + pageToMoveByMassMover + "</b> not found. </li>" ); } // If old name and new name are same if ( data === "selfmove") { orderedList.append( "<li><b>" + pageToMoveByMassMover + "</b> no changes made. </li>" ); } */ if( data.move ) { orderedList.append( "<li><b>" + data.move.from + "</b> moved to <b>" + data.move.to + "</b>.</li>" ); } } moveStart.on( 'click', function() { pagesList = listofPages.getValue().replace(/^\s*[\r\n]/gm, '').split("\n"); var find = findInput.getValue().trim(); var replace = replaceInput.getValue().trim(); var reason = reasonInput.getValue().trim() + " (By [[meta:Indic-TechCom/Tools|MassMover]])"; var noRedirect = false; var AsRegex = treatAsRegexInside.isSelected(); if( pagesList[0].trim() !== "" && find !== "" && replace !== "" ) { moveLogHeading.empty(); $("<h1>").wrapInner( "<span class='mw-headline'>Move Log</span>").appendTo( moveLogHeading ); moveLogHeading.show(); } else { missingAlertMsg( "any source page" ); return; } if ( find === "" ) { missingAlertMsg( "\'find\' string" ); return; } if ( replace === "" ) { missingAlertMsg( "replace string" ); return; } var getParams = function (bltitle) { return { action: 'query', format: 'json', list: 'backlinks', bltitle: bltitle }; }, api = new mw.Api(); pagesList.forEach( function(page){ var p1 = api.get(getParams(page)), p2 = api.get(getParams('Talk:' + page)); Promise.all([p1, p2]).then( function ( data ) { if (data[0].query.backlinks.length === 0 && data[1].query.backlinks.length === 0) noRedirect = true; } ); // Lengthy name to aviod override in the global variable window.pageToMoveByMassMover = page.trim(); // Simple find/replace without Regex if ( !AsRegex ) { find = escapeRegExp(find); newPagename = pageToMoveByMassMover.replace( find, replace ); rename_file( pageToMoveByMassMover, newPagename, reason, noRedirect, responeHanddler ); } // Find/replace with Regex else { // Check whether the Regex is correct or not try { find = new RegExp( find, 'gi' ); } catch (e) { alert( "Regex Error: " + e ); // Hack to break the loop pagesList.length = 0; return; } newPagename = pageToMoveByMassMover.replace( find, replace ); rename_file( pageToMoveByMassMover, newPagename, reason, noRedirect, responeHanddler); } }); }); } // On every page $.when(mw.loader.using('mediawiki.util'), $.ready).then(function () { mw.util.addPortletLink( 'p-tb', mw.util.getUrl('Special:BlankPage/MassMover'), 'MassMover' ); }); if ( mw.config.get('wgCanonicalSpecialPageName') === 'Blankpage' && mw.config.get('wgTitle').split('/', 2)[1] === 'MassMover' ) { $.when(mw.loader.using('oojs-ui-core'), $.ready).then(function () { init(); }); } }); 72c2p2h3bjvsiatzetzz5ah5h7235hz 396488 396487 2022-08-29T01:45:55Z Lt2818 18630 javascript text/javascript /* This is userscirpt is usefull for Mass pages Move. @Author [[User:Jayprakash12345]] @Author from [[User:Legoktm/massrename.js]] @OwnBy [[meta:Indic-TechCom]] */ $( document ).ready( function() { function init() { $('#mw-content-text > p').remove(); $('#firstHeading').text('MassMover'); var listofPages = new OO.ui.MultilineTextInputWidget( { placeholder: 'List of Pages', autosize: true, rows: 10 } ), findInput = new OO.ui.TextInputWidget( { placeholder: 'Find' } ); replaceInput = new OO.ui.TextInputWidget( { placeholder: 'Replace' } ), reasonInput = new OO.ui.TextInputWidget( { placeholder: 'Reason' } ), treatAsRegex = new OO.ui.FieldLayout( treatAsRegexInside = new OO.ui.CheckboxInputWidget( { selected: false } ), { label: 'Treat search string as a regular expression', align: 'inline' } ), moveStart = new OO.ui.ButtonWidget( { label: 'Start Moving', icon: 'alert', flags: [ 'primary', 'progressive' ] } ), cancelBtn = new OO.ui.ButtonWidget( { label: 'Cancel', flags: [ 'primary', 'destructive' ], href: 'https:' + mw.config.get( 'wgServer' ) } ), moveLogHeading = $("<div>").hide(); label1 = $('<p>').text('List of Pages:').css('font-weight','bold' ); label2 = $('<p>').text('Find:').css('font-weight','bold' ); label3 = $('<p>').text('Replace:').css('font-weight','bold' ); label4 = $('<p>').text('Reason:').css('font-weight','bold' ); $( '#mw-content-text' ).append( label1, listofPages.$element, label2, findInput.$element, label3, replaceInput.$element, label4, reasonInput.$element, treatAsRegex.$element, '<br/>', moveStart.$element, cancelBtn.$element, '<br/>', moveLogHeading ); // Thanks [[User:Legoktm]], Stolen from [[User:Legoktm/massrename.js]] function rename_file( old, newname, reason, noRedirect, callback ) { ( new mw.Api() ).postWithToken ( 'csrf', { action: 'move', from: old, to: newname, reason: reason, movetalk: 1, noredirect: noRedirect }, { async: false // Don't run parallel requests, be nice to sever kittens! }) .done( callback ) .fail( callback ); } function escapeRegExp(str) { // From MDN return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"); } function missingAlertMsg ( str ) { return alert( "Did not find " + str + " :(" ); } function responeHanddler( data ) { var orderedList = $("<ul>").appendTo( moveLogHeading ); /* // If source page is not exist if ( data === "missingtitle") { orderedList.append( "<li> Page <b>" + pageToMoveByMassMover + "</b> not found. </li>" ); } // If old name and new name are same if ( data === "selfmove") { orderedList.append( "<li><b>" + pageToMoveByMassMover + "</b> no changes made. </li>" ); } */ if( data.move ) { orderedList.append( "<li><b>" + data.move.from + "</b> moved to <b>" + data.move.to + "</b>.</li>" ); } } moveStart.on( 'click', function() { pagesList = listofPages.getValue().replace(/^\s*[\r\n]/gm, '').split("\n"); var find = findInput.getValue().trim(); var replace = replaceInput.getValue().trim(); var reason = reasonInput.getValue().trim() + " (By [[meta:Indic-TechCom/Tools|MassMover]])"; var noRedirect = false; var AsRegex = treatAsRegexInside.isSelected(); if( pagesList[0].trim() !== "" && find !== "" && replace !== "" ) { moveLogHeading.empty(); $("<h1>").wrapInner( "<span class='mw-headline'>Move Log</span>").appendTo( moveLogHeading ); moveLogHeading.show(); } else { missingAlertMsg( "any source page" ); return; } if ( find === "" ) { missingAlertMsg( "\'find\' string" ); return; } if ( replace === "" ) { missingAlertMsg( "replace string" ); return; } var getParams = function (bltitle) { return { action: 'query', format: 'json', list: 'backlinks', bltitle: bltitle }; }, api = new mw.Api(); pagesList.forEach( function(page){ var p1 = api.get(getParams(page)), p2 = api.get(getParams('Talk:' + page)); Promise.all([p1, p2]).then( function ( data ) { if (data[0].query.backlinks.length === 0 && data[1].query.backlinks.length === 0) noRedirect = true; // Lengthy name to aviod override in the global variable window.pageToMoveByMassMover = page.trim(); // Simple find/replace without Regex if ( !AsRegex ) { find = escapeRegExp(find); newPagename = pageToMoveByMassMover.replace( find, replace ); rename_file( pageToMoveByMassMover, newPagename, reason, noRedirect, responeHanddler ); } // Find/replace with Regex else { // Check whether the Regex is correct or not try { find = new RegExp( find, 'gi' ); } catch (e) { alert( "Regex Error: " + e ); // Hack to break the loop pagesList.length = 0; return; } newPagename = pageToMoveByMassMover.replace( find, replace ); rename_file( pageToMoveByMassMover, newPagename, reason, noRedirect, responeHanddler); } } ); }); }); } // On every page $.when(mw.loader.using('mediawiki.util'), $.ready).then(function () { mw.util.addPortletLink( 'p-tb', mw.util.getUrl('Special:BlankPage/MassMover'), 'MassMover' ); }); if ( mw.config.get('wgCanonicalSpecialPageName') === 'Blankpage' && mw.config.get('wgTitle').split('/', 2)[1] === 'MassMover' ) { $.when(mw.loader.using('oojs-ui-core'), $.ready).then(function () { init(); }); } }); 8hjz3hdhae9m5p9shw7hfxx469t58hf 396489 396488 2022-08-29T01:50:09Z Lt2818 18630 移卟頁面嗰全部內容 javascript text/javascript phoiac9h4m842xq45sp7s6u21eteeq1