From c1f9b1f7b1b77776192048005dcc66dcf3df2bfb Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 27 Dec 2014 15:41:37 +0100 Subject: Update to MediaWiki 1.24.1 --- includes/MagicWord.php | 175 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 126 insertions(+), 49 deletions(-) (limited to 'includes/MagicWord.php') diff --git a/includes/MagicWord.php b/includes/MagicWord.php index 232f43e8..4d17298b 100644 --- a/includes/MagicWord.php +++ b/includes/MagicWord.php @@ -59,20 +59,44 @@ * @ingroup Parser */ class MagicWord { - /**#@+ - * @private - */ - var $mId, $mSynonyms, $mCaseSensitive; - var $mRegex = ''; - var $mRegexStart = ''; - var $mBaseRegex = ''; - var $mVariableRegex = ''; - var $mVariableStartToEndRegex = ''; - var $mModified = false; - var $mFound = false; + /**#@-*/ + + /** @var int */ + public $mId; + + /** @var array */ + public $mSynonyms; + + /** @var bool */ + public $mCaseSensitive; + + /** @var string */ + private $mRegex = ''; + + /** @var string */ + private $mRegexStart = ''; + + /** @var string */ + private $mRegexStartToEnd = ''; + + /** @var string */ + private $mBaseRegex = ''; + + /** @var string */ + private $mVariableRegex = ''; + + /** @var string */ + private $mVariableStartToEndRegex = ''; + + /** @var bool */ + private $mModified = false; + + /** @var bool */ + private $mFound = false; static public $mVariableIDsInitialised = false; static public $mVariableIDs = array( + '!', 'currentmonth', 'currentmonth1', 'currentmonthname', @@ -149,6 +173,7 @@ class MagicWord { 'contentlanguage', 'numberofadmins', 'numberofviews', + 'cascadingsources', ); /* Array of caching hints for ParserCache */ @@ -192,7 +217,7 @@ class MagicWord { 'numberofadmins' => 3600, 'numberofviews' => 3600, 'numberingroup' => 3600, - ); + ); static public $mDoubleUnderscoreIDs = array( 'notoc', @@ -229,7 +254,7 @@ class MagicWord { /** * Factory: creates an object representing an ID * - * @param $id + * @param int $id * * @return MagicWord */ @@ -267,8 +292,8 @@ class MagicWord { /** * Allow external reads of TTL array * - * @param $id int - * @return array + * @param int $id + * @return int */ static function getCacheTTL( $id ) { if ( array_key_exists( $id, self::$mCacheTTLs ) ) { @@ -302,7 +327,7 @@ class MagicWord { /** * Initialises this object with an ID * - * @param $id + * @param int $id * @throws MWException */ function load( $id ) { @@ -338,6 +363,7 @@ class MagicWord { $case = $this->mCaseSensitive ? '' : 'iu'; $this->mRegex = "/{$this->mBaseRegex}/{$case}"; $this->mRegexStart = "/^(?:{$this->mBaseRegex})/{$case}"; + $this->mRegexStartToEnd = "/^(?:{$this->mBaseRegex})$/{$case}"; $this->mVariableRegex = str_replace( "\\$1", "(.*?)", $this->mRegex ); $this->mVariableStartToEndRegex = str_replace( "\\$1", "(.*?)", "/^(?:{$this->mBaseRegex})$/{$case}" ); @@ -348,8 +374,8 @@ class MagicWord { * first string is longer, the same length or shorter than the second * string. * - * @param $s1 string - * @param $s2 string + * @param string $s1 + * @param string $s2 * * @return int */ @@ -404,6 +430,19 @@ class MagicWord { return $this->mRegexStart; } + /** + * Gets a regex matching the word from start to end of a string + * + * @return string + * @since 1.23 + */ + function getRegexStartToEnd() { + if ( $this->mRegexStartToEnd == '' ) { + $this->initRegex(); + } + return $this->mRegexStartToEnd; + } + /** * regex without the slashes and what not * @@ -419,7 +458,7 @@ class MagicWord { /** * Returns true if the text contains the word * - * @param $text string + * @param string $text * * @return bool */ @@ -430,7 +469,7 @@ class MagicWord { /** * Returns true if the text starts with the word * - * @param $text string + * @param string $text * * @return bool */ @@ -438,13 +477,25 @@ class MagicWord { return (bool)preg_match( $this->getRegexStart(), $text ); } + /** + * Returns true if the text matched the word + * + * @param string $text + * + * @return bool + * @since 1.23 + */ + function matchStartToEnd( $text ) { + return (bool)preg_match( $this->getRegexStartToEnd(), $text ); + } + /** * Returns NULL if there's no match, the value of $1 otherwise * The return code is the matched string, if there's no variable * part in the regex and the matched variable part ($1) if there * is one. * - * @param $text string + * @param string $text * * @return string */ @@ -473,23 +524,33 @@ class MagicWord { * Returns true if the text matches the word, and alters the * input string, removing all instances of the word * - * @param $text string + * @param string $text * * @return bool */ function matchAndRemove( &$text ) { $this->mFound = false; - $text = preg_replace_callback( $this->getRegex(), array( &$this, 'pregRemoveAndRecord' ), $text ); + $text = preg_replace_callback( + $this->getRegex(), + array( &$this, 'pregRemoveAndRecord' ), + $text + ); + return $this->mFound; } /** - * @param $text + * @param string $text * @return bool */ function matchStartAndRemove( &$text ) { $this->mFound = false; - $text = preg_replace_callback( $this->getRegexStart(), array( &$this, 'pregRemoveAndRecord' ), $text ); + $text = preg_replace_callback( + $this->getRegexStart(), + array( &$this, 'pregRemoveAndRecord' ), + $text + ); + return $this->mFound; } @@ -506,14 +567,19 @@ class MagicWord { /** * Replaces the word with something else * - * @param $replacement - * @param $subject - * @param $limit int + * @param string $replacement + * @param string $subject + * @param int $limit * * @return string */ function replace( $replacement, $subject, $limit = -1 ) { - $res = preg_replace( $this->getRegex(), StringUtils::escapeRegexReplacement( $replacement ), $subject, $limit ); + $res = preg_replace( + $this->getRegex(), + StringUtils::escapeRegexReplacement( $replacement ), + $subject, + $limit + ); $this->mModified = $res !== $subject; return $res; } @@ -523,8 +589,8 @@ class MagicWord { * Calls back a function to determine what to replace xxx with * Input word must contain $1 * - * @param $text string - * @param $callback + * @param string $text + * @param callable $callback * * @return string */ @@ -561,7 +627,7 @@ class MagicWord { /** * Accesses the synonym list directly * - * @param $i int + * @param int $i * * @return string */ @@ -593,9 +659,9 @@ class MagicWord { * $result. The return value is true if something was replaced. * @todo Should this be static? It doesn't seem to be used at all * - * @param $magicarr - * @param $subject - * @param $result + * @param array $magicarr + * @param string $subject + * @param string $result * * @return bool */ @@ -616,8 +682,8 @@ class MagicWord { * Adds all the synonyms of this MagicWord to an array, to allow quick * lookup in a list of magic words * - * @param $array - * @param $value + * @param array $array + * @param string $value */ function addToArray( &$array, $value ) { global $wgContLang; @@ -646,13 +712,21 @@ class MagicWord { * @ingroup Parser */ class MagicWordArray { - var $names = array(); - var $hash; - var $baseRegex, $regex; - var $matches; + /** @var array */ + public $names = array(); + + /** @var array */ + private $hash; + + private $baseRegex; + + private $regex; + + /** @todo Unused? */ + private $matches; /** - * @param $names array + * @param array $names */ function __construct( $names = array() ) { $this->names = $names; @@ -661,7 +735,7 @@ class MagicWordArray { /** * Add a magic word by name * - * @param $name string + * @param string $name */ public function add( $name ) { $this->names[] = $name; @@ -671,7 +745,7 @@ class MagicWordArray { /** * Add a number of magic words by name * - * @param $names array + * @param array $names */ public function addArray( $names ) { $this->names = array_merge( $this->names, array_values( $names ) ); @@ -680,6 +754,7 @@ class MagicWordArray { /** * Get a 2-d hashtable for this array + * @return array */ function getHash() { if ( is_null( $this->hash ) ) { @@ -701,6 +776,7 @@ class MagicWordArray { /** * Get the base regex + * @return array */ function getBaseRegex() { if ( is_null( $this->baseRegex ) ) { @@ -725,6 +801,7 @@ class MagicWordArray { /** * Get an unanchored regex that does not match parameters + * @return array */ function getRegex() { if ( is_null( $this->regex ) ) { @@ -796,7 +873,7 @@ class MagicWordArray { * Returns array(magic word ID, parameter value) * If there is no parameter value, that element will be false. * - * @param $m array + * @param array $m * * @throws MWException * @return array @@ -827,7 +904,7 @@ class MagicWordArray { * parameter in the second element. * Both elements are false if there was no match. * - * @param $text string + * @param string $text * * @return array */ @@ -848,7 +925,7 @@ class MagicWordArray { * Match some text, without parameter capture * Returns the magic word name, or false if there was no capture * - * @param $text string + * @param string $text * * @return string|bool False on failure */ @@ -869,7 +946,7 @@ class MagicWordArray { * Returns an associative array, ID => param value, for all items that match * Removes the matched items from the input string (passed by reference) * - * @param $text string + * @param string $text * * @return array */ @@ -896,7 +973,7 @@ class MagicWordArray { * Return false if no match found and $text is not modified. * Does not match parameters. * - * @param $text string + * @param string $text * * @return int|bool False on failure */ -- cgit v1.2.2