MediaWiki:Gadget-site.js

    来自真佛百科

    注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。

    • Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5Ctrl-R(Mac为⌘-R
    • Google Chrome:Ctrl-Shift-R(Mac为⌘-Shift-R
    • Internet Explorer或Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
    • Opera:Ctrl-F5
    /* global mw, $ */
    /**
     * Hide prefix in category
     *
     * @source www.mediawiki.org/wiki/Snippets/Hide_prefix_in_category
     * @rev 5
     */
    var prefix = $.trim( $( '#mw-cat-hideprefix' ).text() ) || ( mw.config.get( 'wgTitle' ) + '/' );
    $( '#mw-pages' ).find( 'a' ).text( function ( i, val ) {
        return val.slice( 0, prefix.length ) === prefix ? val.slice( prefix.length ) : val;
    } );
    
    /**
     * @source https://www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
     * @revision 2017-05-16
     */
    mw.loader.using( ['mediawiki.util'], function () {
    	var extraCSS = mw.util.getParamValue( 'withCSS' ),
    		extraJS = mw.util.getParamValue( 'withJS' ),
    		extraModule = mw.util.getParamValue( 'withModule' );
    
    	if ( extraCSS ) {
    		// WARNING: DO NOT REMOVE THIS "IF" - REQUIRED FOR SECURITY (against XSS/CSRF attacks)
    		if ( /^MediaWiki:[^&<>=%#]*\.css$/.test( extraCSS ) ) {
    			mw.loader.load( '/w/index.php?title=' + encodeURIComponent( extraCSS ) + '&action=raw&ctype=text/css', 'text/css' );
    		} else {
    			mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withCSS value' } );
    		}
    	}
    
    	if ( extraJS ) {
    		// WARNING: DO NOT REMOVE THIS "IF" - REQUIRED FOR SECURITY (against XSS/CSRF attacks)
    		if ( /^MediaWiki:[^&<>=%#]*\.js$/.test( extraJS ) ) {
    			mw.loader.load( '/w/index.php?title=' + encodeURIComponent( extraJS ) + '&action=raw&ctype=text/javascript' );
    		} else {
    			mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
    		}
    	}
    
    	if ( extraModule ) {
    		if ( /^ext\.gadget\.[^,\|]+$/.test( extraModule ) ) {
    			mw.loader.load( extraModule );
    		} else {
    			mw.notify( 'Only gadget modules are allowed.', { title: 'Invalid withModule value' } );
    		}
    	}
    });
    
    
    // TemplateScripts are JavaScript scripts that extend the functionality of templates
    var templatescripts = [];
    $( '#mw-content-text' ).find( '[data-templatescript]' ).each( function () {
    	var script = $( this ).data( 'templatescript' );
    	if ( script && !templatescripts.includes( script ) && /^[^&<>=%#]*\.js$/.test( script ) ) {
    		templatescripts.push( script );
    		script = encodeURIComponent( script );
    		mw.loader.load( '/wiki/MediaWiki:TemplateScript-' + script + '?action=raw&ctype=text/javascript' );
    	}
    } );