From c60c6a37d0f4082b07612707c7f0c0ab3f5ef6a7 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Tue, 25 Mar 2008 15:31:24 +0000 Subject: [PATCH] API: Adding inprop=talkid,subjectid to prop=info --- RELEASE-NOTES | 1 + includes/api/ApiQueryInfo.php | 54 +++++++++++++++++++++++++++++++++-- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 2067c4eee9..d38a5a541d 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -160,6 +160,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN handled properly. * (bug 13444) Add description to list=watchlist * (bug 13482) Disabled search types handled properly +* Added inprop=talkid,subjectid to prop=info === Languages updated in 1.13 === diff --git a/includes/api/ApiQueryInfo.php b/includes/api/ApiQueryInfo.php index b7e4d6133a..93a69d2b68 100644 --- a/includes/api/ApiQueryInfo.php +++ b/includes/api/ApiQueryInfo.php @@ -58,6 +58,8 @@ class ApiQueryInfo extends ApiQueryBase { if(!is_null($params['prop'])) { $prop = array_flip($params['prop']); $fld_protection = isset($prop['protection']); + $fld_talkid = isset($prop['talkid']); + $fld_subjectid = isset($prop['subjectid']); } if(!is_null($params['token'])) { $token = $params['token']; @@ -122,6 +124,42 @@ class ApiQueryInfo extends ApiQueryBase { } $db->freeResult($res); } + + // Run the talkid/subjectid query + if($fld_talkid || $fld_subjectid) + { + $talktitles = $subjecttitles = + $talkids = $subjectids = array(); + $everything = array_merge($titles, $missing); + foreach($everything as $t) + { + if(MWNamespace::isTalk($t->getNamespace())) + { + if($fld_subjectid) + $subjecttitles[] = $t->getSubjectPage(); + } + else if($fld_talkid) + $talktitles[] = $t->getTalkPage(); + } + if(!empty($talktitles) || !empty($subjecttitles)) + { + // Construct a custom WHERE clause that matches + // all titles in $talktitles and $subjecttitles + $lb = new LinkBatch(array_merge($talktitles, $subjecttitles)); + $this->resetQueryParams(); + $this->addTables('page'); + $this->addFields(array('page_title', 'page_namespace', 'page_id')); + $this->addWhere($lb->constructSet('page', $db)); + $res = $this->select(__METHOD__); + while($row = $db->fetchObject($res)) + { + if(MWNamespace::isTalk($row->page_namespace)) + $talkids[MWNamespace::getSubject($row->page_namespace)][$row->page_title] = $row->page_id; + else + $subjectids[MWNamespace::getTalk($row->page_namespace)][$row->page_title] = $row->page_id; + } + } + } foreach ( $titles as $pageid => $title ) { $pageInfo = array ( @@ -186,6 +224,10 @@ class ApiQueryInfo extends ApiQueryBase { } } } + if($fld_talkid && isset($talkids[$title->getNamespace()][$title->getDbKey()])) + $pageInfo['talkid'] = $talkids[$title->getNamespace()][$title->getDbKey()]; + if($fld_subjectid && isset($subjectids[$title->getNamespace()][$title->getDbKey()])) + $pageInfo['subjectid'] = $subjectids[$title->getNamespace()][$title->getDbKey()]; $result->addValue(array ( 'query', @@ -213,6 +255,10 @@ class ApiQueryInfo extends ApiQueryBase { $res['query']['pages'][$pageid]['protection'] = array(); $result->setIndexedTagName($res['query']['pages'][$pageid]['protection'], 'pr'); } + if($fld_talkid && isset($talkids[$title->getNamespace()][$title->getDbKey()])) + $res['query']['pages'][$pageid]['talkid'] = $talkids[$title->getNamespace()][$title->getDbKey()]; + if($fld_subjectid && isset($subjectids[$title->getNamespace()][$title->getDbKey()])) + $res['query']['pages'][$pageid]['subjectid'] = $subjectids[$title->getNamespace()][$title->getDbKey()]; } } } @@ -223,7 +269,9 @@ class ApiQueryInfo extends ApiQueryBase { ApiBase :: PARAM_DFLT => NULL, ApiBase :: PARAM_ISMULTI => true, ApiBase :: PARAM_TYPE => array ( - 'protection' + 'protection', + 'talkid', + 'subjectid' )), 'token' => array ( ApiBase :: PARAM_DFLT => NULL, @@ -241,7 +289,9 @@ class ApiQueryInfo extends ApiQueryBase { return array ( 'prop' => array ( 'Which additional properties to get:', - ' "protection" - List the protection level of each page' + ' "protection" - List the protection level of each page', + ' "talkid" - The page ID of the talk page for each non-talk page', + ' "subjectid" - The page ID of the parent page for each talk page' ), 'token' => 'Request a token to perform a data-modifying action on a page', ); -- 2.20.1