Glaisher has uploaded a new change for review. https://gerrit.wikimedia.org/r/278743
Change subject: Update code to match current coding conventions ...................................................................... Update code to match current coding conventions * Run phpcbf with MediaWiki standard * Run stylize.php Change-Id: Ib11d92561e0a574f8727b106c963496cd9208a1e --- M CreateAccountTestWiki.php M IncubatorUnitTests.php M InfoPage.php M ListUsersTestWiki.php M SpecialIncubatorFirstSteps.php M SpecialMyMainPage.php M SpecialRandomByTest.php M SpecialSearchWiki.php M SpecialViewUserLang.php M TestWikiRC.php M WikimediaIncubator.alias.php M WikimediaIncubator.class.php M WikimediaIncubator.i18n.magic.php M WikimediaIncubator.php 14 files changed, 155 insertions(+), 150 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikimediaIncubator refs/changes/43/278743/1 diff --git a/CreateAccountTestWiki.php b/CreateAccountTestWiki.php index 80fb213..eafb14b 100644 --- a/CreateAccountTestWiki.php +++ b/CreateAccountTestWiki.php @@ -23,8 +23,8 @@ $codevalue = strtolower( $wgRequest->getVal( 'testwikicode', '' ) ); if ( WikimediaIncubator::validateLanguageCode( $codevalue ) && isset( $wmincProjects[$projectvalue] ) ) { $template->set( 'header', - Html::hidden('testwiki-project', $projectvalue). - Html::hidden('testwiki-code', $codevalue) + Html::hidden( 'testwiki-project', $projectvalue ) . + Html::hidden( 'testwiki-code', $codevalue ) ); } return true; diff --git a/IncubatorUnitTests.php b/IncubatorUnitTests.php index b94489c..1f8fd6d 100644 --- a/IncubatorUnitTests.php +++ b/IncubatorUnitTests.php @@ -9,14 +9,14 @@ } function testShouldWeShowUnprefixedError() { - $testPages = array( + $testPages = [ 'Bl/urb' => true, 'Talk:Bl/urb' => true, 'Template:Bl/urb' => true, 'Wt/da/Test' => false, 'File:Blurb.png' => false, - ); - foreach( $testPages as $testPage => $outcome ) { + ]; + foreach ( $testPages as $testPage => $outcome ) { $title = Title::newFromText( $testPage ); $function = $outcome ? 'assertTrue' : 'assertFalse'; $this->$function( diff --git a/InfoPage.php b/InfoPage.php index 9b154bd..74194cf 100644 --- a/InfoPage.php +++ b/InfoPage.php @@ -37,7 +37,7 @@ $this->mIsSister = array_key_exists( $this->mProjectCode, $wmincSisterProjects ); $this->mDBStatus = ''; $this->mSubStatus = ''; - $this->mThisLangData = array( 'type' => 'valid' ); # For later code check feature + $this->mThisLangData = [ 'type' => 'valid' ]; # For later code check feature $name = Language::fetchLanguageName( $this->mLangCode, $wgLang->getCode(), 'all' ); $this->mLangName = $name ? $name : Language::fetchLanguageName( $this->mLangCode, 'en', 'all' ); @@ -63,11 +63,11 @@ * @param $mul Boolean * @return String */ - public function makeLogo( $project, $clickable = true, $params = array(), $url = null, $lang = null, $mul = false ) { + public function makeLogo( $project, $clickable = true, $params = [], $url = null, $lang = null, $mul = false ) { $lang = $lang ? $lang : $this->mLangCode; if ( !$mul ) { // for non-multilingual wikis $getDbStatus = WikimediaIncubator::getDBState( - array( 'error' => null, 'lang' => $lang, 'project' => $project ) + [ 'error' => null, 'lang' => $lang, 'project' => $project ] ); $lang = $getDbStatus == 'missing' ? 'en' : $lang; $params['title'] = WikimediaIncubator::getProject( $project, true, true ); @@ -79,7 +79,7 @@ if ( $url === null ) { $url = WikimediaIncubator::getSubdomain( 'www', $project ); } - return Html::rawElement( 'a', array( 'href' => $url ), $img ); + return Html::rawElement( 'a', [ 'href' => $url ], $img ); } return $img; } @@ -92,10 +92,10 @@ global $wmincProjects, $wmincSisterProjects; $otherProjects = $wmincProjects + $wmincSisterProjects; unset( $otherProjects[$this->mProjectCode] ); - $listOtherProjects = array(); + $listOtherProjects = []; foreach ( $otherProjects as $code => $name ) { $listOtherProjects[$code] = '<li>' . $this->makeLogo( $code, true, - array( 'width' => 75 ), WikimediaIncubator::getSubdomain( $this->mLangCode, $code ) ) . '</li>'; + [ 'width' => 75 ], WikimediaIncubator::getSubdomain( $this->mLangCode, $code ) ) . '</li>'; } return '<ul class="wminc-infopage-otherprojects">' . implode( '', $listOtherProjects ) . '</ul>'; @@ -107,14 +107,15 @@ */ public function listMultilingualProjects() { global $wmincMultilingualProjects, $wmincProjects; - if ( !is_array( $wmincMultilingualProjects ) ) { return ''; } - $list = array(); + if ( !is_array( $wmincMultilingualProjects ) ) { return ''; + } + $list = []; foreach ( $wmincMultilingualProjects as $key => $name ) { # multilingual projects are listed under wikipedia $fakeProject = key( $wmincProjects ); $url = WikimediaIncubator::getSubdomain( $key, $fakeProject ); $list[$url] = '<li>' . $this->makeLogo( $fakeProject, true, - array( 'width' => 75 ), $url, $key, true ) . '</li>'; + [ 'width' => 75 ], $url, $key, true ) . '</li>'; } return '<ul class="wminc-infopage-multilingualprojects">' . implode( '', $list ) . '</ul>'; @@ -124,7 +125,7 @@ * @return String: "Welcome to Incubator" message */ public function showWelcome() { - return Html::rawElement( 'div', array( 'class' => 'wminc-infopage-welcome' ), + return Html::rawElement( 'div', [ 'class' => 'wminc-infopage-welcome' ], wfMessage( 'wminc-infopage-welcome' )->parseAsBlock() ); } @@ -133,13 +134,13 @@ */ public function StandardInfoPage( $beforetitle, $aftertitle, $content ) { global $wgLang; - return Html::rawElement( 'div', array( 'class' => 'wminc-infopage plainlinks', - 'lang' => $wgLang->getCode(), 'dir' => $wgLang->getDir() ), + return Html::rawElement( 'div', [ 'class' => 'wminc-infopage plainlinks', + 'lang' => $wgLang->getCode(), 'dir' => $wgLang->getDir() ], $beforetitle . - Html::rawElement( 'div', array( 'class' => 'wminc-infopage-logo' ), + Html::rawElement( 'div', [ 'class' => 'wminc-infopage-logo' ], $this->makeLogo( $this->mProjectCode ) ) . - Html::rawElement( 'div', array( 'class' => 'wminc-infopage-title' ), + Html::rawElement( 'div', [ 'class' => 'wminc-infopage-title' ], $this->mFormatTitle . $aftertitle ) . $content ); } @@ -150,16 +151,16 @@ public function showMissingWiki() { global $wgRequest; $link = SpecialPage::getTitleFor( 'IncubatorFirstSteps' ); - $query = array( 'testwiki' => $this->mPrefix, - 'uselang' => $wgRequest->getVal( 'uselang' ) ); + $query = [ 'testwiki' => $this->mPrefix, + 'uselang' => $wgRequest->getVal( 'uselang' ) ]; $steps = $link->getFullUrl( $query ); $content = Html::rawElement( 'div', - array( 'class' => 'wminc-infopage-status' ), + [ 'class' => 'wminc-infopage-status' ], wfMessage( 'wminc-infopage-missingwiki-text', $this->mProjectName, $this->mLangName )->parseAsBlock() ) . - Html::rawElement( 'ul', array( 'class' => 'wminc-infopage-options' ), + Html::rawElement( 'ul', [ 'class' => 'wminc-infopage-options' ], Html::rawElement( 'li', null, wfMessage( $this->mIsSister ? 'wminc-infopage-option-startsister' : 'wminc-infopage-option-startwiki', $this->mProjectName, $this->mPortal, $steps )->parse() ) . @@ -194,7 +195,7 @@ $mainpage, wfMessage( 'wminc-infopage-enter' )->escaped() ); $gotoMainPage = Html::rawElement( 'span', - array( 'class' => 'wminc-infopage-entertest' ), + [ 'class' => 'wminc-infopage-entertest' ], $wgLang->getArrow() . ' ' . ( $this->mIsSister ? $portalLink : $gotoLink ) ); } $subdomain = WikimediaIncubator::getSubdomain( $this->mLangCode, $this->mProjectCode ); @@ -202,14 +203,14 @@ # Give grep a chance to find the usages: # wminc-infopage-status-open, wminc-infopage-status-imported, wminc-infopage-status-closedsister, # wminc-infopage-status-approved, wminc-infopage-status-created, wminc-infopage-status-beforeincubator - $content = Html::rawElement( 'div', array( 'class' => 'wminc-infopage-status' ), + $content = Html::rawElement( 'div', [ 'class' => 'wminc-infopage-status' ], wfMessage( 'wminc-infopage-status-' . $substatus )->rawParams( $subdomainLink, $portalLink )->parseAsBlock() ); if ( $this->mSubStatus != 'approved' && $this->mThisLangData['type'] != 'invalid' ) { $content .= Html::element( 'div', - array( 'class' => 'wminc-infopage-contribute' ), + [ 'class' => 'wminc-infopage-contribute' ], wfMessage( 'wminc-infopage-contribute' )->plain() ); } - $content .= Html::rawElement( 'div', array( 'class' => 'wminc-infopage-links' ), + $content .= Html::rawElement( 'div', [ 'class' => 'wminc-infopage-links' ], # custom links and other stuff wfMessage( 'wminc-infopage-links', $this->mSubStatus, $this->mPrefix, @@ -217,7 +218,7 @@ $this->mLangCode, $this->mLangName )->inContentLanguage()->parse() ); - $content .= Html::rawElement( 'ul', array( 'class' => 'wminc-infopage-options' ), + $content .= Html::rawElement( 'ul', [ 'class' => 'wminc-infopage-options' ], Html::rawElement( 'li', null, wfMessage( 'wminc-infopage-option-sisterprojects-other' )->parseAsBlock() . $this->listOtherProjects() ) ); return $this->StandardInfoPage( '', $gotoMainPage, $content ); @@ -234,7 +235,7 @@ $subdomainLink = WikimediaIncubator::makeExternalLinkText( $subdomain, true ); if ( $this->mThisLangData['type'] != 'invalid' ) { $gotoSubdomain = Html::rawElement( 'span', - array( 'class' => 'wminc-infopage-entertest' ), + [ 'class' => 'wminc-infopage-entertest' ], $wgLang->getArrow() . ' ' . $subdomainLink ); } # Give grep a chance to find the usages: @@ -245,9 +246,9 @@ $msgname = 'wminc-infopage-status-beforeincubator-sister'; } $content = Html::rawElement( 'div', - array( 'class' => 'wminc-infopage-status' ), + [ 'class' => 'wminc-infopage-status' ], wfMessage( $msgname )->rawParams( $subdomainLink )->parseAsBlock() - ) . Html::rawElement( 'ul', array( 'class' => 'wminc-infopage-options' ), + ) . Html::rawElement( 'ul', [ 'class' => 'wminc-infopage-options' ], Html::rawElement( 'li', null, wfMessage( 'wminc-infopage-option-sisterprojects-other' )->parseAsBlock() . $this->listOtherProjects() ) . Html::rawElement( 'li', null, wfMessage( 'wminc-infopage-option-multilingual' )->parseAsBlock() . diff --git a/ListUsersTestWiki.php b/ListUsersTestWiki.php index 4fd1bdb..4bf8b9b 100644 --- a/ListUsersTestWiki.php +++ b/ListUsersTestWiki.php @@ -11,7 +11,7 @@ static function getProjectInput() { global $wmincProjectSite, $wgRequest; $input = strtolower( $wgRequest->getVal( 'testwiki' ) ); - if( $input == strtolower( $wmincProjectSite['name'] ) || $input == strtolower( $wmincProjectSite['short'] ) ) { + if ( $input == strtolower( $wmincProjectSite['name'] ) || $input == strtolower( $wmincProjectSite['short'] ) ) { return $wmincProjectSite; } return null; @@ -25,7 +25,7 @@ $project = self::getProjectInput(); $input = $project ? $project['name'] : ( $testwiki ? $testwiki['prefix'] : null ); $out .= Xml::label( wfMessage( 'wminc-testwiki' )->text(), 'testwiki' ) . ' ' . - Xml::input( 'testwiki', 20, $input, array( 'id' => 'testwiki' ) ) . '<br />'; + Xml::input( 'testwiki', 20, $input, [ 'id' => 'testwiki' ] ) . '<br />'; return true; } @@ -60,18 +60,18 @@ } global $wmincPref; $query['tables']['p1'] = 'user_properties'; - $query['join_conds']['p1'] = array( 'JOIN', array( 'user_id=p1.up_user', + $query['join_conds']['p1'] = [ 'JOIN', [ 'user_id=p1.up_user', 'p1.up_property' => "$wmincPref-project", 'p1.up_value' => $project ? $project['short'] : $testwiki['project'] - ) ); + ] ]; if ( $project ) { return true; # project site doesn't need language code = returning } $query['tables']['p2'] = 'user_properties'; - $query['join_conds']['p2'] = array( 'JOIN', array( 'user_id=p2.up_user', + $query['join_conds']['p2'] = [ 'JOIN', [ 'user_id=p2.up_user', 'p2.up_property' => "$wmincPref-code", 'p2.up_value' => $testwiki['lang'] - ) ); + ] ]; return true; } } diff --git a/SpecialIncubatorFirstSteps.php b/SpecialIncubatorFirstSteps.php index ee3eeb1..1c1933e 100644 --- a/SpecialIncubatorFirstSteps.php +++ b/SpecialIncubatorFirstSteps.php @@ -32,7 +32,7 @@ $this->getOutput()->addWikiMsg( 'wminc-fs-intro' ); $step = false; - $this->addLanguageSelector( ); + $this->addLanguageSelector(); $step = $this->showSignup( $step ); $step = $this->showTestwikiSetting( $step ); @@ -49,7 +49,7 @@ * @param $done bool */ protected function showHeader( $msg, $opaque = true, $done = false ) { - $attrs = array(); + $attrs = []; if ( $opaque ) { $attrs['class'] = 'mw-special-incubatorfirststeps-header'; } @@ -93,17 +93,17 @@ ksort( $getLangCodes ); // sorting by language code is not ideal, but well - $showLanguages = array(); + $showLanguages = []; foreach ( $getLangCodes as $code => $nothing ) { $code = trim( $code ); if ( !isset( $names[$code] ) || $code === $currentLangCode ) { # language code not recognised, or is current interface language continue; } - $linkParams = array( 'uselang' => $code, - 'testwiki' => $this->getRequest()->getVal( 'testwiki' ) ); + $linkParams = [ 'uselang' => $code, + 'testwiki' => $this->getRequest()->getVal( 'testwiki' ) ]; $showLanguages[] = Linker::linkKnown( $this->getPageTitle(), - $names[$code], array(), $linkParams ); + $names[$code], [], $linkParams ); } # Show list @@ -130,8 +130,8 @@ # Login / create account links $link = SpecialPage::getTitleFor( 'Userlogin' ); - $query = array( 'returnto' => $this->getPageTitle(), - 'uselang' => $this->getRequest()->getVal( 'uselang' ) ); + $query = [ 'returnto' => $this->getPageTitle(), + 'uselang' => $this->getRequest()->getVal( 'uselang' ) ]; $urlTestWiki = WikimediaIncubator::getUrlParam(); if ( $urlTestWiki ) { // set preferences automatically, based on the "testwiki" URL param @@ -139,7 +139,7 @@ $query['testwikicode'] = $urlTestWiki['lang']; } $login = $link->getFullUrl( $query ); - $signup = $link->getFullUrl( $query + array( 'type' => 'signup' ) ); + $signup = $link->getFullUrl( $query + [ 'type' => 'signup' ] ); $this->getOutput()->addWikiMsg( 'wminc-fs-signup-text', $login, $signup ); diff --git a/SpecialMyMainPage.php b/SpecialMyMainPage.php index 5054f17..dd553a5 100644 --- a/SpecialMyMainPage.php +++ b/SpecialMyMainPage.php @@ -17,16 +17,16 @@ public function execute( $par ) { $title = ''; - $params = array(); + $params = []; # Build Wx/xyz?goto=mainpage[&testwiki=] if ( WikimediaIncubator::isContentProject() ) { $title = Title::newFromText( WikimediaIncubator::displayPrefix() ); - if( $this->getRequest()->getVal( 'goto' ) != 'infopage' ) { + if ( $this->getRequest()->getVal( 'goto' ) != 'infopage' ) { $params['goto'] = 'mainpage'; } $url = WikimediaIncubator::getUrlParam(); - if( $url ) { + if ( $url ) { $params['testwiki'] = $url['prefix']; } } diff --git a/SpecialRandomByTest.php b/SpecialRandomByTest.php index bdb543d..b153b1e 100644 --- a/SpecialRandomByTest.php +++ b/SpecialRandomByTest.php @@ -15,13 +15,13 @@ $target = WikimediaIncubator::analyzePrefix( $target ); $project = isset( $target['project'] ) ? $target['project'] : ''; $lang = isset( $target['lang'] ) ? $target['lang'] : ''; - if( WikimediaIncubator::isContentProject() || ( $project && $lang ) ) { + if ( WikimediaIncubator::isContentProject() || ( $project && $lang ) ) { $dbr = wfGetDB( DB_SLAVE ); $this->extra[] = 'page_title' . $dbr->buildLike( WikimediaIncubator::displayPrefix( $project, $lang ) . '/', $dbr->anyString() ); - } elseif( $this->getUser()->getOption( $wmincPref . '-project' ) == $wmincProjectSite['short'] ) { + } elseif ( $this->getUser()->getOption( $wmincPref . '-project' ) == $wmincProjectSite['short'] ) { # project or help namespace - $this->extra['page_namespace'] = array( 4, 12 ); + $this->extra['page_namespace'] = [ 4, 12 ]; } parent::__construct( 'RandomByTest' ); } diff --git a/SpecialSearchWiki.php b/SpecialSearchWiki.php index 355a47f..0714fae 100644 --- a/SpecialSearchWiki.php +++ b/SpecialSearchWiki.php @@ -32,7 +32,7 @@ $uselang = $this->getRequest()->getVal( 'uselang' ); $this->getOutput()->addHTML( Xml::fieldset( wfMessage( 'wminc-searchwiki' )->plain(), - Html::rawElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'wminc-searchwiki-form' ), + Html::rawElement( 'form', [ 'method' => 'get', 'action' => $wgScript, 'id' => 'wminc-searchwiki-form' ], Html::hidden( 'title', SpecialPage::getTitleFor( 'SearchWiki' ) ) . ( $uselang ? Html::hidden( 'uselang', $uselang ) : '' ) . '<p>' . Xml::label( wfMessage( 'wminc-searchwiki-selectproject' )->text(), 'wminc-searchproject' ) . @@ -78,8 +78,8 @@ } else { return $this->getOutput()->addWikiMsg( 'wminc-searchwiki-noproject' ); } - - $results = array(); + + $results = []; $lcLanguageQuery = strtolower( $languageQuery ); # The more important, the more below, because they override earlier codes @@ -96,13 +96,13 @@ $results[$codeUserLang] = 'userlangname'; # Match name in user language } if ( $codeByNativeName = array_search( $lcLanguageQuery, array_map( 'self::strip', $this->mNativeNames ) ) ) { - $results[$codeByNativeName] = 'nativename'; # Match native name + $results[$codeByNativeName] = 'nativename'; # Match native name } if ( count( $results ) === 1 ) { $this->gotoWiki( $matchProject, key( $results ) ); } elseif ( count( $results ) < 1 ) { - $noresult = Html::element( 'p', array( 'class' => 'error' ), + $noresult = Html::element( 'p', [ 'class' => 'error' ], wfMessage( 'wminc-searchwiki-noresults' )->text() ); return $this->getOutput()->addHTML( $noresult ); } elseif ( count( $results ) > 1 ) { @@ -117,7 +117,7 @@ */ protected function strip( $str ) { $str = strtolower( trim( $str ) ); - $replace = array( ' ' => '', '-' => '' ); + $replace = [ ' ' => '', '-' => '' ]; return str_replace( array_keys( $replace ), array_values( $replace ), $str ); } @@ -128,12 +128,12 @@ */ protected function goToWiki( $project, $lang ) { $lang = self::getRootCode( $lang ); - $dbarray = array( 'project' => $project, 'lang' => $lang, 'error' => null ); + $dbarray = [ 'project' => $project, 'lang' => $lang, 'error' => null ]; $status = WikimediaIncubator::getDBState( $dbarray ); - $infopageParams = array( + $infopageParams = [ 'goto' => 'mainpage', 'uselang' => $this->getRequest()->getVal( 'uselang' ) - ); + ]; $url = $status == 'existing' ? WikimediaIncubator::getSubdomain( $lang, $project ) : Title::newFromText( 'W' . $project . '/' . $lang )->getFullURL( $infopageParams ); $this->getOutput()->redirect( $url ); @@ -145,7 +145,7 @@ */ protected function getRootCode( $code ) { # e.g. ks-arab -> ks - $stripLangTags = array( '-arab', '-latn', '-cyrl', '-deva', '-cans', '-grek' ); + $stripLangTags = [ '-arab', '-latn', '-cyrl', '-deva', '-cans', '-grek' ]; return str_replace( $stripLangTags, '', $code ); } @@ -156,7 +156,7 @@ */ protected function showMultipleResults( $project, $languageQuery, $results ) { $this->getOutput()->addHTML( '<div id="wminc-searchwiki-results">' . - Xml::element( 'p', array(), + Xml::element( 'p', [], wfMessage( 'wminc-searchwiki-multiplematches' )->text() ) . '<ul>' ); @@ -174,7 +174,7 @@ # wminc-infopage-title-v, wminc-infopage-title-y $linkMainPage = Linker::linkKnown( $infopage, wfMessage( 'wminc-infopage-title-' . $project, $langName )->text(), - array(), array( 'goto' => 'mainpage' ) + [], [ 'goto' => 'mainpage' ] ); # Give grep a chance to find the usages: # wminc-searchwiki-match-langcode, wminc-searchwiki-match-englishname, diff --git a/SpecialViewUserLang.php b/SpecialViewUserLang.php index 0c93510..f52ae5c 100644 --- a/SpecialViewUserLang.php +++ b/SpecialViewUserLang.php @@ -19,7 +19,9 @@ /** * @return String */ - function getDescription() { return wfMessage( 'wminc-viewuserlang' )->plain(); } + function getDescription() { + return wfMessage( 'wminc-viewuserlang' )->plain(); + } /** * Show the special page @@ -51,7 +53,7 @@ $this->getOutput()->addHTML( Xml::fieldset( wfMessage( 'wminc-viewuserlang' )->plain() ) . - Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) . + Xml::openElement( 'form', [ 'method' => 'get', 'action' => $wgScript ] ) . Html::hidden( 'title', $this->getPageTitle()->getPrefixedText() ) . "<p>" . Xml::inputLabel( wfMessage( 'wminc-viewuserlang-user' )->text(), 'target', 'viewuserlang-username', 40, $target ) . @@ -115,12 +117,12 @@ */ public function prefixSearchSubpages( $search, $limit, $offset ) { if ( !class_exists( 'UserNamePrefixSearch' ) ) { // check for version 1.27 - return array(); + return []; } $user = User::newFromName( $search ); if ( !$user ) { // No prefix suggestion for invalid user - return array(); + return []; } // Autocomplete subpage as user list - public to allow caching return UserNamePrefixSearch::search( 'public', $search, $limit, $offset ); diff --git a/TestWikiRC.php b/TestWikiRC.php index a2fd9ab..c7a9cea 100644 --- a/TestWikiRC.php +++ b/TestWikiRC.php @@ -15,7 +15,7 @@ $codevalue = $url ? $url['lang'] : $wgUser->getOption( $wmincPref . '-code' ); $projectvalue = strtolower( $wgRequest->getVal( 'rc-testwiki-project', $projectvalue ) ); $codevalue = strtolower( $wgRequest->getVal( 'rc-testwiki-code', $codevalue ) ); - return array( $projectvalue, $codevalue ); + return [ $projectvalue, $codevalue ]; } static function onRcQuery( &$conds, &$tables, &$join_conds, $opts ) { @@ -47,7 +47,7 @@ static function onRcForm( &$items, $opts ) { global $wmincProjects, $wmincProjectSite, $wmincLangCodeLength; - + list( $projectvalue, $codevalue ) = self::getValues(); $opts->consumeValue( 'rc-testwiki-project' ); $opts->consumeValue( 'rc-testwiki-code' ); @@ -59,8 +59,8 @@ } $select->addOption( $wmincProjectSite['name'], $wmincProjectSite['short'] ); $langcode = Xml::input( 'rc-testwiki-code', (int)$wmincLangCodeLength, $codevalue, - array( 'id' => 'rc-testwiki-code', 'maxlength' => (int)$wmincLangCodeLength ) ); - $items['testwiki'] = array( $label, $select->getHTML() . ' ' . $langcode ); + [ 'id' => 'rc-testwiki-code', 'maxlength' => (int)$wmincLangCodeLength ] ); + $items['testwiki'] = [ $label, $select->getHTML() . ' ' . $langcode ]; return true; } } diff --git a/WikimediaIncubator.alias.php b/WikimediaIncubator.alias.php index 956a9ff..9159fa4 100644 --- a/WikimediaIncubator.alias.php +++ b/WikimediaIncubator.alias.php @@ -6,13 +6,13 @@ * @ingroup Extensions */ -$specialPageAliases = array(); +$specialPageAliases = []; /** English (English) */ -$specialPageAliases['en'] = array( - 'IncubatorFirstSteps' => array( 'IncubatorFirstSteps' ), - 'ViewUserLang' => array( 'ViewUserLang' ), - 'MyMainPage' => array( 'MyMainPage' ), - 'RandomByTest' => array( 'RandomByTest' ), - 'SearchWiki' => array( 'SearchWiki' ), -); +$specialPageAliases['en'] = [ + 'IncubatorFirstSteps' => [ 'IncubatorFirstSteps' ], + 'ViewUserLang' => [ 'ViewUserLang' ], + 'MyMainPage' => [ 'MyMainPage' ], + 'RandomByTest' => [ 'RandomByTest' ], + 'SearchWiki' => [ 'SearchWiki' ], +]; diff --git a/WikimediaIncubator.class.php b/WikimediaIncubator.class.php index c7290cb..e160db2 100644 --- a/WikimediaIncubator.class.php +++ b/WikimediaIncubator.class.php @@ -35,18 +35,18 @@ $preferences['language']['help-message'] = 'wminc-prefinfo-language'; - $prefinsert[$wmincPref . '-project'] = array( + $prefinsert[$wmincPref . '-project'] = [ 'type' => 'select', 'options' => - array( wfMessage( 'wminc-testwiki-none' )->plain() => 'none' ) + + [ wfMessage( 'wminc-testwiki-none' )->plain() => 'none' ] + array_flip( $wmincProjects ) + - array( wfMessage( 'wminc-testwiki-site' )->plain() => $wmincProjectSite['short'] ), + [ wfMessage( 'wminc-testwiki-site' )->plain() => $wmincProjectSite['short'] ], 'section' => 'personal/i18n', 'label-message' => 'wminc-testwiki', 'id' => $wmincPref . '-project', 'help-message' => 'wminc-prefinfo-project', - ); - $prefinsert[$wmincPref . '-code'] = array( + ]; + $prefinsert[$wmincPref . '-code'] = [ 'type' => 'text', 'section' => 'personal/i18n', 'label-message' => 'wminc-testwiki-code', @@ -56,9 +56,9 @@ 'help' => wfMessage( 'wminc-prefinfo-code' )->parse() . self::getTestWikiLanguages(), 'list' => 'wminc-testwiki-codelist', - 'validation-callback' => array( 'WikimediaIncubator', 'validateCodePreference' ), - 'filter-callback' => array( 'WikimediaIncubator', 'filterCodePreference' ), - ); + 'validation-callback' => [ 'WikimediaIncubator', 'validateCodePreference' ], + 'filter-callback' => [ 'WikimediaIncubator', 'filterCodePreference' ], + ]; $preferences = wfArrayInsertAfter( $preferences, $prefinsert, 'language' ); @@ -73,8 +73,8 @@ static function getTestWikiLanguages() { $list = Language::fetchLanguageNames( null, 'all' ); $t = '<datalist id="wminc-testwiki-codelist">' . "\n"; - foreach( $list as $code => $name ) { - $t .= Xml::element( 'option', array( 'value' => $code ), + foreach ( $list as $code => $name ) { + $t .= Xml::element( 'option', [ 'value' => $code ], $code . ' - ' . $name ) . "\n"; } $t .= '</datalist>'; @@ -92,10 +92,10 @@ # If the user selected a project that NEEDS a language code, # but the user DID NOT enter a valid language code, give an error $filteredInput = self::filterCodePreference( $input ); - if ( isset( $alldata[$wmincPref.'-project'] ) && - self::isContentProject( $alldata[$wmincPref.'-project'] ) && + if ( isset( $alldata[$wmincPref . '-project'] ) && + self::isContentProject( $alldata[$wmincPref . '-project'] ) && !self::validateLanguageCode( $filteredInput ) ) { - return Xml::element( 'span', array( 'class' => 'error' ), + return Xml::element( 'span', [ 'class' => 'error' ], wfMessage( 'wminc-prefinfo-error' )->plain() ); } return true; @@ -117,7 +117,8 @@ */ static function validateLanguageCode( $code ) { global $wmincLangCodeLength; - if ( strlen( $code ) > $wmincLangCodeLength ) { return false; } + if ( strlen( $code ) > $wmincLangCodeLength ) { return false; + } if ( $code == 'be-x-old' ) { return true; # one exception... waiting to be renamed to be-tarask } @@ -140,16 +141,16 @@ * optionally 'realtitle' */ static function analyzePrefix( $input, $onlyInfoPage = false, $allowSister = false ) { - $data = array( 'error' => null ); + $data = [ 'error' => null ]; if ( $input instanceof Title ) { global $wmincTestWikiNamespaces; $title = $input->getText(); if ( !in_array( $input->getNamespace(), $wmincTestWikiNamespaces ) ) { - return array( 'error' => 'notestwikinamespace' ); + return [ 'error' => 'notestwikinamespace' ]; } if ( $onlyInfoPage && $input->getNamespace() != NS_MAIN ) { # Info pages are only in the main NS - return array( 'error' => 'nomainnamespace' ); + return [ 'error' => 'nomainnamespace' ]; } } else { $title = $input; @@ -161,26 +162,26 @@ } else { $data['project'] = ( isset( $titleparts[0][1] ) ? $titleparts[0][1] : '' ); # get the x from Wx/... $data['lang'] = $titleparts[1]; # language code - $data['prefix'] = 'W'.$data['project'].'/'.$data['lang']; + $data['prefix'] = 'W' . $data['project'] . '/' . $data['lang']; # check language code if ( !self::validateLanguageCode( $data['lang'] ) ) { $data['error'] = 'invalidlangcode'; } } global $wmincProjects, $wmincSisterProjects; - $listProjects = array_map( array( __CLASS__, 'preg_quote_slash' ), array_keys( $wmincProjects ) ); + $listProjects = array_map( [ __CLASS__, 'preg_quote_slash' ], array_keys( $wmincProjects ) ); if ( $allowSister && is_array( $wmincSisterProjects ) ) { # join the project codes with those of the sister projects - $listSister = array_map( array( __CLASS__, 'preg_quote_slash' ), array_keys( $wmincSisterProjects ) ); + $listSister = array_map( [ __CLASS__, 'preg_quote_slash' ], array_keys( $wmincSisterProjects ) ); $listProjects = array_merge( $listProjects, $listSister ); } $listProjects = implode( '|', $listProjects ); - if ( !preg_match( '/^W['.$listProjects.']\/[a-z-]+' . - ($onlyInfoPage ? '$/' : '(\/.+)?$/' ), $title ) ) { + if ( !preg_match( '/^W[' . $listProjects . ']\/[a-z-]+' . + ( $onlyInfoPage ? '$/' : '(\/.+)?$/' ), $title ) ) { $data['error'] = 'invalidprefix'; } if ( !$onlyInfoPage && $data['error'] != 'invalidprefix' ) { # there is a Page_title - $prefixn = strlen( $data['prefix'].'/' ); # number of chars in prefix + $prefixn = strlen( $data['prefix'] . '/' ); # number of chars in prefix # get Page_title from Wx/xx/Page_title $data['realtitle'] = substr( $title, $prefixn ); } @@ -274,8 +275,8 @@ } else { global $wgUser, $wmincPref; $url = self::getUrlParam(); - $projectvalue = ( $url ? $url['project'] : $wgUser->getOption($wmincPref . '-project') ); - $codevalue = ( $url ? $url['lang'] : $wgUser->getOption($wmincPref . '-code') ); + $projectvalue = ( $url ? $url['project'] : $wgUser->getOption( $wmincPref . '-project' ) ); + $codevalue = ( $url ? $url['lang'] : $wgUser->getOption( $wmincPref . '-code' ) ); } $sister = (bool)( $allowSister && isset( $wmincSisterProjects[$projectvalue] ) ); if ( self::isContentProject( $projectvalue ) || $sister ) { @@ -307,7 +308,7 @@ * TITLE + NS => Wx/xxx/NS:TITLE * (with localized namespace name) */ - $title = Title::makeTitleSafe( NULL, self::displayPrefix() . '/' . + $title = Title::makeTitleSafe( null, self::displayPrefix() . '/' . $wgLang->getNsText( $ns ) . ':' . $title ); } return $title; @@ -333,7 +334,7 @@ global $wmincTestWikiNamespaces, $wmincProjectSite, $wmincPseudoCategoryNSes; $prefixdata = self::analyzePrefix( $title->getText() ); $ns = $title->getNamespace(); - $categories = array_map( array( __CLASS__, 'preg_quote_slash' ), $wmincPseudoCategoryNSes ); + $categories = array_map( [ __CLASS__, 'preg_quote_slash' ], $wmincPseudoCategoryNSes ); if ( !$prefixdata['error'] ) { # no error in prefix -> no error to show return false; @@ -344,7 +345,7 @@ # OK if it's not in one of the content namespaces return false; } elseif ( ( $ns == NS_CATEGORY || $ns == NS_CATEGORY_TALK ) && - preg_match( '/^(' . implode( '|', $categories ) .'):.+$/', $title->getText() ) ) { + preg_match( '/^(' . implode( '|', $categories ) . '):.+$/', $title->getText() ) ) { # whitelisted unprefixed categories return false; } @@ -373,8 +374,8 @@ $prefixdata['project'], ( $title->getNsText() ? $title->getNsText() . ':' : '' ) . str_replace( ' ', '_', $prefixdata['realtitle'] ) ); # faking external link to support prot-rel URLs - $link = "[$link ". self::makeExternalLinkText( $link ) . "]"; - $result[] = array( 'wminc-error-wiki-exists', $link ); + $link = "[$link " . self::makeExternalLinkText( $link ) . "]"; + $result[] = [ 'wminc-error-wiki-exists', $link ]; return $action != 'edit'; } @@ -382,14 +383,14 @@ # only check if needed & if on page creation return true; } elseif ( $prefixdata['error'] == 'invalidlangcode' ) { - $error[] = array( 'wminc-error-wronglangcode', $prefixdata['lang'] ); + $error[] = [ 'wminc-error-wronglangcode', $prefixdata['lang'] ]; } elseif ( self::isContentProject() ) { # If the user has a test wiki pref, suggest a page title with prefix $suggesttitle = isset( $prefixdata['realtitle'] ) ? $prefixdata['realtitle'] : $titletext; $suggest = self::displayPrefixedTitle( $suggesttitle, $title->getNamespace() ); # Suggest to create a prefixed page - $error[] = array( 'wminc-error-unprefixed-suggest', $suggest ); + $error[] = [ 'wminc-error-unprefixed-suggest', $suggest ]; } else { $error = 'wminc-error-unprefixed'; } @@ -463,12 +464,12 @@ $projectCode = array_search( $project, $wmincMultilingualProjects ); } $site = strtolower( $projectName ); - $params = array( + $params = [ 'lang' => $langHyphen, 'site' => $site, # I don't see any other way than to hardcode it here (from: CommonSettings.php) 'stdlogo' => "//upload.wikimedia.org/$site/$langHyphen/b/bc/Wiki.png", - ); + ]; $dbSuffix = isset( $wmincProjectDatabases[$projectCode] ) ? $wmincProjectDatabases[$projectCode] : $site; return $wgConf->get( $setting, $langUnderscore . $dbSuffix, $dbSuffix, $params ); @@ -499,7 +500,7 @@ return false; # shouldn't be, but you never know } global $wmincProjectDatabases, $wgDummyLanguageCodes; - $dbLang = str_replace('-', '_', $prefix['lang'] ); + $dbLang = str_replace( '-', '_', $prefix['lang'] ); $project = $prefix['project']; $dbProject = isset( $wmincProjectDatabases[$project] ) ? $wmincProjectDatabases[$project] : $project; @@ -645,10 +646,10 @@ wfMessage( 'wminc-infopage-error' )->plain() . '</span>'; } $infopage = new InfoPage( $title, $prefix ); - $infopage->mOptions = array( + $infopage->mOptions = [ 'status' => 'open', # other (optional) options: mainpage - ); + ]; $parseOptions = func_get_args(); array_shift( $parseOptions ); # not $parser @@ -667,7 +668,7 @@ $parser->getOptions()->getUserLangObj(); # we have to split the cache by language $parser->getOutput()->setTitleText( $infopage->mFormatTitle ); # sets <h1> & <title> - if ( in_array( $infopage->mSubStatus, array( 'created', 'beforeincubator' ) ) ) { + if ( in_array( $infopage->mSubStatus, [ 'created', 'beforeincubator' ] ) ) { $return = $infopage->showExistingWiki(); } elseif ( self::getMainPage( $prefix['lang'], $prefix['prefix'] )->exists() ) { $return = $infopage->showIncubatingWiki(); @@ -676,7 +677,7 @@ $return = $infopage->showMissingWiki(); } - return array( $return, 'noparse' => true, 'nowiki' => true, 'isHTML' => true ); + return [ $return, 'noparse' => true, 'nowiki' => true, 'isHTML' => true ]; } /** @@ -813,7 +814,7 @@ $logoMsg = wfMessage( 'Incubator-logo-' . $prefixForPageTitle )->inContentLanguage()->plain(); $file = wfFindFile( Title::newFromText( $logoMsg, NS_FILE ) ); if ( $file ) { - $thumb = $file->transform( array( 'width' => 135, 'height' => 135 ) ); + $thumb = $file->transform( [ 'width' => 135, 'height' => 135 ] ); $wgLogo = $thumb->getUrl(); } else { # if MediaWiki:Incubator-logo-wx-xx(x) doesn't exist, @@ -868,7 +869,7 @@ str_replace( ' ', '_', $newTitleData['realtitle'] ) ); $params[0] = 'wminc-error-wiki-exists'; - $params[1] = "[$link ". self::makeExternalLinkText( $link ) . "]"; + $params[1] = "[$link " . self::makeExternalLinkText( $link ) . "]"; return true; } elseif ( $newTitleData['error'] ) { # only add a prefix to the title if there is no prefix @@ -884,7 +885,7 @@ return true; } $params[] = wfEscapeWikiText( $t->getPrefixedText() ); - $params[0] = $prefix && $prefix != 'none' ? 'wminc-search-nocreate-suggest' :'wminc-search-nocreate-nopref'; + $params[0] = $prefix && $prefix != 'none' ? 'wminc-search-nocreate-suggest' : 'wminc-search-nocreate-nopref'; return true; } @@ -894,7 +895,7 @@ */ public static function onSpecialSearchPowerBox( &$showSections, $term, $opts ) { $showSections['testwiki'] = Xml::label( wfMessage( 'wminc-testwiki' )->text(), 'testwiki' ) . ' ' . - Xml::input( 'testwiki', 20, self::displayPrefix(), array( 'id' => 'testwiki' ) ); + Xml::input( 'testwiki', 20, self::displayPrefix(), [ 'id' => 'testwiki' ] ); return true; } @@ -929,7 +930,7 @@ * @return true */ public static function onUnitTestsList( array &$files ) { - $files[] = dirname( __FILE__ ) . '/IncubatorUnitTests.php'; + $files[] = __DIR__ . '/IncubatorUnitTests.php'; return true; } } diff --git a/WikimediaIncubator.i18n.magic.php b/WikimediaIncubator.i18n.magic.php index 6c6b741..0ee446e 100644 --- a/WikimediaIncubator.i18n.magic.php +++ b/WikimediaIncubator.i18n.magic.php @@ -3,9 +3,9 @@ * Internationalization file for magic words. */ -$magicWords = array(); +$magicWords = []; -$magicWords['en'] = array( - 'usertestwiki' => array( 0, 'USERTESTWIKI' ), - 'infopage' => array( 0, 'infopage' ), -); +$magicWords['en'] = [ + 'usertestwiki' => [ 0, 'USERTESTWIKI' ], + 'infopage' => [ 0, 'infopage' ], +]; diff --git a/WikimediaIncubator.php b/WikimediaIncubator.php index df3a4d9..296c084 100644 --- a/WikimediaIncubator.php +++ b/WikimediaIncubator.php @@ -1,5 +1,6 @@ <?php -if ( !defined( 'MEDIAWIKI' ) ) { die( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" ); } +if ( !defined( 'MEDIAWIKI' ) ) { die( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" ); +} /** * An extension that adds features (such as a preference, recent changes, ...) * for a test wiki system (i.e. incubated wikis inside one actual wiki) @@ -13,54 +14,54 @@ * @author Robin Pepermans (SPQRobin) */ -$wgExtensionCredits['other'][] = array( +$wgExtensionCredits['other'][] = [ 'path' => __FILE__, 'name' => 'Wikimedia Incubator', - 'author' => array( 'SPQRobin', 'Hydriz' ), + 'author' => [ 'SPQRobin', 'Hydriz' ], 'version' => '5.3.0', 'url' => 'https://www.mediawiki.org/wiki/Extension:WikimediaIncubator', 'descriptionmsg' => 'wminc-desc', -); +]; /* General (globals and/or configuration) */ $wmincPref = 'incubatortestwiki'; // Name of the preference # only one-letter codes can be used for projects -$wmincProjects = array( +$wmincProjects = [ 'p' => 'Wikipedia', 'b' => 'Wikibooks', 't' => 'Wiktionary', 'q' => 'Wikiquote', 'n' => 'Wikinews', 'y' => 'Wikivoyage', -); +]; # Sister projects is here defined as projects that are not on Incubator -$wmincSisterProjects = array( +$wmincSisterProjects = [ 's' => 'Wikisource', 'v' => 'Wikiversity', -); -$wmincMultilingualProjects = array( +]; +$wmincMultilingualProjects = [ 'meta' => 'Meta-Wiki', 'commons' => 'Wikimedia Commons', 'species' => 'Wikispecies', 'mediawiki' => 'MediaWiki', 'wikidata' => 'Wikidata', -); -$wmincProjectSite = array( +]; +$wmincProjectSite = [ 'name' => 'Incubator', 'short' => 'inc', -); -$wmincTestWikiNamespaces = array( +]; +$wmincTestWikiNamespaces = [ NS_MAIN, NS_TALK, NS_TEMPLATE, NS_TEMPLATE_TALK, NS_CATEGORY, NS_CATEGORY_TALK, - 828, 829, //NS_MODULE, NS_MODULE_TALK, -); + 828, 829, // NS_MODULE, NS_MODULE_TALK, +]; $wmincLangCodeLength = 12; // can be changed if needed (depends on policy) // Pseudo category namespaces like "Category:Maintenance:Delete", for easy whitelisting and structure -$wmincPseudoCategoryNSes = array( +$wmincPseudoCategoryNSes = [ 'Incubator', 'Help', 'Users', 'Maintenance', 'Files', -); +]; /* Test wiki admin user group */ $wgGroupPermissions['test-sysop']['delete'] = true; @@ -119,7 +120,7 @@ /* 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( +$wmincProjectDatabases = [ 'p' => 'wiki', 'b' => 'wikibooks', 't' => 'wiktionary', @@ -128,7 +129,7 @@ 's' => 'wikisource', 'v' => 'wikiversity', 'y' => 'wikivoyage', -); +]; # set this to an array or file of closed wikis (like SiteMatrix $wgSiteMatrixClosedSites) $wmincClosedWikis = false; @@ -140,12 +141,12 @@ $wgHooks['TitleIsAlwaysKnown'][] = 'WikimediaIncubator::onTitleIsAlwaysKnown'; $wgHooks['ParserFirstCallInit'][] = 'WikimediaIncubator::onParserFirstCallInit'; -$wgResourceModules['WikimediaIncubator.InfoPage'] = array( +$wgResourceModules['WikimediaIncubator.InfoPage'] = [ 'position' => 'top', 'styles' => 'InfoPage.css', 'localBasePath' => __DIR__, 'remoteExtPath' => 'WikimediaIncubator', -); +]; /* Possibility to set a logo per test wiki */ $wgHooks['BeforePageDisplay'][] = 'WikimediaIncubator::fnTestWikiLogo'; -- To view, visit https://gerrit.wikimedia.org/r/278743 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib11d92561e0a574f8727b106c963496cd9208a1e Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikimediaIncubator Gerrit-Branch: master Gerrit-Owner: Glaisher <glaisher.w...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits