Index: branches/iwtransclusion/phase3v3/includes/parser/Parser.php |
— | — | @@ -3059,7 +3059,6 @@ |
3060 | 3060 | $found = false; # $text has been filled |
3061 | 3061 | $nowiki = false; # wiki markup in $text should be escaped |
3062 | 3062 | $isHTML = false; # $text is HTML, armour it against wikitext transformation |
3063 | | - $forceRawInterwiki = false; # Force interwiki transclusion to be done in raw mode not rendered |
3064 | 3063 | $isChildObj = false; # $text is a DOM node needing expansion in a child frame |
3065 | 3064 | $isLocalObj = false; # $text is a DOM node needing expansion in the current frame |
3066 | 3065 | |
— | — | @@ -3132,12 +3131,6 @@ |
3133 | 3132 | $mwMsg = MagicWord::get( 'msg' ); |
3134 | 3133 | $mwMsg->matchStartAndRemove( $part1 ); |
3135 | 3134 | } |
3136 | | - |
3137 | | - # Check for RAW: |
3138 | | - $mwRaw = MagicWord::get( 'raw' ); |
3139 | | - if ( $mwRaw->matchStartAndRemove( $part1 ) ) { |
3140 | | - $forceRawInterwiki = true; |
3141 | | - } |
3142 | 3135 | } |
3143 | 3136 | wfProfileOut( __METHOD__.'-modifiers' ); |
3144 | 3137 | |
— | — | @@ -3271,16 +3264,17 @@ |
3272 | 3265 | $found = true; |
3273 | 3266 | } |
3274 | 3267 | } elseif ( $title->isTrans() ) { |
| 3268 | + // TODO: Work by Peter17 in progress |
3275 | 3269 | # 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 ); |
3281 | 3275 | # Preprocess it like a template |
3282 | 3276 | $text = $this->preprocessToDom( $text, self::PTD_FOR_INCLUSION ); |
3283 | 3277 | $isChildObj = true; |
3284 | | - } |
| 3278 | + //} |
3285 | 3279 | $found = true; |
3286 | 3280 | } |
3287 | 3281 | |
— | — | @@ -3514,6 +3508,7 @@ |
3515 | 3509 | 'deps' => $deps ); |
3516 | 3510 | } |
3517 | 3511 | |
| 3512 | + |
3518 | 3513 | /** |
3519 | 3514 | * Fetch a file and its title and register a reference to it. |
3520 | 3515 | * @param Title $title |
— | — | @@ -3565,26 +3560,88 @@ |
3566 | 3561 | * @param $action |
3567 | 3562 | * |
3568 | 3563 | * @return string |
| 3564 | + * TODO: separate in interwikiTranscludeFromDB & interwikiTranscludeFromAPI according to the iw type |
3569 | 3565 | */ |
3570 | | - function interwikiTransclude( $title, $action ) { |
| 3566 | + function interwikiTransclude( $title ) { |
| 3567 | + |
3571 | 3568 | global $wgEnableScaryTranscluding; |
3572 | 3569 | |
3573 | 3570 | if ( !$wgEnableScaryTranscluding ) { |
3574 | 3571 | return wfMsgForContent('scarytranscludedisabled'); |
3575 | 3572 | } |
| 3573 | + |
| 3574 | + $fullTitle = $title->getNsText().':'.$title->getText(); |
3576 | 3575 | |
3577 | | - $url = $title->getFullUrl( "action=$action" ); |
| 3576 | + $url1 = $title->getTransAPI( )."?action=query&prop=revisions&titles=$fullTitle&rvprop=content&format=json"; |
3578 | 3577 | |
3579 | | - if ( strlen( $url ) > 255 ) { |
| 3578 | + if ( strlen( $url1 ) > 255 ) { |
3580 | 3579 | return wfMsgForContent( 'scarytranscludetoolong' ); |
3581 | 3580 | } |
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; |
3583 | 3608 | } |
3584 | 3609 | |
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 | + |
3589 | 3646 | function fetchScaryTemplateMaybeFromCache( $url ) { |
3590 | 3647 | global $wgTranscludeCacheExpiry; |
3591 | 3648 | $dbr = wfGetDB( DB_SLAVE ); |