mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Linter
synced 2024-11-23 15:36:52 +00:00
SpecialLintErrors: Reduce code always run in findNamespace
Array filtering/manipulation is only useful if wpNamespaceRestrictions is set and a useable value, so only manipulate canonical namespace list if we're going to use it Change-Id: Ib6d0884f396ca6e0b32817d9b4b90a0de36ba707
This commit is contained in:
parent
61152ae1ac
commit
e352f39fc3
|
@ -198,25 +198,26 @@ class SpecialLintErrors extends SpecialPage {
|
|||
* @return array
|
||||
*/
|
||||
protected function findNamespaces( $request ) {
|
||||
$namespaces = [];
|
||||
$activeNamespaces = array_keys(
|
||||
$this->namespaceInfo->getCanonicalNamespaces()
|
||||
);
|
||||
$namespaceRequestValues = $request->getRawVal( 'wpNamespaceRestrictions' ) ?? '';
|
||||
if ( $namespaceRequestValues === '' ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Security measure: only allow active namespace IDs to reach the query
|
||||
return array_values(
|
||||
array_intersect(
|
||||
// Remove -2 = "media" and -1 = "Special" namespace elements
|
||||
$activeNamespaces = array_filter( $activeNamespaces,
|
||||
array_filter(
|
||||
array_keys(
|
||||
$this->namespaceInfo->getCanonicalNamespaces()
|
||||
),
|
||||
static function ( $x ) {
|
||||
return $x >= 0;
|
||||
}
|
||||
),
|
||||
array_map( 'intval', explode( "\n", $namespaceRequestValues ) )
|
||||
)
|
||||
);
|
||||
if ( $request->getCheck( 'wpNamespaceRestrictions' ) ) {
|
||||
$namespaceRequestValues = $request->getRawVal( 'wpNamespaceRestrictions' ) ?? '';
|
||||
if ( $namespaceRequestValues !== '' ) {
|
||||
$namespaceIDs = array_map( 'intval', explode( "\n", $namespaceRequestValues ) );
|
||||
// Security measure: only allow active namespace IDs to reach the query
|
||||
$namespaces = array_values( array_intersect( $activeNamespaces, $namespaceIDs ) );
|
||||
}
|
||||
}
|
||||
return $namespaces;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue