Index: branches/iwtransclusion/phase3v2/maintenance/archives/patch-globaltemplatelinks.sql |
— | — | @@ -0,0 +1,31 @@ |
| 2 | +-- Table tracking interwiki transclusions in the spirit of templatelinks. |
| 3 | +-- This table tracks transclusions of this wiki's templates on another wiki |
| 4 | +-- The gtl_from_* fields describe the (remote) page the template is transcluded from |
| 5 | +-- The gtl_to_* fields describe the (local) template being transcluded |
| 6 | +CREATE TABLE /*_*/globaltemplatelinks ( |
| 7 | + -- The wiki ID of the remote wiki |
| 8 | + gtl_from_wiki varchar(64) NOT NULL, |
| 9 | + |
| 10 | + -- The page ID of the calling page on the remote wiki |
| 11 | + gtl_from_page int unsigned NOT NULL, |
| 12 | + |
| 13 | + -- The namespace name of the calling page on the remote wiki |
| 14 | + -- Needed for display purposes, since the foreign namespace ID doesn't necessarily match a local one |
| 15 | + gtl_from_namespace varchar(255) NOT NULL, |
| 16 | + |
| 17 | + -- The title of the calling page on the remote wiki |
| 18 | + -- Needed for display purposes |
| 19 | + gtl_from_title varchar(255) binary NOT NULL, |
| 20 | + |
| 21 | + -- The wiki ID of the wiki that hosts the transcluded page |
| 22 | + gtl_to_wiki varchar(64) NOT NULL, |
| 23 | + |
| 24 | + -- The namespace of the transcluded page on that wiki |
| 25 | + gtl_to_namespace int NOT NULL, |
| 26 | + |
| 27 | + -- The title of the transcluded page on that wiki |
| 28 | + gtl_to_title varchar(255) binary NOT NULL |
| 29 | +) /*$wgDBTableOptions*/; |
| 30 | + |
| 31 | +CREATE UNIQUE INDEX /*i*/gtl_to_from ON /*_*/globaltemplatelinks (gtl_to_wiki, gtl_to_namespace, gtl_to_title, gtl_from_wiki, gtl_from_page); |
| 32 | +CREATE UNIQUE INDEX /*i*/gtl_from_to ON /*_*/globaltemplatelinks (gtl_from_wiki, gtl_from_page, gtl_to_wiki, gtl_to_namespace, gtl_to_title); |
Property changes on: branches/iwtransclusion/phase3v2/maintenance/archives/patch-globaltemplatelinks.sql |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 33 | + native |
Index: branches/iwtransclusion/phase3v2/includes/parser/Preprocessor_Hash.php |
— | — | @@ -962,6 +962,7 @@ |
963 | 963 | if ( $flags & PPFrame::NO_TEMPLATES ) { |
964 | 964 | $newIterator = $this->virtualBracketedImplode( '{{', '|', '}}', $bits['title'], $bits['parts'] ); |
965 | 965 | } else { |
| 966 | + $bits['interwiki'] = $this->title->getInterwiki( ); |
966 | 967 | $ret = $this->parser->braceSubstitution( $bits, $this ); |
967 | 968 | if ( isset( $ret['object'] ) ) { |
968 | 969 | $newIterator = $ret['object']; |
Index: branches/iwtransclusion/phase3v2/includes/parser/Parser.php |
— | — | @@ -3220,6 +3220,9 @@ |
3221 | 3221 | } |
3222 | 3222 | $title = Title::newFromText( $part1, $ns ); |
3223 | 3223 | if ( $title ) { |
| 3224 | + if ( !$title->isExternal() && $piece['interwiki'] !== '' ) { |
| 3225 | + $title->setInterwiki( $piece['interwiki'] ); |
| 3226 | + } |
3224 | 3227 | $titleText = $title->getPrefixedText(); |
3225 | 3228 | # Check for language variants if the template is not found |
3226 | 3229 | if ( $wgContLang->hasVariants() && $title->getArticleID() == 0 ) { |
Index: branches/iwtransclusion/phase3v2/includes/parser/Preprocessor_DOM.php |
— | — | @@ -982,7 +982,8 @@ |
983 | 983 | $params = array( |
984 | 984 | 'title' => new PPNode_DOM( $title ), |
985 | 985 | 'parts' => new PPNode_DOM( $parts ), |
986 | | - 'lineStart' => $lineStart ); |
| 986 | + 'lineStart' => $lineStart, |
| 987 | + 'interwiki' => $this->title->getInterwiki( ) ); |
987 | 988 | $ret = $this->parser->braceSubstitution( $params, $this ); |
988 | 989 | if ( isset( $ret['object'] ) ) { |
989 | 990 | $newIterator = $ret['object']; |
Index: branches/iwtransclusion/phase3v2/includes/interwiki/Interwiki.php |
— | — | @@ -291,37 +291,11 @@ |
292 | 292 | |
293 | 293 | } else if( $transAPI !== '' ) { |
294 | 294 | |
| 295 | + $interwiki = $title->getInterwiki( ); |
295 | 296 | $fullTitle = $title->getSemiPrefixedText( ); |
296 | 297 | |
297 | | - $finalText = self::fetchTemplateFromAPI( $wikiID, $transAPI, $fullTitle ); |
298 | | - |
299 | | - //Retrieve the list of subtemplates |
300 | | - $url2 = wfAppendQuery( $transAPI, |
301 | | - array( 'action' => 'query', |
302 | | - 'titles' => $fullTitle, |
303 | | - 'prop' => 'templates', |
304 | | - 'format' => 'json' |
305 | | - ) |
306 | | - ); |
| 298 | + $finalText = self::fetchTemplateFromAPI( $interwiki, $transAPI, $fullTitle ); |
307 | 299 | |
308 | | - $get = Http::get( $url2 ); |
309 | | - $myArray = FormatJson::decode($get, true); |
310 | | - |
311 | | - if ( ! empty( $myArray['query'] )) { |
312 | | - if ( ! empty( $myArray['query']['pages'] )) { |
313 | | - $templates = array_pop( $myArray['query']['pages'] ); |
314 | | - if ( ! empty( $templates['templates'] )) { |
315 | | - $templates = $templates['templates']; |
316 | | - } else { |
317 | | - $templates = array( ); |
318 | | - } |
319 | | - } |
320 | | - } |
321 | | - |
322 | | - // TODO: The subtemplates are retrieved one by one. We should get them all in 1 request |
323 | | - // Here, we preload and cache the subtemplates |
324 | | - self::cacheTemplatesFromAPI( $wikiID, $transAPI, $templates ); |
325 | | - |
326 | 300 | return $finalText; |
327 | 301 | |
328 | 302 | } |
— | — | @@ -346,10 +320,10 @@ |
347 | 321 | /** |
348 | 322 | * Retrieve the wikitext of a distant page using the API of the foreign wiki |
349 | 323 | */ |
350 | | - public static function fetchTemplateFromAPI( $wikiID, $transAPI, $fullTitle ) { |
| 324 | + public static function fetchTemplateFromAPI( $interwiki, $transAPI, $fullTitle ) { |
351 | 325 | global $wgMemc, $wgTranscludeCacheExpiry; |
352 | 326 | |
353 | | - $key = wfMemcKey( 'iwtransclustiontext', 'textid', $wikiID, $fullTitle ); |
| 327 | + $key = wfMemcKey( 'iwtransclustiontext', 'textid', $interwiki, $fullTitle ); |
354 | 328 | $text = $wgMemc->get( $key ); |
355 | 329 | if( is_array ( $text ) && |
356 | 330 | isset ( $text['missing'] ) && |
— | — | @@ -378,6 +352,11 @@ |
379 | 353 | if ( $page && isset( $page['revisions'][0]['*'] ) ) { |
380 | 354 | $text = $page['revisions'][0]['*']; |
381 | 355 | $wgMemc->set( $key, $text, $wgTranscludeCacheExpiry ); |
| 356 | + |
| 357 | + // When we cache a template, we also retrieve and cache its subtemplates |
| 358 | + $subtemplates = self::getSubtemplatesListFromAPI( $interwiki, $transAPI, $fullTitle ); |
| 359 | + self::cacheTemplatesFromAPI( $interwiki, $transAPI, $subtemplates ); |
| 360 | + |
382 | 361 | return $text; |
383 | 362 | } else { |
384 | 363 | $wgMemc->set( $key, array ( 'missing' => true ), $wgTranscludeCacheExpiry ); |
— | — | @@ -386,14 +365,38 @@ |
387 | 366 | return false; |
388 | 367 | } |
389 | 368 | |
390 | | - public static function cacheTemplatesFromAPI( $wikiID, $transAPI, $titles ){ |
| 369 | + public static function getSubtemplatesListFromAPI ( $interwiki, $transAPI, $title ) { |
| 370 | + $url = wfAppendQuery( $transAPI, |
| 371 | + array( 'action' => 'query', |
| 372 | + 'titles' => $title, |
| 373 | + 'prop' => 'templates', |
| 374 | + 'format' => 'json' |
| 375 | + ) |
| 376 | + ); |
| 377 | + |
| 378 | + $get = Http::get( $url ); |
| 379 | + $myArray = FormatJson::decode($get, true); |
| 380 | + |
| 381 | + $templates = array( ); |
| 382 | + if ( ! empty( $myArray['query'] )) { |
| 383 | + if ( ! empty( $myArray['query']['pages'] )) { |
| 384 | + $templates = array_pop( $myArray['query']['pages'] ); |
| 385 | + if ( ! empty( $templates['templates'] )) { |
| 386 | + $templates = $templates['templates']; |
| 387 | + } |
| 388 | + } |
| 389 | + return $templates; |
| 390 | + } |
| 391 | + } |
| 392 | + |
| 393 | + public static function cacheTemplatesFromAPI( $interwiki, $transAPI, $titles ){ |
391 | 394 | global $wgMemc, $wgTranscludeCacheExpiry; |
392 | 395 | |
393 | 396 | $outdatedTitles = array( ); |
394 | 397 | |
395 | 398 | foreach( $titles as $title ){ |
396 | 399 | if ( isset ( $title['title'] ) ) { |
397 | | - $key = wfMemcKey( 'iwtransclustiontext', 'textid', $wikiID, $title['title'] ); |
| 400 | + $key = wfMemcKey( 'iwtransclustiontext', 'textid', $interwiki, $title['title'] ); |
398 | 401 | $text = $wgMemc->get( $key ); |
399 | 402 | if( !$text ){ |
400 | 403 | $outdatedTitles[] = $title['title']; |
— | — | @@ -419,7 +422,7 @@ |
420 | 423 | if ( isset ( $content['query'] ) && |
421 | 424 | isset ( $content['query']['pages'] ) ) { |
422 | 425 | foreach( $content['query']['pages'] as $page ) { |
423 | | - $key = wfMemcKey( 'iwtransclustiontext', 'textid', $wikiID, $page['title'] ); |
| 426 | + $key = wfMemcKey( 'iwtransclustiontext', 'textid', $interwiki, $page['title'] ); |
424 | 427 | if ( isset ( $page['revisions'][0]['*'] ) ) { |
425 | 428 | $text = $page['revisions'][0]['*']; |
426 | 429 | } else { |
Property changes on: branches/iwtransclusion/phase3v2/includes/interwiki/Interwiki.php |
___________________________________________________________________ |
Modified: svn:mergeinfo |
427 | 430 | Merged /branches/iwtransclusion/phase3/includes/interwiki/Interwiki.php:r69853,69948,70411,70575 |
Index: branches/iwtransclusion/phase3v2/includes/Revision.php |
— | — | @@ -907,7 +907,7 @@ |
908 | 908 | // Caching may be beneficial for massive use of external storage |
909 | 909 | global $wgRevisionCacheExpiry, $wgMemc; |
910 | 910 | $textId = $this->getTextId(); |
911 | | - if( isset( $this->mWikiID ) ) { |
| 911 | + if( isset( $this->mWikiID ) && $this->mWikiID !== false ) { |
912 | 912 | $key = wfForeignMemcKey( $this->mWikiID, null, 'revisiontext', 'textid', $textId ); |
913 | 913 | } else { |
914 | 914 | $key = wfMemcKey( 'revisiontext', 'textid', $textId ); |
Property changes on: branches/iwtransclusion/phase3v2/includes/Revision.php |
___________________________________________________________________ |
Modified: svn:mergeinfo |
915 | 915 | Merged /branches/iwtransclusion/phase3/includes/Revision.php:r69853,69948,70411,70575 |
Index: branches/iwtransclusion/phase3v2/includes/Title.php |
— | — | @@ -2778,6 +2778,10 @@ |
2779 | 2779 | $this->mFragment = str_replace( '_', ' ', substr( $fragment, 1 ) ); |
2780 | 2780 | } |
2781 | 2781 | |
| 2782 | + public function setInterwiki( $interwiki ) { |
| 2783 | + $this->mInterwiki = $interwiki; |
| 2784 | + } |
| 2785 | + |
2782 | 2786 | /** |
2783 | 2787 | * Get a Title object associated with the talk page of this article |
2784 | 2788 | * |
Property changes on: branches/iwtransclusion/phase3v2/includes/Title.php |
___________________________________________________________________ |
Modified: svn:mergeinfo |
2785 | 2789 | Merged /branches/iwtransclusion/phase3/includes/Title.php:r69853,69948,70411,70575 |
Property changes on: branches/iwtransclusion/phase3v2 |
___________________________________________________________________ |
Modified: svn:mergeinfo |
2786 | 2790 | Merged /branches/iwtransclusion/phase3:r69853,69948,70411,70575 |