<?php
/**
- * File for magic words
+ * File for magic words.
*
- * See docs/magicword.txt
+ * See docs/magicword.txt.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
*
* @file
* @ingroup Parser
/**
* This class encapsulates "magic words" such as #redirect, __NOTOC__, etc.
- * Usage:
- * if (MagicWord::get( 'redirect' )->match( $text ) )
+ *
+ * @par Usage:
+ * @code
+ * if (MagicWord::get( 'redirect' )->match( $text ) ) {
+ * // some code
+ * }
+ * @endcode
*
* Possible future improvements:
* * Simultaneous searching for a number of magic words
* Please avoid reading the data out of one of these objects and then writing
* special case code. If possible, add another match()-like function here.
*
- * To add magic words in an extension, use the LanguageGetMagic hook. For
- * magic words which are also Parser variables, add a MagicWordwgVariableIDs
+ * To add magic words in an extension, use $magicWords in a file listed in
+ * $wgExtensionMessagesFiles[].
+ *
+ * @par Example:
+ * @code
+ * $magicWords = array();
+ *
+ * $magicWords['en'] = array(
+ * 'magicwordkey' => array( 0, 'case_insensitive_magic_word' ),
+ * 'magicwordkey2' => array( 1, 'CASE_sensitive_magic_word2' ),
+ * );
+ * @endcode
+ *
+ * For magic words which are also Parser variables, add a MagicWordwgVariableIDs
* hook. Use string keys.
*
* @ingroup Parser
'fullpagenamee',
'namespace',
'namespacee',
+ 'namespacenumber',
'currentweek',
'currentdow',
'localweek',
*/
static function getVariableIDs() {
if ( !self::$mVariableIDsInitialised ) {
- # Deprecated constant definition hook, available for extensions that need it
- $magicWords = array();
- wfRunHooks( 'MagicWordMagicWords', array( &$magicWords ) );
- foreach ( $magicWords as $word ) {
- define( $word, $word );
- }
-
# Get variable IDs
wfRunHooks( 'MagicWordwgVariableIDs', array( &self::$mVariableIDs ) );
self::$mVariableIDsInitialised = true;
/**
* Get an array of parser substitution modifier IDs
+ * @return array
*/
static function getSubstIDs() {
return self::$mSubstIDs;
/**
* Allow external reads of TTL array
*
+ * @param $id int
* @return array
*/
- static function getCacheTTL($id) {
+ static function getCacheTTL( $id ) {
if ( array_key_exists( $id, self::$mCacheTTLs ) ) {
return self::$mCacheTTLs[$id];
} else {
$wgContLang->getMagic( $this );
if ( !$this->mSynonyms ) {
$this->mSynonyms = array( 'dkjsagfjsgashfajsh' );
- #throw new MWException( "Error: invalid magic word '$id'" );
- wfDebugLog( 'exception', "Error: invalid magic word '$id'\n" );
+ throw new MWException( "Error: invalid magic word '$id'" );
+ #wfDebugLog( 'exception', "Error: invalid magic word '$id'\n" );
}
wfProfileOut( __METHOD__ );
}
/**
* Returns true if the text contains the word
*
- * @paran $text string
+ * @param $text string
*
* @return bool
*/
/**
* Get a regex anchored to the start of the string that does not match parameters
*
- * @return string
+ * @return array
*/
function getRegexStart() {
$base = $this->getBaseRegex();
/**
* Get an anchored regex for matching variables with parameters
*
- * @return string
+ * @return array
*/
function getVariableStartToEndRegex() {
$base = $this->getBaseRegex();
*/
function parseMatch( $m ) {
reset( $m );
- foreach ( $m as $key => $value ) {
+ while ( list( $key, $value ) = each( $m ) ) {
if ( $key === 0 || $value === '' ) {
continue;
}
*
* @param $text string
*
- * @return string|false
+ * @return string|bool False on failure
*/
public function matchStartToEnd( $text ) {
$hash = $this->getHash();
*
* @param $text string
*
- * @return int|false
+ * @return int|bool False on failure
*/
public function matchStartAndRemove( &$text ) {
$regexes = $this->getRegexStart();