r94378 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94377‎ | r94378 | r94379 >
Date:20:15, 12 August 2011
Author:robin
Status:ok
Tags:
Comment:
* Make use of $wgConf to form the URLs
* Only redirect to the main page if that page exists
Modified paths:
  • /trunk/extensions/WikimediaIncubator/IncubatorTest.php (modified) (history)
  • /trunk/extensions/WikimediaIncubator/InfoPage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/WikimediaIncubator/IncubatorTest.php
@@ -513,19 +513,20 @@
514514 }
515515
516516 /**
517 - * This forms a URL based on the language and project, and optionally title.
518 - * TODO: add support for secure server, or are links automatically converted?
 517+ * This forms a URL based on the language and project.
519518 * @param $lang Language code
520 - * @param $project Project code (or project name)
521 - * @param $title Optional title on the target wiki
522 - * @param $protocol Whether to include the protocol
 519+ * @param $project Project code
523520 * @return String
524521 */
525 - public static function getSubdomain( $lang, $project, $title = '', $protocol = true ) {
526 - global $wmincProjects;
527 - $projectName = isset( $wmincProjects[$project] ) ? $wmincProjects[$project] : $project;
528 - return ( $protocol ? 'http://' : '' ) . strtolower( $lang ) . '.' .
529 - strtolower( $projectName ) . '.org' . ( $title ? '/wiki/' . $title : '' );
 522+ public static function getSubdomain( $lang, $projectCode ) {
 523+ global $wgConf, $wmincProjectDatabases;
 524+ $projectName = strtolower( $wmincProjectDatabases[$projectCode] );
 525+ # Imitate analyzePrefix() array :p
 526+ $prefix = array( 'error' => null, 'lang' => $lang, 'project' => $projectCode );
 527+ return $wgConf->get( 'wgServer',
 528+ self::getDB( $prefix ), $projectName,
 529+ array( 'lang' => str_replace( '_', '-', $lang ), 'site' => $projectName )
 530+ );
530531 }
531532
532533 /**
@@ -543,7 +544,7 @@
544545 * @return True
545546 */
546547 public static function onArticleFromTitle( &$title, &$article ) {
547 - global $wgRequest;
 548+ global $wgRequest, $wgOut;
548549 $prefix = IncubatorTest::analyzePrefix( $title, true );
549550 if( $prefix['error'] || $wgRequest->getVal('goto') != 'mainpage' ) {
550551 return true;
@@ -553,20 +554,23 @@
554555 return true;
555556 }
556557 if( $dbstate == 'existing' ) {
557 - $url = self::getSubdomain( $prefix['lang'], $prefix['project'] );
558 - } else {
559 - $params['redirectfrom'] = 'infopage';
560 - $uselang = $wgRequest->getVal( 'uselang' );
561 - if( $uselang ) {
562 - $params['uselang'] = $uselang;
563 - }
564 - $mainpage = Title::newFromText(
565 - self::getMainPage( $prefix['lang'], $prefix['prefix'] )
566 - );
567 - $url = $mainpage->getFullURL( $params );
 558+ # redirect to the existing lang.wikiproject.org if it exists
 559+ $wgOut->redirect( self::getSubdomain( $prefix['lang'], $prefix['project'] ) );
 560+ return true;
568561 }
569 - global $wgOut;
570 - $wgOut->redirect( $url );
 562+ $params['redirectfrom'] = 'infopage';
 563+ $uselang = $wgRequest->getVal( 'uselang' );
 564+ if( $uselang ) {
 565+ # pass through the &uselang parameter
 566+ $params['uselang'] = $uselang;
 567+ }
 568+ $mainpage = Title::newFromText(
 569+ self::getMainPage( $prefix['lang'], $prefix['prefix'] )
 570+ );
 571+ if( $mainpage->exists() ) {
 572+ # Only redirect to the main page if that page exists
 573+ $wgOut->redirect( $mainpage->getFullURL( $params ) );
 574+ }
571575 return true;
572576 }
573577
@@ -598,9 +602,9 @@
599603
600604 /**
601605 * Display a different logo in current test wiki
602 - * if it is set in MediaWiki:Incubator-logo-wx/xxx
 606+ * if it is set in MediaWiki:Incubator-logo-wx-xxx
603607 * and if accessed through &testwiki=wx/xxx
604 - * or it the user preference is set to wx/xxx
 608+ * or if the user preference is set to wx/xxx
605609 * @return Boolean
606610 */
607611 static function fnTestWikiLogo( &$out ) {
Index: trunk/extensions/WikimediaIncubator/InfoPage.php
@@ -73,7 +73,7 @@
7474 $otherProjects = $wmincProjects + $wmincSisterProjects;
7575 foreach( $otherProjects as $code => $name ) {
7676 $listOtherProjects[$code] = '<li>' . $this->makeLogo( $name, true,
77 - 75, null, IncubatorTest::getSubdomain( $this->mLangCode, $name ) ) . '</li>';
 77+ 75, null, IncubatorTest::getSubdomain( $this->mLangCode, $code ) ) . '</li>';
7878 }
7979 unset( $listOtherProjects[$this->mProjectCode] );
8080 return '<ul class="wminc-infopage-otherprojects">' .
@@ -146,7 +146,7 @@
147147 )
148148 );
149149 }
150 - $subdomain = IncubatorTest::getSubdomain( $this->mLangCode, $this->mProjectName );
 150+ $subdomain = IncubatorTest::getSubdomain( $this->mLangCode, $this->mProjectCode );
151151 $subdomainLink = $wgUser->getSkin()->makeExternalLink( $subdomain, $subdomain );
152152 $content = Html::rawElement( 'div', array( 'class' => 'wminc-infopage-status' ),
153153 wfMsgWikiHtml( 'wminc-infopage-status-' . $this->mSubStatus, $subdomainLink ) );
@@ -162,7 +162,7 @@
163163 global $wgLang, $wgUser;
164164 $created = isset( $this->mCreated ) ? $this->mCreated : '';
165165 $bug = isset( $this->mBug ) ? $this->mBug : '';
166 - $subdomain = IncubatorTest::getSubdomain( $this->mLangCode, $this->mProjectName );
 166+ $subdomain = IncubatorTest::getSubdomain( $this->mLangCode, $this->mProjectCode );
167167 $subdomainLink = $wgUser->getSkin()->makeExternalLink( $subdomain, $subdomain );
168168 if( $this->mThisLangData['type'] != 'invalid' ) {
169169 $gotoSubdomain = Html::rawElement( 'span',

Status & tagging log