Year of the Dragon: Through May 28th, claim free Expansion Pack (excluding Vecna Unleashed) or a Greater Elixir of Discovery! Speak to Xatheral in the Hall of Heroes.edit
Game mechanics • Newbie guide • In development • DDO Store • Social Media
Challenges • Classes • Collectables • Crafting • Enhancements • Epic Destinies • Favor • Feats
Glossary • Items • Maps • Monsters • Places • Quests • Races • Reincarnation • Skills • Spells
Please create an account or log in to build a reputation and unlock more editing privileges, and then visit DDO wiki's IRC Chat/Discord if you need any help!
MediaWiki:Autopromote.js
Jump to navigation
Jump to search
Note: After saving, you may have to bypass your browser's cache to see the changes, you can click here or try one of the methods below..
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl+F5 or Ctrl+r (⌘ Command+r on a Mac)
- Google Chrome: Press Ctrl+⇧ Shift+R (⌘ Command+⇧ Shift+R on a Mac)
- Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl+F5
- Konqueror: Click Reload or press F5
- Opera: Clear the cache in Tools ‣ Preferences
//<nowiki>
( function ( mw, $ ) {
// Initialize some constants
var promotionCandidates = {};
/* [[DDO:Ddowikivip]]: "... any user with a triple digit edit count ... is qualified..." */
var ecVIP = 100;// ([[C:100 edit users]])
/* [[DDO:Superuser]]: "... up to at least 250 edit users ..." */
var ecSU = 250;// [[C:250 edit users]]
var toVipTopic = 'Congratulations! You\'re a DDO wiki VIP!';
var toSuTopic = 'Congratulations! You\'re a SuperUser!';
var editsSummary =
encodeURIComponent( 'Updated edit count with [[MediaWiki:Autopromote.js|Auto-promote]]' );
var toVipSummary =
encodeURIComponent( 'Promoted to DDO wiki VIP with [[MediaWiki:Autopromote.js|Auto-promote]]' );
var toSuSummary =
encodeURIComponent( 'Promoted to SuperUser with [[MediaWiki:Autopromote.js|Auto-promote]]' );
var toVipTalk = '';
var toSuTalk = '';
var toVipEmail = '';
var toSuEmail = '';
// Function to send an email through the API
/* function sendEmail( userName = 'Unknown user' ) {
}*/
// Get a complete list of users, edit counts, account ages, and current groups.
var aufrom = '';// start at the beginning
while( aufrom !== '#' ) {
$.ajax( {//* REALLY DON'T LIKE THIS!!! *//*
url: 'https://ddowiki.com/api.php?'
+ 'action=query'
+ '&format=json'
+ '&list=allusers'
+ '&aulimit=max'
+ '&auwitheditsonly=1'
+ '&auexcludegroup=sysop|bureaucrat|steward'
+ '&auprop=groups|blockinfo|editcount|registration'
+ '&aufrom=' + aufrom,
dataType: 'json',
async: false,//* REALLY DON'T LIKE THIS!!! IT WILL FAIL IN THE FUTURE!!! *//*
success: function( successData ) {
var resultObject = successData.query.allusers;
$.each( resultObject, function( ) {
var isBlocked = ( $( this )[ 0 ].blockedby !== undefined ? true : false );
var editCount = $( this )[ 0 ].editcount;// API editcount (deleted edits not included)
var isSU =// Is the user a superuser
( $.inArray( 'superuser', $( this )[ 0 ].groups ) !== -1 ? true : false );
var isVIP =// Is the user a ddowikivip
( $.inArray( 'ddowikivip', $( this )[ 0 ].groups ) !== -1 ? true : false );
// If the user is not blocked, and should be a VIP or SU but isn't, then...
if ( !isBlocked &&
( ( !isVIP && editCount >= ecVIP ) || ( !isSU && editCount >= ecSU ) ) ) {
promotionCandidates[ $( this )[ 0 ].name ] = {};// Create an object with the user name
promotionCandidates[ $( this )[ 0 ].name ].editcount =
editCount;// Put edit count in user's object
var currDate = new Date();// Define a new date constructor
var currDateInMonths =// Calculate the current number of months since Jan 2000
currDate.getFullYear() * 12 + currDate.getMonth();
var regSince =// Date object for registration date
( $( this )[ 0 ].registration === ''
? new Date( 1999, 11, 30 ) : new Date( $( this )[ 0 ].registration ) );
var age =// Calculate age in months
( currDateInMonths - ( ( regSince.getFullYear() * 12 ) + regSince.getMonth() ) );
promotionCandidates[ $( this )[ 0 ].name ].age = age;// account age
promotionCandidates[ $( this )[ 0 ].name ].isSU = isSU;// superuser status
promotionCandidates[ $( this )[ 0 ].name ].isVIP = isVIP;// ddowikivip status
}
} );
if ( successData[ 'query-continue' ] !== undefined ) {
aufrom = successData[ 'query-continue' ].allusers.aufrom;// More users to process
} else {
aufrom = '#';// Last page - [[User:#]] can not exist and returns "Bad title" if you try.
}
},
fail: function( failureData ) {
alert( 'Sorry, failed to retrieve information from API.\n'
+ 'Please check the console for more details if available.' );
console.error( '%O', failureData );
}
} );
}
$( 'li#ca-nstab-special span a' ).attr( 'href',
'./Special:BlankPage?withJS=MediaWiki:Autopromote.js' );// Reload the script -- needs to be adjusted later
$( '#firstHeading span' ).text( 'Semi-auto-promote' );// The title for the page -- come up with something better later
$( '#mw-content-text' ).html( '<div class="mw-semiautopromote-intro">' +
'<p>List of users meeting the requirements for inclusion in ddowikivip or superuser.</p>'
+ '</div>' );// Page description
$( '.mw-semiautopromote-intro' ).after(
'<ul id="mw-semiautopromote-canididates"></ul>' );// Create a fillable <ul>
function userLastEdit( userName ) {
userName = typeof userName !== 'undefined' ? userName : 'Unknown user';
$.ajax( {//* REALLY DON'T LIKE THIS!!! *//*
url: 'https://ddowiki.com/api.php?'
+ 'action=query'
+ '&format=json'
+ '&list=usercontribs|logevents'
+ '&lelimit=1'
+ '&leprop=timestamp'
+ '&uclimit=1'
+ '&ucprop=timestamp'
+ '&ucuser=' + encodeURIComponent( userName )
+ '&leuser=' + encodeURIComponent( userName ),
dataType: 'json',
success: function( userData ) {
var currDate = new Date();// Define a new date constructor
var currDateInMonths =// Calculate the current number of months since Jan 2000
currDate.getFullYear() * 12 + currDate.getMonth();
var lastEdit =// Date object for date of last edit
( userData.query.usercontribs[ 0 ] === undefined
? new Date( 1999, 11, 30 ) : new Date( userData.query.usercontribs[ 0 ].timestamp ) );
var lastLogEvent =// Date object for date of last log
( userData.query.logevents[ 0 ] === undefined
? new Date( 1999, 11, 30 ) : new Date( userData.query.logevents[ 0 ].timestamp ) );
var lastEditAge =// Calculate age in months
( currDateInMonths - ( ( lastEdit.getFullYear() * 12 ) + lastEdit.getMonth() ) );
var lastLogAge =// Calculate age in months
( currDateInMonths - ( ( lastLogEvent.getFullYear() * 12 ) + lastLogEvent.getMonth() ) );
var lastAge = ( lastEditAge > lastLogAge ? lastLogAge : lastEditAge );
promotionCandidates[ userName ].lastEdit = lastEdit;
promotionCandidates[ userName ].lastLogEvent = lastLogEvent;
promotionCandidates[ userName ].lastEditAge = lastEditAge;
promotionCandidates[ userName ].lastLogAge = lastLogAge;
promotionCandidates[ userName ].lastAge = lastAge;
if ( lastAge <= 12 ) {
$( '#' + userName.replace( / /g, '_' ) + '_ula' ).html( '<b style="color: #007700;">' + lastAge + '</b>' );
} else if ( lastAge >= 24 ) {
$( '#' + userName.replace( / /g, '_' ) + '_ula' ).html( '<i style="color: #770000; text-decoration: line-through;">' + lastAge + '</i>' );
} else {
$( '#' + userName.replace( / /g, '_' ) + '_ula' ).text( lastAge );
}
},
fail: function( failureData ) {
alert( 'Sorry, failed to retrieve information from API.\n'
+ 'Please check the console for more details if available.' );
console.error( '%O', failureData );
}
} );
}
function userAgeEdits( userName, age, editCount ) {
userName = ( typeof userName !== 'undefined' ? userName : 'Unknown user' );
age = ( typeof age !== 'undefined' ? age : 1 );
editCount = ( typeof editCount !== 'undefined' ? editCount : 0 );
var lastEdit = 'Last: <span id="' + userName.replace( / /g, '_' ) +
'_ula"><small><i>retrieving</i></small></span> months ago';
var editsPerMonth = Math.floor( ( editCount / age ) * 100 ) / 100;
return '<span class="age-edits"><small>(</small> <b>' + editCount + '</b>/<i>' + age +
'</i> <small> ' + editsPerMonth + '<sub>/mo</sub></small> ' + lastEdit +
'<small>)</small></span> ';
}
function userPageLink( userName ) {
userName = ( typeof userName !== 'undefined' ? userName : 'Unknown user' );
return '<a id="' + userName.replace( / /g, '_' ) + '_upl" class="userPageLink" href="./User:' +
userName.replace( / /g, '_' ) + '" title="' + userName + '">' + userName + '</a>';
}
function userTalkLink( userName ) {
userName = ( typeof userName !== 'undefined' ? userName : 'Unknown user' );
return '<a id="' + userName.replace( / /g, '_' ) +
'_utl" class="userTalkLink" href="./User_talk:' +
userName.replace( / /g, '_' ) + '" title="' + userName + '">talk</a>';
}
function contribsLink( userName ) {
userName = ( typeof userName !== 'undefined' ? userName : 'Unknown user' );
return '<a id="' + userName.replace( / /g, '_' ) +
'_utl" class="contribsLink" href="./Special:Contributions/' +
userName.replace( / /g, '_' ) + '" title="' + userName + '">contributions</a>';
}
function userEmailLnk( userName ) {
userName = ( typeof userName !== 'undefined' ? userName : 'Unknown user' );
$.ajax( {//* REALLY DON'T LIKE THIS!!! *//*
url: 'https://ddowiki.com/api.php?'
+ 'action=query'
+ '&format=json'
+ '&list=users'
+ '&usprop=emailable'
+ '&ususers=' + encodeURIComponent( userName ),
dataType: 'json',
success: function( userData ) {
promotionCandidates[ userName ].isEmailable =
( userData.query.users[ 0 ].emailable !== undefined ? true : false );
if ( !promotionCandidates[ userName ].isEmailable ) {
$( '#' + userName.replace( / /g, '_' ) + '_uel' ).remove( );
}
},
fail: function( failureData ) {
alert( 'Sorry, failed to retrieve information from API.\n'
+ 'Please check the console for more details if available.' );
console.error( '%O', failureData );
}
} );
return '<span id="' + userName.replace( / /g, '_' ) +
'_uel"> · <a class="userEmailLnk" href="./Special:EmailUser/' +
userName.replace( / /g, '_' ) + '" title="send ' + userName + ' an email">email</a></span>';
}
/* function userPageEdit( userName = 'Unknown user', editCount = 0 ) {
// Function to update [[T:UserEditAward]] on the user's page with current count
}*/
/* function userToVIP( userName = 'Unknown user', editCount = 0, isEmailable = false ) {
// Function to add to ddowikivip group, update [[T:UserEditAward]] on the user's page,
// leave a message on their talk page congratulating them, and send an email
}*/
/* function userToSU( userName = 'Unknown user', editCount = 0, isEmailable = false ) {
// Function to add to superuser group, update [[T:UserEditAward]] on the user's page,
// leave a message on their talk page congratulating them, and send an email
}*/
$.each( promotionCandidates, function( name ) {
$( '#mw-semiautopromote-canididates' ).append( '<li>' +
userAgeEdits( name, $( this )[ 0 ].age, $( this )[ 0 ].editcount) + ' ' +
userPageLink( name ) + ' ( ' +
userTalkLink( name ) +
userEmailLnk( name ) + ' · ' +
contribsLink( name ) + ' )</li>' );
userLastEdit( name );// Retrieve and update the last edit information
} );
console.log( '%O', promotionCandidates );// Log final object
} )( mediaWiki, jQuery );
//</nowiki>