User:Cygnis insignis/Promotable.js

From Wikisource
Jump to navigation Jump to search
Note: After saving, changes may not occur immediately. Click here to learn how to bypass your browser's cache.
  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Cmd-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (Cmd-Shift-R on a Mac)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Clear the cache in Tools → Preferences

For details and instructions about other browsers, see Wikipedia:Bypass your cache.

//<nowiki>

mw.config.set( 'mark-proofread-index-ns', 106 );



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.addPortletLink('p-tb', 'javascript:proofreadIndicatorsGadget.go()', 'Mark pages I can promote');
        },

	go: function() {

                // Validated and without text are done
                // ... but there's no need to flag that
		// COMMENTED OUT: mw.util.$content.find( 'a.quality0, a.quality4' ).addClass( 'ppi-done' );

                // Problematic and not proofread are to do
		mw.util.$content.find( 'a.quality1, a.quality2' ).addClass( 'ppi-todo' );

                // Redlinks are to do, but there's no need to flag that.

                // Proofread needs to be checked
		var $tocheck = mw.util.$content.find( '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();
} );

mw.loader.load('//en.wikisource.org/w/index.php?action=raw&ctype=text/css&title=MediaWiki:Gadget-mark-proofread.css', 'text/css');

//</nowiki>