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) { $this->dieUsageMsg(array('invalidtitle', $params['title'])); } $article = new Article($title); $res = array('title' => $title->getPrefixedText()); if ($params['unwatch']) { $res['unwatched'] = ''; $success = $article->doUnwatch(); } else { $res['watched'] = ''; $success = $article->doWatch(); } if (!$success) { $this->dieUsageMsg(array('hookaborted')); } $this->getResult()->addValue(null, $this->getModuleName(), $res); }
/** * Called for AJAX watch/unwatch requests. * @param $pagename Prefixed title string for page to watch/unwatch * @param $watch String 'w' to watch, 'u' to unwatch * @return String '<w#>' or '<u#>' on successful watch or unwatch, * respectively, followed by an HTML message to display in the alert box; or * '<err#>' on error */ function wfAjaxWatch($pagename = "", $watch = "") { if (wfReadOnly()) { // redirect to action=(un)watch, which will display the database lock // message return '<err#>'; } if ('w' !== $watch && 'u' !== $watch) { return '<err#>'; } $watch = 'w' === $watch; $title = Title::newFromDBkey($pagename); if (!$title) { // Invalid title return '<err#>'; } $article = new Article($title); $watching = $title->userIsWatching(); if ($watch) { if (!$watching) { $dbw = wfGetDB(DB_MASTER); $dbw->begin(); $ok = $article->doWatch(); $dbw->commit(); } } else { if ($watching) { $dbw = wfGetDB(DB_MASTER); $dbw->begin(); $ok = $article->doUnwatch(); $dbw->commit(); } } // Something stopped the change if (isset($ok) && !$ok) { return '<err#>'; } if ($watch) { return '<w#>' . wfMsgExt('addedwatchtext', array('parse'), $title->getPrefixedText()); } else { return '<u#>' . wfMsgExt('removedwatchtext', array('parse'), $title->getPrefixedText()); } }
/** * Really delete the file * * @param $title Title object * @param $file File object * @param $oldimage String: archive name * @param $reason String: reason of the deletion * @param $suppress Boolean: whether to mark all deleted versions as restricted */ public static function doDelete(&$title, &$file, &$oldimage, $reason, $suppress) { global $wgUser; $article = null; $status = Status::newFatal('error'); if ($oldimage) { $status = $file->deleteOld($oldimage, $reason, $suppress); if ($status->ok) { // Need to do a log item $log = new LogPage('delete'); $logComment = wfMsgForContent('deletedrevision', $oldimage); if (trim($reason) != '') { $logComment .= wfMsgForContent('colon-separator') . $reason; } $log->addEntry('delete', $title, $logComment); } } else { $id = $title->getArticleID(Title::GAID_FOR_UPDATE); $article = new Article($title); $error = ''; $dbw = wfGetDB(DB_MASTER); try { if (wfRunHooks('ArticleDelete', array(&$article, &$wgUser, &$reason, &$error))) { // delete the associated article first if ($article->doDeleteArticle($reason, $suppress, $id, false)) { global $wgRequest; if ($wgRequest->getCheck('wpWatch') && $wgUser->isLoggedIn()) { $article->doWatch(); } elseif ($title->userIsWatching()) { $article->doUnwatch(); } $status = $file->delete($reason, $suppress); if ($status->ok) { $dbw->commit(); wfRunHooks('ArticleDeleteComplete', array(&$article, &$wgUser, $reason, $id)); } else { $dbw->rollback(); } } } } catch (MWException $e) { // rollback before returning to prevent UI from displaying incorrect "View or restore N deleted edits?" $dbw->rollback(); throw $e; } } if ($status->isGood()) { wfRunHooks('FileDeleteComplete', array(&$file, &$oldimage, &$article, &$wgUser, &$reason)); } return $status; }
public static function doDelete(&$title, &$file, &$oldimage, $reason, $suppress) { $article = null; if ($oldimage) { $status = $file->deleteOld($oldimage, $reason, $suppress); if ($status->ok) { // Need to do a log item $log = new LogPage('delete'); $logComment = wfMsgForContent('deletedrevision', $oldimage); if (trim($reason) != '') { $logComment .= ": {$reason}"; } $log->addEntry('delete', $title, $logComment); } } else { $status = $file->delete($reason, $suppress); if ($status->ok) { $id = $title->getArticleID(GAID_FOR_UPDATE); // Need to delete the associated article $article = new Article($title); if (wfRunHooks('ArticleDelete', array(&$article, &$wgUser, &$reason))) { if ($article->doDeleteArticle($reason, $suppress, $id)) { global $wgRequest; if ($wgRequest->getCheck('wpWatch')) { $article->doWatch(); } elseif ($title->userIsWatching()) { $article->doUnwatch(); } wfRunHooks('ArticleDeleteComplete', array(&$article, &$wgUser, $reason, $id)); } } } } if ($status->isGood()) { wfRunHooks('FileDeleteComplete', array(&$file, &$oldimage, &$article, &$wgUser, &$reason)); } return $status; }
/** * Called for AJAX watch/unwatch requests. * @param $pageID Integer ID of the page to be watched/unwatched * @param $watch String 'w' to watch, 'u' to unwatch * @return String '<w#>' or '<u#>' on successful watch or unwatch, respectively, or '<err#>' on error (invalid XML in case we want to add HTML sometime) */ function wfAjaxWatch($pageID = "", $watch = "") { if (wfReadOnly()) { return '<err#>'; } // redirect to action=(un)watch, which will display the database lock message if ('w' !== $watch && 'u' !== $watch || !is_numeric($pageID)) { return '<err#>'; } $watch = 'w' === $watch; $pageID = intval($pageID); $title = Title::newFromID($pageID); if (!$title) { return '<err#>'; } $article = new Article($title); $watching = $title->userIsWatching(); if ($watch) { if (!$watching) { $dbw =& wfGetDB(DB_MASTER); $dbw->begin(); $article->doWatch(); $dbw->commit(); } } else { if ($watching) { $dbw =& wfGetDB(DB_MASTER); $dbw->begin(); $article->doUnwatch(); $dbw->commit(); } } return $watch ? '<w#>' : '<u#>'; }
/** * Set a watch (or unwatch) based the based on a watchlist parameter. * @param $watch String Valid values: 'watch', 'unwatch', 'preferences', 'nochange' * @param $titleObj Title the article's title to change * @param $userOption String The user option to consider when $watch=preferences */ protected function setWatch($watch, $titleObj, $userOption = null) { $value = $this->getWatchlistValue($watch, $titleObj, $userOption); if ($value === null) { return; } $articleObj = new Article($titleObj); if ($value) { $articleObj->doWatch(); } else { $articleObj->doUnwatch(); } }