From 8e4bff8976685f018b9bc0f62158c38a3f8d971e Mon Sep 17 00:00:00 2001 From: Umherirrender Date: Tue, 30 May 2017 20:21:54 +0200 Subject: [PATCH] Add phpcs and make pass Change-Id: I52845fc95b53eca5149a947dfc6a1b39100da97b --- ApiCategoryTree.php | 5 +-- CategoryTree.hooks.php | 39 ++++++++++++++-------- CategoryTree.i18n.magic.php | 3 +- CategoryTree.i18n.php | 2 +- CategoryTree.php | 3 +- CategoryTreeFunctions.php | 64 +++++++++++++++++++++++++------------ CategoryTreePage.php | 7 ++-- composer.json | 7 ++-- phpcs.xml | 9 ++++++ 9 files changed, 95 insertions(+), 44 deletions(-) create mode 100644 phpcs.xml diff --git a/ApiCategoryTree.php b/ApiCategoryTree.php index 14627875..d1243d31 100644 --- a/ApiCategoryTree.php +++ b/ApiCategoryTree.php @@ -38,8 +38,9 @@ class ApiCategoryTree extends ApiBase { } else { $this->getMain()->setCacheMaxAge( $config->get( 'SquidMaxage' ) ); } - $this->getRequest()->response()->header( 'Vary: Accept-Encoding, Cookie' ); # cache for anons only - # TODO: purge the squid cache when a category page is invalidated + // cache for anons only + $this->getRequest()->response()->header( 'Vary: Accept-Encoding, Cookie' ); + // TODO: purge the squid cache when a category page is invalidated } $this->getResult()->addContentValue( $this->getModuleName(), 'html', $html ); diff --git a/CategoryTree.hooks.php b/CategoryTree.hooks.php index e1ce466c..074965d0 100644 --- a/CategoryTree.hooks.php +++ b/CategoryTree.hooks.php @@ -17,9 +17,10 @@ class CategoryTreeHooks { */ public static function initialize() { global $wgUseAjax, $wgHooks, $wgRequest; - global $wgCategoryTreeDefaultOptions, $wgCategoryTreeDefaultMode, $wgCategoryTreeOmitNamespace; - global $wgCategoryTreeCategoryPageOptions, $wgCategoryTreeCategoryPageMode, $wgCategoryTreeAllowTag; - global $wgCategoryTreeSidebarRoot, $wgCategoryTreeForceHeaders, $wgCategoryTreeHijackPageCategories; + global $wgCategoryTreeDefaultOptions, $wgCategoryTreeDefaultMode, $wgCategoryTreeAllowTag; + global $wgCategoryTreeCategoryPageOptions, $wgCategoryTreeCategoryPageMode; + global $wgCategoryTreeSidebarRoot, $wgCategoryTreeForceHeaders; + global $wgCategoryTreeHijackPageCategories, $wgCategoryTreeOmitNamespace; # Abort if AJAX is not enabled if ( !$wgUseAjax ) { @@ -29,7 +30,8 @@ class CategoryTreeHooks { if ( $wgCategoryTreeSidebarRoot ) { $wgCategoryTreeForceHeaders = true; # needed on every page anyway - $wgHooks['SkinTemplateOutputPageBeforeExec'][] = 'CategoryTreeHooks::skinTemplateOutputPageBeforeExec'; + $wgHooks['SkinTemplateOutputPageBeforeExec'][] = + 'CategoryTreeHooks::skinTemplateOutputPageBeforeExec'; } if ( $wgCategoryTreeHijackPageCategories ) { @@ -42,16 +44,23 @@ class CategoryTreeHooks { $wgHooks['ParserFirstCallInit'][] = 'CategoryTreeHooks::setHooks'; } - if ( !isset( $wgCategoryTreeDefaultOptions['mode'] ) || is_null( $wgCategoryTreeDefaultOptions['mode'] ) ) { + if ( !isset( $wgCategoryTreeDefaultOptions['mode'] ) + || is_null( $wgCategoryTreeDefaultOptions['mode'] ) + ) { $wgCategoryTreeDefaultOptions['mode'] = $wgCategoryTreeDefaultMode; } - if ( !isset( $wgCategoryTreeDefaultOptions['hideprefix'] ) || is_null( $wgCategoryTreeDefaultOptions['hideprefix'] ) ) { + if ( !isset( $wgCategoryTreeDefaultOptions['hideprefix'] ) + || is_null( $wgCategoryTreeDefaultOptions['hideprefix'] ) + ) { $wgCategoryTreeDefaultOptions['hideprefix'] = $wgCategoryTreeOmitNamespace; } - if ( !isset( $wgCategoryTreeCategoryPageOptions['mode'] ) || is_null( $wgCategoryTreeCategoryPageOptions['mode'] ) ) { - $wgCategoryTreeCategoryPageOptions['mode'] = ( $mode = $wgRequest->getVal( 'mode' ) ) ? CategoryTree::decodeMode( $mode ) : $wgCategoryTreeCategoryPageMode; + if ( !isset( $wgCategoryTreeCategoryPageOptions['mode'] ) + || is_null( $wgCategoryTreeCategoryPageOptions['mode'] ) + ) { + $wgCategoryTreeCategoryPageOptions['mode'] = ( $mode = $wgRequest->getVal( 'mode' ) ) + ? CategoryTree::decodeMode( $mode ) : $wgCategoryTreeCategoryPageMode; } if ( $wgCategoryTreeForceHeaders ) { @@ -68,8 +77,8 @@ class CategoryTreeHooks { * @return bool */ public static function setHooks( $parser ) { - $parser->setHook( 'categorytree' , 'CategoryTreeHooks::parserHook' ); - $parser->setFunctionHook( 'categorytree' , 'CategoryTreeHooks::parserFunction' ); + $parser->setHook( 'categorytree', 'CategoryTreeHooks::parserHook' ); + $parser->setFunctionHook( 'categorytree', 'CategoryTreeHooks::parserFunction' ); return true; } @@ -148,9 +157,11 @@ class CategoryTreeHooks { $attr = Sanitizer::validateTagAttributes( $argv, 'div' ); - $hideroot = isset( $argv[ 'hideroot' ] ) ? CategoryTree::decodeBoolean( $argv[ 'hideroot' ] ) : null; - $onlyroot = isset( $argv[ 'onlyroot' ] ) ? CategoryTree::decodeBoolean( $argv[ 'onlyroot' ] ) : null; - $depthArg = isset( $argv[ 'depth' ] ) ? (int)$argv[ 'depth' ] : null; + $hideroot = isset( $argv['hideroot'] ) + ? CategoryTree::decodeBoolean( $argv['hideroot'] ) : null; + $onlyroot = isset( $argv['onlyroot'] ) + ? CategoryTree::decodeBoolean( $argv['onlyroot'] ) : null; + $depthArg = isset( $argv['depth'] ) ? (int)$argv['depth'] : null; $depth = CategoryTree::capDepth( $ct->getOption( 'mode' ), $depthArg ); if ( $onlyroot ) { @@ -230,7 +241,7 @@ class CategoryTreeHooks { $pop = ''; $sep = ' '; - $result = $embed . implode ( "{$pop} {$sep} {$embed}" , $links ) . $pop; + $result = $embed . implode( "{$pop} {$sep} {$embed}", $links ) . $pop; return false; } diff --git a/CategoryTree.i18n.magic.php b/CategoryTree.i18n.magic.php index 5812a1a2..d0fae668 100644 --- a/CategoryTree.i18n.magic.php +++ b/CategoryTree.i18n.magic.php @@ -138,7 +138,8 @@ $magicWords['kw'] = [ /** Ladino (Ladino) */ $magicWords['lad'] = [ - 'categorytree' => [ 0, 'árvoledekateggorías', 'árboldecategorías', 'arboldecategorias', 'categorytree' ], + 'categorytree' => [ 0, 'árvoledekateggorías', 'árboldecategorías', 'arboldecategorias', + 'categorytree' ], ]; /** Malagasy (Malagasy) */ diff --git a/CategoryTree.i18n.php b/CategoryTree.i18n.php index aa51803b..a3931dcc 100644 --- a/CategoryTree.i18n.php +++ b/CategoryTree.i18n.php @@ -15,7 +15,7 @@ if ( !function_exists( 'wfJsonI18nShimed9738563f370e2c' ) ) { function wfJsonI18nShimed9738563f370e2c( $cache, $code, &$cachedData ) { $codeSequence = array_merge( [ $code ], $cachedData['fallbackSequence'] ); foreach ( $codeSequence as $csCode ) { - $fileName = dirname( __FILE__ ) . "/i18n/$csCode.json"; + $fileName = __DIR__ . "/i18n/$csCode.json"; if ( is_readable( $fileName ) ) { $data = FormatJson::decode( file_get_contents( $fileName ), true ); foreach ( array_keys( $data ) as $key ) { diff --git a/CategoryTree.php b/CategoryTree.php index 98cf3a0b..e0e6934b 100644 --- a/CategoryTree.php +++ b/CategoryTree.php @@ -16,7 +16,8 @@ if ( function_exists( 'wfLoadExtension' ) ) { // Keep i18n globals so mergeMessageFileList.php doesn't break $wgMessagesDirs['CategoryTree'] = __DIR__ . '/i18n'; /* wfWarn( - 'Deprecated PHP entry point used for CategoryTree extension. Please use wfLoadExtension instead, ' . + 'Deprecated PHP entry point used for CategoryTree extension. ' . + 'Please use wfLoadExtension instead, ' . 'see https://www.mediawiki.org/wiki/Extension_registration for more details.' ); */ return true; diff --git a/CategoryTreeFunctions.php b/CategoryTreeFunctions.php index fd7b0d4d..a7108392 100644 --- a/CategoryTreeFunctions.php +++ b/CategoryTreeFunctions.php @@ -19,7 +19,8 @@ class CategoryTree { function __construct( $options ) { global $wgCategoryTreeDefaultOptions; - # ensure default values and order of options. Order may become important, it may influence the cache key! + // ensure default values and order of options. + // Order may become important, it may influence the cache key! foreach ( $wgCategoryTreeDefaultOptions as $option => $default ) { if ( isset( $options[$option] ) && !is_null( $options[$option] ) ) { $this->mOptions[$option] = $options[$option]; @@ -31,7 +32,8 @@ class CategoryTree { $this->mOptions['mode'] = self::decodeMode( $this->mOptions['mode'] ); if ( $this->mOptions['mode'] == CategoryTreeMode::PARENTS ) { - $this->mOptions['namespaces'] = false; # namespace filter makes no sense with CategoryTreeMode::PARENTS + // namespace filter makes no sense with CategoryTreeMode::PARENTS + $this->mOptions['namespaces'] = false; } $this->mOptions['hideprefix'] = self::decodeHidePrefix( $this->mOptions['hideprefix'] ); @@ -62,7 +64,7 @@ class CategoryTree { /** * @return bool */ - function isInverse( ) { + function isInverse() { return $this->getOption( 'mode' ) == CategoryTreeMode::PARENTS; } @@ -169,9 +171,13 @@ class CategoryTree { return ( (int)$value > 0 ); } - if ( $value == 'yes' || $value == 'y' || $value == 'true' || $value == 't' || $value == 'on' ) { + if ( $value == 'yes' || $value == 'y' + || $value == 'true' || $value == 't' || $value == 'on' + ) { return true; - } elseif ( $value == 'no' || $value == 'n' || $value == 'false' || $value == 'f' || $value == 'off' ) { + } elseif ( $value == 'no' || $value == 'n' + || $value == 'false' || $value == 'f' || $value == 'off' + ) { return false; } elseif ( $value == 'null' || $value == 'default' || $value == 'none' || $value == 'x' ) { return null; @@ -202,9 +208,13 @@ class CategoryTree { $value = trim( strtolower( $value ) ); - if ( $value == 'yes' || $value == 'y' || $value == 'true' || $value == 't' || $value == 'on' ) { + if ( $value == 'yes' || $value == 'y' + || $value == 'true' || $value == 't' || $value == 'on' + ) { return CategoryTreeHidePrefix::ALWAYS; - } elseif ( $value == 'no' || $value == 'n' || $value == 'false' || $value == 'f' || $value == 'off' ) { + } elseif ( $value == 'no' || $value == 'n' + || $value == 'false' || $value == 'f' || $value == 'off' + ) { return CategoryTreeHidePrefix::NEVER; } elseif ( $value == 'always' ) { return CategoryTreeHidePrefix::ALWAYS; @@ -255,7 +265,9 @@ class CategoryTree { $key = ""; foreach ( $this->mOptions as $k => $v ) { - if ( is_array( $v ) ) $v = implode( '|', $v ); + if ( is_array( $v ) ) { + $v = implode( '|', $v ); + } $key .= $k . ':' . $v . ';'; } @@ -299,7 +311,9 @@ class CategoryTree { * @param $allowMissing bool * @return bool|string */ - function getTag( $parser, $category, $hideroot = false, $attr, $depth = 1, $allowMissing = false ) { + function getTag( $parser, $category, $hideroot = false, $attr, $depth = 1, + $allowMissing = false + ) { global $wgCategoryTreeDisableCache; $category = trim( $category ); @@ -336,13 +350,13 @@ class CategoryTree { if ( !$allowMissing && !$title->getArticleID() ) { $html .= Html::openElement( 'span', [ 'class' => 'CategoryTreeNotice' ] ); if ( $parser ) { - $html .= $parser->recursiveTagParse( wfMessage( 'categorytree-not-found', $category )->plain() ); + $html .= $parser->recursiveTagParse( + wfMessage( 'categorytree-not-found', $category )->plain() ); } else { $html .= wfMessage( 'categorytree-not-found', $category )->parse(); } $html .= Html::closeElement( 'span' ); - } - else { + } else { if ( !$hideroot ) { $html .= $this->renderNode( $title, $depth, false ); } else { @@ -385,7 +399,9 @@ class CategoryTree { $options = [ 'ORDER BY' => 'cl_type, cl_sortkey', 'LIMIT' => $wgCategoryTreeMaxChildren ]; if ( $inverse ) { - $joins['categorylinks'] = [ 'RIGHT JOIN', [ 'cl_to = page_title', 'page_namespace' => NS_CATEGORY ] ]; + $joins['categorylinks'] = [ 'RIGHT JOIN', [ + 'cl_to = page_title', 'page_namespace' => NS_CATEGORY + ] ]; $where['cl_from'] = $title->getArticleID(); } else { $joins['categorylinks'] = [ 'JOIN', 'cl_from = page_id' ]; @@ -394,7 +410,8 @@ class CategoryTree { # namespace filter. if ( $namespaces ) { - # NOTE: we assume that the $namespaces array contains only integers! decodeNamepsaces makes it so. + // NOTE: we assume that the $namespaces array contains only integers! + // decodeNamepsaces makes it so. $where['page_namespace'] = $namespaces; } elseif ( $mode != CategoryTreeMode::ALL ) { if ( $mode == CategoryTreeMode::PAGES ) { @@ -410,8 +427,12 @@ class CategoryTree { if ( $doCount ) { $tables = array_merge( $tables, [ 'category' ] ); - $fields = array_merge( $fields, [ 'cat_id', 'cat_title', 'cat_subcats', 'cat_pages', 'cat_files' ] ); - $joins['category'] = [ 'LEFT JOIN', [ 'cat_title = page_title', 'page_namespace' => NS_CATEGORY ] ]; + $fields = array_merge( $fields, [ + 'cat_id', 'cat_title', 'cat_subcats', 'cat_pages', 'cat_files' + ] ); + $joins['category'] = [ 'LEFT JOIN', [ + 'cat_title = page_title', 'page_namespace' => NS_CATEGORY ] + ]; } $res = $dbr->select( $tables, $fields, $where, __METHOD__, $options, $joins ); @@ -509,7 +530,9 @@ class CategoryTree { function renderNode( $title, $children = 0 ) { global $wgCategoryTreeUseCategoryTable; - if ( $wgCategoryTreeUseCategoryTable && $title->getNamespace() == NS_CATEGORY && !$this->isInverse() ) { + if ( $wgCategoryTreeUseCategoryTable && $title->getNamespace() == NS_CATEGORY + && !$this->isInverse() + ) { $cat = Category::newFromTitle( $title ); } else { $cat = null; @@ -544,8 +567,9 @@ class CategoryTree { $hideprefix = true; } - # when showing only categories, omit namespace in label unless we explicitely defined the configuration setting - # patch contributed by Manuel Schneider , Bug 8011 + // when showing only categories, omit namespace in label unless we explicitely defined the + // configuration setting + // patch contributed by Manuel Schneider , Bug 8011 if ( $hideprefix ) { $label = htmlspecialchars( $title->getText() ); } else { @@ -686,7 +710,7 @@ class CategoryTree { $attr = [ 'title' => $context->msg( 'categorytree-member-counts' ) - ->numParams( $subcatCount, $pages , $fileCount, $allCount, $countMode )->text(), + ->numParams( $subcatCount, $pages, $fileCount, $allCount, $countMode )->text(), 'dir' => $context->getLanguage()->getDir() # numbers and commas get messed up in a mixed dir env ]; diff --git a/CategoryTreePage.php b/CategoryTreePage.php index ada47c0d..864cff96 100644 --- a/CategoryTreePage.php +++ b/CategoryTreePage.php @@ -41,7 +41,8 @@ class CategoryTreePage extends SpecialPage { * @param $par array Parameters passed to the page */ function execute( $par ) { - global $wgCategoryTreeDefaultOptions, $wgCategoryTreeSpecialPageOptions, $wgCategoryTreeForceHeaders; + global $wgCategoryTreeDefaultOptions, $wgCategoryTreeSpecialPageOptions, + $wgCategoryTreeForceHeaders; $this->setHeaders(); $request = $this->getRequest(); @@ -114,11 +115,11 @@ class CategoryTreePage extends SpecialPage { */ function executeInputForm() { $namespaces = $this->getRequest()->getVal( 'namespaces', '' ); - //mode may be overriden by namespaces option + // mode may be overriden by namespaces option $mode = ( $namespaces == '' ? $this->getOption( 'mode' ) : CategoryTreeMode::ALL ); if ( $mode == CategoryTreeMode::CATEGORIES ) { $modeDefault = 'categories'; - } elseif( $mode == CategoryTreeMode::PAGES ) { + } elseif ( $mode == CategoryTreeMode::PAGES ) { $modeDefault = 'pages'; } else { $modeDefault = 'all'; diff --git a/composer.json b/composer.json index 686b65b9..b8f68fb3 100644 --- a/composer.json +++ b/composer.json @@ -1,11 +1,14 @@ { "require-dev": { "jakub-onderka/php-parallel-lint": "0.9.2", - "jakub-onderka/php-console-highlighter": "0.3.2" + "jakub-onderka/php-console-highlighter": "0.3.2", + "mediawiki/mediawiki-codesniffer": "0.7.2" }, "scripts": { + "fix": "phpcbf", "test": [ - "parallel-lint . --exclude vendor" + "parallel-lint . --exclude vendor", + "phpcs -p -s" ] } } diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 00000000..4ffde0b0 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,9 @@ + + + + . + + + vendor + node_modules +