https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113893

Revision: 113893
Author:   krinkle
Date:     2012-03-15 05:54:58 +0000 (Thu, 15 Mar 2012)
Log Message:
-----------
[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: trunk/phase3/resources/mediawiki.api/mediawiki.api.watch.js
===================================================================
--- trunk/phase3/resources/mediawiki.api/mediawiki.api.watch.js 2012-03-15 
04:34:22 UTC (rev 113892)
+++ trunk/phase3/resources/mediawiki.api/mediawiki.api.watch.js 2012-03-15 
05:54:58 UTC (rev 113893)
@@ -4,47 +4,51 @@
  */
 ( function( $, mw ) {
 
+       /**
+        * @context {mw.Api}
+        */
+       function doWatchInternal( page, success, err, addParams ) {
+               var params = {
+                       action: 'watch',
+                       title: String( page ),
+                       token: mw.user.tokens.get( 'watchToken' ),
+                       uselang: mw.config.get( 'wgUserLanguage' )
+               };
+               function ok( data ) {
+                       success( data.watch );
+               }
+               if ( addParams ) {
+                       $.extend( params, addParams );
+               }
+               return this.post( params, { ok: ok, err: err } );
+       }
+
        $.extend( mw.Api.prototype, {
                /**
                 * Convinience method for 'action=watch'.
                 *
                 * @param page {String|mw.Title} Full page name or instance of 
mw.Title
-                * @param success {Function} callback to which the watch object 
will be passed
-                * watch object contains 'title' (full page name), 'watched' 
(boolean) and
+                * @param success {Function} Callback to which the watch object 
will be passed.
+                * Watch object contains properties 'title' (full pagename), 
'watched' (boolean) and
                 * 'message' (parsed HTML of the 'addedwatchtext' message).
-                * @param _unwatch {Boolean} Internally used to re-use this 
logic for unwatch(),
-                * do not use outside this module.
-                * @param err {Function} callback if error (optional)
+                * @param err {Function} Error callback (optional)
                 * @return {jqXHR}
                 */
-               watch: function( page, success, err, _unwatch ) {
-                       var params, ok;
-                       params = {
-                               action: 'watch',
-                               title: String( page ),
-                               token: mw.user.tokens.get( 'watchToken' ),
-                               uselang: mw.config.get( 'wgUserLanguage' )
-                       };
-                       if ( _unwatch ) {
-                               params.unwatch = 1;
-                       }
-                       ok = function( data ) {
-                               success( data.watch );
-                       };
-                       return this.post( params, { ok: ok, err: err } );
+               watch: function ( page, success, err ) {
+                       return doWatchInternal.call( this, page, success, err );
                },
                /**
                 * Convinience method for 'action=watch&unwatch=1'.
                 *
                 * @param page {String|mw.Title} Full page name or instance of 
mw.Title
-                * @param success {Function} callback to which the watch object 
will be passed
-                * watch object contains 'title' (full page name), 'unwatched' 
(boolean) and
+                * @param success {Function} Callback to which the watch object 
will be passed.
+                * Watch object contains properties 'title' (full pagename), 
'watched' (boolean) and
                 * 'message' (parsed HTML of the 'removedwatchtext' message).
-                * @param err {Function} callback if error (optional)
+                * @param err {Function} Error callback (optional)
                 * @return {jqXHR}
                 */
-               unwatch: function( page, success, err ) {
-                       return this.watch( page, success, err, true );
+               unwatch: function ( page, success, err ) {
+                       return doWatchInternal.call( this, page, success, err, 
{ unwatch: 1 } );
                }
 
        } );


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to