MediaWiki:Gadget-wikibugs.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.
/*jslint browser: true, white: true*/
/*global mediaWiki, jQuery, wikiBugsGadget*/
( function ( mw, $ ) {
'use strict';
var wb = {
/**
* Define pages where it's not needed or tends to encourage submission of large
* volumes of unrelated errors; instead, these load CSS which hides the "Report A Bug" link
*/
excludedPages: [
// 'Wikipédia:Página principal'
],
/**
* Returns a refined page title.
* @param title A title of the page.
*/
getRefinedPageName: function( title ) {
return ( title || mw.config.get( 'wgPageName' ) ).replace( /_/g, ' ' ).trim();
},
/**
* Sets up the gadget.
*/
init: function() {
var excluded = false,
name, $articleBugLink, $imageBugLink,
onClick = function( event ) {
event.preventDefault();
mw.loader.using([ 'mediawiki.user', 'jquery.ui', 'mediawiki.api' ], function(){
if( wb.open ){
wb.open( wb[ $(event.target).data( 'wikibugs-message-name') ] );
} else {
mw.loader.using( 'ext.gadget.wikibugsCore', function(){
wb.open( wb[ $(event.target).data( 'wikibugs-message-name') ] );
});
}
});
};
// Special pages and MediaWiki pages are excluded
if ( $.inArray( mw.config.get( 'wgNamespaceNumber' ), [-1, 8] ) > -1 ) {
excluded = true;
} else {
name = wb.getRefinedPageName();
excluded = $.inArray( name, wb.excludedPages ) !== -1;
}
// FIXME: This doesn't exists on "standard", "cologneblue" (no ids) and "nostalgia" (no sidebar)
$articleBugLink = $( '#n-bug_in_article' );
$imageBugLink = $( '#n-bad-image' );
if ( excluded ) {
// Hide the links
$articleBugLink.hide();
$imageBugLink.hide();
return;
}
$articleBugLink.find( 'a' )
.data( 'wikibugs-message-name', 'articleIntro' )
.attr( 'href', '#' )
.click( onClick );
$imageBugLink.find( 'a' )
.data( 'wikibugs-message-name', 'imageIntro' )
.attr( 'href', '#' )
.click( onClick );
if( mw.config.get('wgPageName') === 'Ajuda:Informe_um_erro' ){
// Link on the report-an-error page itself
$( '#report-bug-link a, #ca-addsection a' )
.data( 'wikibugs-message-name', 'articleIntro' )
.click( onClick );
}
}
};
window.wikiBugsGadget = wb;
$( wb.init );
}( mediaWiki, jQuery ) );