r92985 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92984‎ | r92985 | r92986 >
Date:17:19, 24 July 2011
Author:reedy
Status:deferred
Tags:
Comment:
Merge r87104, which itself is a merge of r68170, r68448, r69480
Modified paths:
  • /branches/iwtransclusion/phase3v3/includes/parser/Parser.php (modified) (history)

Diff [purge]

Index: branches/iwtransclusion/phase3v3/includes/parser/Parser.php
@@ -3059,7 +3059,6 @@
30603060 $found = false; # $text has been filled
30613061 $nowiki = false; # wiki markup in $text should be escaped
30623062 $isHTML = false; # $text is HTML, armour it against wikitext transformation
3063 - $forceRawInterwiki = false; # Force interwiki transclusion to be done in raw mode not rendered
30643063 $isChildObj = false; # $text is a DOM node needing expansion in a child frame
30653064 $isLocalObj = false; # $text is a DOM node needing expansion in the current frame
30663065
@@ -3132,12 +3131,6 @@
31333132 $mwMsg = MagicWord::get( 'msg' );
31343133 $mwMsg->matchStartAndRemove( $part1 );
31353134 }
3136 -
3137 - # Check for RAW:
3138 - $mwRaw = MagicWord::get( 'raw' );
3139 - if ( $mwRaw->matchStartAndRemove( $part1 ) ) {
3140 - $forceRawInterwiki = true;
3141 - }
31423135 }
31433136 wfProfileOut( __METHOD__.'-modifiers' );
31443137
@@ -3271,16 +3264,17 @@
32723265 $found = true;
32733266 }
32743267 } elseif ( $title->isTrans() ) {
 3268+ // TODO: Work by Peter17 in progress
32753269 # Interwiki transclusion
3276 - if ( $this->ot['html'] && !$forceRawInterwiki ) {
3277 - $text = $this->interwikiTransclude( $title, 'render' );
3278 - $isHTML = true;
3279 - } else {
3280 - $text = $this->interwikiTransclude( $title, 'raw' );
 3270+ //if ( $this->ot['html'] && !$forceRawInterwiki ) {
 3271+ // $text = $this->interwikiTransclude( $title, 'render' );
 3272+ // $isHTML = true;
 3273+ //} else {
 3274+ $text = $this->interwikiTransclude( $title );
32813275 # Preprocess it like a template
32823276 $text = $this->preprocessToDom( $text, self::PTD_FOR_INCLUSION );
32833277 $isChildObj = true;
3284 - }
 3278+ //}
32853279 $found = true;
32863280 }
32873281
@@ -3514,6 +3508,7 @@
35153509 'deps' => $deps );
35163510 }
35173511
 3512+
35183513 /**
35193514 * Fetch a file and its title and register a reference to it.
35203515 * @param Title $title
@@ -3565,26 +3560,88 @@
35663561 * @param $action
35673562 *
35683563 * @return string
 3564+ * TODO: separate in interwikiTranscludeFromDB & interwikiTranscludeFromAPI according to the iw type
35693565 */
3570 - function interwikiTransclude( $title, $action ) {
 3566+ function interwikiTransclude( $title ) {
 3567+
35713568 global $wgEnableScaryTranscluding;
35723569
35733570 if ( !$wgEnableScaryTranscluding ) {
35743571 return wfMsgForContent('scarytranscludedisabled');
35753572 }
 3573+
 3574+ $fullTitle = $title->getNsText().':'.$title->getText();
35763575
3577 - $url = $title->getFullUrl( "action=$action" );
 3576+ $url1 = $title->getTransAPI( )."?action=query&prop=revisions&titles=$fullTitle&rvprop=content&format=json";
35783577
3579 - if ( strlen( $url ) > 255 ) {
 3578+ if ( strlen( $url1 ) > 255 ) {
35803579 return wfMsgForContent( 'scarytranscludetoolong' );
35813580 }
3582 - return $this->fetchScaryTemplateMaybeFromCache( $url );
 3581+
 3582+ $text = $this->fetchTemplateMaybeFromCache( $url1 );
 3583+
 3584+ $url2 = $title->getTransAPI( )."?action=parse&text={{".$fullTitle."}}&prop=templates&format=json";
 3585+
 3586+ $get = Http::get( $url2 );
 3587+ $myArray = FormatJson::decode($get, true);
 3588+
 3589+ if ( ! empty( $myArray['parse'] )) {
 3590+ $templates = $myArray['parse']['templates'];
 3591+ }
 3592+
 3593+
 3594+ // TODO: The templates are retrieved one by one.
 3595+ // We should split the templates in two groups: up-to-date and out-of-date
 3596+ // Only the second group would be retrieved through the API or DB request
 3597+ for ($i = 0 ; $i < count( $templates ) ; $i++) {
 3598+ $newTitle = $templates[$i]['*'];
 3599+
 3600+ $url = $title->getTransAPI( )."?action=query&prop=revisions&titles=$newTitle&rvprop=content&format=json";
 3601+
 3602+ $listSubTemplates.= $newTitle."\n";
 3603+ $list2.="<h2>".$newTitle."</h2>\n<pre>".$this->fetchTemplateMaybeFromCache( $url )."</pre>";
 3604+
 3605+ }
 3606+
 3607+ return "<h2>$fullTitle</h2><pre>$url1\n$url2\n$text</pre> List of templates: <pre>".$listSubTemplates.'</pre>' . $list2;
35833608 }
35843609
3585 - /**
3586 - * @param $url string
3587 - * @return Mixed|String
3588 - */
 3610+ function fetchTemplateMaybeFromCache( $url ) {
 3611+ global $wgTranscludeCacheExpiry;
 3612+ $dbr = wfGetDB( DB_SLAVE );
 3613+ $tsCond = $dbr->timestamp( time() - $wgTranscludeCacheExpiry );
 3614+ $obj = $dbr->selectRow( 'transcache', array('tc_time', 'tc_contents' ),
 3615+ array( 'tc_url' => $url, "tc_time >= " . $dbr->addQuotes( $tsCond ) ) );
 3616+
 3617+ if ( $obj ) {
 3618+ return $obj->tc_contents;
 3619+ }
 3620+
 3621+ $get = Http::get( $url );
 3622+
 3623+ $content = FormatJson::decode( $get, true );
 3624+
 3625+ if ( ! empty($content['query']['pages']) ) {
 3626+
 3627+ $page = array_pop( $content['query']['pages'] );
 3628+ $text = $page['revisions'][0]['*'];
 3629+
 3630+ } else {
 3631+
 3632+ return wfMsg( 'scarytranscludefailed', $url );
 3633+
 3634+ }
 3635+
 3636+ $dbw = wfGetDB( DB_MASTER );
 3637+ $dbw->replace( 'transcache', array('tc_url'), array(
 3638+ 'tc_url' => $url,
 3639+ 'tc_time' => $dbw->timestamp( time() ),
 3640+ 'tc_contents' => $text)
 3641+ );
 3642+
 3643+ return $text;
 3644+ }
 3645+
35893646 function fetchScaryTemplateMaybeFromCache( $url ) {
35903647 global $wgTranscludeCacheExpiry;
35913648 $dbr = wfGetDB( DB_SLAVE );

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
r87104Merge of r86170, r68448, r69480reedy00:19, 29 April 2011

Status & tagging log