Index: branches/iwtransclusion/phase3/includes/Interwiki.php |
— | — | @@ -15,11 +15,12 @@ |
16 | 16 | protected static $smCache = array(); |
17 | 17 | const CACHE_LIMIT = 100; // 0 means unlimited, any other value is max number of entries. |
18 | 18 | |
19 | | - protected $mPrefix, $mURL, $mLocal, $mTrans; |
| 19 | + protected $mPrefix, $mURL, $mAPI, $mLocal, $mTrans; |
20 | 20 | |
21 | | - public function __construct( $prefix = null, $url = '', $local = 0, $trans = 0 ) { |
| 21 | + public function __construct( $prefix = null, $url = '', $api = '', $local = 0, $trans = 0 ) { |
22 | 22 | $this->mPrefix = $prefix; |
23 | 23 | $this->mURL = $url; |
| 24 | + $this->mAPI = $api; |
24 | 25 | $this->mLocal = $local; |
25 | 26 | $this->mTrans = $trans; |
26 | 27 | } |
— | — | @@ -153,7 +154,7 @@ |
154 | 155 | __METHOD__ ) ); |
155 | 156 | $iw = Interwiki::loadFromArray( $row ); |
156 | 157 | if ( $iw ) { |
157 | | - $mc = array( 'iw_url' => $iw->mURL, 'iw_local' => $iw->mLocal, 'iw_trans' => $iw->mTrans ); |
| 158 | + $mc = array( 'iw_url' => $iw->mURL, 'iw_api' => $iw->mAPI, 'iw_local' => $iw->mLocal, 'iw_trans' => $iw->mTrans ); |
158 | 159 | $wgMemc->add( $key, $mc, $wgInterwikiExpiry ); |
159 | 160 | return $iw; |
160 | 161 | } |
— | — | @@ -168,9 +169,10 @@ |
169 | 170 | * @return Boolean: whether everything was there |
170 | 171 | */ |
171 | 172 | protected static function loadFromArray( $mc ) { |
172 | | - if( isset( $mc['iw_url'] ) && isset( $mc['iw_local'] ) && isset( $mc['iw_trans'] ) ) { |
| 173 | + if( isset( $mc['iw_url'] ) && isset( $mc['iw_api'] ) && isset( $mc['iw_local'] ) && isset( $mc['iw_trans'] ) ) { |
173 | 174 | $iw = new Interwiki(); |
174 | 175 | $iw->mURL = $mc['iw_url']; |
| 176 | + $iw->mAPI = $mc['iw_api']; |
175 | 177 | $iw->mLocal = $mc['iw_local']; |
176 | 178 | $iw->mTrans = $mc['iw_trans']; |
177 | 179 | return $iw; |
— | — | @@ -193,6 +195,17 @@ |
194 | 196 | } |
195 | 197 | |
196 | 198 | /** |
| 199 | + * Get the API URL for this wiki |
| 200 | + * |
| 201 | + * @return String: the URL |
| 202 | + */ |
| 203 | + public function getAPI( ) { |
| 204 | + $url = $this->mAPI; |
| 205 | + |
| 206 | + return $url; |
| 207 | + } |
| 208 | + |
| 209 | + /** |
197 | 210 | * Is this a local link from a sister project, or is |
198 | 211 | * it something outside, like Google |
199 | 212 | * |
Index: branches/iwtransclusion/phase3/includes/parser/Parser.php |
— | — | @@ -2846,7 +2846,6 @@ |
2847 | 2847 | $found = false; # $text has been filled |
2848 | 2848 | $nowiki = false; # wiki markup in $text should be escaped |
2849 | 2849 | $isHTML = false; # $text is HTML, armour it against wikitext transformation |
2850 | | - $forceRawInterwiki = false; # Force interwiki transclusion to be done in raw mode not rendered |
2851 | 2850 | $isChildObj = false; # $text is a DOM node needing expansion in a child frame |
2852 | 2851 | $isLocalObj = false; # $text is a DOM node needing expansion in the current frame |
2853 | 2852 | |
— | — | @@ -2917,12 +2916,6 @@ |
2918 | 2917 | $mwMsg = MagicWord::get( 'msg' ); |
2919 | 2918 | $mwMsg->matchStartAndRemove( $part1 ); |
2920 | 2919 | } |
2921 | | - |
2922 | | - # Check for RAW: |
2923 | | - $mwRaw = MagicWord::get( 'raw' ); |
2924 | | - if ( $mwRaw->matchStartAndRemove( $part1 ) ) { |
2925 | | - $forceRawInterwiki = true; |
2926 | | - } |
2927 | 2920 | } |
2928 | 2921 | wfProfileOut( __METHOD__.'-modifiers' ); |
2929 | 2922 | |
— | — | @@ -3056,16 +3049,17 @@ |
3057 | 3050 | $found = true; |
3058 | 3051 | } |
3059 | 3052 | } elseif ( $title->isTrans() ) { |
| 3053 | + // TODO: Work by Peter17 in progress |
3060 | 3054 | # Interwiki transclusion |
3061 | | - if ( $this->ot['html'] && !$forceRawInterwiki ) { |
3062 | | - $text = $this->interwikiTransclude( $title, 'render' ); |
3063 | | - $isHTML = true; |
3064 | | - } else { |
| 3055 | + //if ( $this->ot['html'] && !$forceRawInterwiki ) { |
| 3056 | + // $text = $this->interwikiTransclude( $title, 'render' ); |
| 3057 | + // $isHTML = true; |
| 3058 | + //} else { |
3065 | 3059 | $text = $this->interwikiTransclude( $title, 'raw' ); |
3066 | 3060 | # Preprocess it like a template |
3067 | 3061 | $text = $this->preprocessToDom( $text, self::PTD_FOR_INCLUSION ); |
3068 | 3062 | $isChildObj = true; |
3069 | | - } |
| 3063 | + //} |
3070 | 3064 | $found = true; |
3071 | 3065 | } |
3072 | 3066 | |
— | — | @@ -3274,24 +3268,91 @@ |
3275 | 3269 | 'deps' => $deps ); |
3276 | 3270 | } |
3277 | 3271 | |
| 3272 | + |
3278 | 3273 | /** |
3279 | 3274 | * Transclude an interwiki link. |
| 3275 | + * TODO: separate in interwikiTranscludeFromDB & interwikiTranscludeFromAPI according to the iw type |
3280 | 3276 | */ |
3281 | 3277 | function interwikiTransclude( $title, $action ) { |
| 3278 | + |
3282 | 3279 | global $wgEnableScaryTranscluding; |
3283 | 3280 | |
3284 | 3281 | if ( !$wgEnableScaryTranscluding ) { |
3285 | 3282 | return wfMsg('scarytranscludedisabled'); |
3286 | 3283 | } |
3287 | 3284 | |
3288 | | - $url = $title->getFullUrl( "action=$action" ); |
| 3285 | + $url1 = $title->getTransAPI( )."?action=query&prop=revisions&titles=$titles&rvprop=content&format=json"; |
3289 | 3286 | |
3290 | | - if ( strlen( $url ) > 255 ) { |
| 3287 | + if ( strlen( $url1 ) > 255 ) { |
3291 | 3288 | return wfMsg( 'scarytranscludetoolong' ); |
3292 | 3289 | } |
3293 | | - return $this->fetchScaryTemplateMaybeFromCache( $url ); |
| 3290 | + |
| 3291 | + $text = $this->fetchTemplateMaybeFromCache( $url1 ); |
| 3292 | + |
| 3293 | + $titles = $title->getNsText().':'.$title->getText(); |
| 3294 | + $url2 = $title->getTransAPI( )."?action=parse&text={{".$titles."}}&prop=templates&format=json"; |
| 3295 | + |
| 3296 | + $get = Http::get( $url2 ); |
| 3297 | + $myArray = FormatJson::decode($get, true); |
| 3298 | + |
| 3299 | + if ( ! empty( $myArray['parse'] )) { |
| 3300 | + $templates = $myArray['parse']['templates']; |
| 3301 | + } |
| 3302 | + |
| 3303 | + |
| 3304 | + // TODO: The templates are retrieved one by one. |
| 3305 | + // We should split the templates in two groups: up-to-date and out-of-date |
| 3306 | + // Only the second group would be retrieved through the API or DB request |
| 3307 | + for ($i = 0 ; $i < count( $templates ) ; $i++) { |
| 3308 | + $newTitle = $templates[$i]['*']; |
| 3309 | + |
| 3310 | + $url = $title->getTransAPI( )."?action=query&prop=revisions&titles=$newTitle&rvprop=content&format=json"; |
| 3311 | + |
| 3312 | + $listSubTemplates.= $newTitle."\n"; |
| 3313 | + $list2.="<h2>".$newTitle."</h2>\n<pre>".$this->fetchTemplateMaybeFromCache( $url )."</pre>"; |
| 3314 | + |
| 3315 | + } |
| 3316 | + |
| 3317 | + return "<h2>$titles</h2><pre>$text</pre> List of templates: <pre>".$listSubTemplates.'</pre>' . $list2; |
3294 | 3318 | } |
| 3319 | + |
| 3320 | + |
| 3321 | + function fetchTemplateMaybeFromCache( $url ) { |
| 3322 | + global $wgTranscludeCacheExpiry; |
| 3323 | + $dbr = wfGetDB( DB_SLAVE ); |
| 3324 | + $tsCond = $dbr->timestamp( time() - $wgTranscludeCacheExpiry ); |
| 3325 | + $obj = $dbr->selectRow( 'transcache', array('tc_time', 'tc_contents' ), |
| 3326 | + array( 'tc_url' => $url, "tc_time >= " . $dbr->addQuotes( $tsCond ) ) ); |
3295 | 3327 | |
| 3328 | + if ( $obj ) { |
| 3329 | + return $obj->tc_contents; |
| 3330 | + } |
| 3331 | + |
| 3332 | + $get = Http::get( $url ); |
| 3333 | + |
| 3334 | + $content = FormatJson::decode( $get, true ); |
| 3335 | + |
| 3336 | + if ( ! empty($content['query']['pages']) ) { |
| 3337 | + |
| 3338 | + $page = array_pop( $content['query']['pages'] ); |
| 3339 | + $text = $page['revisions'][0]['*']; |
| 3340 | + |
| 3341 | + } else { |
| 3342 | + |
| 3343 | + return wfMsg( 'scarytranscludefailed', $url ); |
| 3344 | + |
| 3345 | + } |
| 3346 | + |
| 3347 | + $dbw = wfGetDB( DB_MASTER ); |
| 3348 | + $dbw->replace( 'transcache', array('tc_url'), array( |
| 3349 | + 'tc_url' => $url, |
| 3350 | + 'tc_time' => $dbw->timestamp( time() ), |
| 3351 | + 'tc_contents' => $text) |
| 3352 | + ); |
| 3353 | + |
| 3354 | + return $text; |
| 3355 | + } |
| 3356 | + |
3296 | 3357 | function fetchScaryTemplateMaybeFromCache( $url ) { |
3297 | 3358 | global $wgTranscludeCacheExpiry; |
3298 | 3359 | $dbr = wfGetDB( DB_SLAVE ); |
Index: branches/iwtransclusion/phase3/includes/Title.php |
— | — | @@ -513,7 +513,20 @@ |
514 | 514 | |
515 | 515 | return Interwiki::fetch( $this->mInterwiki )->isTranscludable(); |
516 | 516 | } |
| 517 | + |
| 518 | + /** |
| 519 | + * Returns the API URL of the distant wiki |
| 520 | + * which owns the object. |
| 521 | + * |
| 522 | + * @return \type{\string} the API URL |
| 523 | + */ |
| 524 | + public function getTransAPI() { |
| 525 | + if ( $this->mInterwiki == '' ) |
| 526 | + return false; |
517 | 527 | |
| 528 | + return Interwiki::fetch( $this->mInterwiki )->getAPI(); |
| 529 | + } |
| 530 | + |
518 | 531 | /** |
519 | 532 | * Escape a text fragment, say from a link, for a URL |
520 | 533 | * |