r107350 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107349‎ | r107350 | r107351 >
Date:00:44, 27 December 2011
Author:krinkle
Status:resolved (Comments)
Tags:
Comment:
[mediawiki.api] write mediawiki.api.watch module
* add mediawiki.api.watch module
* mediawiki.api.parse.js: remove 'data && ' check to match the other modules. If data is not good, then the internal error handler will have already handled it and never call the ok-callback in the first place.
* mw.Api.errors: adding error codes by ApiWatch.php
Modified paths:
  • /trunk/phase3/resources/Resources.php (modified) (history)
  • /trunk/phase3/resources/mediawiki/mediawiki.api.js (modified) (history)
  • /trunk/phase3/resources/mediawiki/mediawiki.api.parse.js (modified) (history)
  • /trunk/phase3/resources/mediawiki/mediawiki.api.watch.js (added) (history)

Diff [purge]

Index: trunk/phase3/resources/Resources.php
@@ -526,6 +526,10 @@
527527 'mediawiki.Title'
528528 ),
529529 ),
 530+ 'mediawiki.api.watch' => array(
 531+ 'scripts' => 'resources/mediawiki/mediawiki.api.watch.js',
 532+ 'dependencies' => 'mediawiki.api',
 533+ ),
530534 'mediawiki.debug' => array(
531535 'scripts' => 'resources/mediawiki/mediawiki.debug.js',
532536 'styles' => 'resources/mediawiki/mediawiki.debug.css',
@@ -614,6 +618,7 @@
615619 ),
616620 'mediawiki.action.watch.ajax' => array(
617621 'scripts' => 'resources/mediawiki.action/mediawiki.action.watch.ajax.js',
 622+ 'dependencies' => 'mediawiki.api.watch',
618623 'messages' => array(
619624 'watch',
620625 'unwatch',
Index: trunk/phase3/resources/mediawiki/mediawiki.api.js
@@ -182,7 +182,6 @@
183183 // upload succeeded, but no image info.
184184 // this is probably impossible, but might as well check for it
185185 'noimageinfo',
186 -
187186 // remote errors, defined in API
188187 'uploaddisabled',
189188 'nomodule',
@@ -207,7 +206,9 @@
208207 'overwrite',
209208 'badtoken',
210209 'fetchfileerror',
211 - 'fileexists-shared-forbidden'
 210+ 'fileexists-shared-forbidden',
 211+ 'invalidtitle',
 212+ 'notloggedin'
212213 ];
213214
214215 /**
Index: trunk/phase3/resources/mediawiki/mediawiki.api.watch.js
@@ -0,0 +1,59 @@
 2+/**
 3+ * Additional mw.Api methods to assist with (un)watching wiki pages.
 4+ */
 5+( function( $, mw ) {
 6+
 7+ $.extend( mw.Api.prototype, {
 8+ /**
 9+ * Convinience method for 'action=watch'.
 10+ *
 11+ * @param page {String|mw.Title} Full page name or instance of mw.Title
 12+ * @param success {Function} callback to which the watch object will be passed
 13+ * watch object contains 'title' (full page name), 'watched' (boolean) and
 14+ * 'message' (parsed HTML of the 'addedwatchtext' message).
 15+ * @param err {Function} callback if error (optional)
 16+ * @param unwatch {Boolean} Internal variable, do not use. Used by unwatch() to
 17+ * reuse this function.
 18+ * @return {jqXHR}
 19+ */
 20+ watch: function( page, success, err, unwatch ) {
 21+ var params, ok;
 22+ params = {
 23+ action: 'watch',
 24+ title: String( page ),
 25+ token: mw.user.tokens.get( 'watchToken' ),
 26+ uselang: mw.config.get( 'wgUserLanguage' )
 27+ };
 28+ ok = function( data ) {
 29+ success( data.watch );
 30+ };
 31+ return this.post( params, { ok: ok, err: err } );
 32+ },
 33+ /**
 34+ * Convinience method for 'action=watch&unwatch='.
 35+ *
 36+ * @param page {String|mw.Title} Full page name or instance of mw.Title
 37+ * @param success {Function} callback to which the watch object will be passed
 38+ * watch object contains 'title' (full page name), 'unwatched' (boolean) and
 39+ * 'message' (parsed HTML of the 'removedwatchtext' message).
 40+ * @param err {Function} callback if error (optional)
 41+ * @return {jqXHR}
 42+ */
 43+ unwatch: function( page, success, err, unwatch ) {
 44+ var params, ok;
 45+ params = {
 46+ action: 'watch',
 47+ unwatch: 1,
 48+ title: String( page ),
 49+ token: mw.user.tokens.get( 'watchToken' ),
 50+ uselang: mw.config.get( 'wgUserLanguage' )
 51+ };
 52+ ok = function( data ) {
 53+ success( data.watch );
 54+ };
 55+ return this.post( params, { ok: ok, err: err } );
 56+ }
 57+
 58+ } );
 59+
 60+} )( jQuery, mediaWiki );
Index: trunk/phase3/resources/mediawiki/mediawiki.api.parse.js
@@ -19,7 +19,7 @@
2020 action: 'parse'
2121 },
2222 ok = function( data ) {
23 - if ( data && data.parse && data.parse.text && data.parse.text['*'] ) {
 23+ if ( data.parse && data.parse.text && data.parse.text['*'] ) {
2424 success( data.parse.text['*'] );
2525 }
2626 };

Follow-up revisions

RevisionCommit summaryAuthorDate
r107352fix svn:eol-style for r107350krinkle01:02, 27 December 2011
r107353@since for r107350krinkle01:03, 27 December 2011
r107354[mediawiki.action.watch.ajax.js] Rewrite using mw.Api and fixes bug 27146...krinkle01:21, 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
r113893[mediawiki.action.watch] Move re-used logic into local function...krinkle05:54, 15 March 2012

Comments

#Comment by Reedy (talk | contribs)   00:48, 27 December 2011

Missing svn:eol-style native on mediawiki.api.watch.js

#Comment by Brion VIBBER (talk | contribs)   23:20, 3 January 2012

'unwatch' parameter is not used, and function is not reused as mentioned in the comments.

#Comment by Duplicatebug (talk | contribs)   20:25, 15 March 2012

Using 1 for boolean parameter in api is bad (unwatch=1) because that indicates, that 0 means false, but that is not right. Use an empty string and save that byte. (The equal sign is necessary, because sometimes (most in post requests) without the equal sign the parameter is not recognised by the api)

Status & tagging log