«MediaWiki:Common.js» e «Wikipedia:Zona de probas»: Diferenzas entre as páxinas

(Diferenzas entre páxinas)
Páxina 1
Páxina 2
Contido eliminado Contido engadido
Toliño (conversa | contribucións)
Sen resumo de edición
 
He7d3r (conversa | contribucións)
m Migração para MW 1.17 e jQuery: addOnloadHook$; getParamValuemw.util.getParamValue; addPortletLinkmw.util.addPortletLink; str.escapeRE()$.escapeRE(str); wg*mw.config.get('wg*'); a==1||a==2$.inArray(a,[1,2])!==-1...
 
Liña 1: Liña 1:
// Overwriting deprecated functions
//<source lang="javascript">
// Map addPortletLink to mw.util
window.addPortletLink = function(){
return mw.util.addPortletLink.apply( mw.util, arguments );
};


/** "Technical restrictions" title fix *****************************************
/** "Technical restrictions" title fix *****************************************
Liña 16: Liña 20:
// </nowiki>An element with id=DisableRealTitle disables the function.
// </nowiki>An element with id=DisableRealTitle disables the function.
var disableRealTitle = 0; // users can disable this by making this true from their monobook.js
var disableRealTitle = 0; // users can disable this by making this true from their monobook.js
if (wgIsArticle) { // don't display the RealTitle when editing, since it is apparently inconsistent (doesn't show when editing sections, doesn't show when not previewing)
if (mw.config.get( 'wgIsArticle' )) { // don't display the RealTitle when editing, since it is apparently inconsistent (doesn't show when editing sections, doesn't show when not previewing)
addOnloadHook(function() {
$(function() {
try {
try {
var realTitleBanner = document.getElementById("RealTitleBanner");
var realTitleBanner = document.getElementById("RealTitleBanner");
Liña 34: Liña 38:
// if the namespace prefix is there, remove it on our verification copy. If it isn't there, add it to the original realValue copy.
// if the namespace prefix is there, remove it on our verification copy. If it isn't there, add it to the original realValue copy.
if (wgNamespaceNumber != 0) {
if (mw.config.get( 'wgNamespaceNumber' ) != 0) {
if (wgCanonicalNamespace == verifyTitle.substr(0, wgCanonicalNamespace.length).replace(/ /g, "_") && verifyTitle.charAt(wgCanonicalNamespace.length) == ":") {
if (mw.config.get( 'wgCanonicalNamespace' ) == verifyTitle.substr(0, mw.config.get( 'wgCanonicalNamespace' ).length).replace(/ /g, "_") && verifyTitle.charAt(mw.config.get( 'wgCanonicalNamespace' ).length) == ":") {
verifyTitle = verifyTitle.substr(wgCanonicalNamespace.length + 1);
verifyTitle = verifyTitle.substr(mw.config.get( 'wgCanonicalNamespace' ).length + 1);
} else {
} else {
realTitleText = wgCanonicalNamespace.replace(/_/g, " ") + ":" + realTitleText;
realTitleText = mw.config.get( 'wgCanonicalNamespace' ).replace(/_/g, " ") + ":" + realTitleText;
realTitleHTML = wgCanonicalNamespace.replace(/_/g, " ") + ":" + realTitleHTML;
realTitleHTML = mw.config.get( 'wgCanonicalNamespace' ).replace(/_/g, " ") + ":" + realTitleHTML;
}
}
}
}
// verify whether wgTitle matches
// verify whether mw.config.get( 'wgTitle' ) matches
verifyTitle = verifyTitle.replace(/^ +/, "").replace(/ +$/, ""); // trim left and right spaces
verifyTitle = verifyTitle.replace(/^ +/, "").replace(/ +$/, ""); // trim left and right spaces
verifyTitle = verifyTitle.replace(/_/g, " "); // underscores to spaces
verifyTitle = verifyTitle.replace(/_/g, " "); // underscores to spaces
verifyTitle = verifyTitle.charAt(0).toUpperCase() + verifyTitle.substring(1, verifyTitle.length); // uppercase first character
verifyTitle = verifyTitle.charAt(0).toUpperCase() + verifyTitle.substring(1, verifyTitle.length); // uppercase first character
isPasteable = (verifyTitle == wgTitle);
isPasteable = (verifyTitle == mw.config.get( 'wgTitle' ));
var h1 = document.getElementsByTagName("h1")[0];
var h1 = document.getElementsByTagName("h1")[0];
Liña 87: Liña 91:


//HIDDENCAT (mostra as categorías ocultas).
//HIDDENCAT (mostra as categorías ocultas).
//@deprecated: Use $( 'algum seletor' ).addClass( 'nome da classe' )
function addClass(node, className) {
function addClass(node, className) {
if (hasClass(node, className)) {
if (hasClass(node, className)) {
Liña 94: Liña 99:
return true;
return true;
}
}

function eregReplace(search, replace, subject) {
function eregReplace(search, replace, subject) {
return subject.replace(new RegExp(search,'g'), replace);
return subject.replace(new RegExp(search,'g'), replace);
}
}

// @deprecated: Use $( 'algum seletor' ).removeClass( 'nome da classe' )
function removeClass(node, className) {
function removeClass(node, className) {
if (!hasClass(node, className)) {
if (!hasClass(node, className)) {
Liña 106: Liña 112:
return true;
return true;
}
}

// @deprecated: Use $( 'algum seletor' ).hasClass( 'nome da classe' )
function isClass(element, classe) {
function isClass(element, classe) {
return hasClass(element, classe);
return hasClass(element, classe);
Liña 144: Liña 151:
}
}
addOnloadHook(hiddencat);
$(hiddencat);




Liña 166: Liña 173:
}
}
}
}
addOnloadHook( LinkFA );
$( LinkFA );




Liña 264: Liña 271:
}
}


addOnloadHook( createCollapseButtons );
$( createCollapseButtons );




Liña 271: Liña 278:
* Description: Uses regular expressions and caching for better performance.
* Description: Uses regular expressions and caching for better performance.
* Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]]
* Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]]
* @deprecated: Use $( 'algum seletor' ).hasClass( 'nome da classe' )
*/
*/
Liña 421: Liña 429:
/**
/**
* Desactivar o botón "Gardar a páxina" aos usuarios anónimos que non usen antes o botón "Mostrar a vista previa"
* Desactivar o botón "Gardar a páxina" aos usuarios anónimos que non usen antes o botón "Mostrar a vista previa"
* @source: [[b:pt:MediaWiki:Common.js/edit.js]] & [[w:fr:MediaWiki:Common.js/edit.js]]
* Copyright Marc Mongenet, 2006 (fr.wikipedia.org)
* @author: Copyright Marc Mongenet, 2006 (fr.wikipedia.org)
* Plyd 05/2007: add "after preview" in the button to prevent misunderstanding from beginners
* @see: [[mw:Manual:Force preview]]
* Toliño 26/06/08: traído a gl.wikipedia
*/
*/
function forcePreview() {
$( function() {
var $save = $( '#wpSave' );
if (wgUserName != null || wgAction != "edit") return;
if ( mw.config.get( 'wgUserName' ) !== null || mw.config.get( 'wgAction' ) !== 'edit' || $save.length === 0 ) {
saveButton = document.getElementById("wpSave");
if (!saveButton) return;
return;
}
saveButton.disabled = true;
$save.attr( 'disabled', 'disabled' )
saveButton.value = "Gardar (use antes a vista previa!)";
.attr( 'value', 'Gardar (use antes a vista previa!)' )
saveButton.style.fontWeight = "normal";
.css( 'font-weight', 'normal' );
document.getElementById("wpPreview").style.fontWeight = "bold";
$( '#wpPreview' ).css( 'font-weight', 'bold' );
}
});

addOnloadHook(forcePreview);


/** Para administradores *****************************************
/** Para administradores *****************************************
Liña 441: Liña 449:
* Descrición: Permite cargar o Javascript específico para administradores presente en [[MediaWiki:Sysop.js]].
* Descrición: Permite cargar o Javascript específico para administradores presente en [[MediaWiki:Sysop.js]].
*/
*/
if ( wgUserGroups ) {
if ( $.inArray( 'sysop', mw.config.get( 'wgUserGroups' ) ) > -1 ) {
importStylesheet('MediaWiki:Sysop.css');
for ( var g = 0; g < wgUserGroups.length; ++g ) {
if ( wgUserGroups[g] == "sysop" ) {
if ( !window.disableSysopJS ) {
$(function(){
importStylesheet("MediaWiki:Sysop.css");
importScript('MediaWiki:Sysop.js');
addOnloadHook( function() {
});
if ( !window.disableSysopJS ) {
}
importScript("MediaWiki:Sysop.js");
}
} );
}
}
}
}
Liña 460: Liña 464:
*/
*/
if (wgPageName == 'Portada' || wgPageName == 'Conversa:Portada')
if ($.inArray( mw.config.get('wgPageName'), [ 'Portada', 'Conversa:Portada' ]) > -1)
addOnloadHook(function () {
$(function () {
addPortletLink('p-lang', 'http://meta.wikimedia.org/wiki/List_of_Wikipedias',
mw.util.addPortletLink('p-lang', 'http://meta.wikimedia.org/wiki/List_of_Wikipedias',
'Lista completa', 'interwiki-completelist', 'Lista completa de wikipedias')
'Lista completa', 'interwiki-completelist', 'Lista completa de wikipedias')
var nstab = document.getElementById('ca-nstab-main')
var nstab = document.getElementById('ca-nstab-main')
if (nstab && wgUserLanguage=='gl') {
if (nstab && mw.config.get( 'wgUserLanguage' )=='gl') {
while (nstab.firstChild) nstab = nstab.firstChild
while (nstab.firstChild) nstab = nstab.firstChild
nstab.nodeValue = 'Portada'
nstab.nodeValue = 'Portada'
Liña 471: Liña 475:
}
}
)
)

//


/**
/**
* Escape all RegExp special characters such that the result can be safely used in a RegExp as a literal.
* 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]]
* @author [[User:Krinkle]] at [[commons:MediaWiki:Common.js]]
* @deprecated: Use $.escapeRE( string )
*/
*/
if ( typeof String.prototype.escapeRE === 'undefined' ) {
if ( typeof String.prototype.escapeRE === 'undefined' ) {
Liña 483: Liña 486:
};
};
}
}

/**
* 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
/** &withJS= URL parameter
* Allow to try custom scripts from MediaWiki space without editing [[Special:Mypage/vector.js]]
* Allow to try custom scripts from MediaWiki space without editing [[Special:Mypage/vector.js]]
* @author From [[en:w:MediaWiki:Common.js]]
* @author From [[en:w:MediaWiki:Common.js]]
*/
*/
var withJS = getParamValue("withJS");
var withJS = mw.util.getParamValue("withJS");
if ( withJS && withJS.match("^MediaWiki:[^&<>=%]*\.js$") ) {
if ( withJS && withJS.match("^MediaWiki:[^&<>=%]*\.js$") ) {
importScript(withJS);
importScript(withJS);
}
}
</source>