From e7a3ec43bf74112d11c8869206b926eb2696aa4e Mon Sep 17 00:00:00 2001 From: "James D. Forrester" Date: Wed, 17 Feb 2016 08:18:02 -0800 Subject: [PATCH] build: Update mediawiki-codesniffer to 0.6.0, add "composer fix" Change-Id: Ic96081539c2ae98b5b239b59ca9b0362b337e522 --- ApiVisualEditor.php | 130 +++++++++--------- ApiVisualEditorEdit.php | 52 +++---- VisualEditor.hooks.php | 118 ++++++++-------- VisualEditor.php | 4 +- VisualEditorDataModule.php | 44 +++--- ...alEditorDesktopArticleTargetInitModule.php | 2 +- autodisablePref.php | 18 +-- composer.json | 5 +- 8 files changed, 187 insertions(+), 186 deletions(-) diff --git a/ApiVisualEditor.php b/ApiVisualEditor.php index 795210651c..5f8371d1c0 100644 --- a/ApiVisualEditor.php +++ b/ApiVisualEditor.php @@ -11,9 +11,9 @@ class ApiVisualEditor extends ApiBase { // These are safe even if VE is not enabled on the page. // This is intended for other VE interfaces, such as Flow's. - protected static $SAFE_ACTIONS = array( + protected static $SAFE_ACTIONS = [ 'parsefragment', - ); + ]; /** * @var Config @@ -28,7 +28,7 @@ class ApiVisualEditor extends ApiBase { public function __construct( ApiMain $main, $name, Config $config ) { parent::__construct( $main, $name ); $this->veConfig = $config; - $this->serviceClient = new VirtualRESTServiceClient( new MultiHttpClient( array() ) ); + $this->serviceClient = new VirtualRESTServiceClient( new MultiHttpClient( [] ) ); $this->serviceClient->mount( '/restbase/', $this->getVRSObject() ); } @@ -44,7 +44,7 @@ class ApiVisualEditor extends ApiBase { */ private function getVRSObject() { // the params array to create the service object with - $params = array(); + $params = []; // the VRS class to use, defaults to Parsoid $class = 'ParsoidVirtualRESTService'; $config = $this->veConfig; @@ -61,7 +61,7 @@ class ApiVisualEditor extends ApiBase { $params['restbaseCompat'] = true; } else { // no global modules defined, fall back to old defaults - $params = array( + $params = [ 'URL' => $config->get( 'VisualEditorParsoidURL' ), 'prefix' => $config->get( 'VisualEditorParsoidPrefix' ), 'domain' => $config->get( 'VisualEditorParsoidDomain' ), @@ -69,7 +69,7 @@ class ApiVisualEditor extends ApiBase { 'HTTPProxy' => $config->get( 'VisualEditorParsoidHTTPProxy' ), 'forwardCookies' => $config->get( 'VisualEditorParsoidForwardCookies' ), 'restbaseCompat' => true - ); + ]; } // merge the global and service-specific params if ( isset( $vrs['global'] ) ) { @@ -85,11 +85,11 @@ class ApiVisualEditor extends ApiBase { return new $class( $params ); } - private function requestRestbase( $method, $path, $params, $reqheaders = array() ) { - $request = array( + private function requestRestbase( $method, $path, $params, $reqheaders = [] ) { + $request = [ 'method' => $method, 'url' => '/restbase/local/v1/' . $path - ); + ]; if ( $method === 'GET' ) { $request['query'] = $params; } else { @@ -121,7 +121,7 @@ class ApiVisualEditor extends ApiBase { global $wgMemc; // Convert the VE HTML to wikitext - $text = $this->postHTML( $title, $html, array( 'oldid' => $oldid ), $etag ); + $text = $this->postHTML( $title, $html, [ 'oldid' => $oldid ], $etag ); if ( $text === false ) { return false; } @@ -161,11 +161,11 @@ class ApiVisualEditor extends ApiBase { return $this->requestRestbase( 'POST', $path, - array( + [ 'html' => $html, 'scrub_wikitext' => 1, - ), - array( 'If-Match' => $etag ) + ], + [ 'If-Match' => $etag ] ); } @@ -183,20 +183,20 @@ class ApiVisualEditor extends ApiBase { return $this->requestRestbase( 'POST', 'transform/wikitext/to/html/' . urlencode( $title->getPrefixedDBkey() ), - array( + [ 'wikitext' => $wikitext, 'body_only' => 1, - ) + ] ); } protected function diffWikitext( $title, $wikitext ) { - $apiParams = array( + $apiParams = [ 'action' => 'query', 'prop' => 'revisions', 'titles' => $title->getPrefixedDBkey(), 'rvdifftotext' => $this->pstWikitext( $title, $wikitext ) - ); + ]; $api = new ApiMain( new DerivativeRequest( $this->getRequest(), @@ -207,15 +207,15 @@ class ApiVisualEditor extends ApiBase { ); $api->execute(); if ( defined( 'ApiResult::META_CONTENT' ) ) { - $result = $api->getResult()->getResultData( null, array( - 'BC' => array(), // Transform content nodes to '*' - 'Types' => array(), // Add back-compat subelements - ) ); + $result = $api->getResult()->getResultData( null, [ + 'BC' => [], // Transform content nodes to '*' + 'Types' => [], // Add back-compat subelements + ] ); } else { $result = $api->getResultData(); } if ( !isset( $result['query']['pages'][$title->getArticleID()]['revisions'][0]['diff']['*'] ) ) { - return array( 'result' => 'fail' ); + return [ 'result' => 'fail' ]; } $diffRows = $result['query']['pages'][$title->getArticleID()]['revisions'][0]['diff']['*']; @@ -223,27 +223,27 @@ class ApiVisualEditor extends ApiBase { $context = new DerivativeContext( $this->getContext() ); $context->setTitle( $title ); $engine = new DifferenceEngine( $context ); - return array( + return [ 'result' => 'success', 'diff' => $engine->addHeader( $diffRows, $context->msg( 'currentrev' )->parse(), $context->msg( 'yourtext' )->parse() ) - ); + ]; } else { - return array( 'result' => 'nochanges' ); + return [ 'result' => 'nochanges' ]; } } protected function getLangLinks( $title ) { - $apiParams = array( + $apiParams = [ 'action' => 'query', 'prop' => 'langlinks', 'lllimit' => 500, 'titles' => $title->getPrefixedDBkey(), 'indexpageids' => 1, - ); + ]; $api = new ApiMain( new DerivativeRequest( $this->getRequest(), @@ -255,11 +255,11 @@ class ApiVisualEditor extends ApiBase { $api->execute(); if ( defined( 'ApiResult::META_CONTENT' ) ) { - $result = $api->getResult()->getResultData( null, array( - 'BC' => array(), // Backwards-compatible structure transformations - 'Types' => array(), // Backwards-compatible structure transformations + $result = $api->getResult()->getResultData( null, [ + 'BC' => [], // Backwards-compatible structure transformations + 'Types' => [], // Backwards-compatible structure transformations 'Strip' => 'all', // Remove any metadata keys from the langlinks array - ) ); + ] ); } else { $result = $api->getResultData(); } @@ -295,7 +295,7 @@ class ApiVisualEditor extends ApiBase { $title->getNamespace(), 'novenamespace' ); } - $parserParams = array(); + $parserParams = []; if ( isset( $params['oldid'] ) ) { $parserParams['oldid'] = $params['oldid']; } @@ -346,7 +346,7 @@ class ApiVisualEditor extends ApiBase { $content = $this->requestRestbase( 'GET', 'page/html/' . urlencode( $title->getPrefixedDBkey() ) . '/' . $oldid, - array() + [] ); if ( $content === false ) { $this->dieUsage( 'Error contacting the document server', 'docserver' ); @@ -394,8 +394,8 @@ class ApiVisualEditor extends ApiBase { } // Look at protection status to set up notices + surface class(es) - $protectedClasses = array(); - if ( MWNamespace::getRestrictionLevels( $title->getNamespace() ) !== array( '' ) ) { + $protectedClasses = []; + if ( MWNamespace::getRestrictionLevels( $title->getNamespace() ) !== [ '' ] ) { // Page protected from editing if ( $title->isProtected( 'edit' ) ) { # Is the title semi-protected? @@ -434,7 +434,7 @@ class ApiVisualEditor extends ApiBase { if ( $permErrors && !$title->exists() ) { $notices[] = $this->msg( 'permissionserrorstext-withaction', 1, $this->msg( 'action-createpage' ) - ) . "
" . call_user_func_array( array( $this, 'msg' ), $permErrors[0] )->parse(); + ) . "
" . call_user_func_array( [ $this, 'msg' ], $permErrors[0] )->parse(); } // Show notice when editing user / user talk page of a user that doesn't exist @@ -463,7 +463,7 @@ class ApiVisualEditor extends ApiBase { // Blocked user notice if ( $user->isBlockedFrom( $title ) && $user->getBlock()->prevents( 'edit' ) !== false ) { $notices[] = call_user_func_array( - array( $this, 'msg' ), + [ $this, 'msg' ], $user->getBlock()->getPermissionsError( $this->getContext() ) )->parseAsBlock(); } @@ -476,7 +476,7 @@ class ApiVisualEditor extends ApiBase { ); if ( count( $error ) ) { $notices[] = call_user_func_array( - array( $this, 'msg' ), + [ $this, 'msg' ], $error )->parseAsBlock(); } @@ -489,24 +489,24 @@ class ApiVisualEditor extends ApiBase { $req->setVal( 'format', 'text/x-wiki' ); $ep->importFormData( $req ); // By reference for some reason (bug 52466) $tabindex = 0; - $states = array( 'minor' => false, 'watch' => false ); + $states = [ 'minor' => false, 'watch' => false ]; $checkboxes = $ep->getCheckboxes( $tabindex, $states ); // HACK: Find out which red links are on the page // We do the lookup for the current version. This might not be entirely complete // if we're loading an oldid, but it'll probably be close enough, and LinkCache // will automatically request any additional data it needs. - $links = array(); + $links = []; $wikipage = WikiPage::factory( $title ); $popts = $wikipage->makeParserOptions( 'canonical' ); $cached = ParserCache::singleton()->get( $article, $popts, true ); - $links = array( + $links = [ // Array of linked pages that are missing - 'missing' => array(), + 'missing' => [], // For current revisions: 1 (treat all non-missing pages as known) // For old revisions: array of linked pages that are known - 'known' => $restoring || !$cached ? array() : 1, - ); + 'known' => $restoring || !$cached ? [] : 1, + ]; if ( $cached ) { foreach ( $cached->getLinks() as $namespace => $cachedTitles ) { foreach ( $cachedTitles as $cachedTitleText => $exists ) { @@ -528,7 +528,7 @@ class ApiVisualEditor extends ApiBase { // On parser cache miss, just don't bother populating red link data - $result = array( + $result = [ 'result' => 'success', 'notices' => $notices, 'checkboxes' => $checkboxes, @@ -539,7 +539,7 @@ class ApiVisualEditor extends ApiBase { 'starttimestamp' => wfTimestampNow(), 'oldid' => $oldid, - ); + ]; if ( $params['paction'] === 'parse' ) { $result['content'] = $content; } @@ -554,10 +554,10 @@ class ApiVisualEditor extends ApiBase { if ( $content === false ) { $this->dieUsage( 'Error contacting the document server', 'docserver' ); } else { - $result = array( + $result = [ 'result' => 'success', 'content' => $content - ); + ]; } break; @@ -576,7 +576,7 @@ class ApiVisualEditor extends ApiBase { $this->dieUsage( 'Error contacting the document server', 'docserver' ); } } - $result = array( 'result' => 'success', 'content' => $content ); + $result = [ 'result' => 'success', 'content' => $content ]; break; case 'diff': @@ -610,7 +610,7 @@ class ApiVisualEditor extends ApiBase { $html, $params['etag'] ); - $result = array( 'result' => 'success', 'cachekey' => $key ); + $result = [ 'result' => 'success', 'cachekey' => $key ]; break; case 'getlanglinks': @@ -618,7 +618,7 @@ class ApiVisualEditor extends ApiBase { if ( $langlinks === false ) { $this->dieUsage( 'Error querying MediaWiki API', 'api-langlinks-error' ); } else { - $result = array( 'result' => 'success', 'langlinks' => $langlinks ); + $result = [ 'result' => 'success', 'langlinks' => $langlinks ]; } break; } @@ -645,26 +645,26 @@ class ApiVisualEditor extends ApiBase { return $lp->getBody() . Linker::link( SpecialPage::getTitleFor( 'Log' ), $this->msg( 'log-fulllog' )->escaped(), - array(), - array( + [], + [ 'page' => $title->getPrefixedDBkey(), 'type' => is_string( $types ) ? $types : null - ) + ] ); } public function getAllowedParams() { - return array( - 'page' => array( + return [ + 'page' => [ ApiBase::PARAM_REQUIRED => true, - ), - 'format' => array( + ], + 'format' => [ ApiBase::PARAM_DFLT => 'jsonfm', - ApiBase::PARAM_TYPE => array( 'json', 'jsonfm' ), - ), - 'paction' => array( + ApiBase::PARAM_TYPE => [ 'json', 'jsonfm' ], + ], + 'paction' => [ ApiBase::PARAM_REQUIRED => true, - ApiBase::PARAM_TYPE => array( + ApiBase::PARAM_TYPE => [ 'parse', 'metadata', 'parsefragment', @@ -672,15 +672,15 @@ class ApiVisualEditor extends ApiBase { 'serializeforcache', 'diff', 'getlanglinks', - ), - ), + ], + ], 'wikitext' => null, 'oldid' => null, 'html' => null, 'etag' => null, 'cachekey' => null, 'pst' => false, - ); + ]; } public function needsToken() { diff --git a/ApiVisualEditorEdit.php b/ApiVisualEditorEdit.php index dc4eb10683..b6c1c816f8 100644 --- a/ApiVisualEditorEdit.php +++ b/ApiVisualEditorEdit.php @@ -15,7 +15,7 @@ class ApiVisualEditorEdit extends ApiVisualEditor { } protected function saveWikitext( $title, $wikitext, $params ) { - $apiParams = array( + $apiParams = [ 'action' => 'edit', 'title' => $title->getPrefixedDBkey(), 'text' => $wikitext, @@ -23,7 +23,7 @@ class ApiVisualEditorEdit extends ApiVisualEditor { 'basetimestamp' => $params['basetimestamp'], 'starttimestamp' => $params['starttimestamp'], 'token' => $params['token'], - ); + ]; if ( $params['minor'] ) { $apiParams['minor'] = true; @@ -61,12 +61,12 @@ class ApiVisualEditorEdit extends ApiVisualEditor { } protected function parseWikitext( $title, $newRevId ) { - $apiParams = array( + $apiParams = [ 'action' => 'parse', 'page' => $title->getPrefixedDBkey(), 'oldid' => $newRevId, 'prop' => 'text|revid|categorieshtml|displaytitle|modules|jsconfigvars', - ); + ]; $api = new ApiMain( new DerivativeRequest( $this->getRequest(), @@ -78,25 +78,25 @@ class ApiVisualEditorEdit extends ApiVisualEditor { $api->execute(); if ( defined( 'ApiResult::META_CONTENT' ) ) { - $result = $api->getResult()->getResultData( null, array( - 'BC' => array(), // Transform content nodes to '*' - 'Types' => array(), // Add back-compat subelements + $result = $api->getResult()->getResultData( null, [ + 'BC' => [], // Transform content nodes to '*' + 'Types' => [], // Add back-compat subelements 'Strip' => 'all', // Remove any metadata keys from the links array - ) ); + ] ); } else { $result = $api->getResultData(); } $content = isset( $result['parse']['text']['*'] ) ? $result['parse']['text']['*'] : false; $categorieshtml = isset( $result['parse']['categorieshtml']['*'] ) ? $result['parse']['categorieshtml']['*'] : false; - $links = isset( $result['parse']['links'] ) ? $result['parse']['links'] : array(); + $links = isset( $result['parse']['links'] ) ? $result['parse']['links'] : []; $revision = Revision::newFromId( $result['parse']['revid'] ); $timestamp = $revision ? $revision->getTimestamp() : wfTimestampNow(); $displaytitle = isset( $result['parse']['displaytitle'] ) ? $result['parse']['displaytitle'] : false; - $modules = isset( $result['parse']['modules'] ) ? $result['parse']['modules'] : array(); + $modules = isset( $result['parse']['modules'] ) ? $result['parse']['modules'] : []; $jsconfigvars = isset( $result['parse']['jsconfigvars'] ) ? - $result['parse']['jsconfigvars'] : array(); + $result['parse']['jsconfigvars'] : []; if ( $content === false || ( strlen( $content ) && $revision === null ) ) { return false; @@ -108,7 +108,7 @@ class ApiVisualEditorEdit extends ApiVisualEditor { Sanitizer::removeHTMLtags( $displaytitle ) ); } - return array( + return [ 'content' => $content, 'categorieshtml' => $categorieshtml, 'basetimestamp' => $timestamp, @@ -116,7 +116,7 @@ class ApiVisualEditorEdit extends ApiVisualEditor { 'displayTitleHtml' => $displaytitle, 'modules' => $modules, 'jsconfigvars' => $jsconfigvars - ); + ]; } public function execute() { @@ -133,7 +133,7 @@ class ApiVisualEditorEdit extends ApiVisualEditor { $page->getNamespace(), 'novenamespace' ); } - $parserParams = array(); + $parserParams = []; if ( isset( $params['oldid'] ) ) { $parserParams['oldid'] = $params['oldid']; } @@ -160,10 +160,10 @@ class ApiVisualEditorEdit extends ApiVisualEditor { // Error if ( $editStatus !== 'Success' ) { - $result = array( + $result = [ 'result' => 'error', 'edit' => $saveresult['edit'] - ); + ]; if ( isset( $saveresult['edit']['spamblacklist'] ) ) { $matches = explode( '|', $saveresult['edit']['spamblacklist'] ); @@ -202,11 +202,11 @@ class ApiVisualEditorEdit extends ApiVisualEditor { // Defeat !$this->isPageView( $request ) || $request->getVal( 'oldid' ) check in setPageContent $view->getContext()->setRequest( new DerivativeRequest( $this->getRequest(), - array( + [ 'diff' => null, 'oldid' => '', 'action' => 'view' - ) + $this->getRequest()->getValues() + ] + $this->getRequest()->getValues() ) ); // The two parameters here are references but we don't care @@ -222,10 +222,10 @@ class ApiVisualEditorEdit extends ApiVisualEditor { if ( isset( $saveresult['edit']['newtimestamp'] ) ) { $ts = $saveresult['edit']['newtimestamp']; - $result['lastModified'] = array( + $result['lastModified'] = [ 'date' => $lang->userDate( $ts, $user ), 'time' => $lang->userTime( $ts, $user ) - ); + ]; } if ( isset( $saveresult['edit']['newrevid'] ) ) { @@ -239,13 +239,13 @@ class ApiVisualEditorEdit extends ApiVisualEditor { } public function getAllowedParams() { - return array( - 'page' => array( + return [ + 'page' => [ ApiBase::PARAM_REQUIRED => true, - ), - 'token' => array( + ], + 'token' => [ ApiBase::PARAM_REQUIRED => true, - ), + ], 'wikitext' => null, 'basetimestamp' => null, 'starttimestamp' => null, @@ -258,7 +258,7 @@ class ApiVisualEditorEdit extends ApiVisualEditor { 'captchaid' => null, 'captchaword' => null, 'cachekey' => null, - ); + ]; } public function needsToken() { diff --git a/VisualEditor.hooks.php b/VisualEditor.hooks.php index 9f46b18ea7..753f969d60 100644 --- a/VisualEditor.hooks.php +++ b/VisualEditor.hooks.php @@ -30,7 +30,6 @@ class VisualEditorHooks { return new $class( $main, $name, $config ); } - /** * Adds VisualEditor JS to the output. * @@ -41,11 +40,11 @@ class VisualEditorHooks { * @return boolean */ public static function onBeforePageDisplay( OutputPage &$output, Skin &$skin ) { - $output->addModules( array( + $output->addModules( [ 'ext.visualEditor.desktopArticleTarget.init', 'ext.visualEditor.targetLoader' - ) ); - $output->addModuleStyles( array( 'ext.visualEditor.desktopArticleTarget.noscript' ) ); + ] ); + $output->addModuleStyles( [ 'ext.visualEditor.desktopArticleTarget.noscript' ] ); // add scroll offset js variable to output $veConfig = ConfigFactory::getDefaultInstance()->makeConfig( 'visualeditor' ); $skinsToolbarScrollOffset = $veConfig->get( 'VisualEditorSkinToolbarScrollOffset' ); @@ -79,7 +78,7 @@ class VisualEditorHooks { return true; } - $matches = array(); + $matches = []; $ret = preg_match( '/' . $uaSubstr . '\/([0-9\.]*) ?/i', $ua, $matches ); if ( $ret !== 1 ) { continue; @@ -131,7 +130,7 @@ class VisualEditorHooks { $params = $req->getValues(); if ( isset( $params['venoscript'] ) ) { - $req->response()->setCookie( 'VEE', 'wikitext', 0, array( 'prefix' => '' ) ); + $req->response()->setCookie( 'VEE', 'wikitext', 0, [ 'prefix' => '' ] ); $user->setOption( 'visualeditor-editor', 'wikitext' ); $user->saveSettings(); return true; @@ -248,14 +247,14 @@ class VisualEditorHooks { $dbr->select( 'revision', '1', - array( + [ 'rev_user' => $user->getId(), 'rev_timestamp < ' . $dbr->addQuotes( $config->get( 'VisualEditorSingleEditTabSwitchTime' ) ) - ), + ], __METHOD__, - array( 'LIMIT' => 1 ) + [ 'LIMIT' => 1 ] )->numRows() === 1 ) { $links['views']['edit']['class'] .= ' visualeditor-showtabdialog'; @@ -292,7 +291,7 @@ class VisualEditorHooks { // Rebuild the $links['views'] array and inject the VisualEditor tab before or after // the edit tab as appropriate. We have to rebuild the array because PHP doesn't allow // us to splice into the middle of an associative array. - $newViews = array(); + $newViews = []; foreach ( $links['views'] as $action => $data ) { if ( $action === 'edit' ) { // Build the VisualEditor tab @@ -307,12 +306,12 @@ class VisualEditorHooks { $veTabMessage = $tabMessages[$action]; $veTabText = $veTabMessage === null ? $data['text'] : $skin->msg( $veTabMessage )->text(); - $veTab = array( + $veTab = [ 'href' => $title->getLocalURL( $veParams ), 'text' => $veTabText, 'primary' => true, 'class' => '', - ); + ]; // Alter the edit tab $editTab = $data; @@ -395,7 +394,7 @@ class VisualEditorHooks { public static function onEditPageShowEditFormFields( EditPage $editPage, OutputPage $output ) { $request = $output->getRequest(); if ( $request->getBool( 'veswitched' ) ) { - $output->addHTML( Xml::input( 'veswitched', false, '1', array( 'type' => 'hidden' ) ) ); + $output->addHTML( Xml::input( 'veswitched', false, '1', [ 'type' => 'hidden' ] ) ); } return true; } @@ -478,15 +477,15 @@ class VisualEditorHooks { if ( $title->inNamespaces( array_keys( array_filter( $availableNamespaces ) ) ) ) { $veEditSection = $tabMessages['editsection'] !== null ? $tabMessages['editsection'] : 'editsection'; - $veLink = array( + $veLink = [ 'text' => $skin->msg( $veEditSection )->inLanguage( $lang )->text(), 'targetTitle' => $title, - 'attribs' => $result['editsection']['attribs'] + array( + 'attribs' => $result['editsection']['attribs'] + [ 'class' => 'mw-editsection-visualeditor' - ), - 'query' => array( 'veaction' => 'edit', 'vesection' => $section ), - 'options' => array( 'noclasses', 'known' ) - ); + ], + 'query' => [ 'veaction' => 'edit', 'vesection' => $section ], + 'options' => [ 'noclasses', 'known' ] + ]; $result['veeditsection'] = $veLink; if ( $config->get( 'VisualEditorTabPosition' ) === 'before' ) { @@ -522,30 +521,30 @@ class VisualEditorHooks { ->get( 'VisualEditorAvailableNamespaces' ); $onNamespaces = array_keys( array_filter( $namespaces ) ); - $enablePreference = array( + $enablePreference = [ 'type' => 'toggle', - 'label-message' => array( + 'label-message' => [ 'visualeditor-preference-enable', $wgLang->commaList( array_map( - array( 'self', 'convertNs' ), + [ 'self', 'convertNs' ], $onNamespaces ) ), count( $onNamespaces ) - ), + ], 'section' => 'editing/editor' - ); + ]; if ( $user->getOption( 'visualeditor-autodisable' ) ) { $enablePreference['default'] = false; } $preferences['visualeditor-enable'] = $enablePreference; } - $preferences['visualeditor-betatempdisable'] = array( + $preferences['visualeditor-betatempdisable'] = [ 'type' => 'toggle', 'label-message' => 'visualeditor-preference-betatempdisable', 'section' => 'editing/editor', 'default' => $user->getOption( 'visualeditor-betatempdisable' ) || $user->getOption( 'visualeditor-autodisable' ) - ); + ]; $config = ConfigFactory::getDefaultInstance()->makeConfig( 'visualeditor' ); if ( @@ -553,20 +552,20 @@ class VisualEditorHooks { !$user->getOption( 'visualeditor-autodisable' ) && !$user->getOption( 'visualeditor-betatempdisable' ) ) { - $preferences['visualeditor-tabs'] = array( + $preferences['visualeditor-tabs'] = [ 'type' => 'select', 'label-message' => 'visualeditor-preference-tabs', 'section' => 'editing/editor', - 'options' => array( + 'options' => [ wfMessage( 'visualeditor-preference-tabs-remember-last' )->escaped() => 'remember-last', wfMessage( 'visualeditor-preference-tabs-prefer-ve' )->escaped() => 'prefer-ve', wfMessage( 'visualeditor-preference-tabs-prefer-wt' )->escaped() => 'prefer-wt', wfMessage( 'visualeditor-preference-tabs-multi-tab' )->escaped() => 'multi-tab' - ) - ); + ] + ]; } - $api = array( 'type' => 'api' ); + $api = [ 'type' => 'api' ]; $preferences['visualeditor-autodisable'] = $api; $preferences['visualeditor-editor'] = $api; $preferences['visualeditor-hidebetawelcome'] = $api; @@ -586,22 +585,22 @@ class VisualEditorHooks { $iconpath = $coreConfig->get( 'ExtensionAssetsPath' ) . "/VisualEditor"; $veConfig = ConfigFactory::getDefaultInstance()->makeConfig( 'visualeditor' ); - $preferences['visualeditor-enable'] = array( + $preferences['visualeditor-enable'] = [ 'version' => '1.0', 'label-message' => 'visualeditor-preference-core-label', 'desc-message' => 'visualeditor-preference-core-description', - 'screenshot' => array( + 'screenshot' => [ 'ltr' => "$iconpath/betafeatures-icon-VisualEditor-ltr.svg", 'rtl' => "$iconpath/betafeatures-icon-VisualEditor-rtl.svg", - ), + ], 'info-message' => 'visualeditor-preference-core-info-link', 'discussion-message' => 'visualeditor-preference-core-discussion-link', - 'requirements' => array( + 'requirements' => [ 'javascript' => true, 'blacklist' => $veConfig->get( 'VisualEditorBrowserBlacklist' ), 'skins' => $veConfig->get( 'VisualEditorSupportedSkins' ), - ) - ); + ] + ]; } /** @@ -656,12 +655,12 @@ class VisualEditorHooks { public static function onMakeGlobalVariablesScript( array &$vars, OutputPage $out ) { $pageLanguage = $out->getTitle()->getPageLanguage(); - $vars['wgVisualEditor'] = array( + $vars['wgVisualEditor'] = [ 'pageLanguageCode' => $pageLanguage->getHtmlCode(), 'pageLanguageDir' => $pageLanguage->getDir(), 'usePageImages' => defined( 'PAGE_IMAGES_INSTALLED' ), 'usePageDescriptions' => defined( 'WBC_VERSION' ), - ); + ]; return true; } @@ -677,7 +676,7 @@ class VisualEditorHooks { $availableNamespaces = $veConfig->get( 'VisualEditorAvailableNamespaces' ); $enabledNamespaces = array_keys( array_filter( $availableNamespaces ) ); - $vars['wgVisualEditorConfig'] = array( + $vars['wgVisualEditorConfig'] = [ 'disableForAnons' => $veConfig->get( 'VisualEditorDisableForAnons' ), 'preferenceModules' => $veConfig->get( 'VisualEditorPreferenceModules' ), 'namespaces' => $enabledNamespaces, @@ -688,9 +687,9 @@ class VisualEditorHooks { ExtensionRegistry::getInstance()->getAttribute( 'VisualEditorPluginModules' ), $veConfig->get( 'VisualEditorPluginModules' ) // @todo deprecate the global setting ), - 'defaultUserOptions' => array( + 'defaultUserOptions' => [ 'defaultthumbsize' => $thumbLimits[ $defaultUserOptions['thumbsize'] ] - ), + ], 'blacklist' => $veConfig->get( 'VisualEditorBrowserBlacklist' ), 'skins' => $veConfig->get( 'VisualEditorSupportedSkins' ), 'tabPosition' => $veConfig->get( 'VisualEditorTabPosition' ), @@ -705,7 +704,7 @@ class VisualEditorHooks { 'fullRestbaseUrl' => $coreConfig->get( 'VisualEditorFullRestbaseURL' ), 'feedbackApiUrl' => $veConfig->get( 'VisualEditorFeedbackAPIURL' ), 'feedbackTitle' => $veConfig->get( 'VisualEditorFeedbackTitle' ), - ); + ]; return true; } @@ -720,10 +719,10 @@ class VisualEditorHooks { public static function onResourceLoaderRegisterModules( ResourceLoader &$resourceLoader ) { $resourceModules = $resourceLoader->getConfig()->get( 'ResourceModules' ); - $veResourceTemplate = array( + $veResourceTemplate = [ 'localBasePath' => __DIR__, 'remoteExtPath' => 'VisualEditor', - ); + ]; // Only pull in VisualEditor core's local version of jquery.uls.data if it hasn't been // installed locally already (presumably, by the UniversalLanguageSelector extension). @@ -731,14 +730,14 @@ class VisualEditorHooks { !isset( $resourceModules[ 'jquery.uls.data' ] ) && !$resourceLoader->isModuleRegistered( 'jquery.uls.data' ) ) { - $resourceLoader->register( array( - 'jquery.uls.data' => $veResourceTemplate + array( - 'scripts' => array( + $resourceLoader->register( [ + 'jquery.uls.data' => $veResourceTemplate + [ + 'scripts' => [ 'lib/ve/lib/jquery.uls/src/jquery.uls.data.js', 'lib/ve/lib/jquery.uls/src/jquery.uls.data.utils.js', - ), - 'targets' => array( 'desktop', 'mobile' ), - ) ) ); + ], + 'targets' => [ 'desktop', 'mobile' ], + ] ] ); } return true; @@ -748,12 +747,12 @@ class VisualEditorHooks { array &$testModules, ResourceLoader &$resourceLoader ) { - $testModules['qunit']['ext.visualEditor.test'] = array( - 'styles' => array( + $testModules['qunit']['ext.visualEditor.test'] = [ + 'styles' => [ // jsdifflib 'lib/ve/lib/jsdifflib/diffview.css', - ), - 'scripts' => array( + ], + 'scripts' => [ // MW config preload 'modules/ve-mw/tests/mw-preload.js', // jsdifflib @@ -865,8 +864,8 @@ class VisualEditorHooks { 'lib/ve/tests/ce/imetests/leftarrow-chromium-ubuntu-none.js', 'lib/ve/tests/ce/imetests/leftarrow-firefox-ubuntu-none.js', 'lib/ve/tests/ce/imetests/leftarrow-ie9-win7-none.js', - ), - 'dependencies' => array( + ], + 'dependencies' => [ 'unicodejs', 'ext.visualEditor.standalone', 'ext.visualEditor.core', @@ -881,10 +880,10 @@ class VisualEditorHooks { 'ext.visualEditor.experimental', 'ext.visualEditor.desktopArticleTarget.init', 'ext.visualEditor.desktopArticleTarget', - ), + ], 'localBasePath' => __DIR__, 'remoteExtPath' => 'VisualEditor', - ); + ]; return true; } @@ -966,5 +965,4 @@ class VisualEditorHooks { return true; } - } diff --git a/VisualEditor.php b/VisualEditor.php index 79b4cef5d1..0f6c3844a2 100644 --- a/VisualEditor.php +++ b/VisualEditor.php @@ -16,11 +16,11 @@ if ( function_exists( 'wfLoadExtension' ) ) { wfLoadExtension( 'VisualEditor' ); // Keep i18n globals so mergeMessageFileList.php doesn't break - $wgMessagesDirs['VisualEditor'] = array( + $wgMessagesDirs['VisualEditor'] = [ __DIR__ . '/lib/ve/i18n', __DIR__ . '/modules/ve-mw/i18n', __DIR__ . '/modules/ve-wmf/i18n' - ); + ]; /* wfWarn( 'Deprecated PHP entry point used for VisualEditor extension. Please use wfLoadExtension '. diff --git a/VisualEditorDataModule.php b/VisualEditorDataModule.php index 66a12ddb60..21e7e3a614 100644 --- a/VisualEditorDataModule.php +++ b/VisualEditorDataModule.php @@ -13,7 +13,7 @@ class VisualEditorDataModule extends ResourceLoaderModule { /* Protected Members */ protected $origin = self::ORIGIN_USER_SITEWIDE; - protected $targets = array( 'desktop', 'mobile' ); + protected $targets = [ 'desktop', 'mobile' ]; /* Methods */ @@ -23,8 +23,8 @@ class VisualEditorDataModule extends ResourceLoaderModule { public function getScript( ResourceLoaderContext $context ) { // Messages $msgInfo = $this->getMessageInfo(); - $parsedMessages = array(); - $messages = array(); + $parsedMessages = []; + $messages = []; foreach ( $msgInfo['args'] as $msgKey => $msgArgs ) { $parsedMessages[ $msgKey ] = call_user_func_array( 'wfMessage', $msgArgs ) ->inLanguage( $context->getLanguage() ) @@ -47,44 +47,44 @@ class VisualEditorDataModule extends ResourceLoaderModule { protected function getMessageInfo() { // Messages that just require simple parsing - $msgArgs = array( - 'minoredit' => array( 'minoredit' ), - 'missingsummary' => array( 'missingsummary' ), - 'summary' => array( 'summary' ), - 'watchthis' => array( 'watchthis' ), - 'visualeditor-browserwarning' => array( 'visualeditor-browserwarning' ), - 'visualeditor-wikitext-warning' => array( 'visualeditor-wikitext-warning' ), - ); + $msgArgs = [ + 'minoredit' => [ 'minoredit' ], + 'missingsummary' => [ 'missingsummary' ], + 'summary' => [ 'summary' ], + 'watchthis' => [ 'watchthis' ], + 'visualeditor-browserwarning' => [ 'visualeditor-browserwarning' ], + 'visualeditor-wikitext-warning' => [ 'visualeditor-wikitext-warning' ], + ]; // Override message value - $msgVals = array( + $msgVals = [ 'visualeditor-feedback-link' => wfMessage( 'visualeditor-feedback-link' ) ->inContentLanguage() ->text(), - ); + ]; // Copyright warning (based on EditPage::getCopyrightWarning) $rightsText = $this->config->get( 'RightsText' ); if ( $rightsText ) { - $copywarnMsg = array( 'copyrightwarning', + $copywarnMsg = [ 'copyrightwarning', '[[' . wfMessage( 'copyrightpage' )->inContentLanguage()->text() . ']]', - $rightsText ); + $rightsText ]; } else { - $copywarnMsg = array( 'copyrightwarning2', - '[[' . wfMessage( 'copyrightpage' )->inContentLanguage()->text() . ']]' ); + $copywarnMsg = [ 'copyrightwarning2', + '[[' . wfMessage( 'copyrightpage' )->inContentLanguage()->text() . ']]' ]; } // EditPage supports customisation based on title, we can't support that here // since these messages are cached on a site-level. $wgTitle is likely set to null. $title = Title::newFromText( 'Dwimmerlaik' ); - Hooks::run( 'EditPageCopyrightWarning', array( $title, &$copywarnMsg ) ); + Hooks::run( 'EditPageCopyrightWarning', [ $title, &$copywarnMsg ] ); // Normalise to 'copyrightwarning' so we have a consistent key in the front-end. $msgArgs[ 'copyrightwarning' ] = $copywarnMsg; - return array( + return [ 'args' => $msgArgs, 'vals' => $msgVals, - ); + ]; } public function enableModuleContentVersion() { @@ -92,9 +92,9 @@ class VisualEditorDataModule extends ResourceLoaderModule { } public function getDependencies( ResourceLoaderContext $context = null ) { - return array( + return [ 'ext.visualEditor.base', 'ext.visualEditor.mediawiki', - ); + ]; } } diff --git a/VisualEditorDesktopArticleTargetInitModule.php b/VisualEditorDesktopArticleTargetInitModule.php index d1156834b1..aa3838aafa 100644 --- a/VisualEditorDesktopArticleTargetInitModule.php +++ b/VisualEditorDesktopArticleTargetInitModule.php @@ -13,7 +13,7 @@ class VisualEditorDesktopArticleTargetInitModule extends ResourceLoaderFileModule { public function __construct( - $options = array(), + $options = [], $localBasePath = null, $remoteBasePath = null ) { diff --git a/autodisablePref.php b/autodisablePref.php index 046cd6eb3a..618b04e914 100644 --- a/autodisablePref.php +++ b/autodisablePref.php @@ -27,24 +27,24 @@ class VEAutodisablePref extends Maintenance { $lastUserId = -1; do { $results = $dbr->select( - array( 'user', 'user_properties' ), + [ 'user', 'user_properties' ], 'user_id', - array( + [ 'user_id > ' . $dbr->addQuotes( $lastUserId ), 'up_value IS NULL', // only select users with no entry in user_properties 'user_editcount > 0' - ), + ], __METHOD__, - array( + [ 'LIMIT' => $this->mBatchSize, 'ORDER BY' => 'user_id' - ), - array( - 'user_properties' => array( + ], + [ + 'user_properties' => [ 'LEFT OUTER JOIN', 'user_id = up_user and up_property = "visualeditor-enable"' - ) - ) + ] + ] ); foreach ( $results as $userRow ) { $user = User::newFromId( $userRow->user_id ); diff --git a/composer.json b/composer.json index 083767bafe..99102588ba 100644 --- a/composer.json +++ b/composer.json @@ -1,12 +1,15 @@ { "require-dev": { "jakub-onderka/php-parallel-lint": "0.9.2", - "mediawiki/mediawiki-codesniffer": "0.5.1" + "mediawiki/mediawiki-codesniffer": "0.6.0" }, "scripts": { "test": [ "parallel-lint . --exclude vendor", "phpcs -p -s" + ], + "fix": [ + "phpcbf" ] } }