Index: trunk/extensions/WikimediaIncubator/IncubatorTest.php |
— | — | @@ -513,19 +513,20 @@ |
514 | 514 | } |
515 | 515 | |
516 | 516 | /** |
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. |
519 | 518 | * @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 |
523 | 520 | * @return String |
524 | 521 | */ |
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 | + ); |
530 | 531 | } |
531 | 532 | |
532 | 533 | /** |
— | — | @@ -543,7 +544,7 @@ |
544 | 545 | * @return True |
545 | 546 | */ |
546 | 547 | public static function onArticleFromTitle( &$title, &$article ) { |
547 | | - global $wgRequest; |
| 548 | + global $wgRequest, $wgOut; |
548 | 549 | $prefix = IncubatorTest::analyzePrefix( $title, true ); |
549 | 550 | if( $prefix['error'] || $wgRequest->getVal('goto') != 'mainpage' ) { |
550 | 551 | return true; |
— | — | @@ -553,20 +554,23 @@ |
554 | 555 | return true; |
555 | 556 | } |
556 | 557 | 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; |
568 | 561 | } |
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 | + } |
571 | 575 | return true; |
572 | 576 | } |
573 | 577 | |
— | — | @@ -598,9 +602,9 @@ |
599 | 603 | |
600 | 604 | /** |
601 | 605 | * 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 |
603 | 607 | * 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 |
605 | 609 | * @return Boolean |
606 | 610 | */ |
607 | 611 | static function fnTestWikiLogo( &$out ) { |
Index: trunk/extensions/WikimediaIncubator/InfoPage.php |
— | — | @@ -73,7 +73,7 @@ |
74 | 74 | $otherProjects = $wmincProjects + $wmincSisterProjects; |
75 | 75 | foreach( $otherProjects as $code => $name ) { |
76 | 76 | $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>'; |
78 | 78 | } |
79 | 79 | unset( $listOtherProjects[$this->mProjectCode] ); |
80 | 80 | return '<ul class="wminc-infopage-otherprojects">' . |
— | — | @@ -146,7 +146,7 @@ |
147 | 147 | ) |
148 | 148 | ); |
149 | 149 | } |
150 | | - $subdomain = IncubatorTest::getSubdomain( $this->mLangCode, $this->mProjectName ); |
| 150 | + $subdomain = IncubatorTest::getSubdomain( $this->mLangCode, $this->mProjectCode ); |
151 | 151 | $subdomainLink = $wgUser->getSkin()->makeExternalLink( $subdomain, $subdomain ); |
152 | 152 | $content = Html::rawElement( 'div', array( 'class' => 'wminc-infopage-status' ), |
153 | 153 | wfMsgWikiHtml( 'wminc-infopage-status-' . $this->mSubStatus, $subdomainLink ) ); |
— | — | @@ -162,7 +162,7 @@ |
163 | 163 | global $wgLang, $wgUser; |
164 | 164 | $created = isset( $this->mCreated ) ? $this->mCreated : ''; |
165 | 165 | $bug = isset( $this->mBug ) ? $this->mBug : ''; |
166 | | - $subdomain = IncubatorTest::getSubdomain( $this->mLangCode, $this->mProjectName ); |
| 166 | + $subdomain = IncubatorTest::getSubdomain( $this->mLangCode, $this->mProjectCode ); |
167 | 167 | $subdomainLink = $wgUser->getSkin()->makeExternalLink( $subdomain, $subdomain ); |
168 | 168 | if( $this->mThisLangData['type'] != 'invalid' ) { |
169 | 169 | $gotoSubdomain = Html::rawElement( 'span', |