public function execute() { $user = $this->getUser(); if ($user->isAnon()) { $this->dieUsage('Anonymous users cannot use watchlist change notifications', 'notloggedin'); } $params = $this->extractRequestParams(); $this->requireMaxOneParameter($params, 'timestamp', 'torevid', 'newerthanrevid'); $pageSet = new ApiPageSet($this); $args = array_merge(array($params, 'entirewatchlist'), array_keys($pageSet->getAllowedParams())); call_user_func_array(array($this, 'requireOnlyOneParameter'), $args); $dbw = $this->getDB(DB_MASTER); $timestamp = null; if (isset($params['timestamp'])) { $timestamp = $dbw->timestamp($params['timestamp']); } if (!$params['entirewatchlist']) { $pageSet->execute(); } if (isset($params['torevid'])) { if ($params['entirewatchlist'] || $pageSet->getGoodTitleCount() > 1) { $this->dieUsage('torevid may only be used with a single page', 'multpages'); } $title = reset($pageSet->getGoodTitles()); $timestamp = Revision::getTimestampFromId($title, $params['torevid']); if ($timestamp) { $timestamp = $dbw->timestamp($timestamp); } else { $timestamp = null; } } elseif (isset($params['newerthanrevid'])) { if ($params['entirewatchlist'] || $pageSet->getGoodTitleCount() > 1) { $this->dieUsage('newerthanrevid may only be used with a single page', 'multpages'); } $title = reset($pageSet->getGoodTitles()); $revid = $title->getNextRevisionID($params['newerthanrevid']); if ($revid) { $timestamp = $dbw->timestamp(Revision::getTimestampFromId($title, $revid)); } else { $timestamp = null; } } $apiResult = $this->getResult(); $result = array(); if ($params['entirewatchlist']) { // Entire watchlist mode: Just update the thing and return a success indicator $dbw->update('watchlist', array('wl_notificationtimestamp' => $timestamp), array('wl_user' => $user->getID()), __METHOD__); $result['notificationtimestamp'] = is_null($timestamp) ? '' : wfTimestamp(TS_ISO_8601, $timestamp); } else { // First, log the invalid titles foreach ($pageSet->getInvalidTitles() as $title) { $r = array(); $r['title'] = $title; $r['invalid'] = ''; $result[] = $r; } foreach ($pageSet->getMissingPageIDs() as $p) { $page = array(); $page['pageid'] = $p; $page['missing'] = ''; $page['notwatched'] = ''; $result[] = $page; } foreach ($pageSet->getMissingRevisionIDs() as $r) { $rev = array(); $rev['revid'] = $r; $rev['missing'] = ''; $rev['notwatched'] = ''; $result[] = $rev; } // Now process the valid titles $lb = new LinkBatch($pageSet->getTitles()); $dbw->update('watchlist', array('wl_notificationtimestamp' => $timestamp), array('wl_user' => $user->getID(), $lb->constructSet('wl', $dbw)), __METHOD__); // Query the results of our update $timestamps = array(); $res = $dbw->select('watchlist', array('wl_namespace', 'wl_title', 'wl_notificationtimestamp'), array('wl_user' => $user->getID(), $lb->constructSet('wl', $dbw)), __METHOD__); foreach ($res as $row) { $timestamps[$row->wl_namespace][$row->wl_title] = $row->wl_notificationtimestamp; } // Now, put the valid titles into the result foreach ($pageSet->getTitles() as $title) { $ns = $title->getNamespace(); $dbkey = $title->getDBkey(); $r = array('ns' => intval($ns), 'title' => $title->getPrefixedText()); if (!$title->exists()) { $r['missing'] = ''; } if (isset($timestamps[$ns]) && array_key_exists($dbkey, $timestamps[$ns])) { $r['notificationtimestamp'] = ''; if ($timestamps[$ns][$dbkey] !== null) { $r['notificationtimestamp'] = wfTimestamp(TS_ISO_8601, $timestamps[$ns][$dbkey]); } } else { $r['notwatched'] = ''; } $result[] = $r; } $apiResult->setIndexedTagName($result, 'page'); } $apiResult->addValue(null, $this->getModuleName(), $result); }
/** * Purges the cache of a page */ public function execute() { $user = $this->getUser(); $params = $this->extractRequestParams(); if (!$user->isAllowed('purge') && !$this->getMain()->isInternalMode() && !$this->getRequest()->wasPosted()) { $this->dieUsageMsg(array('mustbeposted', $this->getModuleName())); } $forceLinkUpdate = $params['forcelinkupdate']; $pageSet = new ApiPageSet($this); $pageSet->execute(); $result = array(); foreach ($pageSet->getInvalidTitles() as $title) { $r = array(); $r['title'] = $title; $r['invalid'] = ''; $result[] = $r; } foreach ($pageSet->getMissingPageIDs() as $p) { $page = array(); $page['pageid'] = $p; $page['missing'] = ''; $result[] = $page; } foreach ($pageSet->getMissingRevisionIDs() as $r) { $rev = array(); $rev['revid'] = $r; $rev['missing'] = ''; $result[] = $rev; } foreach ($pageSet->getTitles() as $title) { $r = array(); ApiQueryBase::addTitleInfo($r, $title); if (!$title->exists()) { $r['missing'] = ''; $result[] = $r; continue; } $page = WikiPage::factory($title); $page->doPurge(); // Directly purge and skip the UI part of purge(). $r['purged'] = ''; if ($forceLinkUpdate) { if (!$user->pingLimiter()) { global $wgParser, $wgEnableParserCache; $popts = $page->makeParserOptions('canonical'); $p_result = $wgParser->parse($page->getRawText(), $title, $popts, true, true, $page->getLatest()); # Update the links tables $updates = $p_result->getSecondaryDataUpdates($title); DataUpdate::runUpdates($updates); $r['linkupdate'] = ''; if ($wgEnableParserCache) { $pcache = ParserCache::singleton(); $pcache->save($p_result, $page, $popts); } } else { $error = $this->parseMsg(array('actionthrottledtext')); $this->setWarning($error['info']); $forceLinkUpdate = false; } } $result[] = $r; } $apiResult = $this->getResult(); $apiResult->setIndexedTagName($result, 'page'); $apiResult->addValue(null, $this->getModuleName(), $result); }