Index: trunk/phase3/maintenance/dumpInterwiki.php |
— | — | @@ -118,7 +118,7 @@ |
119 | 119 | $this->error( "m:Interwiki_map not found", true ); |
120 | 120 | } |
121 | 121 | |
122 | | - # Global iterwiki map |
| 122 | + # Global interwiki map |
123 | 123 | foreach ( $lines as $line ) { |
124 | 124 | if ( preg_match( '/^\|\s*(.*?)\s*\|\|\s*(.*?)\s*$/', $line, $matches ) ) { |
125 | 125 | $prefix = $wgContLang->lc( $matches[1] ); |
— | — | @@ -195,6 +195,17 @@ |
196 | 196 | foreach ( $extraLinks as $link ) { |
197 | 197 | $this->makeLink( $link, "__global" ); |
198 | 198 | } |
| 199 | + |
| 200 | + # List prefixes for each source |
| 201 | + foreach ( $this->prefixLists as $source => $hash ) { |
| 202 | + $list = array_keys( $hash ); |
| 203 | + sort( $list ); |
| 204 | + if ( $this->dbFile ) { |
| 205 | + $this->dbFile->set( "__list:{$source}", implode( ' ', $list ) ); |
| 206 | + } else { |
| 207 | + print "__list:{$source} " . implode( ' ', $list ) . "\n"; |
| 208 | + } |
| 209 | + } |
199 | 210 | } |
200 | 211 | |
201 | 212 | # ------------------------------------------------------------------------------------------ |
— | — | @@ -229,6 +240,9 @@ |
230 | 241 | } else { |
231 | 242 | $this->output( "{$source}:{$entry['iw_prefix']} {$entry['iw_url']} {$entry['iw_local']}\n" ); |
232 | 243 | } |
| 244 | + |
| 245 | + # Add to list of prefixes |
| 246 | + $this->prefixLists[$source][$entry['iw_prefix']] = 1; |
233 | 247 | } |
234 | 248 | } |
235 | 249 | |
Index: trunk/phase3/RELEASE-NOTES-1.19 |
— | — | @@ -15,6 +15,7 @@ |
16 | 16 | === New features in 1.19 === |
17 | 17 | |
18 | 18 | === Bug fixes in 1.19 === |
| 19 | +* (bug 19838) API does not use interwiki cache. |
19 | 20 | |
20 | 21 | === API changes in 1.19 === |
21 | 22 | |
Index: trunk/phase3/CREDITS |
— | — | @@ -158,6 +158,9 @@ |
159 | 159 | * Yuvaraj Pandian T |
160 | 160 | * Zachary Hauri |
161 | 161 | |
| 162 | +== Patch Contributors == |
| 163 | +* Beau |
| 164 | + |
162 | 165 | == Translators == |
163 | 166 | * Anders Wegge Jakobsen |
164 | 167 | * Hk kng |
Index: trunk/phase3/includes/interwiki/Interwiki.php |
— | — | @@ -199,6 +199,125 @@ |
200 | 200 | } |
201 | 201 | |
202 | 202 | /** |
| 203 | + * Fetch all interwiki prefixes from interwiki cache |
| 204 | + * |
| 205 | + * @param $local If set, limits output to local/non-local interwikis |
| 206 | + * @return Array List of prefixes |
| 207 | + * @since 1.19 |
| 208 | + * @static |
| 209 | + */ |
| 210 | + protected static function getAllPrefixesCached( $local ) { |
| 211 | + global $wgInterwikiCache, $wgInterwikiScopes, $wgInterwikiFallbackSite; |
| 212 | + static $db, $site; |
| 213 | + |
| 214 | + wfDebug( __METHOD__ . "()\n" ); |
| 215 | + if( !$db ) { |
| 216 | + $db = CdbReader::open( $wgInterwikiCache ); |
| 217 | + } |
| 218 | + /* Resolve site name */ |
| 219 | + if( $wgInterwikiScopes >= 3 && !$site ) { |
| 220 | + $site = $db->get( '__sites:' . wfWikiID() ); |
| 221 | + if ( $site == '' ) { |
| 222 | + $site = $wgInterwikiFallbackSite; |
| 223 | + } |
| 224 | + } |
| 225 | + |
| 226 | + // List of interwiki sources |
| 227 | + $sources = array(); |
| 228 | + // Global Level |
| 229 | + if ( $wgInterwikiScopes >= 2 ) { |
| 230 | + $sources[] = '__global'; |
| 231 | + } |
| 232 | + // Site level |
| 233 | + if ( $wgInterwikiScopes >= 3 ) { |
| 234 | + $sources[] = '_' . $site; |
| 235 | + } |
| 236 | + $sources[] = wfWikiID(); |
| 237 | + |
| 238 | + $data = array(); |
| 239 | + |
| 240 | + foreach( $sources as $source ) { |
| 241 | + $list = $db->get( "__list:{$source}" ); |
| 242 | + foreach ( explode( ' ', $list ) as $iw_prefix ) { |
| 243 | + $row = $db->get( "{$source}:{$iw_prefix}" ); |
| 244 | + if( !$row ) { |
| 245 | + continue; |
| 246 | + } |
| 247 | + |
| 248 | + list( $iw_local, $iw_url ) = explode( ' ', $row ); |
| 249 | + |
| 250 | + if ( isset( $local ) && $local != $iw_local ) { |
| 251 | + continue; |
| 252 | + } |
| 253 | + |
| 254 | + $data[$iw_prefix] = array( |
| 255 | + 'iw_prefix' => $iw_prefix, |
| 256 | + 'iw_url' => $iw_url, |
| 257 | + 'iw_local' => $iw_local, |
| 258 | + ); |
| 259 | + } |
| 260 | + } |
| 261 | + |
| 262 | + ksort( $data ); |
| 263 | + |
| 264 | + return array_values( $data ); |
| 265 | + } |
| 266 | + |
| 267 | + /** |
| 268 | + * Fetch all interwiki prefixes from DB |
| 269 | + * |
| 270 | + * @param $local If set, limits output to local/non-local interwikis |
| 271 | + * @return Array List of prefixes |
| 272 | + * @since 1.19 |
| 273 | + * @static |
| 274 | + */ |
| 275 | + protected static function getAllPrefixesDb( $local ) { |
| 276 | + $db = wfGetDB( DB_SLAVE ); |
| 277 | + |
| 278 | + $where = array(); |
| 279 | + |
| 280 | + if ( isset($local) ) { |
| 281 | + if ( $local == 1 ) { |
| 282 | + $where['iw_local'] = 1; |
| 283 | + } |
| 284 | + elseif ( $local == 0 ) { |
| 285 | + $where['iw_local'] = 0; |
| 286 | + } |
| 287 | + } |
| 288 | + |
| 289 | + $res = $db->select( 'interwiki', |
| 290 | + array( 'iw_prefix', 'iw_url', 'iw_api', 'iw_wikiid', 'iw_local', 'iw_trans' ), |
| 291 | + $where, __METHOD__, array( 'ORDER BY' => 'iw_prefix' ) |
| 292 | + ); |
| 293 | + |
| 294 | + $data = array(); |
| 295 | + while( $row = $db->fetchRow($res) ) { |
| 296 | + $data[] = $row; |
| 297 | + } |
| 298 | + $db->freeResult( $res ); |
| 299 | + |
| 300 | + return $data; |
| 301 | + } |
| 302 | + |
| 303 | + /** |
| 304 | + * Returns all interwiki prefixes |
| 305 | + * |
| 306 | + * @param $local If set, limits output to local/non-local interwikis |
| 307 | + * @return Array List of prefixes |
| 308 | + * @since 1.19 |
| 309 | + * @static |
| 310 | + */ |
| 311 | + public static function getAllPrefixes( $local ) { |
| 312 | + global $wgInterwikiCache; |
| 313 | + |
| 314 | + if ( $wgInterwikiCache ) { |
| 315 | + return self::getAllPrefixesCached( $local ); |
| 316 | + } else { |
| 317 | + return self::getAllPrefixesDb( $local ); |
| 318 | + } |
| 319 | + } |
| 320 | + |
| 321 | + /** |
203 | 322 | * Get the URL for a particular title (or with $1 if no title given) |
204 | 323 | * |
205 | 324 | * @param $title String: what text to put for the article name |
Index: trunk/phase3/includes/api/ApiQuerySiteinfo.php |
— | — | @@ -256,37 +256,36 @@ |
257 | 257 | } |
258 | 258 | |
259 | 259 | protected function appendInterwikiMap( $property, $filter ) { |
260 | | - $this->resetQueryParams(); |
261 | | - $this->addTables( 'interwiki' ); |
262 | | - $this->addFields( array( 'iw_prefix', 'iw_local', 'iw_url', 'iw_wikiid', 'iw_api' ) ); |
263 | | - |
| 260 | + $local = null; |
264 | 261 | if ( $filter === 'local' ) { |
265 | | - $this->addWhere( 'iw_local = 1' ); |
| 262 | + $local = 1; |
266 | 263 | } elseif ( $filter === '!local' ) { |
267 | | - $this->addWhere( 'iw_local = 0' ); |
| 264 | + $local = 0; |
268 | 265 | } elseif ( $filter ) { |
269 | 266 | ApiBase::dieDebug( __METHOD__, "Unknown filter=$filter" ); |
270 | 267 | } |
271 | 268 | |
272 | | - $this->addOption( 'ORDER BY', 'iw_prefix' ); |
273 | | - |
274 | | - $res = $this->select( __METHOD__ ); |
275 | | - |
| 269 | + $getPrefixes = Interwiki::getAllPrefixes( $local ); |
276 | 270 | $data = array(); |
277 | 271 | $langNames = Language::getLanguageNames(); |
278 | | - foreach ( $res as $row ) { |
| 272 | + foreach ( $getPrefixes as $row ) { |
| 273 | + $prefix = $row['iw_prefix']; |
279 | 274 | $val = array(); |
280 | | - $val['prefix'] = $row->iw_prefix; |
281 | | - if ( $row->iw_local == '1' ) { |
| 275 | + $val['prefix'] = $prefix; |
| 276 | + if ( $row['iw_local'] == '1' ) { |
282 | 277 | $val['local'] = ''; |
283 | 278 | } |
284 | | - // $val['trans'] = intval( $row->iw_trans ); // should this be exposed? |
285 | | - if ( isset( $langNames[$row->iw_prefix] ) ) { |
286 | | - $val['language'] = $langNames[$row->iw_prefix]; |
| 279 | + // $val['trans'] = intval( $row['iw_trans'] ); // should this be exposed? |
| 280 | + if ( isset( $langNames[$prefix] ) ) { |
| 281 | + $val['language'] = $langNames[$prefix]; |
287 | 282 | } |
288 | | - $val['url'] = wfExpandUrl( $row->iw_url ); |
289 | | - $val['wikiid'] = $row->iw_wikiid; |
290 | | - $val['api'] = $row->iw_api; |
| 283 | + $val['url'] = wfExpandUrl( $row['iw_url'] ); |
| 284 | + if( isset( $row['iw_wikiid'] ) ) { |
| 285 | + $val['wikiid'] = $row['iw_wikiid']; |
| 286 | + } |
| 287 | + if( isset( $row['iw_api'] ) ) { |
| 288 | + $val['api'] = $row['iw_api']; |
| 289 | + } |
291 | 290 | |
292 | 291 | $data[] = $val; |
293 | 292 | } |