Index: trunk/phase3/includes/api/ApiQuerySiteinfo.php |
— | — | @@ -40,58 +40,110 @@ |
41 | 41 | } |
42 | 42 | |
43 | 43 | public function execute() { |
44 | | - $prop = null; |
45 | | - extract($this->extractRequestParams()); |
46 | 44 | |
47 | | - foreach ($prop as $p) { |
| 45 | + $params = $this->extractRequestParams(); |
| 46 | + |
| 47 | + foreach ($params['prop'] as $p) { |
48 | 48 | switch ($p) { |
49 | | - |
| 49 | + default : |
| 50 | + ApiBase :: dieDebug(__METHOD__, "Unknown prop=$p"); |
50 | 51 | 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); |
64 | 53 | break; |
65 | | - |
66 | 54 | 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); |
78 | 56 | 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; |
82 | 61 | } |
83 | 62 | } |
84 | 63 | } |
85 | 64 | |
| 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 | + |
86 | 131 | protected function getAllowedParams() { |
87 | 132 | return array ( |
| 133 | + |
88 | 134 | 'prop' => array ( |
89 | 135 | ApiBase :: PARAM_DFLT => 'general', |
90 | 136 | ApiBase :: PARAM_ISMULTI => true, |
91 | 137 | ApiBase :: PARAM_TYPE => array ( |
92 | 138 | 'general', |
93 | | - 'namespaces' |
94 | | - ) |
95 | | - ) |
| 139 | + 'namespaces', |
| 140 | + 'interwikimap' |
| 141 | + )), |
| 142 | + |
| 143 | + 'filteriw' => array ( |
| 144 | + ApiBase :: PARAM_TYPE => array ( |
| 145 | + 'local', |
| 146 | + '!local', |
| 147 | + )), |
96 | 148 | ); |
97 | 149 | } |
98 | 150 | |
— | — | @@ -99,9 +151,11 @@ |
100 | 152 | return array ( |
101 | 153 | 'prop' => array ( |
102 | 154 | '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', |
106 | 160 | ); |
107 | 161 | } |
108 | 162 | |
— | — | @@ -110,7 +164,10 @@ |
111 | 165 | } |
112 | 166 | |
113 | 167 | 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 | + ); |
115 | 172 | } |
116 | 173 | |
117 | 174 | public function getVersion() { |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -83,8 +83,8 @@ |
84 | 84 | * (bug 8869) Introduce Special:Uncategorizedtemplates |
85 | 85 | * (bug 8734) Different log message when article protection level is changed |
86 | 86 | * (bug 8458) Limit custom signature length to $wgMaxSigChars bytes |
| 87 | +* (bug 10096) Added an ability to query interwiki map table |
87 | 88 | |
88 | | - |
89 | 89 | == Bugfixes since 1.10 == |
90 | 90 | |
91 | 91 | * (bug 9712) Use Arabic comma in date/time formats for Arabic and Farsi |