MediaWiki:Gadget-mark-proofread.js

Z Wikiźródeł, wolnej biblioteki

Uwaga: aby zobaczyć zmiany po opublikowaniu, może zajść potrzeba wyczyszczenia pamięci podręcznej przeglądarki.

  • Firefox / Safari: Przytrzymaj Shift podczas klikania Odśwież bieżącą stronę, lub naciśnij klawisze Ctrl+F5, lub Ctrl+R (⌘-R na komputerze Mac)
  • Google Chrome: Naciśnij Ctrl-Shift-R (⌘-Shift-R na komputerze Mac)
  • Internet Explorer / Edge: Przytrzymaj Ctrl, jednocześnie klikając Odśwież, lub naciśnij klawisze Ctrl+F5
  • Opera: Naciśnij klawisze Ctrl+F5.
var proofreadIndicatorsGadget = {
	version: 5,
	queue: [],

	init: function() {
		if ( mw.config.get( 'wgNamespaceNumber' ) !== mw.config.get( 'mark-proofread-index-ns', 102 ) || ( mw.config.get( 'wgAction' ) !== 'view' && mw.config.get( 'wgAction' ) !== 'purge' ) ) {
			return;
		}
		if ( mw.config.get( 'wgUserName' ) == null ) {
			// Anonymous users are not supported
			return;
		}
		mw.util.$content.find( 'a.quality0, a.quality2, a.quality4' ).addClass( 'ppi-done' );
		// FIXME: this needs to affect only links to page-namespace...
		mw.util.$content.find( 'a.new' ).addClass( 'ppi-todo' );
		var $tocheck = mw.util.$content.find( 'a.quality1, a.quality3' );
		$tocheck.addClass( 'ppi-tocheck' );
		this.queue = $tocheck.toArray();
		this.fetchRevisions();
	},

	fetchRevisions: function() {
		if ( !this.queue.length ) {
			return;
		}
		var link = this.queue.shift();
		var title = new String( link.href ).replace( /^(?:https?:)?\/\/[^\/]+\/wiki\//, '' );

		var request = {
			action: 'query',
			titles: decodeURIComponent( title ),
			prop: 'revisions',
			rvlimit: 'max',
			rvprop: 'content',
			rvuser: mw.config.get( 'wgUserName' ),
			format: 'json'
		};

		var that = this;
		jQuery.getJSON( mw.util.wikiScript( 'api' ), request, function( result ) {
			that.processRevisions( result, link );
		} );
	},

	processRevisions: function( result, link ) {
		if ( result && result.query && result.query.pages ) {
			for ( var pageid in result.query.pages ) {
				this.processPage( result.query.pages[pageid], link );
			}
		}
		this.fetchRevisions();
	},

	processPage: function( page, link ) {
		if ( page.missing !== undefined ) {
			return;
		}

		var modified = false;

		for ( var revisionid in page.revisions ) {
			var revision = page.revisions[revisionid];
			if ( revision['*'] ) {
				var m = revision['*'].match( / user="([^"]+)" / );
				if ( m ) {
					if ( m[1] == mw.config.get( 'wgUserName' ) ) {
						modified = true;
						break;
					}
				}
			}
		}

		jQuery( link ).removeClass( 'ppi-tocheck' ).addClass( modified ? 'ppi-done' : 'ppi-todo' );
	}
};

jQuery( document ).ready( function() {
	proofreadIndicatorsGadget.init();
} );