Index: branches/iwtransclusion/phase3/includes/Interwiki.php |
— | — | @@ -277,7 +277,7 @@ |
278 | 278 | |
279 | 279 | } else if( $transAPI !== '' ) { |
280 | 280 | |
281 | | - $fullTitle = $title->getNsText().':'.$title->getText(); |
| 281 | + $fullTitle = $title->getSemiPrefixedText( ); |
282 | 282 | |
283 | 283 | $finalText = self::fetchTemplateFromAPI( $wikiID, $transAPI, $fullTitle ); |
284 | 284 | |
— | — | @@ -337,9 +337,13 @@ |
338 | 338 | |
339 | 339 | $key = wfMemcKey( 'iwtransclustiontext', 'textid', $wikiID, $fullTitle ); |
340 | 340 | $text = $wgMemc->get( $key ); |
341 | | - if( $text ){ |
342 | | - return $text; |
343 | | - } |
| 341 | + if( is_array ( $text ) |
| 342 | + && isset ( $text['missing'] ) |
| 343 | + && $text['missing'] === true ){ |
| 344 | + return false; |
| 345 | + } else if ( $text ) { |
| 346 | + return $text; |
| 347 | + } |
344 | 348 | |
345 | 349 | $url = wfAppendQuery( |
346 | 350 | $transAPI, |
— | — | @@ -354,12 +358,17 @@ |
355 | 359 | $get = Http::get( $url ); |
356 | 360 | $content = FormatJson::decode( $get, true ); |
357 | 361 | |
358 | | - if ( ! empty($content['query']['pages']) ) { |
359 | | - |
360 | | - $page = array_pop( $content['query']['pages'] ); |
361 | | - $text = $page['revisions'][0]['*']; |
362 | | - $wgMemc->set( $key, $text, $wgTranscludeCacheExpiry ); |
363 | | - return $text; |
| 362 | + if ( isset ( $content['query'] ) |
| 363 | + && isset ( $content['query']['pages'] ) ) { |
| 364 | + $page = array_pop( $content['query']['pages'] ); |
| 365 | + if ( $page |
| 366 | + && isset( $page['revisions'][0]['*'] ) ) { |
| 367 | + $text = $page['revisions'][0]['*']; |
| 368 | + $wgMemc->set( $key, $text, $wgTranscludeCacheExpiry ); |
| 369 | + return $text; |
| 370 | + } else { |
| 371 | + $wgMemc->set( $key, array ( 'missing' => true ), $wgTranscludeCacheExpiry ); |
| 372 | + } |
364 | 373 | } |
365 | 374 | return false; |
366 | 375 | } |
— | — | @@ -370,10 +379,12 @@ |
371 | 380 | $outdatedTitles = array( ); |
372 | 381 | |
373 | 382 | foreach( $titles as $title ){ |
374 | | - $key = wfMemcKey( 'iwtransclustiontext', 'textid', $wikiID, $title['title'] ); |
375 | | - $text = $wgMemc->get( $key ); |
376 | | - if( !$text ){ |
377 | | - $outdatedTitles[] = $title['title']; |
| 383 | + if ( isset ( $title['title'] ) ) { |
| 384 | + $key = wfMemcKey( 'iwtransclustiontext', 'textid', $wikiID, $title['title'] ); |
| 385 | + $text = $wgMemc->get( $key ); |
| 386 | + if( !$text ){ |
| 387 | + $outdatedTitles[] = $title['title']; |
| 388 | + } |
378 | 389 | } |
379 | 390 | } |
380 | 391 | |
— | — | @@ -392,14 +403,18 @@ |
393 | 404 | $get = Http::get( $url ); |
394 | 405 | $content = FormatJson::decode( $get, true ); |
395 | 406 | |
396 | | - if ( ! empty($content['query']['pages']) ) { |
| 407 | + if ( isset ( $content['query'] ) |
| 408 | + && isset ( $content['query']['pages'] ) ) { |
397 | 409 | foreach( $content['query']['pages'] as $page ) { |
398 | 410 | $key = wfMemcKey( 'iwtransclustiontext', 'textid', $wikiID, $page['title'] ); |
399 | | - $text = $page['revisions'][0]['*']; |
| 411 | + if ( isset ( $page['revisions'][0]['*'] ) ) { |
| 412 | + $text = $page['revisions'][0]['*']; |
| 413 | + } else { |
| 414 | + $text = array ( 'missing' => true ); |
| 415 | + } |
400 | 416 | $wgMemc->set( $key, $text, $wgTranscludeCacheExpiry ); |
401 | 417 | } |
402 | 418 | } |
403 | 419 | } |
404 | 420 | } |
405 | | - |
406 | 421 | } |
Index: branches/iwtransclusion/phase3/includes/Title.php |
— | — | @@ -718,6 +718,20 @@ |
719 | 719 | } |
720 | 720 | |
721 | 721 | /** |
| 722 | + * Return the prefixed title with spaces _without_ the interwiki prefix |
| 723 | + * |
| 724 | + * @return \type{\string} the title, prefixed by the namespace but not by the interwiki prefix, with spaces |
| 725 | + */ |
| 726 | + public function getSemiPrefixedText() { |
| 727 | + if ( !isset( $this->mSemiPrefixedText ) ){ |
| 728 | + $s = ( $this->mNamespace === NS_MAIN ? '' : $this->getNsText() . ':' ) . $this->mTextform; |
| 729 | + $s = str_replace( '_', ' ', $s ); |
| 730 | + $this->mSemiPrefixedText = $s; |
| 731 | + } |
| 732 | + return $this->mSemiPrefixedText; |
| 733 | + } |
| 734 | + |
| 735 | + /** |
722 | 736 | * Get the prefixed title with spaces, plus any fragment |
723 | 737 | * (part beginning with '#') |
724 | 738 | * |