From: <ro...@us...> - 2011-07-14 21:26:54
|
Revision: 19 http://wm-incubator.svn.sourceforge.net/wm-incubator/?rev=19&view=rev Author: robin-p Date: 2011-07-14 21:26:43 +0000 (Thu, 14 Jul 2011) Log Message: ----------- Basic support for databast list checking: when the wiki exists, the default template is shown accordingly. + further work Modified Paths: -------------- trunk/IncubatorLanguages.php trunk/IncubatorTest.php trunk/InfoPage.css trunk/InfoPage.i18n.php trunk/InfoPage.php trunk/WikimediaIncubator.php Modified: trunk/IncubatorLanguages.php =================================================================== --- trunk/IncubatorLanguages.php 2011-07-14 17:51:12 UTC (rev 18) +++ trunk/IncubatorLanguages.php 2011-07-14 21:26:43 UTC (rev 19) @@ -74,7 +74,7 @@ return $cachedData; } - $msg = wfMessage( strtolower( $wmincProjectSite['name'] . '-codes' ) )->inContentLanguage()->plain(); + $msg = wfMsgForContentNoTrans( strtolower( $wmincProjectSite['name'] . '-codes' ) ); $lines = preg_split( '#\n(?!s)#' , $msg ); if( !is_array( $lines ) ) { return array(); Modified: trunk/IncubatorTest.php =================================================================== --- trunk/IncubatorTest.php 2011-07-14 17:51:12 UTC (rev 18) +++ trunk/IncubatorTest.php 2011-07-14 21:26:43 UTC (rev 19) @@ -277,12 +277,60 @@ // ########### START DEVELOPMENT STUFF ############# /** + * Do we know the databases of the existing wikis? + * @return Boolean + */ + static function canWeCheckDB() { + global $wmincExistingWikis, $wmincProjectDatabases; + if( !is_array( $wmincProjectDatabases ) ) { + return false; # We don't know the database names of the projects + } elseif( !isset( $wmincExistingWikis ) || !is_array( $wmincExistingWikis ) ) { + return false; # No list of databases + } + return true; # Should work now + } + + /** + * Given an incubator testwiki prefix, get the database name of the + * corresponding wiki, whether it exists or not + * @param $prefix Array from IncubatorTest::analyzePrefix(); + * @return false or string + */ + static function getDB( $prefix ) { + if( !self::canWeCheckDB() ) { + return false; + } elseif( isset( $prefix['error'] ) ) { + return false; # shouldn't be, but you never know + } + global $wmincProjectDatabases; + return $prefix['lang'] . $wmincProjectDatabases[$prefix['project']]; + } + + /** + * @param $prefix Array from IncubatorTest::analyzePrefix(); + * @return false or string 'existing' 'closed' 'missing' + */ + static function getDBState( $prefix ) { + $db = self::getDB( $prefix ); + if( !$db ) { + return false; + } + global $wmincExistingWikis, $wmincClosedWikis; + if( !in_array( $db, $wmincExistingWikis ) ) { + return 'missing'; # not in the list + } elseif( is_array( $wmincClosedWikis ) && in_array( $db, $wmincClosedWikis ) ) { + return 'closed'; # in the list of closed wikis + } + return 'existing'; + } + + /** * Make the page content language depend on the test wiki * Only works for codes that are known to MediaWiki :( */ static function onPageContentLanguage( $title, &$pageLang ) { global $wmincTestWikiNamespaces; - $prefix = IncubatorTest::analyzePrefix( $title, + $prefix = self::analyzePrefix( $title, /* onlyInfoPage*/ false, /* noInfoPage */ true ); if( isset( $prefix['error'] ) || !in_array( $title->getNamespace(), $wmincTestWikiNamespaces ) ) { @@ -300,13 +348,18 @@ */ static function onShowMissingArticle( $article ) { $titleObject = $article->mTitle; - $prefix = IncubatorTest::analyzePrefix( $titleObject, true ); + $prefix = self::analyzePrefix( $titleObject, true ); if( isset( $prefix['error'] ) ) { return true; } $infopage = new InfoPage( $titleObject, $prefix ); global $wgOut; - $wgOut->addHtml( $infopage->showMissingWiki() ); + if( self::getDBState( $prefix ) == 'existing' ) { + $infopage->mStatus = 'beforeincubator'; + $wgOut->addHtml( $infopage->showExistingWiki() ); + } else { + $wgOut->addHtml( $infopage->showMissingWiki() ); + } return true; } Modified: trunk/InfoPage.css =================================================================== --- trunk/InfoPage.css 2011-07-14 17:51:12 UTC (rev 18) +++ trunk/InfoPage.css 2011-07-14 21:26:43 UTC (rev 19) @@ -16,11 +16,13 @@ } .wminc-infopage p { margin: .2em 0 .3em; } .wminc-infopage li { padding:.2em 0 .3em; } -.wminc-infopage-missingwiki-welcome { font-style: italic; } +.wminc-infopage-welcome { font-style: italic; } ul.wminc-infopage-otherprojects, ul.wminc-infopage-multilingualprojects { list-style: none; } .wminc-infopage-otherprojects li, .wminc-infopage-multilingualprojects li { display: inline; padding:.5em; } -.wminc-infopage-title { font-size:140%; padding:.3em 0; font-weight:bold; } +.wminc-infopage-title { font-size:145%; padding:.3em 0; font-weight:bold; } .wminc-infopage-text { font-size: 125%; } -.wminc-infopage-missingwiki-options { padding: .2em; } +.wminc-infopage-options { padding: .2em; } .wminc-infopage-logo { float: right; } .wminc-infopage-createmainpage { margin-left: .5em; font-weight: bold; } +.wminc-infopage-status { margin: 1em; } +#ca-nstab-main a { color: black; } \ No newline at end of file Modified: trunk/InfoPage.i18n.php =================================================================== --- trunk/InfoPage.i18n.php 2011-07-14 17:51:12 UTC (rev 18) +++ trunk/InfoPage.i18n.php 2011-07-14 21:26:43 UTC (rev 19) @@ -29,16 +29,24 @@ 'wminc-logo-mediawiki' => 'MediaWiki.svg', 'wminc-manual-url' => 'Help:Manual', # only translate if necessary 'wminc-infopage-title' => '$1 $2', # only translate if necessary - 'wminc-infopage-missingwiki-welcome' => 'Welcome to the Wikimedia Incubator, a project of the Wikimedia Foundation ([[{{MediaWiki:Aboutpage}}|About]])', + 'wminc-infopage-welcome' => 'Welcome to the Wikimedia Incubator, a project of the Wikimedia Foundation ([[{{MediaWiki:Aboutpage}}|About]])', + 'wminc-infopage-missingwiki-text' => 'A $1 in this language does not yet exist.', - 'wminc-infopage-missingwiki-options' => ' -* If you want to start this wiki, you can [{{fullurl:{{FULLPAGENAME}}|createmainpage=yes}} create the page] and follow [[{{MediaWiki:Wminc-manual-url}}|our manual]]. $3 -* You can search for [http://www.$1.org existing language editions of $1]. -* You can search for existing projects in this language: $4 -* You can go to a multilingual wiki: $5', + 'wminc-infopage-option-startwiki' => 'If you want to start this wiki, +you can [{{fullurl:{{FULLPAGENAME}}|createmainpage=yes}} create the page] and follow [[{{MediaWiki:Wminc-manual-url}}|our manual]].', + 'wminc-infopage-option-languages' => 'You can search for [http://www.$1.org existing language editions of $1].', + 'wminc-infopage-option-sisterprojects' => 'You can search for existing projects in this language:', + 'wminc-infopage-option-multilingual' => 'You can go to a multilingual wiki:', 'wminc-infopage-createmainpage' => 'Enter the word "Main Page" in this language:', 'wminc-infopage-prefill' => '{{#infopage:open}}', # need to improve this! 'wminc-infopage-contribute' => 'If you know this language, you are encouraged to contribute!', + + 'wminc-infopage-status-open' => 'This is a new Incubator wiki that is not yet verified by the language committee.', + 'wminc-infopage-status-eligible' => 'This Incubator wiki has been marked as eligible by the language committee.', + 'wminc-infopage-status-imported' => 'This Incubator wiki has been imported from xyz.wikiproject.org after that wiki was closed.', + 'wminc-infopage-status-approved' => 'This Incubator wiki has been approved by the language committee and will soon be created.', + 'wminc-infopage-status-created' => 'This project has been approved by the language committee and is now available at $1.', + 'wminc-infopage-status-beforeincubator' => 'This project was created before Wikimedia Incubator started and is available at $1.', ); /** German (Deutsch) Modified: trunk/InfoPage.php =================================================================== --- trunk/InfoPage.php 2011-07-14 17:51:12 UTC (rev 18) +++ trunk/InfoPage.php 2011-07-14 21:26:43 UTC (rev 19) @@ -7,7 +7,7 @@ 'eligible': This Incubator wiki has been marked as eligible by the language committee. 'imported': This Incubator wiki has been imported from xyz.wikiproject.org after that wiki was closed. 'approved': This Incubator wiki has been approved by the language committee and will soon be created. -'subdomain' showExistingWiki() +'existing' showExistingWiki() 'created': This project has been approved by the language committee and is now available at xyz.wikiproject.org. 'beforeincubator': This project was created before Wikimedia Incubator started and is available at xyz.wikiproject.org. */ @@ -17,16 +17,12 @@ if( isset( $prefixdata['error'] ) || $title->getNamespace() != NS_MAIN ) { return; } - global $wgRequest, $wmincScriptDir, $wmincProjects; + global $wmincProjects; $this->mPrefix = $prefixdata['prefix']; $this->mLangCode = $prefixdata['lang']; $this->mProjectCode = $prefixdata['project']; $this->mProjectName = isset( $wmincProjects[$this->mProjectCode] ) ? $wmincProjects[$this->mProjectCode] : ''; - # Redirect to real main page if URL is Wx/xxx?goto=mainpage - if( $wgRequest->getVal('goto') == 'mainpage' ) { - $this->redirectToMainPage(); - } $this->mLangNames = IncubatorLanguages::getLanguageNames(); $this->mLangsData = IncubatorLanguages::loadLanguagesData(); $this->mThisLangData = ( isset( $this->mLangsData[$this->mLangCode] ) ? @@ -41,11 +37,10 @@ * In the second case, it adds &redirectfrom and &uselang=xx if set */ public function redirectToMainPage() { - # need to find a proper way - if( isset( $this->mSubdomain ) && $this->mSubdomain == true ) { - header( 'Location: ' . $this->getMainPage() ); + global $wgOut, $wgRequest; + if( in_array( $this->mStatus, array( 'created', 'beforeincubator' ) ) ) { + $url = $this->getSubdomain(); } else { - global $wgOut, $wgRequest; $params = 'redirectfrom=infopage'; $uselang = $wgRequest->getVal( 'uselang' ); if( $uselang ) { @@ -53,16 +48,15 @@ } $mainpage = Title::newFromText( $this->getMainPage() ); $url = $mainpage->getFullURL( $params ); - $wgOut->redirect( $url ); } + $wgOut->redirect( $url ); return; } # Small convenience function to display a (clickable) logo public function makeLogo( $project, $clickable = true, $width = 25, $height = '', $url = '', $args = '' ) { $projectForFile = preg_replace('/ /', '-', strtolower( $project ) ); - # TEMPORARILY TO REDUCE PAGE LOAD - $imageobj = '';/*wfFindFile( wfMsg( 'wminc-logo-' . $projectForFile ) );*/ + $imageobj = wfFindFile( wfMsg( 'wminc-logo-' . $projectForFile ) ); if ( $imageobj ) { $thumb = $imageobj->transform( array( 'width' => $width ) ); $logo = '<img src="' . $thumb->getUrl() . @@ -127,8 +121,17 @@ ); } + public function showWelcome() { + return Html::rawElement( 'div', array( 'class' => 'wminc-infopage-welcome' ), + wfMsgWikiHtml( 'wminc-infopage-welcome' ) ); + } + public function StandardInfoPage( $beforetitle, $aftertitle, $content ) { - global $wgLang, $wgOut, $wmincScriptDir; + global $wgRequest, $wgLang, $wgOut, $wmincScriptDir; + # Redirect to real main page if URL is Wx/xxx?goto=mainpage + if( $wgRequest->getVal('goto') == 'mainpage' ) { + $this->redirectToMainPage(); + } $wgOut->addModules( 'WikimediaIncubator.InfoPage' ); return Html::rawElement( 'div', array( 'class' => 'wminc-infopage plainlinks', 'lang' => $wgLang->getCode(), 'dir' => $wgLang->getDir() ), @@ -144,22 +147,24 @@ public function showMissingWiki() { global $wgRequest; - $welcome = Html::rawElement( 'div', array( 'class' => 'wminc-infopage-missingwiki-welcome' ), - wfMsgWikiHtml( 'wminc-infopage-missingwiki-welcome' ) ); - $content = Html::rawElement( 'div', array( 'class' => 'wminc-infopage-missingwiki-text' ), + $content = Html::rawElement( 'div', array( 'class' => 'wminc-infopage-status' ), wfMsgWikiHtml( 'wminc-infopage-missingwiki-text', $this->mProjectName, $this->mLangName ) ) . - Html::rawElement( 'ul', array( 'class' => 'wminc-infopage-missingwiki-options' ), - wfMsgWikiHtml( 'wminc-infopage-missingwiki-options', $this->mProjectName, - $this->mLangName, ( $wgRequest->getVal( 'createmainpage' ) ? - '<br />' . $this->CreateMainPage() : ''), - $this->listOtherProjects(), $this->listMultilingualProjects() ) + Html::rawElement( 'ul', array( 'class' => 'wminc-infopage-options' ), + Html::rawElement( 'li', null, wfMsgWikiHtml( 'wminc-infopage-option-startwiki', $this->mProjectName ) . + # TODO: create main page feature + ( $wgRequest->getVal( 'createmainpage' ) ? '<br />' . $this->CreateMainPage() : '') ) . + Html::rawElement( 'li', null, wfMsgWikiHtml( 'wminc-infopage-option-languages', $this->mProjectName ) ) . + Html::rawElement( 'li', null, wfMsgWikiHtml( 'wminc-infopage-option-sisterprojects' ) . + $this->listOtherProjects() ) . + Html::rawElement( 'li', null, wfMsgWikiHtml( 'wminc-infopage-option-multilingual' ) . + $this->listMultilingualProjects() ) ); - return $this->StandardInfoPage( $welcome, '', $content ); + return $this->StandardInfoPage( $this->showWelcome(), '', $content ); } public function showIncubatingWiki() { global $wgUser; - $status = $this->mStatus; + $status = isset( $this->mStatus ) ? $this->mStatus : ''; $bug = isset( $this->mBug ) ? $this->mBug : ''; if( $this->mThisLangData['type'] != 'invalid' ) { $gotoMainPage = Html::rawElement( 'span', @@ -177,21 +182,25 @@ } public function showExistingWiki() { + global $wgLang; $created = isset( $this->mCreated ) ? $this->mCreated : ''; - $status = $this->mStatus; + $status = isset( $this->mStatus ) ? $this->mStatus : ''; $bug = isset( $this->mBug ) ? $this->mBug : ''; + $subdomainLink = Linker::makeExternalLink( $this->getSubdomain(), $this->getSubdomain() ); if( $this->mThisLangData['type'] != 'invalid' ) { $gotoSubdomain = Html::rawElement( 'span', array( 'class' => 'wminc-infopage-entertest' ), - '→ <a href="' . $this->getSubdomain() . '">' - . $this->getSubdomain( '', false ). '</a>' ); + $wgLang->getArrow() . ' ' . $subdomainLink ); } - $content = ''; - $content .= Html::element( 'div', array( 'class' => 'wminc-infopage-status' ), wfMsg( 'wminc-infopage-status-' . $status ) ); - if( $status != 'approved' && $this->mThisLangData['type'] != 'invalid' ) { - $content .= Html::element( 'div', array( 'class' => 'wminc-infopage-contribute' ), wfMsg( 'wminc-infopage-contribute' ) ); - } - $content .= wfMsg( 'wminc-infopage-text-' . $status, array( $status, 'Lol!', '', $bug ) ); - return $this->StandardInfoPage( '', $gotoSubdomain, $content ); + $content = Html::rawElement( 'div', + array( 'class' => 'wminc-infopage-status' ), + wfMsg( 'wminc-infopage-status-' . $status, $subdomainLink ) + ) . Html::rawElement( 'ul', array( 'class' => 'wminc-infopage-options' ), + Html::rawElement( 'li', null, wfMsgWikiHtml( 'wminc-infopage-option-sisterprojects' ) . + $this->listOtherProjects() ) . + Html::rawElement( 'li', null, wfMsgWikiHtml( 'wminc-infopage-option-multilingual' ) . + $this->listMultilingualProjects() ) + ); + return $this->StandardInfoPage( $this->showWelcome(), $gotoSubdomain, $content ); } } \ No newline at end of file Modified: trunk/WikimediaIncubator.php =================================================================== --- trunk/WikimediaIncubator.php 2011-07-14 17:51:12 UTC (rev 18) +++ trunk/WikimediaIncubator.php 2011-07-14 21:26:43 UTC (rev 19) @@ -105,6 +105,22 @@ /* ==================== BEGIN OF STUFF IN DEVELOPMENT ================ */ +/* support for automatic checking in a list of databases if a wiki exists */ +$wmincExistingWikis = $wgLocalDatabases; +/* Stupid "wiki" referring to "wikipedia" in WMF config */ +$wmincProjectDatabases = array( + 'p' => 'wiki', + 'b' => 'wikibooks', + 't' => 'wiktionary', + 'q' => 'wikiquote', + 'n' => 'wikinews', + 's' => 'wikisource', + 'v' => 'wikiversity', +); +# if WMF/SiteMatrix config is available, use if +# NOTICE: include SiteMatrix extension before this extension (this is the case for WMF) +$wmincClosedWikis = isset( $wgSiteMatrixClosedSites ) ? $wgSiteMatrixClosedSites : array(); + /* Messages not in SVN */ $wgExtensionMessagesFiles['WikimediaIncubator-dev'] = $dir . 'WikimediaIncubator.dev-i18n.php'; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |