mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CategoryTree
synced 2024-11-27 09:43:06 +00:00
Add phpcs and make pass
Change-Id: I52845fc95b53eca5149a947dfc6a1b39100da97b
This commit is contained in:
parent
713021e015
commit
8e4bff8976
|
@ -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 );
|
||||
|
|
|
@ -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 = '</div>';
|
||||
$sep = ' ';
|
||||
|
||||
$result = $embed . implode ( "{$pop} {$sep} {$embed}" , $links ) . $pop;
|
||||
$result = $embed . implode( "{$pop} {$sep} {$embed}", $links ) . $pop;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -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) */
|
||||
|
|
|
@ -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 ) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 <manuel.schneider@wikimedia.ch>, Bug 8011
|
||||
// when showing only categories, omit namespace in label unless we explicitely defined the
|
||||
// configuration setting
|
||||
// patch contributed by Manuel Schneider <manuel.schneider@wikimedia.ch>, 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
|
||||
];
|
||||
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
9
phpcs.xml
Normal file
9
phpcs.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ruleset>
|
||||
<rule ref="vendor/mediawiki/mediawiki-codesniffer/MediaWiki"/>
|
||||
<file>.</file>
|
||||
<arg name="extensions" value="php,php5,inc"/>
|
||||
<arg name="encoding" value="UTF-8"/>
|
||||
<exclude-pattern>vendor</exclude-pattern>
|
||||
<exclude-pattern>node_modules</exclude-pattern>
|
||||
</ruleset>
|
Loading…
Reference in a new issue