r65017 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65016‎ | r65017 | r65018 >
Date:12:17, 14 April 2010
Author:btongminh
Status:ok
Tags:
Comment:
Followup to r64962: Fixed watchlist parameter in API. User options watchdeletions and watchmoves can now by overridden. Unwatching while editting is now possible.
Modified paths:
  • /trunk/phase3/includes/api/ApiBase.php (modified) (history)
  • /trunk/phase3/includes/api/ApiDelete.php (modified) (history)
  • /trunk/phase3/includes/api/ApiEditPage.php (modified) (history)
  • /trunk/phase3/includes/api/ApiMove.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiMove.php
@@ -125,15 +125,15 @@
126126 $watch = "preferences";
127127 if ( isset( $params['watchlist'] ) ) {
128128 $watch = $params['watchlist'];
129 - } elseif ( $wgUser->getOption( 'watchmoves' ) || $params['watch'] ) {
 129+ } elseif ( $params['watch'] ) {
130130 $watch = 'watch';
131131 } elseif ( $params['unwatch'] ) {
132132 $watch = 'unwatch';
133133 }
134134
135135 // Watch pages
136 - $this->setWatch( $watch, $fromTitle );
137 - $this->setWatch( $watch, $toTitle );
 136+ $this->setWatch( $watch, $fromTitle, 'watchmoves' );
 137+ $this->setWatch( $watch, $toTitle, 'watchmoves' );
138138
139139 $this->getResult()->addValue( null, $this->getModuleName(), $r );
140140 }
Index: trunk/phase3/includes/api/ApiDelete.php
@@ -88,12 +88,10 @@
8989 $watch = 'watch';
9090 } elseif ( $params['unwatch'] ) {
9191 $watch = 'unwatch';
92 - } elseif ( $wgUser->getOption( 'watchdeletion' ) ) {
93 - $watch = 'watch';
9492 } else {
9593 $watch = $params['watchlist'];
9694 }
97 - $this->setWatch( $watch, $titleObj );
 95+ $this->setWatch( $watch, $titleObj, 'watchdeletion' );
9896 }
9997
10098 $r = array( 'title' => $titleObj->getPrefixedText(), 'reason' => $reason );
Index: trunk/phase3/includes/api/ApiEditPage.php
@@ -211,7 +211,7 @@
212212 $watch = false;
213213 }
214214
215 - if ( $watch || $titleObj->userIsWatching() ) {
 215+ if ( $watch ) {
216216 $reqArr['wpWatchthis'] = '';
217217 }
218218
Index: trunk/phase3/includes/api/ApiBase.php
@@ -538,10 +538,12 @@
539539 /**
540540 * Return true if we're to watch the page, false if not, null if no change.
541541 * @param $watchlist String Valid values: 'watch', 'unwatch', 'preferences', 'nochange'
542 - * @param $titleObj Title (optional) the page under consideration
 542+ * @param $titleObj Title the page under consideration
 543+ * @param $userOption The user option to consider when $watchlist=preferences.
 544+ * If not set will magically default to either watchdefault or watchcreations
543545 * @returns mixed
544546 */
545 - protected function getWatchlistValue ( $watchlist, $titleObj = null ) {
 547+ protected function getWatchlistValue ( $watchlist, $titleObj, $userOption = null ) {
546548 switch ( $watchlist ) {
547549 case 'watch':
548550 return true;
@@ -551,16 +553,17 @@
552554
553555 case 'preferences':
554556 global $wgUser;
555 - if ( isset($titleObj) && !$titleObj->userIsWatching() ) {
556 - if ( $titleObj->exists() ) {
557 - if ( $wgUser->getOption( 'watchdefault' ) ) {
558 - return true;
559 - }
560 - } elseif ( $wgUser->getOption( 'watchcreations' ) ) {
561 - return true;
562 - }
 557+ # If the user is already watching, don't bother checking
 558+ if ( $titleObj->userIsWatching() ) {
 559+ return null;
563560 }
564 - return null;
 561+ # If no user option was passed, use watchdefault or watchcreation
 562+ if ( is_null( $userOption ) ) {
 563+ $userOption = $titleObj->exists()
 564+ ? 'watchdefault' : 'watchcreations';
 565+ }
 566+ # If the corresponding user option is true, watch, else no change
 567+ return $wgUser->getOption( $userOption ) ? true : null;
565568
566569 case 'nochange':
567570 return null;
@@ -574,10 +577,13 @@
575578 * Set a watch (or unwatch) based the based on a watchlist parameter.
576579 * @param $watch String Valid values: 'watch', 'unwatch', 'preferences', 'nochange'
577580 * @param $titleObj Title the article's title to change
 581+ * @param $userOption The user option to consider when $watch=preferences
578582 */
579 - protected function setWatch ( $watch, $titleObj ) {
580 - $value = $this->getWatchlistValue( $watch, $titleObj );
581 - if( $value === null ) return;
 583+ protected function setWatch ( $watch, $titleObj, $userOption = null ) {
 584+ $value = $this->getWatchlistValue( $watch, $titleObj, $userOption );
 585+ if( $value === null ) {
 586+ return;
 587+ }
582588
583589 $articleObj = new Article( $titleObj );
584590 if ( $value ) {

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r64962re r64291 and r64852 use ApiBase::setWatch instead of wgUser->*Watch to set w...mah15:44, 12 April 2010

Status & tagging log