r94434 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94433‎ | r94434 | r94435 >
Date:21:41, 13 August 2011
Author:robin
Status:ok (Comments)
Tags:
Comment:
* Better support for sister projects (wikiversity / wikisource): direct users to the respective sites
* Set the title on info pages to a descriptive "Wikiproject Language" instead of "Wx/xyz"
* Properly make the URLs of the logos
Modified paths:
  • /trunk/extensions/WikimediaIncubator/IncubatorTest.php (modified) (history)
  • /trunk/extensions/WikimediaIncubator/InfoPage.i18n.php (modified) (history)
  • /trunk/extensions/WikimediaIncubator/InfoPage.php (modified) (history)
  • /trunk/extensions/WikimediaIncubator/WikimediaIncubator.i18n.php (modified) (history)
  • /trunk/extensions/WikimediaIncubator/WikimediaIncubator.php (modified) (history)

Diff [purge]

Index: trunk/extensions/WikimediaIncubator/WikimediaIncubator.php
@@ -14,7 +14,7 @@
1515 'path' => __FILE__,
1616 'name' => 'Wikimedia Incubator',
1717 'author' => 'SPQRobin',
18 - 'version' => '4.0',
 18+ 'version' => '4.1',
1919 'url' => 'http://www.mediawiki.org/wiki/Extension:WikimediaIncubator',
2020 'descriptionmsg' => 'wminc-desc',
2121 );
@@ -119,9 +119,8 @@
120120 's' => 'wikisource',
121121 'v' => 'wikiversity',
122122 );
123 -# if WMF/SiteMatrix config is available, use it
124 -# NOTICE: include SiteMatrix extension before this extension (this is the case for WMF)
125 -$wmincClosedWikis = isset( $wgSiteMatrixClosedSites ) ? $wgSiteMatrixClosedSites : null;
 123+# set this to an array or file of closed wikis (like SiteMatrix $wgSiteMatrixClosedSites)
 124+$wmincClosedWikis = false;
126125
127126 /* Wx/xx[x] info page */
128127 $wgAutoloadClasses['InfoPage'] = $dir . 'InfoPage.php';
Index: trunk/extensions/WikimediaIncubator/IncubatorTest.php
@@ -93,10 +93,12 @@
9494 * @param $title String The given title (often $wgTitle->getText() )
9595 * @param $onlyInfoPage Bool Whether to validate only the prefix, or
9696 * also allow other text within the page title (Wx/xxx vs Wx/xxx/Text)
 97+ * @param $allowSister Bool Whether to allow sister projects when checking
 98+ * for the project code.
9799 * @return Array with 'error' or 'project', 'lang', 'prefix' and
98100 * optionally 'realtitle'
99101 */
100 - static function analyzePrefix( $title, $onlyInfoPage = false ) {
 102+ static function analyzePrefix( $title, $onlyInfoPage = false, $allowSister = false ) {
101103 $data = array( 'error' => null );
102104 # split title into parts
103105 $titleparts = explode( '/', $title );
@@ -111,8 +113,12 @@
112114 $data['error'] = 'invalidlangcode';
113115 }
114116 }
115 - global $wmincProjects;
116 - $listProjects = implode( '', array_keys( $wmincProjects ) ); # something like: pbtqn
 117+ global $wmincProjects, $wmincSisterProjects;
 118+ $listProjects = implode( '', array_keys( $wmincProjects ) ); # project codes like: pbtqn
 119+ if( $allowSister && is_array( $wmincSisterProjects ) ) {
 120+ # join the project codes with those of the sister projects, like: pbtqnsv
 121+ $listProjects = $listProjects . implode( '', array_keys( $wmincSisterProjects ) );
 122+ }
117123 if( !preg_match( '/^W['.$listProjects.']\/[a-z-]+' .
118124 ($onlyInfoPage ? '$/' : '(\/.+)?$/' ), $title ) ) {
119125 $data['error'] = 'invalidprefix';
@@ -157,13 +163,16 @@
158164 }
159165
160166 /**
161 - * Whether the given project (or preference by default) is one of the
162 - * projects using the format Wx/xxx (as defined in $wmincProjects)
163 - * @param $project the project code
164 - * @return Boolean
 167+ * Returns the project code or name if the given project code or name (or preference by default)
 168+ * is one of the projects using the format Wx/xxx (as defined in $wmincProjects)
 169+ * Returns false if it is not valid.
 170+ * @param $project String The project code
 171+ * @param $returnName Bool Whether to return the project name instead of the code
 172+ * @param $includeSister Bool Whether to include sister projects
 173+ * @return String or false
165174 */
166 - static function isContentProject( $project = '' ) {
167 - global $wgUser, $wmincPref, $wmincProjects;
 175+ static function getProject( $project = '', $returnName = false, $includeSister = false ) {
 176+ global $wgUser, $wmincPref, $wmincProjects, $wmincSisterProjects;
168177 $url = self::getUrlParam();
169178 if( $project ) {
170179 $r = $project; # Precedence to given value
@@ -172,10 +181,27 @@
173182 } else {
174183 $r = $wgUser->getOption( $wmincPref . '-project' ); # Defaults to preference
175184 }
176 - return (bool) array_key_exists( $r, $wmincProjects );
 185+ $projects = $includeSister ? array_merge( $wmincProjects, $wmincSisterProjects ) : $wmincProjects;
 186+ if( array_key_exists( $r, $projects ) ) {
 187+ # If a code is given, return what is wanted
 188+ return $returnName ? $projects[$r] : $r;
 189+ } elseif( array_search( $r, $projects ) ) {
 190+ # If a name is given, return what is wanted
 191+ return $returnName ? $r : array_search( $r, $projects );
 192+ }
 193+ # Unknown code or name given -> false
 194+ return false;
177195 }
178196
179197 /**
 198+ * Returns a simple boolean based on getProject()
 199+ * @return Bool
 200+ */
 201+ static function isContentProject( $project = '', $returnName = false, $includeSister = false ) {
 202+ return (bool) self::getProject( $project, $returnName, $includeSister );
 203+ }
 204+
 205+ /**
180206 * display the prefix by the given project and code
181207 * (or the URL &testwiki= or user preference if no parameters are given)
182208 * @return String
@@ -398,7 +424,7 @@
399425 */
400426 static function getDBClosedWikis() {
401427 global $wmincClosedWikis;
402 - if( !self::canWeCheckDB() ) {
 428+ if( !self::canWeCheckDB() || !$wmincClosedWikis ) {
403429 return false;
404430 }
405431 # Is probably a file, but it might be that an array is given
@@ -415,10 +441,11 @@
416442 if( !$db ) {
417443 return false;
418444 }
419 - global $wmincExistingWikis, $wmincClosedWikis;
 445+ global $wmincExistingWikis;
 446+ $closed = self::getDBClosedWikis();
420447 if( !in_array( $db, $wmincExistingWikis ) ) {
421448 return 'missing'; # not in the list
422 - } elseif( in_array( $db, self::getDBClosedWikis() ) ) {
 449+ } elseif( is_array( $closed ) && in_array( $db, $closed ) ) {
423450 return 'closed'; # in the list of closed wikis
424451 }
425452 return 'existing';
@@ -433,26 +460,35 @@
434461 static function onShowMissingArticle( $article ) {
435462 global $wgOut;
436463 $title = $article->getTitle();
437 - $prefix = self::analyzePrefix( $title->getText(), true /* only info pages */ );
 464+ $prefix = self::analyzePrefix( $title->getText(),
 465+ true /* only info pages */, true /* allow sister projects */ );
438466
439467 if( $prefix['error'] ) { # We are not on info pages
440 - $prefix2 = self::analyzePrefix( $title->getText() );
 468+ global $wmincSisterProjects;
 469+ $prefix2 = self::analyzePrefix( $title->getText(), false, true );
 470+ $linker = class_exists( 'DummyLinker' ) ? new DummyLinker : new Linker;
 471+ $p = $prefix2['project'];
 472+ $link = self::getSubdomain( $prefix2['lang'], $p,
 473+ ( $title->getNsText() ? $title->getNsText() . ':' : '' ) .
 474+ $prefix2['realtitle'] );
441475 if( self::getDBState( $prefix2 ) == 'existing' ) {
442 - $link = self::getSubdomain( $prefix2['lang'],
443 - $prefix2['project'], ( $title->getNsText() ? $title->getNsText() . ':' : '' ) .
444 - $prefix2['realtitle'] );
445476 if( self::displayPrefix() == $prefix2['prefix'] ) {
446477 # Redirect to the existing wiki if the user has this wiki as preference
447478 $wgOut->redirect( $link );
448479 return true;
449480 } else {
450481 # Show a link to the existing wiki
451 - $linker = class_exists( 'DummyLinker' ) ? new DummyLinker : new Linker;
452482 $showLink = $linker->makeExternalLink( $link, $link );
453483 $wgOut->addHtml( '<div class="wminc-wiki-exists">' .
454484 wfMsgHtml( 'wminc-error-wiki-exists', $showLink ) .
455485 '</div>' );
456486 }
 487+ } elseif( array_key_exists( $p, $wmincSisterProjects ) ) {
 488+ # A sister project is not hosted here, so direct the user to the relevant wiki
 489+ $showLink = $linker->makeExternalLink( $link, $link );
 490+ $wgOut->addHtml( '<div class="wminc-wiki-sister">' .
 491+ wfMsgHtml( 'wminc-error-wiki-sister', $showLink ) .
 492+ '</div>' );
457493 } elseif ( self::shouldWeShowUnprefixedError( $title ) ) {
458494 # Unprefixed pages
459495 if( self::isContentProject() ) {
@@ -488,6 +524,8 @@
489525 } else {
490526 $wgOut->addHtml( $infopage->showMissingWiki() );
491527 }
 528+ # Set the page title from "Wx/xyz - Incubator" to "Wikiproject Language - Incubator"
 529+ $wgOut->setHTMLTitle( wfMsg( 'pagetitle', htmlspecialchars( $infopage->mFormatTitle ) ) );
492530 return true;
493531 }
494532
@@ -514,19 +552,20 @@
515553
516554 /**
517555 * This forms a URL based on the language and project.
518 - * @param $lang Language code
519 - * @param $project Project code
 556+ * @param $lang String Language code
 557+ * @param $project String Project code
 558+ * @param $title String Page name
520559 * @return String
521560 */
522 - public static function getSubdomain( $lang, $projectCode ) {
523 - global $wgConf, $wmincProjectDatabases;
 561+ public static function getSubdomain( $lang, $projectCode, $title = '' ) {
 562+ global $wgConf, $wmincProjectDatabases, $wgArticlePath;
524563 $projectName = strtolower( $wmincProjectDatabases[$projectCode] );
525564 # Imitate analyzePrefix() array :p
526565 $prefix = array( 'error' => null, 'lang' => $lang, 'project' => $projectCode );
527566 return $wgConf->get( 'wgServer',
528567 self::getDB( $prefix ), $projectName,
529568 array( 'lang' => str_replace( '_', '-', $lang ), 'site' => $projectName )
530 - );
 569+ ) . ( $title ? preg_replace( '/\$1/', $title, $wgArticlePath ) : '' );
531570 }
532571
533572 /**
@@ -638,7 +677,6 @@
639678 /**
640679 * Make the page content language depend on the test wiki
641680 * Only works for codes that are known to MediaWiki :(
642 - * @return true
643681 */
644682 static function onPageContentLanguage( $title, &$pageLang ) {
645683 global $wmincTestWikiNamespaces, $wgOut;
Index: trunk/extensions/WikimediaIncubator/InfoPage.i18n.php
@@ -31,6 +31,7 @@
3232 'wminc-infopage-missingwiki-text' => 'A $1 in this language does not yet exist.',
3333 'wminc-infopage-option-startwiki' => 'If you want to start this wiki,
3434 you can [{{fullurl:{{FULLPAGENAME}}|action=edit}} create the page] and follow [[{{MediaWiki:Wminc-manual-url}}|our manual]].',
 35+ 'wminc-infopage-option-startsister' => 'If you want to start this wiki, you can go to <b>[$2 $1]</b>.',
3536 'wminc-infopage-option-languages-existing' => 'You can search for [http://www.$1.org existing language editions of $1].',
3637 'wminc-infopage-option-sisterprojects-existing' => 'You can search for existing projects in this language:',
3738 'wminc-infopage-option-sisterprojects-other' => 'You can search for other projects in this language:',
@@ -44,6 +45,7 @@
4546 'wminc-infopage-contribute' => 'If you know this language, you are encouraged to contribute!',
4647
4748 'wminc-infopage-status-imported' => 'This Incubator wiki has been imported from $1 after the wiki was closed.',
 49+ 'wminc-infopage-status-closedsister' => 'This subdomain was closed. Go to <b>$2</b> to contribute to this wiki.',
4850 'wminc-infopage-status-created' => 'This project has been approved by the language committee and is now available at $1.',
4951 'wminc-infopage-status-beforeincubator' => 'This project was created before Wikimedia Incubator started and is available at $1.',
5052 );
Index: trunk/extensions/WikimediaIncubator/InfoPage.php
@@ -20,22 +20,26 @@
2121
2222 class InfoPage {
2323 public function __construct( $title, $prefixdata ) {
24 - global $wmincProjects;
 24+ global $wmincProjects, $wmincSisterProjects;
2525 $this->mTitle = $title;
2626 $this->mPrefix = $prefixdata['prefix'];
2727 $this->mLangCode = $prefixdata['lang'];
2828 $this->mProjectCode = $prefixdata['project'];
29 - $this->mProjectName = isset( $wmincProjects[$this->mProjectCode] ) ?
30 - $wmincProjects[$this->mProjectCode] : '';
 29+ $allProjects = array_merge( $wmincProjects, $wmincSisterProjects );
 30+ $this->mProjectName = isset( $allProjects[$this->mProjectCode] ) ?
 31+ $allProjects[$this->mProjectCode] : '';
3132 if( isset( $prefixdata['error'] ) || $title->getNamespace() != NS_MAIN ) {
3233 return;
3334 }
 35+ $this->mPortal = IncubatorTest::getSubdomain( 'www', $this->mProjectCode );
 36+ $this->mIsSister = array_key_exists( $this->mProjectCode, $wmincSisterProjects );
3437 $this->mDBStatus = '';
3538 $this->mSubStatus = '';
3639 $this->mThisLangData = array( 'type' => 'valid' ); # For later code check feature
3740 $this->mLangNames = IncubatorTest::getLanguageNames();
3841 $this->mLangName = ( isset( $this->mLangNames[$this->mLangCode] ) ?
3942 $this->mLangNames[$this->mLangCode] : wfMsg( 'wminc-unknownlang', $this->mLangCode ) );
 43+ $this->mFormatTitle = wfMsg( 'wminc-infopage-title', $this->mProjectName, $this->mLangName );
4044 return;
4145 }
4246
@@ -47,7 +51,7 @@
4852 global $wgUser;
4953 $projectForFile = preg_replace('/ /', '-', strtolower( $project ) );
5054 $imageobj = wfFindFile( wfMsg( 'wminc-logo-' . $projectForFile ) );
51 - $useUrl = $url ? $url : 'http://www.'.strtolower( $project ).'.org/';
 55+ $useUrl = $url ? $url : IncubatorTest::getSubdomain( 'www', IncubatorTest::getProject( $project, false, true ) );
5256 if ( !$imageobj ) { # image not found
5357 if( !$clickable ) {
5458 return $logo;
@@ -106,8 +110,7 @@
107111 $this->makeLogo( $this->mProjectName, true, 175 )
108112 ) .
109113 Html::rawElement( 'div', array( 'class' => 'wminc-infopage-title' ),
110 - wfMsg( 'wminc-infopage-title', $this->mProjectName, $this->mLangName ) .
111 - $aftertitle ) .
 114+ $this->mFormatTitle . $aftertitle ) .
112115 $content );
113116 }
114117
@@ -119,8 +122,8 @@
120123 ) .
121124 Html::rawElement( 'ul', array( 'class' => 'wminc-infopage-options' ),
122125 Html::rawElement( 'li', null,
123 - wfMsgExt( 'wminc-infopage-option-startwiki',
124 - array( 'parseinline' ), $this->mProjectName ) ) .
 126+ wfMsgExt( 'wminc-infopage-option-' . ( $this->mIsSister ? 'startsister' : 'startwiki' ),
 127+ array( 'parseinline' ), $this->mProjectName, $this->mPortal ) ) .
125128 Html::rawElement( 'li', null,
126129 wfMsgExt( 'wminc-infopage-option-languages-existing',
127130 array( 'parseinline' ), $this->mProjectName ) ) .
@@ -135,21 +138,24 @@
136139 }
137140
138141 public function showIncubatingWiki() {
139 - global $wgUser;
140 - $bug = isset( $this->mBug ) ? $this->mBug : '';
 142+ global $wgUser, $wgLang;
 143+ $substatus = $this->mSubStatus;
 144+ if( $substatus == 'imported' && $this->mIsSister ) {
 145+ $substatus = 'closedsister';
 146+ }
 147+ $portalLink = $wgUser->getSkin()->makeExternalLink( $this->mPortal, $this->mProjectName );
141148 if( $this->mThisLangData['type'] != 'invalid' ) {
 149+ $gotoLink = $wgUser->getSkin()->link(
 150+ Title::newFromText( IncubatorTest::getMainPage( $this->mLangCode, $this->mPrefix ) ),
 151+ wfMsgNoTrans( 'wminc-infopage-enter' ) );
142152 $gotoMainPage = Html::rawElement( 'span',
143153 array( 'class' => 'wminc-infopage-entertest' ),
144 - '→ ' . $wgUser->getSkin()->link(
145 - Title::newFromText( IncubatorTest::getMainPage( $this->mLangCode, $this->mPrefix ) ),
146 - wfMsgNoTrans( 'wminc-infopage-enter' )
147 - )
148 - );
 154+ $wgLang->getArrow() . ' ' . ( $this->mIsSister ? $portalLink : $gotoLink ) );
149155 }
150156 $subdomain = IncubatorTest::getSubdomain( $this->mLangCode, $this->mProjectCode );
151157 $subdomainLink = $wgUser->getSkin()->makeExternalLink( $subdomain, $subdomain );
152158 $content = Html::rawElement( 'div', array( 'class' => 'wminc-infopage-status' ),
153 - wfMsgWikiHtml( 'wminc-infopage-status-' . $this->mSubStatus, $subdomainLink ) );
 159+ wfMsgWikiHtml( 'wminc-infopage-status-' . $substatus, $subdomainLink, $portalLink ) );
154160 if( $this->mSubStatus != 'approved' && $this->mThisLangData['type'] != 'invalid' ) {
155161 $content .= Html::element( 'div',
156162 array( 'class' => 'wminc-infopage-contribute' ),
Index: trunk/extensions/WikimediaIncubator/WikimediaIncubator.i18n.php
@@ -31,6 +31,7 @@
3232 'wminc-error-unprefixed' => "'''Error:''' This page is [[{{MediaWiki:Helppage}}|unprefixed]]!",
3333 'wminc-error-unprefixed-suggest' => "'''Error:''' This page is [[{{MediaWiki:Helppage}}|unprefixed]]! You can create a page at [[:$1]].",
3434 'wminc-error-wiki-exists' => 'This wiki already exists. You can find this page on $1. If the wiki was recently created, please wait a few hours or days until all content is imported.',
 35+ 'wminc-error-wiki-sister' => 'This page belongs to a project that is not hosted here. Please go to $1 to find the wiki.',
3536
3637 # Special:RandomByTest
3738 'randombytest' => 'Random page by test wiki',

Follow-up revisions

RevisionCommit summaryAuthorDate
r94452Followup r94434:...robin12:31, 14 August 2011

Comments

#Comment by Catrope (talk | contribs)   10:13, 14 August 2011
+		) . ( $title ? preg_replace( '/\$1/', $title, $wgArticlePath ) : '' );

You can use str_replace( '$1', $title, $wgArticlePath ) here too, you don't need a regex.

+				wfMsgExt( 'wminc-infopage-option-' . ( $this->mIsSister ? 'startsister' : 'startwiki' ),

When you do stuff like this (dynamic message keys), please add a comment listing the literal message keys (wminc-infopage-option-startsister and wminc-infopage-option-startwiki in this case) so those keys can still be grepped easily.

OK otherwise, marking OK.

#Comment by SPQRobin (talk | contribs)   12:33, 14 August 2011

Done in r94452.

Status & tagging log