User:Jim Carter/NewPagesFeedrestriction.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:Jim Carter/NewPagesFeedrestriction. |
/* 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";
}
});