r101388 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101387‎ | r101388 | r101389 >
Date:19:26, 31 October 2011
Author:preilly
Status:resolved (Comments)
Tags:
Comment:
fix main page interwiki links
Modified paths:
  • /trunk/extensions/MobileFrontend/MobileFrontend.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MobileFrontend/MobileFrontend.php
@@ -344,31 +344,30 @@
345345 'lang' => $wgLanguageCode,
346346 );
347347
348 - foreach( $wgOut->getLanguageLinks() as $l ) {
349 - if ( preg_match( '!^(\w[-\w]*\w):(.+)$!', $l, $m ) ) {
350 - $lang = $m[1];
351 - $linkText = $m[2];
352 - } else {
353 - continue; //NOTE: shouldn't happen
354 - }
355 -
 348+ foreach( $wgOut->getLanguageLinks() as $l ) {
 349+ $tmp = explode( ':', $l, 2 );
 350+ $class = 'interwiki-' . $tmp[0];
 351+ $lang = $tmp[0];
 352+ unset( $tmp );
356353 $nt = Title::newFromText( $l );
357 - $parsedUrl = wfParseUrl( $nt->getFullURL() );
358 - if ( stristr( $parsedUrl['host'], $wgMobileDomain ) === false ) {
359 - $hostParts = explode( '.', $parsedUrl['host'] );
360 - $parsedUrl['host'] = $hostParts[0] . $wgMobileDomain . $hostParts[1] . '.' . $hostParts[2];
361 - }
362 - $fragmentDelimiter = ( !empty( $parsedUrl['fragment'] ) ) ? '#' : '';
363 - $queryDelimiter = ( !empty( $parsedUrl['query'] ) ) ? '?' : '';
364 - $languageUrl = $parsedUrl['scheme'] . $parsedUrl['delimiter'] . $parsedUrl['host'] . $parsedUrl['path'] . $queryDelimiter . $parsedUrl['query'] . $fragmentDelimiter . $parsedUrl['fragment'];
 354+ if ( $nt ) {
 355+ $parsedUrl = wfParseUrl( $nt->getFullURL() );
 356+ if ( stristr( $parsedUrl['host'], $wgMobileDomain ) === false ) {
 357+ $hostParts = explode( '.', $parsedUrl['host'] );
 358+ $parsedUrl['host'] = $hostParts[0] . $wgMobileDomain . $hostParts[1] . '.' . $hostParts[2];
 359+ }
 360+ $fragmentDelimiter = ( !empty( $parsedUrl['fragment'] ) ) ? '#' : '';
 361+ $queryDelimiter = ( !empty( $parsedUrl['query'] ) ) ? '?' : '';
 362+ $languageUrl = $parsedUrl['scheme'] . $parsedUrl['delimiter'] . $parsedUrl['host'] . $parsedUrl['path'] . $queryDelimiter . $parsedUrl['query'] . $fragmentDelimiter . $parsedUrl['fragment'];
365363
366 - $languageUrls[] = array(
367 - 'href' => $languageUrl,
368 - 'text' => $linkText,
369 - 'language' => $wgContLang->getLanguageName( $lang ),
370 - 'class' => 'interwiki-' . $lang,
371 - 'lang' => $lang,
372 - );
 364+ $languageUrls[] = array(
 365+ 'href' => $languageUrl,
 366+ 'text' => ( $wgContLang->getLanguageName( $nt->getInterwiki() ) != '' ? $wgContLang->getLanguageName( $nt->getInterwiki() ) : $l ),
 367+ 'language' => $wgContLang->getLanguageName( $lang ),
 368+ 'class' => $class,
 369+ 'lang' => $lang,
 370+ );
 371+ }
373372 }
374373
375374 self::$languageUrls = $languageUrls;

Follow-up revisions

RevisionCommit summaryAuthorDate
r101389mft r101388preilly19:27, 31 October 2011

Comments

#Comment by 😂 (talk | contribs)   19:28, 31 October 2011

Stop using empty() please.

#Comment by Preilly (talk | contribs)   19:46, 31 October 2011

This should now be fixed in r101392.

Status & tagging log