Jump to content

User:Jim Carter/NewPagesFeedrestriction.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Jim Carter (talk | contribs) at 14:07, 10 February 2015 (Initial start). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/* Work in progress */
mw.loader.using( [ 'mediawiki.util', 'jquery.ui.dialog', 'jquery.cookie', 'jquery.spinner', 'mediawiki.api', 'user.tokens', 'json' ], function() {
	var minEditCount: 600,
            minRegistration: ( year -1 ) + '-11-01T00:00:00Z'

            },
 api = new mw.Api(),
		page = mw.config.get( 'wgPageName' ),
		user = mw.config.get( 'wgUserName' ),
		$dialog;

function main() {
		if ( $.cookie( 'isEligible' ) === 'false' ) {
			onUserIsNotEligible();
			return;
		}

if ( $.cookie( 'isEligible' ) !== 'true' ) {
			api.get( {
				action: 'query',
				meta: 'userinfo',
				guiuser: user
			} )
			.done( onuserinfoLoad );
		} else {
			onUserIsEligible();
		}
	}
function onuserinfoLoad( data ) {
		var editCount = 0,
			eligible = false,
			i, wikis, oldestAccount;
wikis = data.query.globaluserinfo.merged;
oldestAccount = wikis[0].timestamp;
for ( i = 0; i < wikis.length; i++ ) {
			editCount += parseInt( wikis[i].editcount, 10 );
			if ( wikis[i].timestamp < oldestAccount ) {
				oldestAccount = wikis[i].timestamp;
			}
 
			if ( editCount >= config.minEditCount && oldestAccount <= config.minRegistration) {
				eligible = true;
				break;
			}
		}
NewPage.consts = {};

NewPage.consts = $.extend( {}, {
		
				mockItUp: false,
			
				pagename: mw.config.get( 'wgPageName' ).replace( /_/g, ' ' ),
				
				pagelink: mw.util.getUrl(),
				
				nullstatus: { update: function () { return; } },
				
				user: mw.user.getName(),
				
				whitelistRequired: true,
				
				whitelistTitle: 'User:Jim Carter/Sandbox 2'
			}, NewPage.consts );
if ( NewPage.consts.whitelistRequired ) {
				NewPage.checkWhitelist();
			}
 
			return true;
		},
checkWhitelist: function () {
			var user = NewPage.consts.user,
				whitelist = new NewPage.Page( NewPage.consts.whitelistTitle );
			whitelist.getText().done( function ( text ) {
				var $howToDisable,
					eligible = text.indexOf( user ) !== -1;

 if ( eligible ) {
			$.cookie(
				'isEligible',
				'true',
				{
					expires: 30,
					path: '/'
				}
			);
			onUserIsEligible();
		} else {
			$.cookie(
				'isEligible',
				'false',
				{
					expires: 3,
					path: '/'
				}
			);
			onUserIsNotEligible();
		}
	}
function onUserIsEligible()
{
if ( page.indexOf( 'Special:NewPageFeed' ) !== 0 ) {
			return false;
		}

function onUserIsNotEligible() {
		alert("Sorry! currently you are not allowed to view this page as you don't pass the requirement needed for patrolling new pages. Redirecting to main page.");
		location = "//"+location.host+"/w/index.php?title=Main_Page";
	}
});