Added missing @since and @return tags so other people dont have to waste their time...
[lhc/web/wiklou.git] / includes / parser / Parser.php
index 7991ca6..b351290 100644 (file)
  * transformation of that wiki markup it into XHTML output / markup
  * (which in turn the browser understands, and can display).
  *
- * <pre>
- * There are five main entry points into the Parser class:
- * parse()
+ * There are seven main entry points into the Parser class:
+ *
+ * - Parser::parse()
  *     produces HTML output
- * preSaveTransform().
+ * - Parser::preSaveTransform().
  *     produces altered wiki markup.
- * preprocess()
+ * - Parser::preprocess()
  *     removes HTML comments and expands templates
- * cleanSig() / cleanSigInSig()
+ * - Parser::cleanSig() and Parser::cleanSigInSig()
  *     Cleans a signature before saving it to preferences
- * getSection()
+ * - Parser::getSection()
  *     Return the content of a section from an article for section editing
- * replaceSection()
+ * - Parser::replaceSection()
  *     Replaces a section by number inside an article
- * getPreloadText()
+ * - Parser::getPreloadText()
  *     Removes <noinclude> sections, and <includeonly> tags.
  *
  * Globals used:
  *    object: $wgContLang
  *
- * NOT $wgUser or $wgTitle or $wgRequest or $wgLang. Keep them away!
+ * @warning $wgUser or $wgTitle or $wgRequest or $wgLang. Keep them away!
  *
- * settings:
- *  $wgUseDynamicDates*, $wgInterwikiMagic*,
- *  $wgNamespacesWithSubpages, $wgAllowExternalImages*,
- *  $wgLocaltimezone, $wgAllowSpecialInclusion*,
- *  $wgMaxArticleSize*
+ * @par Settings:
+ * $wgLocaltimezone
+ * $wgNamespacesWithSubpages
  *
- *  * only within ParserOptions
- * </pre>
+ * @par Settings only within ParserOptions:
+ * $wgAllowExternalImages
+ * $wgAllowSpecialInclusion
+ * $wgInterwikiMagic
+ * $wgMaxArticleSize
+ * $wgUseDynamicDates
  *
  * @ingroup Parser
  */
@@ -557,10 +559,11 @@ class Parser {
        }
 
        /**
-        * Process the wikitext for the ?preload= feature. (bug 5210)
+        * Process the wikitext for the "?preload=" feature. (bug 5210)
         *
-        * <noinclude>, <includeonly> etc. are parsed as for template transclusion,
-        * comments, templates, arguments, tags hooks and parser functions are untouched.
+        * "<noinclude>", "<includeonly>" etc. are parsed as for template
+        * transclusion, comments, templates, arguments, tags hooks and parser
+        * functions are untouched.
         *
         * @param $text String
         * @param $title Title
@@ -732,16 +735,22 @@ class Parser {
        /**
         * Get the target language for the content being parsed. This is usually the
         * language that the content is in.
+        *
+        * @since 1.19
+        *
+        * @return Language|null
         */
-       function getTargetLanguage() {
+       public function getTargetLanguage() {
                $target = $this->mOptions->getTargetLanguage();
+
                if ( $target !== null ) {
                        return $target;
                } elseif( $this->mOptions->getInterfaceMessage() ) {
                        return $this->mOptions->getUserLangObj();
                } elseif( is_null( $this->mTitle ) ) {
-                       throw new MWException( __METHOD__.': $this->mTitle is null' );
+                       throw new MWException( __METHOD__ . ': $this->mTitle is null' );
                }
+
                return $this->mTitle->getPageLanguage();
        }
 
@@ -788,11 +797,14 @@ class Parser {
         * in the text with a random marker and returns the next text. The output
         * parameter $matches will be an associative array filled with data in
         * the form:
+        *
+        * @code
         *   'UNIQ-xxxxx' => array(
         *     'element',
         *     'tag content',
         *     array( 'param' => 'x' ),
         *     '<element param="x">tag content</element>' ) )
+        * @endcode
         *
         * @param $elements array list of element names. Comments are always extracted.
         * @param $text string Source text string.
@@ -2940,7 +2952,7 @@ class Parser {
         *
         * @param $text String: The text to parse
         * @param $flags Integer: bitwise combination of:
-        *          self::PTD_FOR_INCLUSION    Handle <noinclude>/<includeonly> as if the text is being
+        *          self::PTD_FOR_INCLUSION    Handle "<noinclude>" and "<includeonly>" as if the text is being
         *                                     included. Default is to assume a direct page view.
         *
         * The generated DOM tree must depend only on the input text and the flags.
@@ -3517,7 +3529,7 @@ class Parser {
         * Static function to get a template
         * Can be overridden via ParserOptions::setTemplateCallback().
         *
-        * @parma $title Title
+        * @param $title  Title
         * @param $parser Parser
         *
         * @return array
@@ -3546,7 +3558,7 @@ class Parser {
                        # Get the revision
                        $rev = $id
                                ? Revision::newFromId( $id )
-                               : Revision::newFromTitle( $title );
+                               : Revision::newFromTitle( $title, 0, Revision::READ_NORMAL );
                        $rev_id = $rev ? $rev->getId() : 0;
                        # If there is no current revision, there is no page
                        if ( $id === false && !$rev ) {
@@ -3691,7 +3703,7 @@ class Parser {
         * Triple brace replacement -- used for template arguments
         * @private
         *
-        * @param $peice array
+        * @param $piece array
         * @param $frame PPFrame
         *
         * @return array
@@ -4324,7 +4336,7 @@ class Parser {
        }
 
        /**
-        * Transform wiki markup when saving a page by doing \r\n -> \n
+        * Transform wiki markup when saving a page by doing "\r\n" -> "\n"
         * conversion, substitting signatures, {{subst:}} templates, etc.
         *
         * @param $text String: the text to transform
@@ -4620,7 +4632,7 @@ class Parser {
        }
 
        /**
-        * Create an HTML-style tag, e.g. <yourtag>special text</yourtag>
+        * Create an HTML-style tag, e.g. "<yourtag>special text</yourtag>"
         * The callback should have the following form:
         *    function myParserHook( $text, $params, $parser, $frame ) { ... }
         *
@@ -4638,7 +4650,7 @@ class Parser {
         * this interface, as it is not documented and injudicious use could smash
         * private variables.**
         *
-        * @param $tag Mixed: the tag to use, e.g. 'hook' for <hook>
+        * @param $tag Mixed: the tag to use, e.g. 'hook' for "<hook>"
         * @param $callback Mixed: the callback function (and object) to use for the tag
         * @return Mixed|null The old value of the mTagHooks array associated with the hook
         */
@@ -4668,7 +4680,7 @@ class Parser {
         * @since 1.10
         * @todo better document or deprecate this
         *
-        * @param $tag Mixed: the tag to use, e.g. 'hook' for <hook>
+        * @param $tag Mixed: the tag to use, e.g. 'hook' for "<hook>"
         * @param $callback Mixed: the callback function (and object) to use for the tag
         * @return Mixed|null The old value of the mTagHooks array associated with the hook
         */
@@ -4776,7 +4788,7 @@ class Parser {
        }
 
        /**
-        * Create a tag function, e.g. <test>some stuff</test>.
+        * Create a tag function, e.g. "<test>some stuff</test>".
         * Unlike tag hooks, tag functions are parsed at preprocessor level.
         * Unlike parser functions, their content is not preprocessed.
         * @return null
@@ -4797,7 +4809,7 @@ class Parser {
 
        /**
         * @todo FIXME: Update documentation. makeLinkObj() is deprecated.
-        * Replace <!--LINK--> link placeholders with actual links, in the buffer
+        * Replace "<!--LINK-->" link placeholders with actual links, in the buffer
         * Placeholders created in Skin::makeLinkObj()
         *
         * @param $text string
@@ -4810,7 +4822,7 @@ class Parser {
        }
 
        /**
-        * Replace <!--LINK--> link placeholders with plain text of links
+        * Replace "<!--LINK-->" link placeholders with plain text of links
         * (not HTML-formatted).
         *
         * @param $text String
@@ -5036,27 +5048,22 @@ class Parser {
 
                                # Special case; width and height come in one variable together
                                if ( $type === 'handler' && $paramName === 'width' ) {
-                                       $m = array();
-                                       # (bug 13500) In both cases (width/height and width only),
-                                       # permit trailing "px" for backward compatibility.
-                                       if ( preg_match( '/^([0-9]*)x([0-9]*)\s*(?:px)?\s*$/', $value, $m ) ) {
-                                               $width = intval( $m[1] );
-                                               $height = intval( $m[2] );
+                                       $parsedWidthParam = $this->parseWidthParam( $value );
+                                       if( isset( $parsedWidthParam['width'] ) ) {
+                                               $width = $parsedWidthParam['width'];
                                                if ( $handler->validateParam( 'width', $width ) ) {
                                                        $params[$type]['width'] = $width;
                                                        $validated = true;
                                                }
+                                       }
+                                       if( isset( $parsedWidthParam['height'] ) ) {
+                                               $height = $parsedWidthParam['height'];
                                                if ( $handler->validateParam( 'height', $height ) ) {
                                                        $params[$type]['height'] = $height;
                                                        $validated = true;
                                                }
-                                       } elseif ( preg_match( '/^[0-9]*\s*(?:px)?\s*$/', $value ) ) {
-                                               $width = intval( $value );
-                                               if ( $handler->validateParam( 'width', $width ) ) {
-                                                       $params[$type]['width'] = $width;
-                                                       $validated = true;
-                                               }
-                                       } # else no validation -- bug 13436
+                                       }
+                                       # else no validation -- bug 13436
                                } else {
                                        if ( $type === 'handler' ) {
                                                # Validate handler parameter
@@ -5173,7 +5180,7 @@ class Parser {
 
                # Linker does the rest
                $time = isset( $options['time'] ) ? $options['time'] : false;
-               $ret = Linker::makeImageLink2( $title, $file, $params['frame'], $params['handler'],
+               $ret = Linker::makeImageLink( $this, $title, $file, $params['frame'], $params['handler'],
                        $time, $descQuery, $this->mOptions->getThumbSize() );
 
                # Give the handler a chance to modify the parser object
@@ -5282,13 +5289,13 @@ class Parser {
         *
         * @param $text String: Page wikitext
         * @param $section String: a section identifier string of the form:
-        *   <flag1> - <flag2> - ... - <section number>
+        *   "<flag1> - <flag2> - ... - <section number>"
         *
         * Currently the only recognised flag is "T", which means the target section number
         * was derived during a template inclusion parse, in other words this is a template
         * section edit link. If no flags are given, it was an ordinary section edit link.
         * This flag is required to avoid a section numbering mismatch when a section is
-        * enclosed by <includeonly> (bug 6563).
+        * enclosed by "<includeonly>" (bug 6563).
         *
         * The section number 0 pulls the text before the first heading; other numbers will
         * pull the given section along with its lower-level subsections. If the section is
@@ -5775,4 +5782,32 @@ class Parser {
        function isValidHalfParsedText( $data ) {
                return isset( $data['version'] ) && $data['version'] == self::HALF_PARSED_VERSION;
        }
+
+       /**
+        * Parsed a width param of imagelink like 300px or 200x300px
+        *
+        * @param $value String
+        *
+        * @return array
+        * @since 1.20
+        */
+       public function parseWidthParam( $value ) {
+               $parsedWidthParam = array();
+               if( $value === '' ) {
+                       return $parsedWidthParam;
+               }
+               $m = array();
+               # (bug 13500) In both cases (width/height and width only),
+               # permit trailing "px" for backward compatibility.
+               if ( preg_match( '/^([0-9]*)x([0-9]*)\s*(?:px)?\s*$/', $value, $m ) ) {
+                       $width = intval( $m[1] );
+                       $height = intval( $m[2] );
+                       $parsedWidthParam['width'] = $width;
+                       $parsedWidthParam['height'] = $height;
+               } elseif ( preg_match( '/^[0-9]*\s*(?:px)?\s*$/', $value ) ) {
+                       $width = intval( $value );
+                       $parsedWidthParam['width'] = $width;
+               }
+               return $parsedWidthParam;
+       }
 }