Share to:

Bruger:Christian75/Scripts/FLT.js

//===========================================================================
//  Markiert Links auf Begriffsklärungsseiten mit der CSS-Klasse  'bkl-link',
// sowohl in der normalen Artikelansicht als auch in der  Vorschau
//===========================================================================

var  bklCheck = {
	cat  : {
		'Kategori:Flertydig' :  {
			className   :  'bkl-link bkl-link-inner', //bkl-link-inner kept for b/c reasons
			titleAppend : '  (Flertydig artikel)',
			htmlAppend  : '<sup  class="bkl-link-sup">FLT</sup>'}//,
		//'Kategori:Wikipedia:Falschschreibung'  : {
		//	className   :  'bkl-link bkl-link-inner',
		//	titleAppend : '  (Falschschreibung)',
		//	htmlAppend  : '<sup  class="bkl-link-sup">FS</sup>'}

	},

	queryUrlView       : mw.config.get('wgScriptPath') + '/api.php?action=query&format=json'
		+  '&prop=categories&pageids=' + mw.config.get('wgArticleId') +  '&callback=bklCheck.viewResultArrived'
		+  '&generator=links&redirects&gpllimit=max&gplnamespace=0&cllimit=max&indexpageids'
		+ '&nocache=' +  mw.config.get('wgCurRevisionId'), //Break client caching, when page has been edited
	queryUrlPreview   :  mw.config.get('wgScriptPath') +  '/api.php?action=query&format=json&prop=categories'
		+  '&cllimit=max&redirects&indexpageids',
	titles            :  {},
	count              : 0,
	previewQueryCount  : 0,

	execute  : function () {
		if (  window.bklCheckOnlyCheckMainNS && mw.config.get('wgNamespaceNumber') != 0 )  return;
		//Use  &clcategories to reduce needed queries
		var cats = [];
		for ( var name in  bklCheck.cat ) if ( bklCheck.cat[name].className )
			cats.push(  encodeURIComponent( name ) );
		bklCheck.queryUrlView  += '&clcategories=' + cats.join( '|' );
		bklCheck.queryUrlPreview  += '&clcategories=' + cats.join( '|' );
		if ( mw.config.get('wgAction') ==  'submit' )	bklCheck.doPreviewQueries();
		else if ( mw.config.get('wgAction') ==  'view' || mw.config.get('wgAction') == 'historysubmit' || mw.config.get('wgAction') == 'purge' )
			mw.loader.load( bklCheck.queryUrlView );
		else {//"Show preview  on first edit" enabled?
			var prev =  document.getElementById( 'wikiPreview' );

			if ( prev &&  prev.firstChild ) mw.loader.load( bklCheck.queryUrlView );
		}
		//Make sure that our  style is put before other css so users can override it easily
		$('<style>').text('.bkl-link {background-color:#FF9191;}').prependTo('head:first');
	},

	storeTitles : function  ( res ) {
		if ( !res ||  !res.query || !res.query.pageids ) return;
		var q = res.query;
		var redirects = {};
		for ( var i = 0;  q.redirects && i < q.redirects.length; i++ ) {
			var r =  q.redirects[i];
			if ( !redirects[r.to] )  redirects[r.to] = [];
			redirects[r.to].push(  r.from );
		}
		for ( var i = 0; i  < q.pageids.length; i++ ) {
			var page =  q.pages[q.pageids[i]];
			if ( page.missing ===  '' || page.ns !== 0 || !page.categories ) continue;
			for ( var j = 0; j  < page.categories.length; j++ ) {
				var cat =  bklCheck.cat[page.categories[j].title];
				if ( !cat ) continue;
				bklCheck.count++;
				bklCheck.titles[page.title]  = cat;
				if (  !redirects[page.title] ) break;
				for ( var k = 0; k  < redirects[page.title].length; k++ )

					bklCheck.titles[redirects[page.title][k]]  = cat;
				break;
			}
		}
	},

	markLinks : function  () {
		if ( !bklCheck.count )  return;
		var links =  bklCheck.getLinks( 'wikiPreview' ) || bklCheck.getLinks( 'bodyContent' )
				|| bklCheck.getLinks(  'mw_contentholder' ) || bklCheck.getLinks( 'article' );
		if ( !links ) return;
		for ( var i = 0; i  < links.length; i++ ) {
			if (  links[i].className == 'image' ) continue; //Don't mess with images!
			var cat =  bklCheck.titles[links[i].title];
			if ( !cat ) continue;
			links[i].innerHTML =  '<span class="' + cat.className + '" title="' + links[i].title
					+ cat.titleAppend +  '">' + links[i].innerHTML	+  cat.htmlAppend + '</span>';
		}
	},

	viewResultArrived :  function ( res ) {
		bklCheck.storeTitles(  res );
		if ( res &&  res['query-continue'] ) {
			var c =  res['query-continue'];
			if ( c.categories ) {
				mw.loader.load( bklCheck.queryUrlView + '&clcontinue='
					+ encodeURIComponent(  c.categories.clcontinue ) );
			} else if ( c.links ) {
				bklCheck.queryUrlView =  bklCheck.queryUrlView.replace( /&gplcontinue=.*|$/,
					'&gplcontinue=' +  encodeURIComponent( c.links.gplcontinue ) );
				mw.loader.load( bklCheck.queryUrlView );
			}
		} else  bklCheck.markLinks();
	},

	PreviewQuery :  function ( titles ) {
		bklCheck.previewQueryCount++;
		//We have to keep the  titles in memory in case we get a query-continue
		this.data = 'titles=' +  titles.join( '|' );		
		this.doQuery(  bklCheck.queryUrlPreview );
	},

	doPreviewQueries :  function () {
		var links =  bklCheck.getLinks( 'wikiPreview' );
		if ( !links ) return;
		var titles=[]; var m;
		var unique = {};
		var rxEscape =  function(s) {return s.replace( /([\/\.\*\+\?\|\(\)\[\]\{\}\\])/g, '\\$1'  );};
		var siteRegex = new  RegExp( rxEscape( mw.config.get('wgServer') ) + rxEscape( mw.config.get('wgArticlePath').replace( /\$1/,  '' ) ) + '([^#]*)' );
		//We only care for  main ns pages, so we can filter out the most common cases to save some  requests
		var namespaceRegex =  /^((Bruger|Wikipedia|Skabelon|Artikeldata|MediaWiki|Fil|Hjælp|Kategori|Portal)(_Diskussion)?|Spe[cz]ial|Diskussion):/i;
		for ( var i = 0; i  < links.length; i++ ) {
			if ( !links[i].title  || !( m = links[i].href.match( siteRegex ) )
				|| m[1].match(  namespaceRegex ) || unique[m[1]] ) continue;
			unique[m[1]] = true;  //Avoid requesting same title multiple times
			titles.push(  m[1].replace( /_/g, '%20' ) ); //Avoid normalization of titles
			if ( titles.length  < 50 ) continue;
			new  bklCheck.PreviewQuery( titles );
			titles=[];
		}
		if ( titles.length )  new bklCheck.PreviewQuery( titles );
	},

	getLinks : function (  id ) {
		var el =  document.getElementById( id );
		return el &&  el.getElementsByTagName( 'a' );
	}
};

bklCheck.PreviewQuery.prototype.doQuery  = function ( url ) {
	var  q = this;
	if(typeof sajax_init_object === 'undefined') return;
	var  req = sajax_init_object();
	if  ( !req ) return;
	req.open(  'POST', url, true );
	req.setRequestHeader(  'Content-Type', 'application/x-www-form-urlencoded' );
	req.onreadystatechange  = function () {
		if ( req.readyState  == 4 && req.status == 200 )
			eval(  'q.resultArrived(' + req.responseText + ');' );
	};
	req.send( q.data );
	delete req;
};

bklCheck.PreviewQuery.prototype.resultArrived  = function ( res ) {
	bklCheck.storeTitles(  res );
	if (  res && res['query-continue'] &&  res['query-continue'].categories ) {
		this.doQuery(  bklCheck.queryUrlPreview + '&clcontinue='
			+ encodeURIComponent(  res['query-continue'].categories.clcontinue ) );
	} else  bklCheck.previewQueryCount--;
	if  ( !bklCheck.previewQueryCount ) bklCheck.markLinks();
};

if (  mw.config.get('wgNamespaceNumber') >= 0 ) $( bklCheck.execute );

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.
Prefix: a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9

Portal di Ensiklopedia Dunia

Kembali kehalaman sebelumnya