r87107 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87106‎ | r87107 | r87108 >
Date:00:31, 29 April 2011
Author:reedy
Status:deferred
Tags:
Comment:
Modified paths:
  • /branches/iwtransclusion/phase3v2 (modified) (history)
  • /branches/iwtransclusion/phase3v2/includes/Revision.php (modified) (history)
  • /branches/iwtransclusion/phase3v2/includes/Title.php (modified) (history)
  • /branches/iwtransclusion/phase3v2/includes/interwiki/Interwiki.php (modified) (history)
  • /branches/iwtransclusion/phase3v2/includes/parser/Parser.php (modified) (history)
  • /branches/iwtransclusion/phase3v2/includes/parser/Preprocessor_DOM.php (modified) (history)
  • /branches/iwtransclusion/phase3v2/includes/parser/Preprocessor_Hash.php (modified) (history)
  • /branches/iwtransclusion/phase3v2/maintenance/archives/patch-globaltemplatelinks.sql (added) (history)

Diff [purge]

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
133 + native
Index: branches/iwtransclusion/phase3v2/includes/parser/Preprocessor_Hash.php
@@ -962,6 +962,7 @@
963963 if ( $flags & PPFrame::NO_TEMPLATES ) {
964964 $newIterator = $this->virtualBracketedImplode( '{{', '|', '}}', $bits['title'], $bits['parts'] );
965965 } else {
 966+ $bits['interwiki'] = $this->title->getInterwiki( );
966967 $ret = $this->parser->braceSubstitution( $bits, $this );
967968 if ( isset( $ret['object'] ) ) {
968969 $newIterator = $ret['object'];
Index: branches/iwtransclusion/phase3v2/includes/parser/Parser.php
@@ -3220,6 +3220,9 @@
32213221 }
32223222 $title = Title::newFromText( $part1, $ns );
32233223 if ( $title ) {
 3224+ if ( !$title->isExternal() && $piece['interwiki'] !== '' ) {
 3225+ $title->setInterwiki( $piece['interwiki'] );
 3226+ }
32243227 $titleText = $title->getPrefixedText();
32253228 # Check for language variants if the template is not found
32263229 if ( $wgContLang->hasVariants() && $title->getArticleID() == 0 ) {
Index: branches/iwtransclusion/phase3v2/includes/parser/Preprocessor_DOM.php
@@ -982,7 +982,8 @@
983983 $params = array(
984984 'title' => new PPNode_DOM( $title ),
985985 'parts' => new PPNode_DOM( $parts ),
986 - 'lineStart' => $lineStart );
 986+ 'lineStart' => $lineStart,
 987+ 'interwiki' => $this->title->getInterwiki( ) );
987988 $ret = $this->parser->braceSubstitution( $params, $this );
988989 if ( isset( $ret['object'] ) ) {
989990 $newIterator = $ret['object'];
Index: branches/iwtransclusion/phase3v2/includes/interwiki/Interwiki.php
@@ -291,37 +291,11 @@
292292
293293 } else if( $transAPI !== '' ) {
294294
 295+ $interwiki = $title->getInterwiki( );
295296 $fullTitle = $title->getSemiPrefixedText( );
296297
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 );
307299
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 -
326300 return $finalText;
327301
328302 }
@@ -346,10 +320,10 @@
347321 /**
348322 * Retrieve the wikitext of a distant page using the API of the foreign wiki
349323 */
350 - public static function fetchTemplateFromAPI( $wikiID, $transAPI, $fullTitle ) {
 324+ public static function fetchTemplateFromAPI( $interwiki, $transAPI, $fullTitle ) {
351325 global $wgMemc, $wgTranscludeCacheExpiry;
352326
353 - $key = wfMemcKey( 'iwtransclustiontext', 'textid', $wikiID, $fullTitle );
 327+ $key = wfMemcKey( 'iwtransclustiontext', 'textid', $interwiki, $fullTitle );
354328 $text = $wgMemc->get( $key );
355329 if( is_array ( $text ) &&
356330 isset ( $text['missing'] ) &&
@@ -378,6 +352,11 @@
379353 if ( $page && isset( $page['revisions'][0]['*'] ) ) {
380354 $text = $page['revisions'][0]['*'];
381355 $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+
382361 return $text;
383362 } else {
384363 $wgMemc->set( $key, array ( 'missing' => true ), $wgTranscludeCacheExpiry );
@@ -386,14 +365,38 @@
387366 return false;
388367 }
389368
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 ){
391394 global $wgMemc, $wgTranscludeCacheExpiry;
392395
393396 $outdatedTitles = array( );
394397
395398 foreach( $titles as $title ){
396399 if ( isset ( $title['title'] ) ) {
397 - $key = wfMemcKey( 'iwtransclustiontext', 'textid', $wikiID, $title['title'] );
 400+ $key = wfMemcKey( 'iwtransclustiontext', 'textid', $interwiki, $title['title'] );
398401 $text = $wgMemc->get( $key );
399402 if( !$text ){
400403 $outdatedTitles[] = $title['title'];
@@ -419,7 +422,7 @@
420423 if ( isset ( $content['query'] ) &&
421424 isset ( $content['query']['pages'] ) ) {
422425 foreach( $content['query']['pages'] as $page ) {
423 - $key = wfMemcKey( 'iwtransclustiontext', 'textid', $wikiID, $page['title'] );
 426+ $key = wfMemcKey( 'iwtransclustiontext', 'textid', $interwiki, $page['title'] );
424427 if ( isset ( $page['revisions'][0]['*'] ) ) {
425428 $text = $page['revisions'][0]['*'];
426429 } else {
Property changes on: branches/iwtransclusion/phase3v2/includes/interwiki/Interwiki.php
___________________________________________________________________
Modified: svn:mergeinfo
427430 Merged /branches/iwtransclusion/phase3/includes/interwiki/Interwiki.php:r69853,69948,70411,70575
Index: branches/iwtransclusion/phase3v2/includes/Revision.php
@@ -907,7 +907,7 @@
908908 // Caching may be beneficial for massive use of external storage
909909 global $wgRevisionCacheExpiry, $wgMemc;
910910 $textId = $this->getTextId();
911 - if( isset( $this->mWikiID ) ) {
 911+ if( isset( $this->mWikiID ) && $this->mWikiID !== false ) {
912912 $key = wfForeignMemcKey( $this->mWikiID, null, 'revisiontext', 'textid', $textId );
913913 } else {
914914 $key = wfMemcKey( 'revisiontext', 'textid', $textId );
Property changes on: branches/iwtransclusion/phase3v2/includes/Revision.php
___________________________________________________________________
Modified: svn:mergeinfo
915915 Merged /branches/iwtransclusion/phase3/includes/Revision.php:r69853,69948,70411,70575
Index: branches/iwtransclusion/phase3v2/includes/Title.php
@@ -2778,6 +2778,10 @@
27792779 $this->mFragment = str_replace( '_', ' ', substr( $fragment, 1 ) );
27802780 }
27812781
 2782+ public function setInterwiki( $interwiki ) {
 2783+ $this->mInterwiki = $interwiki;
 2784+ }
 2785+
27822786 /**
27832787 * Get a Title object associated with the talk page of this article
27842788 *
Property changes on: branches/iwtransclusion/phase3v2/includes/Title.php
___________________________________________________________________
Modified: svn:mergeinfo
27852789 Merged /branches/iwtransclusion/phase3/includes/Title.php:r69853,69948,70411,70575
Property changes on: branches/iwtransclusion/phase3v2
___________________________________________________________________
Modified: svn:mergeinfo
27862790 Merged /branches/iwtransclusion/phase3:r69853,69948,70411,70575

Follow-up revisions

RevisionCommit summaryAuthorDate
r92988Merge r87107, Merge r69853, r69948, r70411, r70575reedy17:27, 24 July 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r69853Force the parser to transclude the foreign subtemplates; NB: VERY slowpeter1722:18, 24 July 2010
r69948Retrieve subtemplates list only when retrieving template from API, not from c...peter1715:01, 26 July 2010
r70411Fix an issue of r69853peter1720:33, 3 August 2010
r70575Adding a globaltemplatelinks tablepeter1715:58, 6 August 2010

Status & tagging log