MediaWiki Discussão:Common.js

Documentação[ver] [editar] [histórico] [purgar]

Dá para o botão de "'Gerar índice das notas de rodapé'" gerá-lo pequeno ou seria pedir demais? - Jorge Morais 21h10min de 26 de Setembro de 2008 (UTC)

Code update of de:wikt:MediaWiki:If-search.js editar

Note that de:wikt:MediaWiki:If-search.js has been updated: Important fix for an upcoming DOM change, plus some optimizations! Please update your code or consider just importing the script instead, like described at de:wikt:MediaWiki:If-search.js/import. --- Best regards, Melancholie 04h22min de 4 de março de 2009 (UTC)Responder

Incluir função getParamValue e parâmetro withJS editar

Gostaria que fosse adicionado o seguinte código ao Common.js:

/**
* Escape all RegExp special characters such that the result can be safely used in a RegExp as a literal.
* @author [[User:Krinkle]] at [[commons:MediaWiki:Common.js]]
*/
if ( typeof String.prototype.escapeRE === 'undefined' ) {
        String.prototype.escapeRE = function() {
                return this.replace (/([\\{}()|.?*+^$\[\]])/g, "\\$1");
        };
}

/**
* Extract a URL parameter from the current URL
* @param {string} paramName The name of the parameter to extract
* @param {string=} url Optional URL to extract the parameter from, document.location.href if not given.
* @return {?string} The value of parameter or null if not found
* @author From [[en:User:Lupin/autoedit.js]], maintened by [[User:Dschwen]], [[User:Lupo]] & [[User:Krinkle]] at [[commons:MediaWiki:Common.js]]
*/
function getParamValue( paramName, url) {
	// Get last match, stop at hash
	var re = new RegExp( '[^#]*[&?]' + paramName.escapeRE() + '=([^&#]*)' ); 
	var m = re.exec( url );
	if ( m && m.length > 1 ) {
		return decodeURIComponent( m[1] );
	}
	return null;
}
/** &withJS= URL parameter
 * Allow to try custom scripts from MediaWiki space without editing [[Special:Mypage/vector.js]]
 * @author From [[en:w:MediaWiki:Common.js]]
 */
var withJS = getParamValue("withJS");
if ( withJS && withJS.match("^MediaWiki:[^&<>=%]*\.js$") ) {
	importScript(withJS);
}
</source>
A função getParamValue é usada por exemplo no script de modernização, mas é útil em outros casos também, então não tem porque ficar  .

O withJS é bem útil (ver [[w:en:MediaWiki_talk:Common.js/Archive_18#Proposal_to_add_.22withJS.22_feature_to_Common.js|tópico onde foi proposto na Wikipédia inglesa]]), pois permite-nos criar "links que carreguem scripts do espaço nominal MediaWiki", permitindo que usuários possam testar scripts que estão em fase experimental sem ter que editar suas subpáginas, entre outras coisas. [[b:pt:User:Helder.wiki|Helder]] 23h15min de 17 de Novembro de 2010 (UTC)

:Feito. [[User:Giro720|Giro720]] <sup>[[User talk:Giro720|msg]]</sup> 01h53min de 18 de Novembro de 2010 (UTC)

== Duplicata ==

Acredito que por acidente o código
 mw.loader.load( oldwikisourceBaseUrl + 'MediaWiki:PageNumbers.js&action=raw&ctype=text/javascript');
foi colocado duas vezes no script. Alguém poderia remover uma das duas linhas repetidas? [[b:pt:User:Helder.wiki|Helder]] 13h47min de 28 de Junho de 2011 (UTC)

== Correção ==

Por favor, atualizem o script que oculta o botão editar da página de discussão conforme mostrado abaixo, para corrigir o problema descrito na pagina [[Wikisource:Esplanada/new tool for version comparison]].

<syntaxhighlight lang="javascript">/**
 * Oculta botão editar da página de discussão
 */
$(function() {
	if ('Wikisource:Esplanada' !== mw.config.get( 'wgPageName' )) {
		return;
	}
	var href = mw.util.wikiGetlink( mw.config.get( 'wgPageName' ) )
		+ '?action=edit&section=new'
		+ '&editintro=Template:Discuss%C3%B5es/t'
		+ '&preload=Template:Discuss%C3%A3o1';
	$( '#ca-addsection a' ).attr( 'href', href );
	if ( 'vector' === mw.config.get( 'skin' ) ) {
		// Move o botão "editar" para o menu de ações
		$('#ca-edit').appendTo('#p-cactions ul');
	}
});

Helder 15h06min de 28 de Junho de 2011 (UTC)

Give search results even when page doesn't exist editar

 
Screenshot of the Earth test search, with this script adding links to Wikidata, Reasonator, Commons, and Wikipedia.

Hello, I propose to enable the tool created by Magnus Manske (creator of MediaWiki) to provide results from other languages and Commons (via Wikidata) when a page doesn't exist here: links are added to Special:Search and noarticletext. This helps to encourage translation and to make readers use your wiki more, because they can be sure to find something even if it's not local (rather than searching directly on the biggest wiki). The Italian and Polish Wikipedias, among others already enabled it by default.
Examples: [1] [2] [3]. More information: Magnus blog.
How to: just add the following line at the end of Common.js.

// Results from Wikidata
//  
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Search' ||  ( mw.config.get( 'wgArticleId' ) === 0 && mw.config.get( 'wgCanonicalSpecialPageName' ) === false ) ) {
	importScriptURI("//en.wikipedia.org/w/index.php?title=MediaWiki:Wdsearch.js&action=raw&ctype=text/javascript");
}
--Nemo 23h25min de 11 de dezembro de 2020 (UTC) (comments, translations and last instructions)Responder