From: Yuri Astrakhan Date: Wed, 25 Oct 2006 03:54:56 +0000 (+0000) Subject: API * simple backlinks module (no redirect resolution yet) X-Git-Tag: 1.31.0-rc.0~55384 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/?a=commitdiff_plain;h=3ec1b5b6469cdafdb7b06857dc512437b1cb5ac4;p=lhc%2Fweb%2Fwiklou.git API * simple backlinks module (no redirect resolution yet) * Cleaned up references --- diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index b1525c546b..21e395f466 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -255,6 +255,7 @@ function __autoload($className) { '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', diff --git a/includes/api/ApiFeedWatchlist.php b/includes/api/ApiFeedWatchlist.php index b26948f3f0..b5003a221b 100644 --- a/includes/api/ApiFeedWatchlist.php +++ b/includes/api/ApiFeedWatchlist.php @@ -62,7 +62,7 @@ class ApiFeedWatchlist extends ApiBase { $module->execute(); // Get data array - $data = & $module->getResultData(); + $data = $module->getResultData(); $feedItems = array (); foreach ($data['query']['watchlist'] as $index => $info) { diff --git a/includes/api/ApiFormatBase.php b/includes/api/ApiFormatBase.php index 1a415eb8e2..cb3c114e3b 100644 --- a/includes/api/ApiFormatBase.php +++ b/includes/api/ApiFormatBase.php @@ -205,10 +205,10 @@ class ApiFormatFeedWrapper extends ApiFormatBase { } 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) diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index 12ad3314ba..77e230ba7c 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -77,12 +77,15 @@ class ApiMain extends ApiBase { * @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); @@ -91,8 +94,6 @@ class ApiMain extends ApiBase { $this->mRequest = & $request; - $this->mInternalMode = ($request instanceof FauxRequest); - $this->mSquidMaxage = 0; } diff --git a/includes/api/ApiOpenSearch.php b/includes/api/ApiOpenSearch.php index 50b8e9cfc5..19b30b1a53 100644 --- a/includes/api/ApiOpenSearch.php +++ b/includes/api/ApiOpenSearch.php @@ -64,7 +64,7 @@ class ApiOpenSearch extends ApiBase { $module->execute(); // Get resulting data - $data = & $module->getResultData(); + $data = $module->getResultData(); // Reformat useful data for future printing by JSON engine $srchres = array (); diff --git a/includes/api/ApiPageSet.php b/includes/api/ApiPageSet.php index 3cf480b552..33ebbf9173 100644 --- a/includes/api/ApiPageSet.php +++ b/includes/api/ApiPageSet.php @@ -243,20 +243,25 @@ class ApiPageSet extends ApiQueryBase { * 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() { @@ -280,13 +285,13 @@ class ApiPageSet extends ApiQueryBase { * #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 @@ -305,11 +310,12 @@ class ApiPageSet extends ApiQueryBase { 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__); @@ -381,7 +387,7 @@ class ApiPageSet extends ApiQueryBase { if(empty($revids)) return; - $db = $this->getDB(); + $db = & $this->getDB(); $pageids = array(); $remaining = array_flip($revids); @@ -413,7 +419,7 @@ class ApiPageSet extends ApiQueryBase { private function resolvePendingRedirects() { if($this->mResolveRedirects) { - $db = $this->getDB(); + $db = & $this->getDB(); $pageFlds = $this->getPageTableFields(); // Repeat until all redirects have been resolved @@ -445,7 +451,7 @@ class ApiPageSet extends ApiQueryBase { private function getRedirectTargets() { $linkBatch = new LinkBatch(); - $db = $this->getDB(); + $db = & $this->getDB(); // find redirect targets for all redirect pages $this->profileDBIn(); diff --git a/includes/api/ApiQuery.php b/includes/api/ApiQuery.php index cda708d800..6ddac0adc3 100644 --- a/includes/api/ApiQuery.php +++ b/includes/api/ApiQuery.php @@ -49,9 +49,9 @@ class ApiQuery extends ApiBase { 'allpages' => 'ApiQueryAllpages', 'logevents' => 'ApiQueryLogEvents', 'watchlist' => 'ApiQueryWatchlist', - 'recentchanges' => 'ApiQueryRecentChanges' + 'recentchanges' => 'ApiQueryRecentChanges', + 'backlinks' => 'ApiQueryBacklinks' ); - // 'backlinks' => 'ApiQueryBacklinks', // 'categorymembers' => 'ApiQueryCategorymembers', // 'embeddedin' => 'ApiQueryEmbeddedin', // 'imagelinks' => 'ApiQueryImagelinks', @@ -79,9 +79,12 @@ class ApiQuery extends ApiBase { $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; } @@ -198,13 +201,12 @@ class ApiQuery extends ApiBase { $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 @@ -213,7 +215,7 @@ class ApiQuery extends ApiBase { $result->setIndexedTagName($revids, 'rev'); $result->addValue('query', 'badrevids', $revids); } - + // // Page elements // @@ -237,7 +239,8 @@ class ApiQuery extends ApiBase { // 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)) { @@ -272,13 +275,13 @@ class ApiQuery extends ApiBase { // 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; } diff --git a/includes/api/ApiQueryAllpages.php b/includes/api/ApiQueryAllpages.php index bf51e1dae3..71868a01db 100644 --- a/includes/api/ApiQueryAllpages.php +++ b/includes/api/ApiQueryAllpages.php @@ -49,7 +49,7 @@ class ApiQueryAllpages extends ApiQueryGeneratorBase { private function run($resultPageSet = null) { wfProfileIn($this->getModuleProfileName() . '-getDB'); - $db = $this->getDB(); + $db = & $this->getDB(); wfProfileOut($this->getModuleProfileName() . '-getDB'); wfProfileIn($this->getModuleProfileName() . '-parseParams'); @@ -79,15 +79,14 @@ class ApiQueryAllpages extends ApiQueryGeneratorBase { $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... @@ -100,11 +99,7 @@ class ApiQueryAllpages extends ApiQueryGeneratorBase { 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); diff --git a/includes/api/ApiQueryBase.php b/includes/api/ApiQueryBase.php index 151dc725a3..e4db51c7c9 100644 --- a/includes/api/ApiQueryBase.php +++ b/includes/api/ApiQueryBase.php @@ -89,7 +89,7 @@ abstract class ApiQueryBase extends ApiBase { $isDirNewer = ($dir === 'newer'); $after = ($isDirNewer ? '<=' : '>='); $before = ($isDirNewer ? '>=' : '<='); - $db = $this->getDB(); + $db = & $this->getDB(); if (!is_null($start)) $this->addWhere($field . $after . $db->addQuotes($start)); @@ -105,9 +105,14 @@ abstract class ApiQueryBase extends ApiBase { } 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; } @@ -129,51 +134,62 @@ abstract class ApiQueryBase extends ApiBase { $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 diff --git a/includes/api/ApiQueryInfo.php b/includes/api/ApiQueryInfo.php index fb1c9c0a16..93b4d08636 100644 --- a/includes/api/ApiQueryInfo.php +++ b/includes/api/ApiQueryInfo.php @@ -46,7 +46,7 @@ class ApiQueryInfo extends ApiQueryBase { $pageSet = $this->getPageSet(); $titles = $pageSet->getGoodTitles(); - $result = & $this->getResult(); + $result = $this->getResult(); $pageIsRedir = $pageSet->getCustomField('page_is_redirect'); $pageTouched = $pageSet->getCustomField('page_touched'); diff --git a/includes/api/ApiQueryLogEvents.php b/includes/api/ApiQueryLogEvents.php index fbe7740b7b..40dd9131f5 100644 --- a/includes/api/ApiQueryLogEvents.php +++ b/includes/api/ApiQueryLogEvents.php @@ -39,7 +39,7 @@ class ApiQueryLogEvents extends ApiQueryBase { $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 " . diff --git a/includes/api/ApiQueryRecentChanges.php b/includes/api/ApiQueryRecentChanges.php index 892e59e0ab..6ed0d4bb19 100644 --- a/includes/api/ApiQueryRecentChanges.php +++ b/includes/api/ApiQueryRecentChanges.php @@ -83,7 +83,7 @@ class ApiQueryRecentChanges extends ApiQueryBase { $data = array (); $count = 0; - $db = $this->getDB(); + $db = & $this->getDB(); $res = $this->select(__METHOD__); while ($row = $db->fetchObject($res)) { if (++ $count > $limit) { diff --git a/includes/api/ApiQueryRevisions.php b/includes/api/ApiQueryRevisions.php index 0ff8b33a40..57e0de483b 100644 --- a/includes/api/ApiQueryRevisions.php +++ b/includes/api/ApiQueryRevisions.php @@ -147,8 +147,9 @@ class ApiQueryRevisions extends ApiQueryBase { $data = array (); $count = 0; - $db = $this->getDB(); $res = $this->select(__METHOD__); + + $db = & $this->getDB(); while ($row = $db->fetchObject($res)) { if (++ $count > $limit) { @@ -176,7 +177,7 @@ class ApiQueryRevisions extends ApiQueryBase { // Ensure that all revisions are shown as '' 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'); diff --git a/includes/api/ApiQueryWatchlist.php b/includes/api/ApiQueryWatchlist.php index 9cb5accc22..dcd0c4508b 100644 --- a/includes/api/ApiQueryWatchlist.php +++ b/includes/api/ApiQueryWatchlist.php @@ -125,7 +125,7 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase { $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...