r87104 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87103‎ | r87104 | r87105 >
Date:00:19, 29 April 2011
Author:reedy
Status:deferred
Tags:
Comment:
Merge of r86170, r68448, r69480
Modified paths:
  • /branches/iwtransclusion/phase3v2/includes/interwiki/Interwiki.php (modified) (history)
  • /branches/iwtransclusion/phase3v2/includes/parser/Parser.php (modified) (history)

Diff [purge]

Index: branches/iwtransclusion/phase3v2/includes/parser/Parser.php
@@ -3063,7 +3063,6 @@
30643064 $found = false; # $text has been filled
30653065 $nowiki = false; # wiki markup in $text should be escaped
30663066 $isHTML = false; # $text is HTML, armour it against wikitext transformation
3067 - $forceRawInterwiki = false; # Force interwiki transclusion to be done in raw mode not rendered
30683067 $isChildObj = false; # $text is a DOM node needing expansion in a child frame
30693068 $isLocalObj = false; # $text is a DOM node needing expansion in the current frame
30703069
@@ -3135,12 +3134,6 @@
31363135 $mwMsg = MagicWord::get( 'msg' );
31373136 $mwMsg->matchStartAndRemove( $part1 );
31383137 }
3139 -
3140 - # Check for RAW:
3141 - $mwRaw = MagicWord::get( 'raw' );
3142 - if ( $mwRaw->matchStartAndRemove( $part1 ) ) {
3143 - $forceRawInterwiki = true;
3144 - }
31453138 }
31463139 wfProfileOut( __METHOD__.'-modifiers' );
31473140
@@ -3274,16 +3267,17 @@
32753268 $found = true;
32763269 }
32773270 } elseif ( $title->isTrans() ) {
 3271+ // TODO: Work by Peter17 in progress
32783272 # Interwiki transclusion
3279 - if ( $this->ot['html'] && !$forceRawInterwiki ) {
3280 - $text = $this->interwikiTransclude( $title, 'render' );
3281 - $isHTML = true;
3282 - } else {
3283 - $text = $this->interwikiTransclude( $title, 'raw' );
 3273+ //if ( $this->ot['html'] && !$forceRawInterwiki ) {
 3274+ // $text = $this->interwikiTransclude( $title, 'render' );
 3275+ // $isHTML = true;
 3276+ //} else {
 3277+ $text = $this->interwikiTransclude( $title );
32843278 # Preprocess it like a template
32853279 $text = $this->preprocessToDom( $text, self::PTD_FOR_INCLUSION );
32863280 $isChildObj = true;
3287 - }
 3281+ //}
32883282 $found = true;
32893283 }
32903284
@@ -3511,6 +3505,7 @@
35123506 'deps' => $deps );
35133507 }
35143508
 3509+
35153510 /**
35163511 * Fetch a file and its title and register a reference to it.
35173512 * @param Title $title
@@ -3553,22 +3548,89 @@
35543549
35553550 /**
35563551 * Transclude an interwiki link.
 3552+ * TODO: separate in interwikiTranscludeFromDB & interwikiTranscludeFromAPI according to the iw type
35573553 */
3558 - function interwikiTransclude( $title, $action ) {
 3554+ function interwikiTransclude( $title ) {
 3555+
35593556 global $wgEnableScaryTranscluding;
35603557
35613558 if ( !$wgEnableScaryTranscluding ) {
35623559 return wfMsgForContent('scarytranscludedisabled');
35633560 }
 3561+
 3562+ $fullTitle = $title->getNsText().':'.$title->getText();
35643563
3565 - $url = $title->getFullUrl( "action=$action" );
 3564+ $url1 = $title->getTransAPI( )."?action=query&prop=revisions&titles=$fullTitle&rvprop=content&format=json";
35663565
3567 - if ( strlen( $url ) > 255 ) {
 3566+ if ( strlen( $url1 ) > 255 ) {
35683567 return wfMsgForContent( 'scarytranscludetoolong' );
35693568 }
3570 - return $this->fetchScaryTemplateMaybeFromCache( $url );
 3569+
 3570+ $text = $this->fetchTemplateMaybeFromCache( $url1 );
 3571+
 3572+ $url2 = $title->getTransAPI( )."?action=parse&text={{".$fullTitle."}}&prop=templates&format=json";
 3573+
 3574+ $get = Http::get( $url2 );
 3575+ $myArray = FormatJson::decode($get, true);
 3576+
 3577+ if ( ! empty( $myArray['parse'] )) {
 3578+ $templates = $myArray['parse']['templates'];
 3579+ }
 3580+
 3581+
 3582+ // TODO: The templates are retrieved one by one.
 3583+ // We should split the templates in two groups: up-to-date and out-of-date
 3584+ // Only the second group would be retrieved through the API or DB request
 3585+ for ($i = 0 ; $i < count( $templates ) ; $i++) {
 3586+ $newTitle = $templates[$i]['*'];
 3587+
 3588+ $url = $title->getTransAPI( )."?action=query&prop=revisions&titles=$newTitle&rvprop=content&format=json";
 3589+
 3590+ $listSubTemplates.= $newTitle."\n";
 3591+ $list2.="<h2>".$newTitle."</h2>\n<pre>".$this->fetchTemplateMaybeFromCache( $url )."</pre>";
 3592+
 3593+ }
 3594+
 3595+ return "<h2>$fullTitle</h2><pre>$url1\n$url2\n$text</pre> List of templates: <pre>".$listSubTemplates.'</pre>' . $list2;
35713596 }
 3597+
 3598+
 3599+ function fetchTemplateMaybeFromCache( $url ) {
 3600+ global $wgTranscludeCacheExpiry;
 3601+ $dbr = wfGetDB( DB_SLAVE );
 3602+ $tsCond = $dbr->timestamp( time() - $wgTranscludeCacheExpiry );
 3603+ $obj = $dbr->selectRow( 'transcache', array('tc_time', 'tc_contents' ),
 3604+ array( 'tc_url' => $url, "tc_time >= " . $dbr->addQuotes( $tsCond ) ) );
35723605
 3606+ if ( $obj ) {
 3607+ return $obj->tc_contents;
 3608+ }
 3609+
 3610+ $get = Http::get( $url );
 3611+
 3612+ $content = FormatJson::decode( $get, true );
 3613+
 3614+ if ( ! empty($content['query']['pages']) ) {
 3615+
 3616+ $page = array_pop( $content['query']['pages'] );
 3617+ $text = $page['revisions'][0]['*'];
 3618+
 3619+ } else {
 3620+
 3621+ return wfMsg( 'scarytranscludefailed', $url );
 3622+
 3623+ }
 3624+
 3625+ $dbw = wfGetDB( DB_MASTER );
 3626+ $dbw->replace( 'transcache', array('tc_url'), array(
 3627+ 'tc_url' => $url,
 3628+ 'tc_time' => $dbw->timestamp( time() ),
 3629+ 'tc_contents' => $text)
 3630+ );
 3631+
 3632+ return $text;
 3633+ }
 3634+
35733635 function fetchScaryTemplateMaybeFromCache( $url ) {
35743636 global $wgTranscludeCacheExpiry;
35753637 $dbr = wfGetDB( DB_SLAVE );
Property changes on: branches/iwtransclusion/phase3v2/includes/interwiki/Interwiki.php
___________________________________________________________________
Modified: svn:mergeinfo
35763638 Merged /branches/iwtransclusion/phase3/includes/interwiki/Interwiki.php:r68170,68448,69480

Follow-up revisions

RevisionCommit summaryAuthorDate
r92985Merge r87104, which itself is a merge of r68170, r68448, r69480reedy17:19, 24 July 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r68170First version of my code, for interwiki transclusionpeter1713:43, 17 June 2010
r68448Adding 2 fields in the interwiki table and upgrading my codepeter1711:47, 23 June 2010
r69480Renaming DBname to WikiIDpeter1717:08, 17 July 2010

Status & tagging log