'ApiQuery' => 'includes/api/ApiQuery.php',
'ApiQueryAllpages' => 'includes/api/ApiQueryAllpages.php',
'ApiQueryBase' => 'includes/api/ApiQueryBase.php',
+ 'ApiQueryBacklinks' => 'includes/api/ApiQueryBacklinks.php',
'ApiQueryInfo' => 'includes/api/ApiQueryInfo.php',
'ApiQueryLogEvents' => 'includes/api/ApiQueryLogEvents.php',
'ApiQueryRecentChanges'=> 'includes/api/ApiQueryRecentChanges.php',
$module->execute();
// Get data array
- $data = & $module->getResultData();
+ $data = $module->getResultData();
$feedItems = array ();
foreach ($data['query']['watchlist'] as $index => $info) {
}
public function execute() {
- $data = & $this->getResultData();
+ $data = $this->getResultData();
if (isset ($data['_feed']) && isset ($data['_feeditems'])) {
- $feed = & $data['_feed'];
- $items = & $data['_feeditems'];
+ $feed = $data['_feed'];
+ $items = $data['_feeditems'];
$feed->outHeader();
foreach ($items as & $item)
* @param $enableWrite bool should be set to true if the api may modify data
*/
public function __construct($request, $enableWrite = false) {
+
+ $this->mInternalMode = ($request instanceof FauxRequest);
+
// Special handling for the main module: $parent === $this
- parent :: __construct($this, 'main');
+ parent :: __construct($this, $this->mInternalMode ? 'main_int' : 'main');
- $this->mModules = & self :: $Modules;
+ $this->mModules = self :: $Modules;
$this->mModuleNames = array_keys($this->mModules); // todo: optimize
- $this->mFormats = & self :: $Formats;
+ $this->mFormats = self :: $Formats;
$this->mFormatNames = array_keys($this->mFormats); // todo: optimize
$this->mResult = new ApiResult($this);
$this->mRequest = & $request;
- $this->mInternalMode = ($request instanceof FauxRequest);
-
$this->mSquidMaxage = 0;
}
$module->execute();
// Get resulting data
- $data = & $module->getResultData();
+ $data = $module->getResultData();
// Reformat useful data for future printing by JSON engine
$srchres = array ();
* Extract all requested fields from the row received from the database
*/
public function processDbRow($row) {
- $pageId = intval($row->page_id);
-
+
// Store Title object in various data structures
$title = Title :: makeTitle($row->page_namespace, $row->page_title);
- $this->mAllPages[$row->page_namespace][$row->page_title] = $pageId;
+
+ // skip any pages that user has no rights to read
+ if ($title->userCanRead()) {
- if ($this->mResolveRedirects && $row->page_is_redirect == '1') {
- $this->mPendingRedirectIDs[$pageId] = $title;
- } else {
- $this->mGoodTitles[$pageId] = $title;
+ $pageId = intval($row->page_id);
+ $this->mAllPages[$row->page_namespace][$row->page_title] = $pageId;
+
+ if ($this->mResolveRedirects && $row->page_is_redirect == '1') {
+ $this->mPendingRedirectIDs[$pageId] = $title;
+ } else {
+ $this->mGoodTitles[$pageId] = $title;
+ }
+
+ foreach ($this->mRequestedPageFields as $fieldName => & $fieldValues)
+ $fieldValues[$pageId] = $row-> $fieldName;
}
-
- foreach ($this->mRequestedPageFields as $fieldName => & $fieldValues)
- $fieldValues[$pageId] = $row-> $fieldName;
}
public function finishPageSetGeneration() {
* #6 Repeat from step #1
*/
private function initFromTitles($titles) {
- $db = $this->getDB();
// Get validated and normalized title objects
$linkBatch = $this->processTitlesStrArray($titles);
if($linkBatch->isEmpty())
return;
+ $db = & $this->getDB();
$set = $linkBatch->constructSet('page', $db);
// Get pageIDs data from the `page` table
if(empty($pageids))
return;
- $db = $this->getDB();
$set = array (
'page_id' => $pageids
);
+ $db = & $this->getDB();
+
// Get pageIDs data from the `page` table
$this->profileDBIn();
$res = $db->select('page', $this->getPageTableFields(), $set, __METHOD__);
if(empty($revids))
return;
- $db = $this->getDB();
+ $db = & $this->getDB();
$pageids = array();
$remaining = array_flip($revids);
private function resolvePendingRedirects() {
if($this->mResolveRedirects) {
- $db = $this->getDB();
+ $db = & $this->getDB();
$pageFlds = $this->getPageTableFields();
// Repeat until all redirects have been resolved
private function getRedirectTargets() {
$linkBatch = new LinkBatch();
- $db = $this->getDB();
+ $db = & $this->getDB();
// find redirect targets for all redirect pages
$this->profileDBIn();
'allpages' => 'ApiQueryAllpages',
'logevents' => 'ApiQueryLogEvents',
'watchlist' => 'ApiQueryWatchlist',
- 'recentchanges' => 'ApiQueryRecentChanges'
+ 'recentchanges' => 'ApiQueryRecentChanges',
+ 'backlinks' => 'ApiQueryBacklinks'
);
- // 'backlinks' => 'ApiQueryBacklinks',
// 'categorymembers' => 'ApiQueryCategorymembers',
// 'embeddedin' => 'ApiQueryEmbeddedin',
// 'imagelinks' => 'ApiQueryImagelinks',
$this->mAllowedGenerators = array_merge($this->mListModuleNames, $this->mPropModuleNames);
}
- public function getDB() {
- if (!isset ($this->mSlaveDB))
+ public function & getDB() {
+ if (!isset ($this->mSlaveDB)) {
+ $this->profileDBIn();
$this->mSlaveDB = & wfGetDB(DB_SLAVE);
+ $this->profileDBOut();
+ }
return $this->mSlaveDB;
}
$result->addValue('query', 'redirects', $redirValues);
}
-
//
// Missing revision elements
//
$missingRevIDs = $pageSet->getMissingRevisionIDs();
- if (!empty($missingRevIDs)) {
- $revids = array();
+ if (!empty ($missingRevIDs)) {
+ $revids = array ();
foreach ($missingRevIDs as $revid) {
$revids[$revid] = array (
'revid' => $revid
$result->setIndexedTagName($revids, 'rev');
$result->addValue('query', 'badrevids', $revids);
}
-
+
//
// Page elements
//
// Output general page information for found titles
foreach ($pageSet->getGoodTitles() as $pageid => $title) {
$pages[$pageid] = array (
- 'pageid' => $pageid, 'ns' => $title->getNamespace(), 'title' => $title->getPrefixedText());
+ 'pageid' => $pageid,
+ 'ns' => $title->getNamespace(), 'title' => $title->getPrefixedText());
}
if (!empty ($pages)) {
// execute current pageSet to get the data for the generator module
$this->mPageSet->execute();
-
+
// populate resultPageSet with the generator output
$generator->profileIn();
$generator->executeGenerator($resultPageSet);
$resultPageSet->finishPageSetGeneration();
$generator->profileOut();
-
+
// Swap the resulting pageset back in
$this->mPageSet = $resultPageSet;
}
private function run($resultPageSet = null) {
wfProfileIn($this->getModuleProfileName() . '-getDB');
- $db = $this->getDB();
+ $db = & $this->getDB();
wfProfileOut($this->getModuleProfileName() . '-getDB');
wfProfileIn($this->getModuleProfileName() . '-parseParams');
$this->addOption( 'LIMIT', $limit +1);
$this->addOption( 'ORDER BY', 'page_namespace, page_title');
- $data = array ();
- $count = 0;
-
wfProfileOut($this->getModuleProfileName() . '-parseParams');
$res = $this->select(__METHOD__);
wfProfileIn($this->getModuleProfileName() . '-saveResults');
+ $data = array ();
+ $count = 0;
while ($row = $db->fetchObject($res)) {
if (++ $count > $limit) {
// We've reached the one extra which shows that there are additional pages to be had. Stop here...
if($vals)
$data[intval($row->page_id)] = $vals;
} else {
- $title = Title :: makeTitle($row->page_namespace, $row->page_title);
- // skip any pages that user has no rights to read
- if ($title->userCanRead()) {
- $resultPageSet->processDbRow($row);
- }
+ $resultPageSet->processDbRow($row);
}
}
$db->freeResult($res);
$isDirNewer = ($dir === 'newer');
$after = ($isDirNewer ? '<=' : '>=');
$before = ($isDirNewer ? '>=' : '<=');
- $db = $this->getDB();
+ $db = & $this->getDB();
if (!is_null($start))
$this->addWhere($field . $after . $db->addQuotes($start));
}
protected function select($method) {
+
+ // getDB has its own profileDBIn/Out calls
+ $db = & $this->getDB();
+
$this->profileDBIn();
- $res = $this->getDB()->select($this->tables, $this->fields, $this->where, $method, $this->options);
+ $res = $db->select($this->tables, $this->fields, $this->where, $method, $this->options);
$this->profileDBOut();
+
return $res;
}
$vals['title'] = $title->getPrefixedText();
}
- if ($prefix === 'rc') {
-
- // PageId
- @$tmp = $row->rc_cur_id;
- if(!is_null($tmp)) $vals['pageid'] = intval($tmp);
+ switch($prefix) {
- @$tmp = $row->rc_this_oldid;
- if(!is_null($tmp)) $vals['revid'] = intval($tmp);
+ case 'page':
+ // page_is_redirect
+ @$tmp = $row->page_is_redirect;
+ if($tmp) $vals['redirect'] = '';
- @$tmp = $row->rc_last_oldid;
- if(!is_null($tmp)) $vals['old_revid'] = intval($tmp);
+ break;
- $title = ApiQueryBase::addRowInfo_title($row, 'rc_moved_to_ns', 'rc_moved_to_title');
- if ($title) {
- if (!$title->userCanRead())
- return false;
- $vals['new_ns'] = $title->getNamespace();
- $vals['new_title'] = $title->getPrefixedText();
- }
-
- @$tmp = $row->rc_patrolled;
- if(!is_null($tmp)) $vals['patrolled'] = '';
-
- } elseif ($prefix === 'log') {
+ case 'rc':
+ // PageId
+ @$tmp = $row->rc_cur_id;
+ if(!is_null($tmp)) $vals['pageid'] = intval($tmp);
+
+ @$tmp = $row->rc_this_oldid;
+ if(!is_null($tmp)) $vals['revid'] = intval($tmp);
+
+ @$tmp = $row->rc_last_oldid;
+ if(!is_null($tmp)) $vals['old_revid'] = intval($tmp);
+
+ $title = ApiQueryBase::addRowInfo_title($row, 'rc_moved_to_ns', 'rc_moved_to_title');
+ if ($title) {
+ if (!$title->userCanRead())
+ return false;
+ $vals['new_ns'] = $title->getNamespace();
+ $vals['new_title'] = $title->getPrefixedText();
+ }
+
+ @$tmp = $row->rc_patrolled;
+ if(!is_null($tmp)) $vals['patrolled'] = '';
- // PageId
- @$tmp = $row->page_id;
- if(!is_null($tmp)) $vals['pageid'] = intval($tmp);
+ break;
- if ($row->log_params !== '') {
- $params = explode("\n", $row->log_params);
- if ($row->log_type == 'move' && isset ($params[0])) {
- $newTitle = Title :: newFromText($params[0]);
- if ($newTitle) {
- $vals['new_ns'] = $newTitle->getNamespace();
- $vals['new_title'] = $newTitle->getPrefixedText();
- $params = null;
+ case 'log':
+ // PageId
+ @$tmp = $row->page_id;
+ if(!is_null($tmp)) $vals['pageid'] = intval($tmp);
+
+ if ($row->log_params !== '') {
+ $params = explode("\n", $row->log_params);
+ if ($row->log_type == 'move' && isset ($params[0])) {
+ $newTitle = Title :: newFromText($params[0]);
+ if ($newTitle) {
+ $vals['new_ns'] = $newTitle->getNamespace();
+ $vals['new_title'] = $newTitle->getPrefixedText();
+ $params = null;
+ }
+ }
+
+ if (!empty ($params)) {
+ $this->getResult()->setIndexedTagName($params, 'param');
+ $vals = array_merge($vals, $params);
}
}
- if (!empty ($params)) {
- $this->getResult()->setIndexedTagName($params, 'param');
- $vals = array_merge($vals, $params);
- }
- }
+ break;
}
// Type
$pageSet = $this->getPageSet();
$titles = $pageSet->getGoodTitles();
- $result = & $this->getResult();
+ $result = $this->getResult();
$pageIsRedir = $pageSet->getCustomField('page_is_redirect');
$pageTouched = $pageSet->getCustomField('page_touched');
$limit = $type = $start = $end = $dir = $user = $title = null;
extract($this->extractRequestParams());
- $db = $this->getDB();
+ $db = & $this->getDB();
extract($db->tableNames('logging', 'page', 'user'), EXTR_PREFIX_ALL, 'tbl');
$this->addTables("$tbl_logging LEFT OUTER JOIN $tbl_page ON " .
$data = array ();
$count = 0;
- $db = $this->getDB();
+ $db = & $this->getDB();
$res = $this->select(__METHOD__);
while ($row = $db->fetchObject($res)) {
if (++ $count > $limit) {
$data = array ();
$count = 0;
- $db = $this->getDB();
$res = $this->select(__METHOD__);
+
+ $db = & $this->getDB();
while ($row = $db->fetchObject($res)) {
if (++ $count > $limit) {
// Ensure that all revisions are shown as '<rev>' elements
$result = $this->getResult();
if ($result->getIsRawMode()) {
- $data = & $result->getData();
+ $data = $result->getData();
foreach ($data['query']['pages'] as & $page) {
if (is_array($page) && array_key_exists('revisions', $page)) {
$result->setIndexedTagName($page['revisions'], 'rev');
$count = 0;
$res = $this->select(__METHOD__);
- $db = $this->getDB();
+ $db = & $this->getDB();
while ($row = $db->fetchObject($res)) {
if (++ $count > $limit) {
// We've reached the one extra which shows that there are additional pages to be had. Stop here...