r86526 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86525‎ | r86526 | r86527 >
Date:19:01, 20 April 2011
Author:nikola
Status:deferred
Tags:
Comment:
Fixes related to use of ParserOutput
Modified paths:
  • /trunk/extensions/Interlanguage/InterlanguageExtension.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Interlanguage/InterlanguageExtension.php
@@ -206,7 +206,8 @@
207207 * Copies interlanguage pages from ParserOutput to OutputPage.
208208 */
209209 function onOutputPageParserOutput( &$out, $parserOutput ) {
210 - $out->interlanguage_pages = $this->getPageLinks( $parserOutput );
 210+ $pagelinks = $this->getPageLinks( $parserOutput );
 211+ if( $pagelinks ) $out->interlanguage_pages = $pagelinks;
211212 return true;
212213 }
213214
@@ -216,7 +217,15 @@
217218 * @param $editPage - standard EditPage object.
218219 */
219220 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 );
221230
222231 if( count( $pagelinktitles ) ) {
223232 $linker = new Linker();
@@ -281,7 +290,9 @@
282291 * @param $editPage - standard EditPage object.
283292 */
284293 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 );
286297
287298 foreach( $pagelinktitles as $title ) {
288299 $template->data['language_urls'][] = array(
@@ -298,33 +309,16 @@
299310 }
300311
301312 /**
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.
304314 *
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.
308317 */
309 - function getPageLinkTitles( $articleid = null, $parserOutput = null ) {
 318+ function makePageLinkTitles( $pagelinks ) {
310319 global $wgInterlanguageExtensionInterwiki;
311320
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 -
327321 $pagelinktitles = array();
328 - if( count( $pagelinks ) ) {
 322+ if( is_array( $pagelinks ) ) {
329323 foreach( $pagelinks as $page => $dummy ) {
330324 $title = Title::newFromText( $wgInterlanguageExtensionInterwiki . $this->translateNamespace( $page ) );
331325 if( $title ) {

Status & tagging log