public function execute() { global $wgUser; if (!$wgUser->isLoggedIn()) { $this->dieUsage('You must be logged-in to have a watchlist', 'notloggedin'); } $params = $this->extractRequestParams(); $title = Title::newFromText($params['title']); if (!$title || $title->getNamespace() < 0) { $this->dieUsageMsg(array('invalidtitle', $params['title'])); } $article = new Article($title, 0); $res = array('title' => $title->getPrefixedText()); if ($params['unwatch']) { $res['unwatched'] = ''; $res['message'] = wfMsgExt('removedwatchtext', array('parse'), $title->getPrefixedText()); $success = WatchAction::doUnwatch($title, $wgUser); } else { $res['watched'] = ''; $res['message'] = wfMsgExt('addedwatchtext', array('parse'), $title->getPrefixedText()); $success = UnwatchAction::doWatch($title, $wgUser); } if (!$success) { $this->dieUsageMsg('hookaborted'); } $this->getResult()->addValue(null, $this->getModuleName(), $res); }
public function execute() { $user = $this->getUser(); if ( !$user->isLoggedIn() ) { $this->dieUsage( 'You must be logged-in to have a watchlist', 'notloggedin' ); } if ( !$user->isAllowed( 'editmywatchlist' ) ) { $this->dieUsage( 'You don\'t have permission to edit your watchlist', 'permissiondenied' ); } $params = $this->extractRequestParams(); $title = Title::newFromText( $params['title'] ); if ( !$title || $title->isExternal() || !$title->canExist() ) { $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) ); } $res = array( 'title' => $title->getPrefixedText() ); // Currently unnecessary, code to act as a safeguard against any change in current behavior of uselang // Copy from ApiParse $oldLang = null; if ( isset( $params['uselang'] ) && $params['uselang'] != $this->getContext()->getLanguage()->getCode() ) { $oldLang = $this->getContext()->getLanguage(); // Backup language $this->getContext()->setLanguage( Language::factory( $params['uselang'] ) ); } if ( $params['unwatch'] ) { $res['unwatched'] = ''; $res['message'] = $this->msg( 'removedwatchtext', $title->getPrefixedText() )->title( $title )->parseAsBlock(); $status = UnwatchAction::doUnwatch( $title, $user ); } else { $res['watched'] = ''; $res['message'] = $this->msg( 'addedwatchtext', $title->getPrefixedText() )->title( $title )->parseAsBlock(); $status = WatchAction::doWatch( $title, $user ); } if ( !is_null( $oldLang ) ) { $this->getContext()->setLanguage( $oldLang ); // Reset language to $oldLang } if ( !$status->isOK() ) { $this->dieStatus( $status ); } $this->getResult()->addValue( null, $this->getModuleName(), $res ); }
private function watchTitle(Title $title, User $user, array $params, $compatibilityMode = false) { if (!$title->isWatchable()) { return array('title' => $title->getPrefixedText(), 'watchable' => 0); } $res = array('title' => $title->getPrefixedText()); if ($params['unwatch']) { $status = UnwatchAction::doUnwatch($title, $user); $res['unwatched'] = $status->isOK(); if ($status->isOK()) { $res['message'] = $this->msg('removedwatchtext', $title->getPrefixedText())->title($title)->parseAsBlock(); } } else { $status = WatchAction::doWatch($title, $user); $res['watched'] = $status->isOK(); if ($status->isOK()) { $res['message'] = $this->msg('addedwatchtext', $title->getPrefixedText())->title($title)->parseAsBlock(); } } if (!$status->isOK()) { if ($compatibilityMode) { $this->dieStatus($status); } $res['error'] = $this->getErrorFromStatus($status); } return $res; }
function watchThisPage() { global $wgOut, $wgUser; ++$this->mWatchLinkNum; // Cache $title = $this->getSkin()->getTitle(); if ($wgOut->isArticleRelated()) { if ($wgUser->isWatched($title)) { $text = wfMessage('unwatchthispage')->text(); $query = array('action' => 'unwatch', 'token' => UnwatchAction::getUnwatchToken($title, $wgUser)); $id = 'mw-unwatch-link' . $this->mWatchLinkNum; } else { $text = wfMessage('watchthispage')->text(); $query = array('action' => 'watch', 'token' => WatchAction::getWatchToken($title, $wgUser)); $id = 'mw-watch-link' . $this->mWatchLinkNum; } $s = Linker::linkKnown($title, $text, array('id' => $id), $query); } else { $s = wfMessage('notanarticle')->text(); } return $s; }
private function watchTitle(Title $title, User $user, array $params, $compatibilityMode = false) { if (!$title->isWatchable()) { return array('title' => $title->getPrefixedText(), 'watchable' => 0); } $res = array('title' => $title->getPrefixedText()); // Currently unnecessary, code to act as a safeguard against any change // in current behavior of uselang. // Copy from ApiParse $oldLang = null; if (isset($params['uselang']) && $params['uselang'] != $this->getContext()->getLanguage()->getCode()) { $oldLang = $this->getContext()->getLanguage(); // Backup language $this->getContext()->setLanguage(Language::factory($params['uselang'])); } if ($params['unwatch']) { $status = UnwatchAction::doUnwatch($title, $user); if ($status->isOK()) { $res['unwatched'] = ''; $res['message'] = $this->msg('removedwatchtext', $title->getPrefixedText())->title($title)->parseAsBlock(); } } else { $status = WatchAction::doWatch($title, $user); if ($status->isOK()) { $res['watched'] = ''; $res['message'] = $this->msg('addedwatchtext', $title->getPrefixedText())->title($title)->parseAsBlock(); } } if (!is_null($oldLang)) { $this->getContext()->setLanguage($oldLang); // Reset language to $oldLang } if (!$status->isOK()) { if ($compatibilityMode) { $this->dieStatus($status); } $res['error'] = $this->getErrorFromStatus($status); } return $res; }