From 8b91bcf777c185ccd44df08f1e08509c7b62fe26 Mon Sep 17 00:00:00 2001 From: theopolisme Date: Tue, 18 Feb 2014 06:10:46 -0600 Subject: [PATCH] Add AFCH.Page.getCreator() used in getSubmitter() --- src/modules/core.js | 40 +++++++++++++++++++++++++++++++++++--- src/modules/submissions.js | 6 ++---- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/modules/core.js b/src/modules/core.js index 0e4b20e..c5955d7 100644 --- a/src/modules/core.js +++ b/src/modules/core.js @@ -148,13 +148,47 @@ // But that seems like a huge pain and would require some more functionality. I'm // lazy. For now we just get the text first. Stupid, I know. var deferred = $.Deferred(); - pg.getText( true ).done( deferred.resolve( pg.additionalData.lastModified ) ); + this.getText( true ).done( deferred.resolve( pg.additionalData.lastModified ) ); return deferred; }; this.getLastEditor = function () { var deferred = $.Deferred(); - pg.getText( true ).done( deferred.resolve( pg.additionalData.lastEditor ) ); + this.getText( true ).done( deferred.resolve( pg.additionalData.lastEditor ) ); + return deferred; + }; + + this.getCreator = function () { + var request, deferred = $.Deferred(); + + if ( this.additionalData.creator ) { + deferred.resolve( this.additionalData.creator ); + } + + request = { + action: 'query', + prop: 'revisions', + rvprop: 'user', + rvdir: 'newer', + rvlimit: 1, + indexpageids: true, + titles: this.rawTitle + }; + + // FIXME: Handle failure more gracefully + AFCH.api.get( request ) + .done( function ( data ) { + var rev, id = data.query.pageids[0]; + // Sanity check, the page might not exist + if ( id && data.query.pages[id] ) { + rev = data.query.pages[id].revisions[0]; + pg.additionalData.creator = rev.user; + deferred.resolve( rev.user ); + } else { + deferred.reject( data ); + } + } ); + return deferred; }; @@ -285,7 +319,7 @@ * Deletes a page * @param {string} pagename Page to delete * @param {string} reason Reason for deletion; shown in deletion log - * @return {bool} Page deleted successfully + * @return {$.Deferred} Resolves with success/failure */ deletePage: function ( pagename, reason ) { // FIXME: implement diff --git a/src/modules/submissions.js b/src/modules/submissions.js index 1f6ae62..755eb7f 100644 --- a/src/modules/submissions.js +++ b/src/modules/submissions.js @@ -320,9 +320,7 @@ /** * Gets the submitter, or, if no specific submitter is available, - * just the last editor - * - * FIXME: get the FIRST editor?? + * just the page creator * * @return {$.Deferred} resolves with user */ @@ -333,7 +331,7 @@ if ( user ) { deferred.resolve( user ); } else { - this.page.getLastEditor().done( function ( user ) { + this.page.getCreator().done( function ( user ) { deferred.resolve( user ); } ); }