User:PB2008/script-installer.js: Difference between revisions

Jump to navigation Jump to search
m
no edit summary
mNo edit summary
mNo edit summary
Tags: Mobile edit Mobile web edit
 
(10 intermediate revisions by the same user not shown)
Line 9: Line 9:


     // How many scripts do we need before we show the quick filter?
     // How many scripts do we need before we show the quick filter?
     var NUM_SCRIPTS_FOR_SEARCH = 5;
     var NUM_SCRIPTS_FOR_SEARCH = 3;


     // The master import list. Set in buildImportList
     // The master import list. Set in buildImportList
Line 21: Line 21:


     // Goes on the end of edit summaries
     // Goes on the end of edit summaries
     var ADVERT = " ([[User:JJBullet/script-installer-core.js|script-installer]])";
     var ADVERT = " ([[MediaWiki:Gadget-script-installer|script-installer]])";


     /**
     /**
Line 27: Line 27:
     */
     */
     var STRINGS = {
     var STRINGS = {
         installSummary: "Installing $1",
         installSummary: "安裝$1",
         uninstallSummary: "Uninstalling $1",
        installLinkText: "安裝",
         remoteUrlDesc: "$1, loaded from $2",
        installProgressMsg: "安裝中...",
         disableSummary: "Disabling $1",
         uninstallSummary: "解除安裝$1",
         enableSummary: "Enabling $1",
         uninstallLinkText: "解除安裝",
         normalizeSummary: "Normalizing script installs",
        uninstallProgressMsg: "解除安裝中...",
         panelHeader: "You currently have the following scripts installed",
         disableSummary: "停用$1",
         cannotInstall: "Cannot install",
        disableLinkText: "停用",
         moveLinkText: "Move",
        disableProgressMsg: "停用中...",
         moveProgressMsg: "Moving",
         enableSummary: "啟用$1",
         insecure: "Insecure"
        enableLinkText: "啟用",
        enableProgressMsg: "啟用中...",
        moveLinkText: "移動",
        moveProgressMsg: "移動中...",
        movePrompt: "您想移動至哪裡?請輸入以下選項之一:", // followed by the names of skins
         normalizeSummary: "標準化腳本安裝",
        remoteUrlDesc: "從 $2 的 $1 開始讀取",
         panelHeader: "目前已安裝以下腳本:",
         cannotInstall: "無法安裝",
         cannotInstallSkin: "此頁面是您的使用者自訂頁面之一,並且可能已經在頁面載入時執行(在common.js的情況下)。",
         cannotInstallContentModel: "頁面的內容模型是$1。 這不是“javascript”。",
         insecure: "不安全", // used at the end of some messages
        notJavaScript: "不是JavaScript",
        installViaPreferences: "從偏好設定安裝",
        showNormalizeLinks: '您想顯示“標準化”連結嗎?',
        showMoveLinks: '您想顯示“移動”連結嗎?',
        quickFilter: "簡易過濾器:",
        tempWarning: "從使用者子頁面或受MediaWiki命名空間之外保護的頁面進行的安裝是臨時的,可能會在某個時候被刪除。",
        badPageError: "頁面不是User或MediaWiki命名空間內,且不受保護",
        manageUserScripts: "管理用戶腳本",
        bigSecurityWarning: "警告!$1 使用者腳本可能包含可能危害您帳號的惡意內容。 安裝此腳本意味著您的帳戶可能會被其他人接管。 安裝前請確保您信任作者。 如果您不確定腳本是否安全,請不要安裝。 您要安裝此腳本嗎?(下次要隱藏此對話框,請在 common.js 中寫入 sciNoConfirm=true;))",
        securityWarningSection: "你相信「$1」嗎?"
     };
     };


Line 70: Line 91:
         if( disabled === undefined ) disabled = false;
         if( disabled === undefined ) disabled = false;
         return new Import( page, null, null, target, disabled );
         return new Import( page, null, null, target, disabled );
     }
     };


     /** URL to Import. Assumes wgScriptPath is "/w" */
     /** URL to Import. Assumes wgScriptPath is "/w" */
Line 336: Line 357:
                 $( "<label>" )
                 $( "<label>" )
                     .attr( "for", "siNormalize" )
                     .attr( "for", "siNormalize" )
                     .text( 'Show "normalize" links?' ),
                     .text( '顯示“標準化”連結?' ),
                 $( "<input>" )
                 $( "<input>" )
                     .attr( { "id": "siMove", "type": "checkbox" } )
                     .attr( { "id": "siMove", "type": "checkbox" } )
Line 344: Line 365:
                 $( "<label>" )
                 $( "<label>" )
                     .attr( "for", "siMove" )
                     .attr( "for", "siMove" )
                     .text( 'Show "move" links?' ) ) );
                     .text( '顯示"移動"連結?' ) ) );
         if( scriptCount > NUM_SCRIPTS_FOR_SEARCH ) {
         if( scriptCount > NUM_SCRIPTS_FOR_SEARCH ) {
             container.append( $( "<div>" )
             container.append( $( "<div>" )
Line 351: Line 372:
                     $( "<label>" )
                     $( "<label>" )
                         .attr( "for", "siQuickFilter" )
                         .attr( "for", "siQuickFilter" )
                         .text( "Quick filter:" ),
                         .text( "簡易過濾器:" ),
                     $( "<input>" )
                     $( "<input>" )
                         .attr( { "id": "siQuickFilter", "type": "text" } )
                         .attr( { "id": "siQuickFilter", "type": "text" } )
Line 373: Line 394:
         $.each( imports, function ( targetName, targetImports ) {
         $.each( imports, function ( targetName, targetImports ) {
             var fmtTargetName = ( targetName === "common"
             var fmtTargetName = ( targetName === "common"
                 ? "common (applies to all skins)"
                 ? "common (適用於所有介面)"
                 : targetName );
                 : targetName );
                 if( targetImports.length ) {
                 if( targetImports.length ) {
Line 384: Line 405:
                             " (",
                             " (",
                             $( "<a>" )
                             $( "<a>" )
                                 .text( "normalize" )
                                 .text( "標準化" )
                                 .click( function () {
                                 .click( function () {
                                     normalize( targetName ).done( function () {
                                     normalize( targetName ).done( function () {
Line 404: Line 425:
                                         " (",
                                         " (",
                                         $( "<a>" )
                                         $( "<a>" )
                                             .text( "Uninstall" )
                                             .text( "解除安裝" )
                                             .click( function () {
                                             .click( function () {
                                                 $( this ).text( "Uninstalling..." );
                                                 $( this ).text( "正在解除安裝..." );
                                                 anImport.uninstall().done( function () {
                                                 anImport.uninstall().done( function () {
                                                     conditionalReload( true );
                                                     conditionalReload( true );
Line 413: Line 434:
                                         " | ",
                                         " | ",
                                         $( "<a>" )
                                         $( "<a>" )
                                             .text( anImport.disabled ? "Enable" : "Disable" )
                                             .text( anImport.disabled ? "啟用" : "取消啟用" )
                                             .click( function () {
                                             .click( function () {
                                                 $( this ).text( $( this ).text().replace( /e$/, "ing" ) );
                                                 $( this ).text( $( this ).text().replace( /e$/, "ing" ) );
Line 426: Line 447:
                                             " | ",
                                             " | ",
                                             $( "<a>" )
                                             $( "<a>" )
                                                 .text( "Move" )
                                                 .text( "移動" )
                                                 .click( function () {
                                                 .click( function () {
                                                     var dest = null;
                                                     var dest = null;
                                                     var PROMPT = "Destination? Enter one of: " + SKINS.join( ", " );
                                                     var PROMPT = "目的地?輸入其中一個:" + SKINS.join( ", " );
                                                     do {
                                                     do {
                                                         dest = ( window.prompt( PROMPT ) || "" ).toLowerCase();
                                                         dest = ( window.prompt( PROMPT ) || "" ).toLowerCase();
                                                     } while( dest && SKINS.indexOf( dest ) < 0 )
                                                     } while( dest && SKINS.indexOf( dest ) < 0 )
                                                     if( !dest ) return;
                                                     if( !dest ) return;
                                                     $( this ).text( "Moving" );
                                                     $( this ).text( "移動中" );
                                                     anImport.move( dest ).done( function () {
                                                     anImport.move( dest ).done( function () {
                                                         conditionalReload( true );
                                                         conditionalReload( true );
Line 465: Line 486:
                     var skinIndex = SKINS.indexOf( pageName.substring( prefixLength ).slice( 0, -3 ) );
                     var skinIndex = SKINS.indexOf( pageName.substring( prefixLength ).slice( 0, -3 ) );
                     if( skinIndex >= 0 ) {
                     if( skinIndex >= 0 ) {
                         return $( "<abbr>" ).text( "Cannot install" )
                         return $( "<abbr>" ).text( "不能安裝" )
                                 .attr( "title", "This page is one of your user customization pages, and " +
                                 .attr( "title", "此頁面是你的使用者自訂頁面之一,並且" +
                                         ( ( skinIndex === 0 ) ? "will" : "may" ) + " already run on each page load." );
                                         ( ( skinIndex === 0 ) ? "" : "可能" ) + "已經在每個頁面加載時運行。" );
                     }
                     }
                 }
                 }
                 addingInstallLink = true;
                 addingInstallLink = true;
             } else {
             } else {
                 return $( "<abbr>" ).text( "Cannot install (not JS)" )
                 return $( "<abbr>" ).text( "不能安裝 (不是 JS)" )
                         .attr( "title", "Page content model is " + contentModel + ", not 'javascript'" );
                         .attr( "title", "頁面內容模型是" + contentModel + ",不是'javascript'" );
             }
             }
         }
         }
Line 479: Line 500:
         // Namespace 8 is MediaWiki
         // Namespace 8 is MediaWiki
         if( namespaceNumber === 8 ) {
         if( namespaceNumber === 8 ) {
             return $( "<a>" ).text( "Install via preferences" )
             return $( "<a>" ).text( "經偏好設定安裝" )
                     .attr( "href", mw.util.getUrl( "Special:Preferences" ) + "#mw-prefsection-gadgets" );
                     .attr( "href", mw.util.getUrl( "Special:Preferences" ) + "#mw-prefsection-gadgets" );
         }
         }
Line 490: Line 511:
                 $( "<abbr>" ).append(
                 $( "<abbr>" ).append(
                     $( "<img>" ).attr( "src", "https://upload.wikimedia.org/wikipedia/commons/thumb/3/35/Achtung-yellow.svg/20px-Achtung-yellow.svg.png" ).addClass( "warning" ),
                     $( "<img>" ).attr( "src", "https://upload.wikimedia.org/wikipedia/commons/thumb/3/35/Achtung-yellow.svg/20px-Achtung-yellow.svg.png" ).addClass( "warning" ),
                     "(insecure)" )
                     "(不安全)" )
                 .attr( "title", "Installation of non-User, non-MediaWiki"+
                 .attr( "title", "不是User空間或MediaWiki空間的安裝"+
                     " protected pages is temporary and may be removed in the future." ) );
                     "受保護的頁面是臨時的,將來可能會被刪除。" ) );
             addingInstallLink = true;
             addingInstallLink = true;
         }
         }
Line 500: Line 521:
             installElement.prepend( $( "<a>" )
             installElement.prepend( $( "<a>" )
                     .attr( "id", "script-installer-main-install" )
                     .attr( "id", "script-installer-main-install" )
                     .text( localScriptsByName[ fixedPageName ] ? "Uninstall" : "Install" )
                     .text( localScriptsByName[ fixedPageName ] ? "取消安裝" : "安裝" )
                     .click( makeLocalInstallClickHandler( fixedPageName ) ) );
                     .click( makeLocalInstallClickHandler( fixedPageName ) ) );
             return installElement;
             return installElement;
         }
         }


         return $( "<abbr>" ).text( "Cannot install (insecure)" )
         return $( "<abbr>" ).text( "不能安裝 (不安全)" )
                 .attr( "title", "Page is not User: or MediaWiki: and is unprotected" );
                 .attr( "title", "頁面不是位於用戶空間或MediaWiki空間,且未被保護" );
     }
     }


Line 517: Line 538:
                 " | ",
                 " | ",
                 $( "<a>" )
                 $( "<a>" )
                     .text( "Manage user scripts" ).click( function () {
                     .text( "管理用戶小工具" ).click( function () {
                         if( !document.getElementById( "script-installer-panel" ) ) {
                         if( !document.getElementById( "script-installer-panel" ) ) {
                             $( "#mw-content-text" ).before( makePanel() );
                             $( "#mw-content-text" ).before( makePanel() );
Line 532: Line 553:
             var scriptName = this.id;
             var scriptName = this.id;
             $( this ).append( " | ", $( "<a>" )
             $( this ).append( " | ", $( "<a>" )
                     .text( localScriptsByName[ scriptName ] ? "Uninstall" : "Install" )
                     .text( localScriptsByName[ scriptName ] ? "解除安裝" : "安裝" )
                     .click( makeLocalInstallClickHandler( scriptName ) ) );
                     .click( makeLocalInstallClickHandler( scriptName ) ) );
         } );
         } );
Line 545: Line 566:
                     .append( $( "<button>" )
                     .append( $( "<button>" )
                         .addClass( "mw-ui-button mw-ui-progressive mw-ui-big" )
                         .addClass( "mw-ui-button mw-ui-progressive mw-ui-big" )
                         .text( localScriptsByName[ scriptName ] ? "Uninstall" : "Install" )
                         .text( localScriptsByName[ scriptName ] ? "解決安裝" : "安裝" )
                         .click( makeLocalInstallClickHandler( scriptName ) ) ) ) );
                         .click( makeLocalInstallClickHandler( scriptName ) ) ) ) );
         } );
         } );
Line 553: Line 574:
         return function () {
         return function () {
             var $this = $( this );
             var $this = $( this );
             if( $this.text() === "Install" ) {
             if( $this.text() === "安裝" ) {
                 var okay = window.sciNoConfirm || window.confirm( "Warning! All user scripts could contain malicious content capable of compromising your account. Installing a script means it could be changed by others; make sure you trust its author. If you're unsure whether a script is safe, check at the technical village pump. Install this script? (Hide this dialog next time with sciNoConfirm=true; in your common.js.)" );
                 var okay = window.sciNoConfirm || window.confirm( "Warning! All user scripts could contain malicious content capable of compromising your account. Installing a script means it could be changed by others; make sure you trust its author. If you're unsure whether a script is safe, check at the technical village pump. Install this script? (Hide this dialog next time with sciNoConfirm=true; in your common.js.)" );
                 if( okay ) {
                 if( okay ) {
                     $( this ).text( "Installing..." )
                     $( this ).text( "安裝中..." )
                     Import.ofLocal( scriptName, "common" ).install().done( function () {
                     Import.ofLocal( scriptName, "common" ).install().done( function () {
                         $( this ).text( "Uninstall" );
                         $( this ).text( "解除安裝" );
                         conditionalReload( false );
                         conditionalReload( false );
                     }.bind( this ) );
                     }.bind( this ) );
                 }
                 }
             } else {
             } else {
                 $( this ).text( "Uninstalling..." )
                 $( this ).text( "解除安裝中..." )
                 var uninstalls = uniques( localScriptsByName[ scriptName ] )
                 var uninstalls = uniques( localScriptsByName[ scriptName ] )
                         .map( function ( target ) { return Import.ofLocal( scriptName, target ).uninstall(); } )
                         .map( function ( target ) { return Import.ofLocal( scriptName, target ).uninstall(); } )
                 $.when.apply( $, uninstalls ).then( function () {
                 $.when.apply( $, uninstalls ).then( function () {
                     $( this ).text( "Install" );
                     $( this ).text( "安裝" );
                     conditionalReload( false );
                     conditionalReload( false );
                 }.bind( this ) );
                 }.bind( this ) );
Line 665: Line 686:
             if( document.cookie.indexOf( "open_script_installer=yes" ) >= 0 ) {
             if( document.cookie.indexOf( "open_script_installer=yes" ) >= 0 ) {
                 document.cookie = "open_script_installer=; expires=Thu, 01 Jan 1970 00:00:01 GMT";
                 document.cookie = "open_script_installer=; expires=Thu, 01 Jan 1970 00:00:01 GMT";
                 $( "#script-installer-top-container a:contains('Manage')" ).trigger( "click" );
                 $( "#script-installer-top-container a:contains('管理')" ).trigger( "click" );
             }
             }
         } );
         } );
     } );
     } );
} )();
} )();
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu