Merge "allow combined width/height param in {{filepath:}}"
authorCatrope <roan.kattouw@gmail.com>
Thu, 26 Jul 2012 02:08:57 +0000 (02:08 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 26 Jul 2012 02:08:57 +0000 (02:08 +0000)
1  2 
includes/parser/Parser.php

   * 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
   */
@@@ -559,11 -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
         * 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.
         *
         * @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.
         * Static function to get a template
         * Can be overridden via ParserOptions::setTemplateCallback().
         *
 -       * @parma $title Title
 +       * @param $title  Title
         * @param $parser Parser
         *
         * @return array
         * Triple brace replacement -- used for template arguments
         * @private
         *
 -       * @param $peice array
 +       * @param $piece array
         * @param $frame PPFrame
         *
         * @return array
        }
  
        /**
 -       * 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
        }
  
        /**
 -       * 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 ) { ... }
         *
         * 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
         */
         * @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
         */
        }
  
        /**
 -       * 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
  
        /**
         * @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
        }
  
        /**
 -       * Replace <!--LINK--> link placeholders with plain text of links
 +       * Replace "<!--LINK-->" link placeholders with plain text of links
         * (not HTML-formatted).
         *
         * @param $text String
  
                                # 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
         *
         * @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
        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;
+       }
  }