MediaWiki:Common.js
Nota: Depois de publicar, poderá ter de contornar a cache do seu navegador para ver as alterações.
- Firefox / Safari: Pressione Shift enquanto clica Recarregar, ou pressione Ctrl-F5 ou Ctrl-R (⌘-R no Mac)
- Google Chrome: Pressione Ctrl-Shift-R (⌘-Shift-R no Mac)
- Edge: Pressione Ctrl enquanto clica Recarregar, ou pressione Ctrl-F5.
/* Qualquer código JavaScript presente aqui será carregado por todos os usuários em cada página carregada. */
/*jshint camelcase: true, curly: true, eqeqeq: true, immed: true, latedef: true, newcap: true, noarg: true, noempty: true, nonew: true, quotmark: single, trailing: true, undef: true, unused: true, bitwise: true, forin: true, regexp: true, strict: true, onevar: true, laxbreak: true */
/*global mw, $ */
( function () {
'use strict';
/**
* Oculta botão editar da [[Wikipédia:Esplanada/propostas]] e da [[Wikipédia:Esplanada/geral]]
*
* @author: Helder (https://github.com/he7d3r)
* @license: CC BY-SA 3.0 <https://creativecommons.org/licenses/by-sa/3.0/>
*/
/* Desativado por causar erro: $.collapsibleTabs.getSettings(...) is undefined ([[phab:T177108]])
mw.loader.using( 'mediawiki.util', function () {
function hideEditButton() {
var temp = 'Template:Esplanada2/Preload';
if ( mw.config.get( 'wgUserLanguage' ) !== 'pt' ) {
temp += '/en';
}
$( '#ca-addsection' ).find( 'a' ).attr(
'href',
mw.util.getUrl( mw.config.get( 'wgPageName' ), {
action: 'edit',
section: 'new',
preload: temp
} )
);
if ( mw.config.get( 'skin' ) === 'vector' ) {
// Move o botão "editar" para o menu de ações
$( '#p-cactions' ).removeClass( 'emptyPortlet' ).find( 'ul' ).append( $( '#ca-edit' ) );
}
}
if ( $.inArray( mw.config.get( 'wgPageName' ), [ 'Wikipédia:Esplanada/propostas', 'Wikipédia:Esplanada/geral' ] ) !== -1 ) {
$( hideEditButton );
}
});*/
/**
* Parâmetros &withCSS= e &withJS= para a URL
*
* Permite que sejam testados scripts e folhas de estilos do domínio MediaWiki
* sem precisar editar páginas ".css" ou ".js" pessoais
* @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=' + extraCSS + '&action=raw&ctype=text/css', 'text/css' );
} else {
mw.notify( 'Só são permitidas páginas do domínio MediaWiki.', { title: 'Valor withCSS inválido' } );
}
}
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=' + extraJS + '&action=raw&ctype=text/javascript' );
} else {
mw.notify( 'Só são permitidas páginas do domínio MediaWiki.', { title: 'Valor withJS inválido' } );
}
}
} );
// Ocultar a barra de sumário das páginas de pedidos
mw.loader.using( 'mediawiki.util', function () {
if ( /Wikipédia:Pedidos\/(?!Outros|Revisão_de_ações_administrativas$)/.test( mw.config.get( 'wgPageName' ) ) && mw.util.getParamValue( 'section' ) === 'new' ) {
$( '.mw-summary' ).hide();
}
} );
/**
* Editnotices mágicos ****************************************************
*
* Descrição: Adiciona editnotices nas páginas de desambiguação e biografias de pessoas vivas.
* Mantenedores: [[:en:User:RockMFR]]
*
* @param {string} name
*/
function addEditIntro( name ) {
$( '.mw-editsection, #ca-edit, #ca-ve-edit' ).find( 'a' ).each( function ( i, el ) {
el.href = $( this ).attr( 'href' ) + '&editintro=' + name;
} );
}
if ( mw.config.get( 'wgNamespaceNumber' ) === 0 ) {
$( function () {
if ( document.getElementById( 'disambig' ) ) {
addEditIntro( 'MediaWiki:Editnotice-0-Desambiguação' );
}
} );
$( function () {
var cats = mw.config.get( 'wgCategories' );
if ( !cats ) {
return;
}
if ( $.inArray( 'Pessoas vivas', cats ) !== -1 ) {
addEditIntro( 'MediaWiki:Editnotice-0-BPV' );
}
} );
}
// Scripts para páginas específicas
/**
* IPBan Desktop
* @author [[w:pt:User:Danilo.mac]]
* @author [[w:pt:User:Albertoleoncio]]
*/
mw.loader.using(['mediawiki.user', 'mediawiki.util']).then( function () {
$(function () {
var IPBanNamespaces = [0, 2, 4, 6, 10, 14, 100, 104, 710, 828];
var caEdit = document.getElementById('ca-edit');
if (mw.user.isAnon() && IPBanNamespaces.indexOf(mw.config.get('wgNamespaceNumber')) > -1) {
mw.util.addCSS( '.mw-editsection{display:none}li#ca-ve-edit{display:none !important;}' );
if(caEdit && caEdit.firstChild) {
caEdit.firstChild.href = 'https://pt.wikipedia.org/w/index.php?title=Especial:Entrar&returnto=' + encodeURIComponent(mw.config.get('wgPageName'));
caEdit.firstChild.innerHTML = 'Editar';
}
}
});
} );
}() );