r22975 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22974‎ | r22975 | r22976 >
Date:05:18, 14 June 2007
Author:yurik
Status:old
Tags:
Comment:
API bug 10096 InterWiki table retrieval through meta=siteinfo
With help from Roan Kattouw
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/api/ApiQuerySiteinfo.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQuerySiteinfo.php
@@ -40,58 +40,110 @@
4141 }
4242
4343 public function execute() {
44 - $prop = null;
45 - extract($this->extractRequestParams());
4644
47 - foreach ($prop as $p) {
 45+ $params = $this->extractRequestParams();
 46+
 47+ foreach ($params['prop'] as $p) {
4848 switch ($p) {
49 -
 49+ default :
 50+ ApiBase :: dieDebug(__METHOD__, "Unknown prop=$p");
5051 case 'general' :
51 -
52 - global $wgSitename, $wgVersion, $wgCapitalLinks, $wgRightsCode, $wgRightsText;
53 - $data = array ();
54 - $mainPage = Title :: newFromText(wfMsgForContent('mainpage'));
55 - $data['mainpage'] = $mainPage->getText();
56 - $data['base'] = $mainPage->getFullUrl();
57 - $data['sitename'] = $wgSitename;
58 - $data['generator'] = "MediaWiki $wgVersion";
59 - $data['case'] = $wgCapitalLinks ? 'first-letter' : 'case-sensitive'; // 'case-insensitive' option is reserved for future
60 - if (isset($wgRightsCode))
61 - $data['rightscode'] = $wgRightsCode;
62 - $data['rights'] = $wgRightsText;
63 - $this->getResult()->addValue('query', $p, $data);
 52+ $this->appendGeneralInfo($p);
6453 break;
65 -
6654 case 'namespaces' :
67 -
68 - global $wgContLang;
69 - $data = array ();
70 - foreach ($wgContLang->getFormattedNamespaces() as $ns => $title) {
71 - $data[$ns] = array (
72 - 'id' => $ns
73 - );
74 - ApiResult :: setContent($data[$ns], $title);
75 - }
76 - $this->getResult()->setIndexedTagName($data, 'ns');
77 - $this->getResult()->addValue('query', $p, $data);
 55+ $this->appendNamespaces($p);
7856 break;
79 -
80 - default :
81 - ApiBase :: dieDebug(__METHOD__, "Unknown prop=$p");
 57+ case 'interwikimap' :
 58+ $filteriw = isset($params['filteriw']) ? $params['filteriw'] : false;
 59+ $this->appendInterwikiMap($p, $filteriw);
 60+ break;
8261 }
8362 }
8463 }
8564
 65+ protected function appendGeneralInfo($property) {
 66+ global $wgSitename, $wgVersion, $wgCapitalLinks, $wgRightsCode, $wgRightsText;
 67+
 68+ $data = array ();
 69+ $mainPage = Title :: newFromText(wfMsgForContent('mainpage'));
 70+ $data['mainpage'] = $mainPage->getText();
 71+ $data['base'] = $mainPage->getFullUrl();
 72+ $data['sitename'] = $wgSitename;
 73+ $data['generator'] = "MediaWiki $wgVersion";
 74+ $data['case'] = $wgCapitalLinks ? 'first-letter' : 'case-sensitive'; // 'case-insensitive' option is reserved for future
 75+ if (isset($wgRightsCode))
 76+ $data['rightscode'] = $wgRightsCode;
 77+ $data['rights'] = $wgRightsText;
 78+
 79+ $this->getResult()->addValue('query', $property, $data);
 80+ }
 81+
 82+ protected function appendNamespaces($property) {
 83+ global $wgContLang;
 84+
 85+ $data = array ();
 86+ foreach ($wgContLang->getFormattedNamespaces() as $ns => $title) {
 87+ $data[$ns] = array (
 88+ 'id' => $ns
 89+ );
 90+ ApiResult :: setContent($data[$ns], $title);
 91+ }
 92+
 93+ $this->getResult()->setIndexedTagName($data, 'ns');
 94+ $this->getResult()->addValue('query', $property, $data);
 95+ }
 96+
 97+ protected function appendInterwikiMap($property, $filter) {
 98+
 99+ $this->addTables('interwiki');
 100+ $this->addFields(array('iw_prefix', 'iw_local', 'iw_url'));
 101+
 102+ if($filter === 'local')
 103+ $this->addWhere('iw_local = 1');
 104+ else if($filter === '!local')
 105+ $this->addWhere('iw_local = 0');
 106+ else if($filter !== false)
 107+ ApiBase :: dieDebug(__METHOD__, "Unknown filter=$filter");
 108+
 109+ $this->addOption('ORDER BY', 'iw_prefix');
 110+
 111+ $db = $this->getDB();
 112+ $res = $this->select(__METHOD__);
 113+
 114+ $data = array();
 115+ while($row = $db->fetchObject($res))
 116+ {
 117+ $val['prefix'] = $row->iw_prefix;
 118+ if ($row->iw_local == '1')
 119+ $val['local'] = '';
 120+// $val['trans'] = intval($row->iw_trans); // should this be exposed?
 121+ $val['url'] = $row->iw_url;
 122+
 123+ $data[] = $val;
 124+ }
 125+ $db->freeResult($res);
 126+
 127+ $this->getResult()->setIndexedTagName($data, 'iw');
 128+ $this->getResult()->addValue('query', $property, $data);
 129+ }
 130+
86131 protected function getAllowedParams() {
87132 return array (
 133+
88134 'prop' => array (
89135 ApiBase :: PARAM_DFLT => 'general',
90136 ApiBase :: PARAM_ISMULTI => true,
91137 ApiBase :: PARAM_TYPE => array (
92138 'general',
93 - 'namespaces'
94 - )
95 - )
 139+ 'namespaces',
 140+ 'interwikimap'
 141+ )),
 142+
 143+ 'filteriw' => array (
 144+ ApiBase :: PARAM_TYPE => array (
 145+ 'local',
 146+ '!local',
 147+ )),
96148 );
97149 }
98150
@@ -99,9 +151,11 @@
100152 return array (
101153 'prop' => array (
102154 'Which sysinfo properties to get:',
103 - ' "general" - Overall system information',
104 - ' "namespaces" - List of registered namespaces (localized)'
105 - )
 155+ ' "general" - Overall system information',
 156+ ' "namespaces" - List of registered namespaces (localized)',
 157+ ' "interwikimap" - Return interwiki map (optionally filtered)'
 158+ ),
 159+ 'filteriw' => 'Return only local or only nonlocal entries of the interwiki map',
106160 );
107161 }
108162
@@ -110,7 +164,10 @@
111165 }
112166
113167 protected function getExamples() {
114 - return 'api.php?action=query&meta=siteinfo&siprop=general|namespaces';
 168+ return array(
 169+ 'api.php?action=query&meta=siteinfo&siprop=general|namespaces',
 170+ 'api.php?action=query&meta=siteinfo&siprop=interwikimap&sifilteriw=local',
 171+ );
115172 }
116173
117174 public function getVersion() {
Index: trunk/phase3/RELEASE-NOTES
@@ -83,8 +83,8 @@
8484 * (bug 8869) Introduce Special:Uncategorizedtemplates
8585 * (bug 8734) Different log message when article protection level is changed
8686 * (bug 8458) Limit custom signature length to $wgMaxSigChars bytes
 87+* (bug 10096) Added an ability to query interwiki map table
8788
88 -
8989 == Bugfixes since 1.10 ==
9090
9191 * (bug 9712) Use Arabic comma in date/time formats for Arabic and Farsi

Follow-up revisions

RevisionCommit summaryAuthorDate
r23039Merged revisions 22967-23037 via svnmerge from...david20:15, 16 June 2007

Status & tagging log