r113893 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113892‎ | r113893 | r113894 >
Date:05:54, 15 March 2012
Author:krinkle
Status:reverted
Tags:gerritmigration, roan 
Comment:
[mediawiki.action.watch] Move re-used logic into local function
* Follows-up r112440, r107969, r107350
Modified paths:
  • /trunk/phase3/resources/mediawiki.api/mediawiki.api.watch.js (modified) (history)

Diff [purge]

Index: trunk/phase3/resources/mediawiki.api/mediawiki.api.watch.js
@@ -4,47 +4,51 @@
55 */
66 ( function( $, mw ) {
77
 8+ /**
 9+ * @context {mw.Api}
 10+ */
 11+ function doWatchInternal( page, success, err, addParams ) {
 12+ var params = {
 13+ action: 'watch',
 14+ title: String( page ),
 15+ token: mw.user.tokens.get( 'watchToken' ),
 16+ uselang: mw.config.get( 'wgUserLanguage' )
 17+ };
 18+ function ok( data ) {
 19+ success( data.watch );
 20+ }
 21+ if ( addParams ) {
 22+ $.extend( params, addParams );
 23+ }
 24+ return this.post( params, { ok: ok, err: err } );
 25+ }
 26+
827 $.extend( mw.Api.prototype, {
928 /**
1029 * Convinience method for 'action=watch'.
1130 *
1231 * @param page {String|mw.Title} Full page name or instance of mw.Title
13 - * @param success {Function} callback to which the watch object will be passed
14 - * watch object contains 'title' (full page name), 'watched' (boolean) and
 32+ * @param success {Function} Callback to which the watch object will be passed.
 33+ * Watch object contains properties 'title' (full pagename), 'watched' (boolean) and
1534 * 'message' (parsed HTML of the 'addedwatchtext' message).
16 - * @param _unwatch {Boolean} Internally used to re-use this logic for unwatch(),
17 - * do not use outside this module.
18 - * @param err {Function} callback if error (optional)
 35+ * @param err {Function} Error callback (optional)
1936 * @return {jqXHR}
2037 */
21 - watch: function( page, success, err, _unwatch ) {
22 - var params, ok;
23 - params = {
24 - action: 'watch',
25 - title: String( page ),
26 - token: mw.user.tokens.get( 'watchToken' ),
27 - uselang: mw.config.get( 'wgUserLanguage' )
28 - };
29 - if ( _unwatch ) {
30 - params.unwatch = 1;
31 - }
32 - ok = function( data ) {
33 - success( data.watch );
34 - };
35 - return this.post( params, { ok: ok, err: err } );
 38+ watch: function ( page, success, err ) {
 39+ return doWatchInternal.call( this, page, success, err );
3640 },
3741 /**
3842 * Convinience method for 'action=watch&unwatch=1'.
3943 *
4044 * @param page {String|mw.Title} Full page name or instance of mw.Title
41 - * @param success {Function} callback to which the watch object will be passed
42 - * watch object contains 'title' (full page name), 'unwatched' (boolean) and
 45+ * @param success {Function} Callback to which the watch object will be passed.
 46+ * Watch object contains properties 'title' (full pagename), 'watched' (boolean) and
4347 * 'message' (parsed HTML of the 'removedwatchtext' message).
44 - * @param err {Function} callback if error (optional)
 48+ * @param err {Function} Error callback (optional)
4549 * @return {jqXHR}
4650 */
47 - unwatch: function( page, success, err ) {
48 - return this.watch( page, success, err, true );
 51+ unwatch: function ( page, success, err ) {
 52+ return doWatchInternal.call( this, page, success, err, { unwatch: 1 } );
4953 }
5054
5155 } );

Follow-up revisions

RevisionCommit summaryAuthorDate
r114335Revert r107309, r113601, r113704, r113742, r113792, r113838, r113859, r113893......catrope00:16, 21 March 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r107350[mediawiki.api] write mediawiki.api.watch module...krinkle00:44, 27 December 2011
r107969Fix unused parameter from r107350...krinkle00:05, 4 January 2012
r112440[mediawiki.api.watch] Re-use watch() in unwatch()....krinkle15:57, 26 February 2012

Status & tagging log