class MagicWord {
/**#@-*/
- /** @var int */
+ /** @var string */
public $mId;
- /** @var array */
+ /** @var string[] */
public $mSynonyms;
/** @var bool */
/** @var bool */
private $mFound = false;
+ /** @var bool */
public static $mVariableIDsInitialised = false;
+
+ /** @var string[] */
public static $mVariableIDs = [
'!',
'currentmonth',
'cascadingsources',
];
- /* Array of caching hints for ParserCache */
+ /** Array of caching hints for ParserCache
+ * @var array [ string => int ]
+ */
public static $mCacheTTLs = [
'currentmonth' => 86400,
'currentmonth1' => 86400,
'numberingroup' => 3600,
];
+ /** @var string[] */
public static $mDoubleUnderscoreIDs = [
'notoc',
'nogallery',
'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;
/**
* Factory: creates an object representing an ID
*
- * @param int $id
+ * @param string $id The internal name of the magic word
*
* @return MagicWord
*/
/**
* Get an array of parser variable IDs
*
- * @return array
+ * @return string[]
*/
public static function getVariableIDs() {
if ( !self::$mVariableIDsInitialised ) {
/**
* Get an array of parser substitution modifier IDs
- * @return array
+ * @return string[]
*/
public static function getSubstIDs() {
return self::$mSubstIDs;
/**
* Allow external reads of TTL array
*
- * @param int $id
+ * @param string $id
* @return int
*/
public static function getCacheTTL( $id ) {
/**
* Initialises this object with an ID
*
- * @param int $id
+ * @param string $id
* @throws MWException
*/
public function load( $id ) {
* 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
*/
}
/**
- * @param string $text
+ * @param string &$text
* @return bool
*/
public function matchStartAndRemove( &$text ) {
}
/**
- * @return array
+ * @return string[]
*/
public function getSynonyms() {
return $this->mSynonyms;
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 ) {
}
/**
- * @return int
+ * @return string
*/
public function getId() {
return $this->mId;