Index: trunk/extensions/Interlanguage/InterlanguageExtension.php |
— | — | @@ -206,7 +206,8 @@ |
207 | 207 | * Copies interlanguage pages from ParserOutput to OutputPage. |
208 | 208 | */ |
209 | 209 | function onOutputPageParserOutput( &$out, $parserOutput ) { |
210 | | - $out->interlanguage_pages = $this->getPageLinks( $parserOutput ); |
| 210 | + $pagelinks = $this->getPageLinks( $parserOutput ); |
| 211 | + if( $pagelinks ) $out->interlanguage_pages = $pagelinks; |
211 | 212 | return true; |
212 | 213 | } |
213 | 214 | |
— | — | @@ -216,7 +217,15 @@ |
217 | 218 | * @param $editPage - standard EditPage object. |
218 | 219 | */ |
219 | 220 | function pageLinks( $editPage ) { |
220 | | - $pagelinktitles = $this->getPageLinkTitles( $editPage->mArticle->mTitle->mArticleID, $editPage->mParserOutput ); |
| 221 | + if( isset( $editPage->mParserOutput ) ) { |
| 222 | + $pagelinks = $this->getPageLinks( $editPage->mParserOutput ); |
| 223 | + if(!$pagelinks) $pagelinks = array(); |
| 224 | + } else { |
| 225 | + // If there is no ParserOutput, it means the article was not parsed, and we should |
| 226 | + // load links from the DB. |
| 227 | + $pagelinks = $this->loadPageLinks( $editPage->mArticle->mTitle->mArticleID ); |
| 228 | + } |
| 229 | + $pagelinktitles = $this->makePageLinkTitles( $pagelinks ); |
221 | 230 | |
222 | 231 | if( count( $pagelinktitles ) ) { |
223 | 232 | $linker = new Linker(); |
— | — | @@ -281,7 +290,9 @@ |
282 | 291 | * @param $editPage - standard EditPage object. |
283 | 292 | */ |
284 | 293 | function onSkinTemplateOutputPageBeforeExec( &$skin, &$template ) { |
285 | | - $pagelinktitles = $this->getPageLinkTitles( $skin->mTitle->mArticleID ); |
| 294 | + global $wgOut; |
| 295 | + $pagelinks = isset( $wgOut->interlanguage_pages )? $wgOut->interlanguage_pages: array(); |
| 296 | + $pagelinktitles = $this->makePageLinkTitles( $pagelinks ); |
286 | 297 | |
287 | 298 | foreach( $pagelinktitles as $title ) { |
288 | 299 | $template->data['language_urls'][] = array( |
— | — | @@ -298,33 +309,16 @@ |
299 | 310 | } |
300 | 311 | |
301 | 312 | /** |
302 | | - * Returns an array of Titles of pages on the central wiki which are linked to from a page |
303 | | - * on this wiki by {{interlanguage:}} magic. |
| 313 | + * Make an array of Titles from the array of links. |
304 | 314 | * |
305 | | - * @param $articleid ID of the article whose links should be returned. |
306 | | - * @param $parserOutput A ParserOutput object. |
307 | | - * @returns The array. If there are no pages linked, an empty array is returned. |
| 315 | + * @param $pagelinks Array of page links. |
| 316 | + * @returns Array of Title objects. If there are no page links, an empty array is returned. |
308 | 317 | */ |
309 | | - function getPageLinkTitles( $articleid = null, $parserOutput = null ) { |
| 318 | + function makePageLinkTitles( $pagelinks ) { |
310 | 319 | global $wgInterlanguageExtensionInterwiki; |
311 | 320 | |
312 | | - if( $parserOutput === null) { |
313 | | - global $wgOut; |
314 | | - if( isset( $wgOut->interlanguage_pages ) ) { |
315 | | - $pagelinks = $wgOut->interlanguage_pages; |
316 | | - } else { |
317 | | - $pagelinks = false; |
318 | | - } |
319 | | - } else { |
320 | | - $pagelinks = $this->getPageLinks( $parserOutput ); |
321 | | - } |
322 | | - |
323 | | - if( ( $pagelinks === false || $pagelinks === null ) && $articleid ) { |
324 | | - $pagelinks = $this->loadPageLinks( $articleid ); |
325 | | - } |
326 | | - |
327 | 321 | $pagelinktitles = array(); |
328 | | - if( count( $pagelinks ) ) { |
| 322 | + if( is_array( $pagelinks ) ) { |
329 | 323 | foreach( $pagelinks as $page => $dummy ) { |
330 | 324 | $title = Title::newFromText( $wgInterlanguageExtensionInterwiki . $this->translateNamespace( $page ) ); |
331 | 325 | if( $title ) { |