Index: branches/iwtransclusion/phase3/includes/Interwiki.php |
— | — | @@ -280,35 +280,11 @@ |
281 | 281 | |
282 | 282 | } else if( $transAPI !== '' ) { |
283 | 283 | |
| 284 | + $interwiki = $title->getInterwiki( ); |
284 | 285 | $fullTitle = $title->getSemiPrefixedText( ); |
285 | 286 | |
286 | | - $finalText = self::fetchTemplateFromAPI( $wikiID, $transAPI, $fullTitle ); |
287 | | - |
288 | | - //Retrieve the list of subtemplates |
289 | | - $url2 = wfAppendQuery( $transAPI, |
290 | | - array( 'action' => 'query', |
291 | | - 'titles' => $fullTitle, |
292 | | - 'prop' => 'templates', |
293 | | - 'format' => 'json' |
294 | | - ) |
295 | | - ); |
| 287 | + $finalText = self::fetchTemplateFromAPI( $interwiki, $transAPI, $fullTitle ); |
296 | 288 | |
297 | | - $get = Http::get( $url2 ); |
298 | | - $myArray = FormatJson::decode($get, true); |
299 | | - |
300 | | - // Here, we preload and cache the subtemplates |
301 | | - if ( ! empty( $myArray['query'] )) { |
302 | | - if ( ! empty( $myArray['query']['pages'] )) { |
303 | | - $templates = array_pop( $myArray['query']['pages'] ); |
304 | | - if ( ! empty( $templates['templates'] )) { |
305 | | - $templates = $templates['templates']; |
306 | | - } else { |
307 | | - $templates = array( ); |
308 | | - } |
309 | | - self::cacheTemplatesFromAPI( $wikiID, $transAPI, $templates ); |
310 | | - } |
311 | | - } |
312 | | - |
313 | 289 | return $finalText; |
314 | 290 | |
315 | 291 | } |
— | — | @@ -333,10 +309,10 @@ |
334 | 310 | /** |
335 | 311 | * Retrieve the wikitext of a distant page using the API of the foreign wiki |
336 | 312 | */ |
337 | | - public static function fetchTemplateFromAPI( $wikiID, $transAPI, $fullTitle ) { |
| 313 | + public static function fetchTemplateFromAPI( $interwiki, $transAPI, $fullTitle ) { |
338 | 314 | global $wgMemc, $wgTranscludeCacheExpiry; |
339 | 315 | |
340 | | - $key = wfMemcKey( 'iwtransclustiontext', 'textid', $wikiID, $fullTitle ); |
| 316 | + $key = wfMemcKey( 'iwtransclustiontext', 'textid', $interwiki, $fullTitle ); |
341 | 317 | $text = $wgMemc->get( $key ); |
342 | 318 | if( is_array ( $text ) && |
343 | 319 | isset ( $text['missing'] ) && |
— | — | @@ -365,6 +341,11 @@ |
366 | 342 | if ( $page && isset( $page['revisions'][0]['*'] ) ) { |
367 | 343 | $text = $page['revisions'][0]['*']; |
368 | 344 | $wgMemc->set( $key, $text, $wgTranscludeCacheExpiry ); |
| 345 | + |
| 346 | + // When we cache a template, we also retrieve and cache its subtemplates |
| 347 | + $subtemplates = self::getSubtemplatesListFromAPI( $interwiki, $transAPI, $fullTitle ); |
| 348 | + self::cacheTemplatesFromAPI( $interwiki, $transAPI, $subtemplates ); |
| 349 | + |
369 | 350 | return $text; |
370 | 351 | } else { |
371 | 352 | $wgMemc->set( $key, array ( 'missing' => true ), $wgTranscludeCacheExpiry ); |
— | — | @@ -373,14 +354,38 @@ |
374 | 355 | return false; |
375 | 356 | } |
376 | 357 | |
377 | | - public static function cacheTemplatesFromAPI( $wikiID, $transAPI, $titles ){ |
| 358 | + public static function getSubtemplatesListFromAPI ( $interwiki, $transAPI, $title ) { |
| 359 | + $url = wfAppendQuery( $transAPI, |
| 360 | + array( 'action' => 'query', |
| 361 | + 'titles' => $title, |
| 362 | + 'prop' => 'templates', |
| 363 | + 'format' => 'json' |
| 364 | + ) |
| 365 | + ); |
| 366 | + |
| 367 | + $get = Http::get( $url ); |
| 368 | + $myArray = FormatJson::decode($get, true); |
| 369 | + |
| 370 | + $templates = array( ); |
| 371 | + if ( ! empty( $myArray['query'] )) { |
| 372 | + if ( ! empty( $myArray['query']['pages'] )) { |
| 373 | + $templates = array_pop( $myArray['query']['pages'] ); |
| 374 | + if ( ! empty( $templates['templates'] )) { |
| 375 | + $templates = $templates['templates']; |
| 376 | + } |
| 377 | + } |
| 378 | + return $templates; |
| 379 | + } |
| 380 | + } |
| 381 | + |
| 382 | + public static function cacheTemplatesFromAPI( $interwiki, $transAPI, $titles ){ |
378 | 383 | global $wgMemc, $wgTranscludeCacheExpiry; |
379 | 384 | |
380 | 385 | $outdatedTitles = array( ); |
381 | 386 | |
382 | 387 | foreach( $titles as $title ){ |
383 | 388 | if ( isset ( $title['title'] ) ) { |
384 | | - $key = wfMemcKey( 'iwtransclustiontext', 'textid', $wikiID, $title['title'] ); |
| 389 | + $key = wfMemcKey( 'iwtransclustiontext', 'textid', $interwiki, $title['title'] ); |
385 | 390 | $text = $wgMemc->get( $key ); |
386 | 391 | if( !$text ){ |
387 | 392 | $outdatedTitles[] = $title['title']; |
— | — | @@ -406,7 +411,7 @@ |
407 | 412 | if ( isset ( $content['query'] ) && |
408 | 413 | isset ( $content['query']['pages'] ) ) { |
409 | 414 | foreach( $content['query']['pages'] as $page ) { |
410 | | - $key = wfMemcKey( 'iwtransclustiontext', 'textid', $wikiID, $page['title'] ); |
| 415 | + $key = wfMemcKey( 'iwtransclustiontext', 'textid', $interwiki, $page['title'] ); |
411 | 416 | if ( isset ( $page['revisions'][0]['*'] ) ) { |
412 | 417 | $text = $page['revisions'][0]['*']; |
413 | 418 | } else { |
Index: branches/iwtransclusion/phase3/includes/Revision.php |
— | — | @@ -905,7 +905,7 @@ |
906 | 906 | // Caching may be beneficial for massive use of external storage |
907 | 907 | global $wgRevisionCacheExpiry, $wgMemc; |
908 | 908 | $textId = $this->getTextId(); |
909 | | - if( isset( $this->mWikiID ) ) { |
| 909 | + if( isset( $this->mWikiID ) && $this->mWikiID !== false ) { |
910 | 910 | $key = wfForeignMemcKey( $this->mWikiID, null, 'revisiontext', 'textid', $textId ); |
911 | 911 | } else { |
912 | 912 | $key = wfMemcKey( 'revisiontext', 'textid', $textId ); |