X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2FMagicWord.php;h=93c8a71c9e501eb6768a16404396d827bd15ecce;hp=1703179c9e289601bf3b2c374df2876cfb271603;hb=631e8695b15412ec16c31623cbd6e5aa3d6efb1e;hpb=d5a7166771613dfe4ed9fb75fa5efeced6134bd1 diff --git a/includes/MagicWord.php b/includes/MagicWord.php index 1703179c9e..93c8a71c9e 100644 --- a/includes/MagicWord.php +++ b/includes/MagicWord.php @@ -59,10 +59,10 @@ class MagicWord { /**#@-*/ - /** @var int */ + /** @var string */ public $mId; - /** @var array */ + /** @var string[] */ public $mSynonyms; /** @var bool */ @@ -92,7 +92,10 @@ class MagicWord { /** @var bool */ private $mFound = false; + /** @var bool */ public static $mVariableIDsInitialised = false; + + /** @var string[] */ public static $mVariableIDs = [ '!', 'currentmonth', @@ -174,7 +177,9 @@ class MagicWord { 'cascadingsources', ]; - /* Array of caching hints for ParserCache */ + /** Array of caching hints for ParserCache + * @var array [ string => int ] + */ public static $mCacheTTLs = [ 'currentmonth' => 86400, 'currentmonth1' => 86400, @@ -216,6 +221,7 @@ class MagicWord { 'numberingroup' => 3600, ]; + /** @var string[] */ public static $mDoubleUnderscoreIDs = [ 'notoc', 'nogallery', @@ -232,17 +238,30 @@ class MagicWord { 'nocontentconvert', ]; + /** @var string[] */ public static $mSubstIDs = [ 'subst', 'safesubst', ]; + /** @var array [ string => MagicWord ] */ public static $mObjects = []; + + /** @var MagicWordArray */ public static $mDoubleUnderscoreArray = null; /**#@-*/ - public function __construct( $id = 0, $syn = [], $cs = false ) { + /** + * Create a new MagicWord object + * + * Use factory instead: MagicWord::get + * + * @param string $id The internal name of the magic word + * @param string[]|string $syn synonyms for the magic word + * @param bool $cs If magic word is case sensitive + */ + public function __construct( $id = null, $syn = [], $cs = false ) { $this->mId = $id; $this->mSynonyms = (array)$syn; $this->mCaseSensitive = $cs; @@ -251,7 +270,7 @@ class MagicWord { /** * Factory: creates an object representing an ID * - * @param int $id + * @param string $id The internal name of the magic word * * @return MagicWord */ @@ -267,7 +286,7 @@ class MagicWord { /** * Get an array of parser variable IDs * - * @return array + * @return string[] */ public static function getVariableIDs() { if ( !self::$mVariableIDsInitialised ) { @@ -280,7 +299,7 @@ class MagicWord { /** * Get an array of parser substitution modifier IDs - * @return array + * @return string[] */ public static function getSubstIDs() { return self::$mSubstIDs; @@ -289,7 +308,7 @@ class MagicWord { /** * Allow external reads of TTL array * - * @param int $id + * @param string $id * @return int */ public static function getCacheTTL( $id ) { @@ -324,7 +343,7 @@ class MagicWord { /** * Initialises this object with an ID * - * @param int $id + * @param string $id * @throws MWException */ public function load( $id ) { @@ -518,7 +537,7 @@ class MagicWord { * Returns true if the text matches the word, and alters the * input string, removing all instances of the word * - * @param string $text + * @param string &$text * * @return bool */ @@ -534,7 +553,7 @@ class MagicWord { } /** - * @param string $text + * @param string &$text * @return bool */ public function matchStartAndRemove( &$text ) { @@ -630,7 +649,7 @@ class MagicWord { } /** - * @return array + * @return string[] */ public function getSynonyms() { return $this->mSynonyms; @@ -646,38 +665,11 @@ class MagicWord { return $this->mModified; } - /** - * $magicarr is an associative array of (magic word ID => replacement) - * This method uses the php feature to do several replacements at the same time, - * thereby gaining some efficiency. The result is placed in the out variable - * $result. The return value is true if something was replaced. - * @deprecated since 1.25, unused - * - * @param array $magicarr - * @param string $subject - * @param string $result - * - * @return bool - */ - public function replaceMultiple( $magicarr, $subject, &$result ) { - wfDeprecated( __METHOD__, '1.25' ); - $search = []; - $replace = []; - foreach ( $magicarr as $id => $replacement ) { - $mw = self::get( $id ); - $search[] = $mw->getRegex(); - $replace[] = $replacement; - } - - $result = preg_replace( $search, $replace, $subject ); - return $result !== $subject; - } - /** * Adds all the synonyms of this MagicWord to an array, to allow quick * lookup in a list of magic words * - * @param array $array + * @param string[] &$array * @param string $value */ public function addToArray( &$array, $value ) { @@ -695,7 +687,7 @@ class MagicWord { } /** - * @return int + * @return string */ public function getId() { return $this->mId;