MediaWiki:Common.js: diferenças entre revisões
Conteúdo apagado Conteúdo adicionado
m Atualização |
Sincronização com mw:Snippets/Load JS and CSS by URL: Remoção do antigo módulo 'mediawiki.notify': a função mw.notify está disponível por padrão desde gerrit:583754 (ver também phab:T233676); Uso de encodeURIComponent |
||
Linha 4: | Linha 4: | ||
/** |
/** |
||
* @source https://www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL |
* @source https://www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL |
||
* @revision |
* @revision 2020-04-04 |
||
*/ |
*/ |
||
mw.loader.using( ['mediawiki.util |
mw.loader.using( ['mediawiki.util'], function () { |
||
var extraCSS = mw.util.getParamValue( 'withCSS' ), |
var extraCSS = mw.util.getParamValue( 'withCSS' ), |
||
extraJS = mw.util.getParamValue( 'withJS' ); |
extraJS = mw.util.getParamValue( 'withJS' ); |
||
if ( extraCSS ) { |
if ( extraCSS ) { |
||
// |
// WARNING: DO NOT REMOVE THIS "IF" - REQUIRED FOR SECURITY (against XSS/CSRF attacks) |
||
if ( /^MediaWiki:[^&<>=%#]*\.css$/.test( extraCSS ) ) { |
if ( /^MediaWiki:[^&<>=%#]*\.css$/.test( extraCSS ) ) { |
||
mw.loader.load( '/w/index.php?title=' + extraCSS + '&action=raw&ctype=text/css', 'text/css' ); |
mw.loader.load( '/w/index.php?title=' + encodeURIComponent( extraCSS ) + '&action=raw&ctype=text/css', 'text/css' ); |
||
} else { |
} else { |
||
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withCSS value' } ); |
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withCSS value' } ); |
||
Linha 20: | Linha 20: | ||
if ( extraJS ) { |
if ( extraJS ) { |
||
// |
// WARNING: DO NOT REMOVE THIS "IF" - REQUIRED FOR SECURITY (against XSS/CSRF attacks) |
||
if ( /^MediaWiki:[^&<>=%#]*\.js$/.test( extraJS ) ) { |
if ( /^MediaWiki:[^&<>=%#]*\.js$/.test( extraJS ) ) { |
||
mw.loader.load( '/w/index.php?title=' + extraJS + '&action=raw&ctype=text/javascript' ); |
mw.loader.load( '/w/index.php?title=' + encodeURIComponent( extraJS ) + '&action=raw&ctype=text/javascript' ); |
||
} else { |
} else { |
||
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } ); |
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } ); |
Edição atual desde as 13h26min de 6 de abril de 2020
/*jshint strict:false*/
/*global mw, $, importScript, importStylesheet*/
/**
* @source https://www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
* @revision 2020-04-04
*/
mw.loader.using( ['mediawiki.util'], function () {
var extraCSS = mw.util.getParamValue( 'withCSS' ),
extraJS = mw.util.getParamValue( 'withJS' );
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' } );
}
}
});
/**
* Variável global para uso em scripts que lidam com o nome dos livros
* @source: [[:en:MediaWiki:Gadget-predef.js]]
* @author: [[:en:User:Whiteknight]]
* @author: Helder (https://github.com/he7d3r)
* @example: 'A:B:C:D/E:F:G:H/I:J:K:L' -> 'A:B:C:D' -> 'A:B'
* @see: [[MediaWiki:Gadget-Common.js]] (alterações deste código devem ser duplicadas lá, para que seja usada pelos Gadgets)
*/
mw.config.set('wgBookName', mw.config.get('wgPageName').split('/', 1)[0] || mw.config.get('wgPageName'));
mw.config.set('wgBookName', mw.config.get('wgBookName').split(':', 2).join(':'));
// [[Categoria:Scripts do Wikilivros|Common.js]]