moar code
This commit is contained in:
parent
a12196a2cf
commit
d76e8001e8
@ -21,6 +21,9 @@
|
|||||||
baseurl: scriptpath + '?action=raw&ctype=text/javascript&title=MediaWiki:Gadget-afchelper.js'
|
baseurl: scriptpath + '?action=raw&ctype=text/javascript&title=MediaWiki:Gadget-afchelper.js'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// FIXME: Right now mw.loader.using doesn't let you load urls.
|
||||||
|
// We can probably use $.ajax instead (also needs to be fixed
|
||||||
|
// in core.js) until this is fixed in mediawiki-core.
|
||||||
mw.loader.using( AFCH.consts.baseurl + '/core.js', function () {
|
mw.loader.using( AFCH.consts.baseurl + '/core.js', function () {
|
||||||
if ( AFCH.beforeLoad() ) {
|
if ( AFCH.beforeLoad() ) {
|
||||||
AFCH.load( afctype );
|
AFCH.load( afctype );
|
||||||
@ -30,5 +33,5 @@
|
|||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
} )( mediawiki, window );
|
} )( mediaWiki, window );
|
||||||
//</nowiki>
|
//</nowiki>
|
||||||
|
168
core.js
168
core.js
@ -32,7 +32,7 @@
|
|||||||
// Run setup function
|
// Run setup function
|
||||||
AFCH.beforeLoad();
|
AFCH.beforeLoad();
|
||||||
|
|
||||||
// Load css
|
// FIXME: Do this via ResourceLoader
|
||||||
mw.loader.load( AFCH.consts.scriptpath + '?action=raw&ctype=text/css&title=MediaWiki:Gadget-afchelper.css', 'text/css' );
|
mw.loader.load( AFCH.consts.scriptpath + '?action=raw&ctype=text/css&title=MediaWiki:Gadget-afchelper.css', 'text/css' );
|
||||||
|
|
||||||
// Load dependencies if required
|
// Load dependencies if required
|
||||||
@ -76,12 +76,12 @@
|
|||||||
initFeedback: function ( $element, type ) {
|
initFeedback: function ( $element, type ) {
|
||||||
var feedback = new mw.Feedback( {
|
var feedback = new mw.Feedback( {
|
||||||
title: new mw.Title( 'Wikipedia talk:Articles for creation/Helper script/Feedback' ),
|
title: new mw.Title( 'Wikipedia talk:Articles for creation/Helper script/Feedback' ),
|
||||||
bugsLink: '//github.com/WPAFC/afch/issues/new',
|
bugsLink: 'https://github.com/WPAFC/afch/issues/new',
|
||||||
bugsListLink: '//github.com/WPAFC/afch/issues?labels=REWRITE&state=open'
|
bugsListLink: 'https://github.com/WPAFC/afch/issues?labels=REWRITE&state=open'
|
||||||
} ),
|
} ),
|
||||||
feedbackLink = $( '<span>' )
|
feedbackLink = $( '<span>' )
|
||||||
.text( 'Give feedback!' )
|
.text( 'Give feedback!' )
|
||||||
.addClass( 'feedbackLink' )
|
.addClass( 'afch-feedbackLink' )
|
||||||
.click( function () {
|
.click( function () {
|
||||||
feedback.launch( {
|
feedback.launch( {
|
||||||
subject: type ? 'Feedback about ' + type : 'AFCH feedback',
|
subject: type ? 'Feedback about ' + type : 'AFCH feedback',
|
||||||
@ -92,6 +92,39 @@
|
|||||||
} );
|
} );
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a page, mainly a wrapper for various actions
|
||||||
|
*/
|
||||||
|
Page: function ( name ) {
|
||||||
|
var pg = this;
|
||||||
|
|
||||||
|
this.Title = new mw.Title( name );
|
||||||
|
this.additionalData = {}
|
||||||
|
|
||||||
|
this.getText = function ( usecache ) {
|
||||||
|
if ( usecache && this.pageText ) {
|
||||||
|
return this.pageText;
|
||||||
|
}
|
||||||
|
$.when( AFCH.action.getPageText( this.Title.getPrefixedText(), { hide: true, moreProps: 'timestamp' } ).done(
|
||||||
|
function ( pagetext, data ) {
|
||||||
|
pg.pageText = pagetext;
|
||||||
|
// Teehee, let's use this opportunity to get some data for later
|
||||||
|
pg.additionalData.lastModified = new Date( data.timestamp );
|
||||||
|
} );
|
||||||
|
|
||||||
|
return this.pageText;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.getLastModifiedDate = function () {
|
||||||
|
// FIXME: I guess the nice thing to do would be to make an API call if necessary.
|
||||||
|
// But that seems like a huge pain and would require some more functionality.
|
||||||
|
// For now we just get the text first. Stupid, I know.
|
||||||
|
this.getText();
|
||||||
|
return this.additionalData.lastModified;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform a specific action
|
* Perform a specific action
|
||||||
* FIXME: callback functions? Or else return $.Promise()?
|
* FIXME: callback functions? Or else return $.Promise()?
|
||||||
@ -100,10 +133,14 @@
|
|||||||
/**
|
/**
|
||||||
* Gets the full wikicode content of a page
|
* Gets the full wikicode content of a page
|
||||||
* @param {string} pagename The page to get the contents of, namespace included
|
* @param {string} pagename The page to get the contents of, namespace included
|
||||||
* @param {bool} hide Set to true to hide the API request in the status log
|
* @param {object} options Object with properties:
|
||||||
|
* hide: {bool} set to true to hide the API request in the status log
|
||||||
|
* moreProps: {string} additional properties to request
|
||||||
|
* @return {string} Page text or false if error
|
||||||
*/
|
*/
|
||||||
getPageText: function ( pagename, hide ) {
|
getPageText: function ( pagename, options ) {
|
||||||
var status, request;
|
var status, request, rvprop = 'content',
|
||||||
|
deferred = $.Deferred();
|
||||||
|
|
||||||
if ( !options.hide ) {
|
if ( !options.hide ) {
|
||||||
status = new AFCH.status.Element( 'Getting $1...',
|
status = new AFCH.status.Element( 'Getting $1...',
|
||||||
@ -115,27 +152,39 @@
|
|||||||
status = AFCH.consts.nullstatus;
|
status = AFCH.consts.nullstatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
request = {
|
if ( options.moreProps ) {
|
||||||
action: 'query',
|
rvprop += '|' + options.moreProps;
|
||||||
prop: 'revisions',
|
}
|
||||||
rvprop: 'content',
|
|
||||||
format: 'json',
|
|
||||||
indexpageids: true,
|
|
||||||
titles: pagename
|
|
||||||
};
|
|
||||||
|
|
||||||
AFCH.api.post( request )
|
request = {
|
||||||
.done( function ( data ) {
|
action: 'query',
|
||||||
if ( data && data.edit && data.edit.result && data.edit.result == 'Success' ) {
|
prop: 'revisions',
|
||||||
status.update( 'Got $1' );
|
rvprop: rvprop,
|
||||||
} else {
|
format: 'json',
|
||||||
// FIXME: get error info from API result
|
indexpageids: true,
|
||||||
}
|
titles: pagename
|
||||||
} )
|
};
|
||||||
.error( function ( err ) {
|
|
||||||
// FIXME
|
$.when( AFCH.api.post( request ) )
|
||||||
} );
|
.done( function ( data ) {
|
||||||
},
|
var rev, id = data.query.pageids[0];
|
||||||
|
if ( id && data.query.pages ) {
|
||||||
|
rev = data.query.pages[id].revisions[0];
|
||||||
|
deferred.resolve( rev['*'], rev );
|
||||||
|
status.update( 'Got $1' );
|
||||||
|
} else {
|
||||||
|
deferred.reject( data );
|
||||||
|
// FIXME: get detailed error info from API result
|
||||||
|
status.update( 'Error getting $1: ' + JSON.stringify( data ) );
|
||||||
|
}
|
||||||
|
} )
|
||||||
|
.fail( function ( err ) {
|
||||||
|
deferred.reject( err );
|
||||||
|
status.update( 'Error getting $1: ' + JSON.stringify( err ) );
|
||||||
|
} );
|
||||||
|
|
||||||
|
return deferred;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Modifies a page's content
|
* Modifies a page's content
|
||||||
@ -147,10 +196,14 @@
|
|||||||
* mode: {string} 'appendtext' or 'prependtext'; default: (replace everything)
|
* mode: {string} 'appendtext' or 'prependtext'; default: (replace everything)
|
||||||
* patrol: {bool} by default true; set to false to not patrol the page
|
* patrol: {bool} by default true; set to false to not patrol the page
|
||||||
* hide: {bool} Set to true to supress logging in statusWindow
|
* hide: {bool} Set to true to supress logging in statusWindow
|
||||||
* @return {bool} Page was saved successfully
|
* @return {jQuery.Deferred} Page was saved successfully
|
||||||
*/
|
*/
|
||||||
editPage: function ( pagename, options ) {
|
editPage: function ( pagename, options ) {
|
||||||
var status, request;
|
var status, request, deferred = $.Deferred();
|
||||||
|
|
||||||
|
if ( !options ) {
|
||||||
|
options = {};
|
||||||
|
}
|
||||||
|
|
||||||
if ( !options.hide ) {
|
if ( !options.hide ) {
|
||||||
status = new AFCH.status.Element( 'Editing $1...',
|
status = new AFCH.status.Element( 'Editing $1...',
|
||||||
@ -162,10 +215,6 @@
|
|||||||
status = AFCH.consts.nullstatus;
|
status = AFCH.consts.nullstatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( options === undefined ) {
|
|
||||||
options = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
request = {
|
request = {
|
||||||
action: 'edit',
|
action: 'edit',
|
||||||
text: options.contents,
|
text: options.contents,
|
||||||
@ -180,14 +229,20 @@
|
|||||||
AFCH.api.post( request )
|
AFCH.api.post( request )
|
||||||
.done( function ( data ) {
|
.done( function ( data ) {
|
||||||
if ( data && data.edit && data.edit.result && data.edit.result == 'Success' ) {
|
if ( data && data.edit && data.edit.result && data.edit.result == 'Success' ) {
|
||||||
|
deferred.resolve( data );
|
||||||
status.update( 'Saved $1' );
|
status.update( 'Saved $1' );
|
||||||
} else {
|
} else {
|
||||||
// FIXME: get error info from API result
|
deferred.reject( data );
|
||||||
|
// FIXME: get detailed error info from API result??
|
||||||
|
status.update( 'Error saving $1: ' + JSON.stringify( data ) );
|
||||||
}
|
}
|
||||||
} )
|
} )
|
||||||
.error( function ( err ) {
|
.fail( function ( err ) {
|
||||||
// FIXME
|
deferred.reject( err );
|
||||||
|
status.update( 'Error saving $1: ' + JSON.stringify( err ) );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
return deferred;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -208,7 +263,7 @@
|
|||||||
status: {
|
status: {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the status container, overwritten by init()
|
* Represents the status container, created ub init()
|
||||||
*/
|
*/
|
||||||
container: false,
|
container: false,
|
||||||
|
|
||||||
@ -272,6 +327,43 @@
|
|||||||
this.update( initialText );
|
this.update( initialText );
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple framework for getting/setting interface messages.
|
||||||
|
* Not every message necessarily needs to go through here. But
|
||||||
|
* it's nice to separate long messages from the code itself.
|
||||||
|
* @type {Object}
|
||||||
|
*/
|
||||||
|
msg: {
|
||||||
|
/**
|
||||||
|
* AFCH messages loaded by default for all subscripts.
|
||||||
|
* @type {Object}
|
||||||
|
*/
|
||||||
|
store: {},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the text of a message, or a placeholder if the
|
||||||
|
* message is not set
|
||||||
|
* @param {string} key Message key
|
||||||
|
* @return {string} Message value
|
||||||
|
*/
|
||||||
|
get: function ( key ) {
|
||||||
|
return AFCH.msg.store[key] || '<' + key + '>';
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a new message or messages
|
||||||
|
* @param {string|object} key
|
||||||
|
* @param {string} value if key is a string, value
|
||||||
|
*/
|
||||||
|
set: function ( key, value ) {
|
||||||
|
if ( typeof key === 'object' ) {
|
||||||
|
$.extend( AFCH.msg.store, key );
|
||||||
|
} else {
|
||||||
|
AFCH.msg.store[key] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
} )( AFCH, jQuery, mediawiki );
|
} )( AFCH, jQuery, mediaWiki );
|
||||||
//</nowiki>
|
//</nowiki>
|
||||||
|
@ -2,6 +2,66 @@
|
|||||||
// Script should be located at [[MediaWiki:Gadget-afchelper.js/submissions.js]]
|
// Script should be located at [[MediaWiki:Gadget-afchelper.js/submissions.js]]
|
||||||
|
|
||||||
( function ( AFCH, $, mw ) {
|
( function ( AFCH, $, mw ) {
|
||||||
// FIXME: make this
|
var $afchReviewPanel;
|
||||||
|
|
||||||
|
AFCH.Page.prototype.isG13Elgibile = function () {
|
||||||
|
// older than six months FIXME
|
||||||
|
if ( this.getLastModifiedDate() ) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AFCH.Page.prototype.getAFCTemplates = function () {
|
||||||
|
// FIXME: Is this the best place for this?
|
||||||
|
// Should we have a designated AFCH.Submission class
|
||||||
|
// instead, perhaps? That makes more sense.
|
||||||
|
}
|
||||||
|
|
||||||
|
function addMessages() {
|
||||||
|
AFCH.msg.set( {
|
||||||
|
'accept': 'Accept',
|
||||||
|
'decline': 'Decline',
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupReviewPanel() {
|
||||||
|
var $buttonWrapper = $( '<div>' )
|
||||||
|
.addClass( 'afch-actions' ),
|
||||||
|
$acceptButton = $( '<button>' )
|
||||||
|
.addClass( 'accept' )
|
||||||
|
.text( 'Accept' );
|
||||||
|
$declineButton,
|
||||||
|
$commentButton,
|
||||||
|
;
|
||||||
|
|
||||||
|
// FIXME: Do this conditionally
|
||||||
|
$buttonWrapper.append(
|
||||||
|
$acceptButton,
|
||||||
|
$declineButton,
|
||||||
|
$commentButton
|
||||||
|
);
|
||||||
|
|
||||||
|
AFCH.initFeedback( $afchReviewPanel, 'article review' );
|
||||||
|
}
|
||||||
|
|
||||||
|
addMessages();
|
||||||
|
|
||||||
|
$afchReviewPanel = $( '<div>' )
|
||||||
|
.attr( 'id', 'afch' )
|
||||||
|
.addClass( 'afch-loading' )
|
||||||
|
.prependTo( '#mw-content-text' )
|
||||||
|
// FIXME: Show a sexy loader graphic
|
||||||
|
.text( 'AFCH is loading...' );
|
||||||
|
|
||||||
|
// Set up the link which opens the interface
|
||||||
|
$( '<span>' )
|
||||||
|
.attr( 'id', 'afch-open' )
|
||||||
|
.appendTo( '#firstHeading' )
|
||||||
|
.text( 'Review submission »' )
|
||||||
|
.on( 'click', function () {
|
||||||
|
$afchReviewPanel.show( 'slide', { direction: 'down' } );
|
||||||
|
setupReviewPanel();
|
||||||
|
})
|
||||||
|
|
||||||
} )( AFCH, jQuery, mediawiki );
|
} )( AFCH, jQuery, mediawiki );
|
||||||
//</nowiki>
|
//</nowiki>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user