Add a way for packagers to override some installation details
[lhc/web/wiklou.git] / includes / MagicWord.php
index 136aac9..f838ad0 100644 (file)
@@ -1,8 +1,23 @@
 <?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
@@ -78,6 +110,7 @@ class MagicWord {
                'fullpagenamee',
                'namespace',
                'namespacee',
+               'namespacenumber',
                'currentweek',
                'currentdow',
                'localweek',
@@ -212,13 +245,6 @@ class MagicWord {
         */
        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;
@@ -228,6 +254,7 @@ class MagicWord {
 
        /**
         * Get an array of parser substitution modifier IDs
+        * @return array
         */
        static function getSubstIDs() {
                return self::$mSubstIDs;
@@ -236,9 +263,10 @@ class MagicWord {
        /**
         * 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 {
@@ -278,8 +306,8 @@ class MagicWord {
                $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__ );
        }
@@ -383,7 +411,7 @@ class MagicWord {
        /**
         * Returns true if the text contains the word
         *
-        * @paran $text string
+        * @param $text string
         *
         * @return bool
         */
@@ -712,7 +740,7 @@ class MagicWordArray {
        /**
         * Get a regex anchored to the start of the string that does not match parameters
         *
-        * @return string
+        * @return array
         */
        function getRegexStart() {
                $base = $this->getBaseRegex();
@@ -729,7 +757,7 @@ class MagicWordArray {
        /**
         * Get an anchored regex for matching variables with parameters
         *
-        * @return string
+        * @return array
         */
        function getVariableStartToEndRegex() {
                $base = $this->getBaseRegex();
@@ -748,13 +776,13 @@ class MagicWordArray {
         * Returns array(magic word ID, parameter value)
         * If there is no parameter value, that element will be false.
         *
-        * @param $m arrray
+        * @param $m array
         *
         * @return array
         */
        function parseMatch( $m ) {
                reset( $m );
-               foreach ( $m as $key => $value ) {
+               while ( list( $key, $value ) = each( $m ) ) {
                        if ( $key === 0 || $value === '' ) {
                                continue;
                        }
@@ -801,7 +829,7 @@ class MagicWordArray {
         *
         * @param $text string
         *
-        * @return string|false
+        * @return string|bool False on failure
         */
        public function matchStartToEnd( $text ) {
                $hash = $this->getHash();
@@ -849,7 +877,7 @@ class MagicWordArray {
         *
         * @param $text string
         *
-        * @return int|false
+        * @return int|bool False on failure
         */
        public function matchStartAndRemove( &$text ) {
                $regexes = $this->getRegexStart();