Index: branches/iwtransclusion/phase3v2/includes/parser/Parser.php |
— | — | @@ -3063,7 +3063,6 @@ |
3064 | 3064 | $found = false; # $text has been filled |
3065 | 3065 | $nowiki = false; # wiki markup in $text should be escaped |
3066 | 3066 | $isHTML = false; # $text is HTML, armour it against wikitext transformation |
3067 | | - $forceRawInterwiki = false; # Force interwiki transclusion to be done in raw mode not rendered |
3068 | 3067 | $isChildObj = false; # $text is a DOM node needing expansion in a child frame |
3069 | 3068 | $isLocalObj = false; # $text is a DOM node needing expansion in the current frame |
3070 | 3069 | |
— | — | @@ -3135,12 +3134,6 @@ |
3136 | 3135 | $mwMsg = MagicWord::get( 'msg' ); |
3137 | 3136 | $mwMsg->matchStartAndRemove( $part1 ); |
3138 | 3137 | } |
3139 | | - |
3140 | | - # Check for RAW: |
3141 | | - $mwRaw = MagicWord::get( 'raw' ); |
3142 | | - if ( $mwRaw->matchStartAndRemove( $part1 ) ) { |
3143 | | - $forceRawInterwiki = true; |
3144 | | - } |
3145 | 3138 | } |
3146 | 3139 | wfProfileOut( __METHOD__.'-modifiers' ); |
3147 | 3140 | |
— | — | @@ -3274,16 +3267,17 @@ |
3275 | 3268 | $found = true; |
3276 | 3269 | } |
3277 | 3270 | } elseif ( $title->isTrans() ) { |
| 3271 | + // TODO: Work by Peter17 in progress |
3278 | 3272 | # 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 ); |
3284 | 3278 | # Preprocess it like a template |
3285 | 3279 | $text = $this->preprocessToDom( $text, self::PTD_FOR_INCLUSION ); |
3286 | 3280 | $isChildObj = true; |
3287 | | - } |
| 3281 | + //} |
3288 | 3282 | $found = true; |
3289 | 3283 | } |
3290 | 3284 | |
— | — | @@ -3511,6 +3505,7 @@ |
3512 | 3506 | 'deps' => $deps ); |
3513 | 3507 | } |
3514 | 3508 | |
| 3509 | + |
3515 | 3510 | /** |
3516 | 3511 | * Fetch a file and its title and register a reference to it. |
3517 | 3512 | * @param Title $title |
— | — | @@ -3553,22 +3548,89 @@ |
3554 | 3549 | |
3555 | 3550 | /** |
3556 | 3551 | * Transclude an interwiki link. |
| 3552 | + * TODO: separate in interwikiTranscludeFromDB & interwikiTranscludeFromAPI according to the iw type |
3557 | 3553 | */ |
3558 | | - function interwikiTransclude( $title, $action ) { |
| 3554 | + function interwikiTransclude( $title ) { |
| 3555 | + |
3559 | 3556 | global $wgEnableScaryTranscluding; |
3560 | 3557 | |
3561 | 3558 | if ( !$wgEnableScaryTranscluding ) { |
3562 | 3559 | return wfMsgForContent('scarytranscludedisabled'); |
3563 | 3560 | } |
| 3561 | + |
| 3562 | + $fullTitle = $title->getNsText().':'.$title->getText(); |
3564 | 3563 | |
3565 | | - $url = $title->getFullUrl( "action=$action" ); |
| 3564 | + $url1 = $title->getTransAPI( )."?action=query&prop=revisions&titles=$fullTitle&rvprop=content&format=json"; |
3566 | 3565 | |
3567 | | - if ( strlen( $url ) > 255 ) { |
| 3566 | + if ( strlen( $url1 ) > 255 ) { |
3568 | 3567 | return wfMsgForContent( 'scarytranscludetoolong' ); |
3569 | 3568 | } |
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; |
3571 | 3596 | } |
| 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 ) ) ); |
3572 | 3605 | |
| 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 | + |
3573 | 3635 | function fetchScaryTemplateMaybeFromCache( $url ) { |
3574 | 3636 | global $wgTranscludeCacheExpiry; |
3575 | 3637 | $dbr = wfGetDB( DB_SLAVE ); |
Property changes on: branches/iwtransclusion/phase3v2/includes/interwiki/Interwiki.php |
___________________________________________________________________ |
Modified: svn:mergeinfo |
3576 | 3638 | Merged /branches/iwtransclusion/phase3/includes/interwiki/Interwiki.php:r68170,68448,69480 |