X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FMagicWordArray.php;h=831d5b99887fb7b00a8817f577f049f6e0669851;hb=25242105e8fd03c9900250bdf9ea91be9a286625;hp=20ac680a98dece0b586c0c87a309fdc5173a548b;hpb=d9327f9a57213488ed35b6a5dd532feb4f70125f;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/MagicWordArray.php b/includes/MagicWordArray.php index 20ac680a98..831d5b9988 100644 --- a/includes/MagicWordArray.php +++ b/includes/MagicWordArray.php @@ -30,7 +30,7 @@ use MediaWiki\MediaWikiServices; * @ingroup Parser */ class MagicWordArray { - /** @var array */ + /** @var string[] */ public $names = []; /** @var MagicWordFactory */ @@ -44,15 +44,12 @@ class MagicWordArray { private $regex; /** - * @param array $names + * @param string[] $names * @param MagicWordFactory|null $factory */ public function __construct( $names = [], MagicWordFactory $factory = null ) { $this->names = $names; - $this->factory = $factory; - if ( !$factory ) { - $this->factory = MediaWikiServices::getInstance()->getMagicWordFactory(); - } + $this->factory = $factory ?: MediaWikiServices::getInstance()->getMagicWordFactory(); } /** @@ -68,7 +65,7 @@ class MagicWordArray { /** * Add a number of magic words by name * - * @param array $names + * @param string[] $names */ public function addArray( $names ) { $this->names = array_merge( $this->names, array_values( $names ) ); @@ -81,14 +78,13 @@ class MagicWordArray { */ public function getHash() { if ( is_null( $this->hash ) ) { - global $wgContLang; $this->hash = [ 0 => [], 1 => [] ]; foreach ( $this->names as $name ) { $magic = $this->factory->get( $name ); $case = intval( $magic->isCaseSensitive() ); foreach ( $magic->getSynonyms() as $syn ) { if ( !$case ) { - $syn = $wgContLang->lc( $syn ); + $syn = $this->factory->getContentLanguage()->lc( $syn ); } $this->hash[$case][$syn] = $name; } @@ -99,7 +95,7 @@ class MagicWordArray { /** * Get the base regex - * @return array + * @return string[] */ public function getBaseRegex() { if ( is_null( $this->baseRegex ) ) { @@ -133,7 +129,7 @@ class MagicWordArray { /** * Get an unanchored regex that does not match parameters - * @return array + * @return string[] */ public function getRegex() { if ( is_null( $this->regex ) ) { @@ -152,7 +148,7 @@ class MagicWordArray { /** * Get a regex for matching variables with parameters * - * @return string + * @return string[] */ public function getVariableRegex() { return str_replace( "\\$1", "(.*?)", $this->getRegex() ); @@ -161,7 +157,7 @@ class MagicWordArray { /** * Get a regex anchored to the start of the string that does not match parameters * - * @return array + * @return string[] */ public function getRegexStart() { $base = $this->getBaseRegex(); @@ -178,7 +174,7 @@ class MagicWordArray { /** * Get an anchored regex for matching variables with parameters * - * @return array + * @return string[] */ public function getVariableStartToEndRegex() { $base = $this->getBaseRegex(); @@ -194,7 +190,7 @@ class MagicWordArray { /** * @since 1.20 - * @return array + * @return string[] */ public function getNames() { return $this->names; @@ -268,12 +264,8 @@ class MagicWordArray { if ( isset( $hash[1][$text] ) ) { return $hash[1][$text]; } - global $wgContLang; - $lc = $wgContLang->lc( $text ); - if ( isset( $hash[0][$lc] ) ) { - return $hash[0][$lc]; - } - return false; + $lc = $this->factory->getContentLanguage()->lc( $text ); + return $hash[0][$lc] ?? false; } /**