r82727 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82726‎ | r82727 | r82728 >
Date:15:51, 24 February 2011
Author:reedy
Status:ok (Comments)
Tags:
Comment:
Seems the api edit watch/unwatch wasn't too well tested (after it got poked a lot)

EditPage::commitWatch() unconditionally does a watch/unwatch...

And multiple watches of a watched page end up with an INSERT IGNORE, so not a big deal
Modified paths:
  • /trunk/phase3/includes/api/ApiBase.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiBase.php
@@ -578,9 +578,12 @@
579579 * @param $titleObj Title the page under consideration
580580 * @param $userOption String The user option to consider when $watchlist=preferences.
581581 * If not set will magically default to either watchdefault or watchcreations
582 - * @returns mixed
 582+ * @returns Boolean
583583 */
584584 protected function getWatchlistValue ( $watchlist, $titleObj, $userOption = null ) {
 585+
 586+ $userWatching = $titleObj->userIsWatching();
 587+
585588 global $wgUser;
586589 switch ( $watchlist ) {
587590 case 'watch':
@@ -591,22 +594,22 @@
592595
593596 case 'preferences':
594597 # If the user is already watching, don't bother checking
595 - if ( $titleObj->userIsWatching() ) {
596 - return null;
 598+ if ( $userWatching ) {
 599+ return true;
597600 }
598601 # If no user option was passed, use watchdefault or watchcreation
599602 if ( is_null( $userOption ) ) {
600603 $userOption = $titleObj->exists()
601604 ? 'watchdefault' : 'watchcreations';
602605 }
603 - # If the corresponding user option is true, watch, else no change
604 - return $wgUser->getOption( $userOption ) ? true : null;
 606+ # If the corresponding user option is true, watch, don't
 607+ return $wgUser->getOption( $userOption ) ? true : false;
605608
606609 case 'nochange':
607 - return null;
 610+ return $userWatching;
608611
609612 default:
610 - return null;
 613+ return $userWatching;
611614 }
612615 }
613616

Follow-up revisions

RevisionCommit summaryAuthorDate
r82729Followup r82727, improve comments, cast return value to boolreedy16:00, 24 February 2011
r82730MFT r82727, 82729reedy16:03, 24 February 2011
r82731MFT r82727, 82729reedy16:03, 24 February 2011

Comments

#Comment by Bryan (talk | contribs)   15:55, 24 February 2011

I think a comment in Article::doWatch() about the fact that it is safe to call multiple times would be appropriate.

The final comment in the preferences branch needs fixing.

You don't need a ternary in the return of preferences, just cast it to bool.

#Comment by Bryan (talk | contribs)   15:57, 24 February 2011

Functionally ok, btw.

Status & tagging log