}
if ($watchthis) {
- if(!$this->mTitle->userIsWatching()) $this->watch();
+ if(!$this->mTitle->userIsWatching()) $this->doWatch();
} else {
if ( $this->mTitle->userIsWatching() ) {
- $this->unwatch();
+ $this->doUnwatch();
}
}
if (!$this->mTitle->userIsWatching()) {
$dbw->immediateCommit();
$dbw->begin();
- $this->watch();
+ $this->doWatch();
$dbw->commit();
}
} else {
if ( $this->mTitle->userIsWatching() ) {
$dbw->immediateCommit();
$dbw->begin();
- $this->unwatch();
+ $this->doUnwatch();
$dbw->commit();
}
}
}
/**
- * Add this page to $wgUser's watchlist
+ * User-interface handler for the "watch" action
*/
function watch() {
$wgOut->readOnlyPage();
return;
}
-
- if (wfRunHooks('WatchArticle', array(&$wgUser, &$this))) {
-
- $wgUser->addWatch( $this->mTitle );
- $wgUser->saveSettings();
-
- wfRunHooks('WatchArticleComplete', array(&$wgUser, &$this));
-
+
+ if( $this->doWatch() ) {
$wgOut->setPagetitle( wfMsg( 'addedwatch' ) );
$wgOut->setRobotpolicy( 'noindex,follow' );
$wgOut->returnToMain( true, $this->mTitle->getPrefixedText() );
}
-
+
/**
- * Stop watching a page
+ * Add this page to $wgUser's watchlist
+ * @return bool true on successful watch operation
*/
+ function doWatch() {
+ global $wgUser;
+ if( $wgUser->isAnon() ) {
+ return false;
+ }
+
+ if (wfRunHooks('WatchArticle', array(&$wgUser, &$this))) {
+ $wgUser->addWatch( $this->mTitle );
+ $wgUser->saveSettings();
+ return wfRunHooks('WatchArticleComplete', array(&$wgUser, &$this));
+ }
+
+ return false;
+ }
+
+ /**
+ * User interface handler for the "unwatch" action.
+ */
function unwatch() {
global $wgUser, $wgOut;
$wgOut->readOnlyPage();
return;
}
-
- if (wfRunHooks('UnwatchArticle', array(&$wgUser, &$this))) {
-
- $wgUser->removeWatch( $this->mTitle );
- $wgUser->saveSettings();
-
- wfRunHooks('UnwatchArticleComplete', array(&$wgUser, &$this));
-
+
+ if( $this->doUnwatch() ) {
$wgOut->setPagetitle( wfMsg( 'removedwatch' ) );
$wgOut->setRobotpolicy( 'noindex,follow' );
$wgOut->returnToMain( true, $this->mTitle->getPrefixedText() );
}
+
+ /**
+ * Stop watching a page
+ * @return bool true on successful unwatch
+ */
+ function doUnwatch() {
+ global $wgUser;
+ if( $wgUser->isAnon() ) {
+ return false;
+ }
+
+ if (wfRunHooks('UnwatchArticle', array(&$wgUser, &$this))) {
+ $wgUser->removeWatch( $this->mTitle );
+ $wgUser->saveSettings();
+
+ return wfRunHooks('UnwatchArticleComplete', array(&$wgUser, &$this));
+ }
+
+ return false;
+ }
/**
* action=protect handler