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

Revision: 112440
Author:   krinkle
Date:     2012-02-26 15:57:01 +0000 (Sun, 26 Feb 2012)
Log Message:
-----------
[mediawiki.api.watch] Re-use watch() in unwatch().
- Fix dependency issue. In practice not an issue due to user.tokens being in 
the HTML output before the first mw.loader.load()
- Follows-up r107969, r107350

Modified Paths:
--------------
    trunk/phase3/resources/Resources.php
    trunk/phase3/resources/mediawiki.api/mediawiki.api.watch.js

Modified: trunk/phase3/resources/Resources.php
===================================================================
--- trunk/phase3/resources/Resources.php        2012-02-26 14:40:26 UTC (rev 
112439)
+++ trunk/phase3/resources/Resources.php        2012-02-26 15:57:01 UTC (rev 
112440)
@@ -537,7 +537,10 @@
        ),
        'mediawiki.api.watch' => array( 
                'scripts' => 'resources/mediawiki.api/mediawiki.api.watch.js',
-               'dependencies' => array( 'mediawiki.api', 'mediawiki.user' ),
+               'dependencies' => array(
+                       'mediawiki.api',
+                       'user.tokens',
+               ),
        ),
        'mediawiki.debug' => array(
                'scripts' => 'resources/mediawiki/mediawiki.debug.js',

Modified: trunk/phase3/resources/mediawiki.api/mediawiki.api.watch.js
===================================================================
--- trunk/phase3/resources/mediawiki.api/mediawiki.api.watch.js 2012-02-26 
14:40:26 UTC (rev 112439)
+++ trunk/phase3/resources/mediawiki.api/mediawiki.api.watch.js 2012-02-26 
15:57:01 UTC (rev 112440)
@@ -12,10 +12,12 @@
                 * @param success {Function} callback to which the watch object 
will be passed
                 * watch object contains 'title' (full page name), '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)
                 * @return {jqXHR}
                 */
-               watch: function( page, success, err ) {
+               watch: function( page, success, err, _unwatch ) {
                        var params, ok;
                        params = {
                                action: 'watch',
@@ -23,13 +25,16 @@
                                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 } );
                },
                /**
-                * Convinience method for 'action=watch&unwatch='.
+                * 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
@@ -39,18 +44,7 @@
                 * @return {jqXHR}
                 */
                unwatch: function( page, success, err ) {
-                       var params, ok;
-                       params = {
-                               action: 'watch',
-                               unwatch: 1,
-                               title: String( page ),
-                               token: mw.user.tokens.get( 'watchToken' ),
-                               uselang: mw.config.get( 'wgUserLanguage' )
-                       };
-                       ok = function( data ) {
-                               success( data.watch );
-                       };
-                       return this.post( params, { ok: ok, err: err } );
+                       return this.watch( page, success, err, true );
                }
 
        } );


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

Reply via email to