MediaWiki:Gadget-Site.js

Dari Wikisumber bahasa Indonesia, perpustakaan bebas

Catatan: Setelah disimpan, Anda mungkin perlu melewati tembolok peramban web untuk melihat perubahan.

  • Firefox/Safari: Tekan dan tahan Shift sembari mengeklik Reload, atau tekan Ctrl-F5 atau Ctrl-R (⌘-R di Mac)
  • Google Chrome: Tekan Ctrl-Shift-R (⌘-Shift-R di Mac)
  • Internet Explorer / Edge: Tahan Ctrl sembari mengeklik Refresh, atau tekan Ctrl-F5
  • Opera: Tekan Ctrl-F5.
//<syntaxhighlight lang="javascript">
/* global mw, $, importScript, jsMsg */

// Add "mainpage" class to the body element
if (
	mw.config.get( 'wgIsMainPage' ) &&
	mw.config.get( 'wgAction' ) === 'view'
) {
	$( function() {
		document.body.className += ' mainpage';
	});
}

/**
 * Quality indicators on "article" tab
 * by [[user:ThomasV]]
 */
// Return src for icon given percentage
function icon_src(t){
	var src='//upload.wikimedia.org/wikipedia/commons/';
	switch(t){
		case '0%': src+='8/83/00_percents'; break;
		case '25%': src+='c/ce/25_percent'; break;
		case '50%': src+='6/62/50_percents'; break;
		case '75%': src+='4/49/75%25'; break;
		case '100%': src+='c/c7/100_percents'; break;
	} 
	return src + '.svg';
}

// add indicator
function pageQuality() {
//	var a = document.getElementById('ca-nstab-main');
//	if(!a) return;

	var a = document.getElementById('mw-indicator-text-integrity');
	if(!a) return;

	var pr_index = document.getElementById('pr_index');
	if(pr_index) return;

	var q = document.getElementById('textquality');
	var new_img;
	if(q) {
		new_img = document.createElement('img');
		new_img.setAttribute('src', icon_src(q.className));
		a.firstChild.firstChild.appendChild(new_img);
	}

	for(var i=0; spanElem = document.getElementsByTagName('span')[i]; i++) {
		if (spanElem.className == 'pagequality') {
			new_img = document.createElement('img');
			new_img.setAttribute('src', icon_src(spanElem.title));

			if(mw.config.get('wgCanonicalNamespace') == 'Page') {
				a.firstChild.appendChild(new_img);
			}
			else {
				s1 = spanElem.parentNode.previousSibling;
				opttext = s1.firstChild.firstChild;
				img = opttext.firstChild.nextSibling.nextSibling.nextSibling;
				next = img.nextSibling;
				opttext.removeChild(img);
				opttext.insertBefore(new_img,next);
			}
		}
	}
}
$(pageQuality);

// Add link to the extension [[user:sanbeg]]
function pr_add_quality_buttons_link(){ 
	if(typeof proofreadPageMessageStatus == 'undefined') return;
	if( self.proofreadpage_no_quality_buttons ) return;
	var ig = document.getElementById("wpWatchthis");
	if( !ig ) return;
	var f = document.createElement("span");
	f.innerHTML = ' (<a href="/wiki/Help:Page Status">help</a>)';

	ig.parentNode.insertBefore(f,ig.nextSibling.nextSibling.nextSibling.nextSibling);
}
$(pr_add_quality_buttons_link);

/**
 * @source https://www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
 * @revision 2017-05-16
 */
mw.loader.using( ['mediawiki.util'], function () {
	var extraCSS = mw.util.getParamValue( 'withCSS' ),
		extraJS = mw.util.getParamValue( 'withJS' ),
		extraModule = mw.util.getParamValue( 'withModule' );

	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' } );
		}
	}

	if ( extraModule ) {
		if ( /^ext\.gadget\.[^,\|]+$/.test( extraModule ) ) {
			mw.loader.load( extraModule );
		} else {
			mw.notify( 'Only gadget modules are allowed.', { title: 'Invalid withModule value' } );
		}
	}
});

/**
 * Load CSS and JS files temporarily through URL.
 * &use=File1.css|File2.css|File3.js
 *
 * Required modules: mediawiki.util
 * @source https://www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL#Load_multiple_files
 * @revision 2017-05-16
 */
mw.loader.using( ['mediawiki.util'], function () {
	var files = mw.util.getParamValue( 'use' ), user, FileRE, ExtRE, path;

	if ( !files ) {
		return;
	}

	user = mw.RegExp.escape( mw.config.get( 'wgUserName', '' ) );
	FileRE = new RegExp( '^(?:MediaWiki:' + ( user ? '|User:' + user + '/' : '' ) + ')[^&<>=%#]*\\.(js|css)$' );
	ExtRE = new RegExp( '^ext\\.[^,]+$' );
	path = mw.config.get('wgServer')
		+ mw.config.get('wgScript')
		+ '?action=raw&ctype=text/';

	$.each( files.split( '|' ), function(k, v) {
		var f = $.trim( v ), what = FileRE.exec( f ) || ['', ''];
		switch ( what[1] ) {
			case  'js':
				mw.loader.load( path + 'javascript&title=' + encodeURIComponent( f ) );
				break;
			case 'css':
				mw.loader.load( path + 'css&title=' + encodeURIComponent( f ) );
				break;
			default:
				if ( ExtRE.exec( f ) ) {
					mw.loader.load(f);
				}
		}
	});
});

/**
 * Import more specific scripts if necessary
 */
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Watchlist' ) {
	/* watchlist script to dismiss announcements */
	mw.loader.load( '//id.wikisource.org/w/index.php?title=MediaWiki:Common.js/watchlist.js&action=raw&ctype=text/javascript' );
	/* script to add sidebar sister projects */
	mw.loader.load( '//id.wikisource.org/w/index.php?title=MediaWiki:InterProject.js&action=raw&ctype=text/javascript' );
}
//</syntaxhighlight>