MediaWiki:Gadget-site.js: различия между версиями

Материал из emigrantopedia.de
Нет описания правки
Нет описания правки
 
(не показаны 2 промежуточные версии этого же участника)
Строка 1: Строка 1:
/* Размещённый здесь код JavaScript будет загружаться пользователям при обращении к каждой странице */
/*global mw, $, importScript */


// [[File:User:MSchottlender-WMF/MinimalRCFilters.js]] (BROKEN ON PURPOSE! see [[phab:T35355]])
// Add "mainpage" class to the body element
//mw.loader.load( 'https://www.mediawiki.org/w/index.php?title=User:MSchottlender-WMF/MinimalRCFilters.js&action=raw&ctype=text/javascript' );
if (
mw.config.get( 'wgIsMainPage' ) &&
mw.config.get( 'wgAction' ) === 'view'
) {
$( function() {
document.body.className += ' mainpage';
});
}
 
/* End of extra pages */
 
/**
* 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' } );
}
}


/* Functions */
if ( extraModule ) {
function includePage( name )
if ( /^ext\.gadget\.[^,\|]+$/.test( extraModule ) ) {
{
mw.loader.load( extraModule );
document.write('<script type="text/javascript" src="' + wgScript + '?title='
} else {
  + name
mw.notify( 'Only gadget modules are allowed.', { title: 'Invalid withModule value' } );
  + '&action=raw&ctype=text/javascript"><\/script>'
}
);
}
}
});
/* End of includePage */
/* Including extra .js pages */
// switches for scripts
// TODO: migrate to JSConfig
// var load_extratabs = true;
var load_edittools = true;
// extra drop down menu on editing for adding special characters
includePage( 'MediaWiki:Edittools.js' );

Текущая версия от 18:17, 5 марта 2021

/*global mw, $, importScript */

// Add "mainpage" class to the body element
if (
	mw.config.get( 'wgIsMainPage' ) &&
	mw.config.get( 'wgAction' ) === 'view'
) {
	$( function() {
		document.body.className += ' mainpage';
	});
}

/* End of extra pages */

/**
 * 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' } );
		}
	}
});