[], self::MEDIUM => [], self::LOW => [], ]; /** * @var string[] */ private $parserMigrationCategories = []; /** * @var string[] */ private $hasNameParam = []; public function __construct() { global $wgLinterCategories; foreach ( $wgLinterCategories as $name => $info ) { if ( $info['enabled'] ) { $this->categories[$info['priority']][] = $name; } if ( isset( $info['parser-migration'] ) ) { $this->parserMigrationCategories[$name] = true; } if ( isset( $info['has-name'] ) ) { $this->hasNameParam[$name] = true; } if ( isset( $info['dbid'] ) ) { if ( isset( $this->categoryIds[$name] ) ) { throw new InvalidArgumentException( "duplicate ID: $name" ); } $this->categoryIds[$name] = $info['dbid']; } } sort( $this->categories[self::HIGH] ); sort( $this->categories[self::MEDIUM] ); sort( $this->categories[self::LOW] ); } public function needsParserMigrationEdit( $name ) { return isset( $this->parserMigrationCategories[$name] ); } public function hasNameParam( $name ) { return isset( $this->hasNameParam[$name] ); } /** * @return string[] */ public function getHighPriority() { return $this->categories[self::HIGH]; } /** * @return string[] */ public function getMediumPriority() { return $this->categories[self::MEDIUM]; } /** * @return string[] */ public function getLowPriority() { return $this->categories[self::LOW]; } /** * Categories that are configured to be displayed to users * * @return string[] */ public function getVisibleCategories() { return array_merge( $this->categories[self::HIGH], $this->categories[self::MEDIUM], $this->categories[self::LOW] ); } /** * Whether this category has a hardcoded id and can be * inserted into the database * * @param string $name * @return bool */ public function isKnownCategory( $name ) { return isset( $this->categoryIds[$name] ); } /** * @param int $id * @throws MissingCategoryException if we can't find the name for the id * @return string */ public function getCategoryName( $id ) { $flip = array_flip( $this->categoryIds ); if ( isset( $flip[$id] ) ) { return $flip[$id]; } throw new MissingCategoryException( "Could not find name for id $id" ); } /** * @param string[] $names * @return int[] */ public function getCategoryIds( array $names ) { $result = []; foreach ( $names as $name ) { $result[$name] = $this->getCategoryId( $name ); } return $result; } /** * Get the int id for the category in lint_categories table * * @param string $name * @return int * @throws MissingCategoryException if we can't find the id for the name */ public function getCategoryId( $name ) { if ( isset( $this->categoryIds[$name] ) ) { return $this->categoryIds[$name]; } throw new MissingCategoryException( "Cannot find id for '$name'" ); } }