merging latest master
[lhc/web/wiklou.git] / includes / parser / Parser.php
index 94af6a8..24d01ce 100644 (file)
@@ -735,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();
        }
 
@@ -1937,6 +1943,7 @@ class Parser {
                                # Interwikis
                                wfProfileIn( __METHOD__."-interwiki" );
                                if ( $iw && $this->mOptions->getInterwikiMagic() && $nottalk && Language::fetchLanguageName( $iw, null, 'mw' ) ) {
+                                       // FIXME: the above check prevents links to sites with identifiers that are not language codes
                                        $this->mOutput->addLanguageLink( $nt->getFullText() );
                                        $s = rtrim( $s . $prefix );
                                        $s .= trim( $trail, "\n" ) == '' ? '': $prefix . $trail;
@@ -3552,7 +3559,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 ) {
@@ -3573,7 +3580,13 @@ class Parser {
                        }
 
                        if ( $rev ) {
-                               $text = $rev->getText();
+                               $content = $rev->getContent();
+                               $text = $content->getWikitextForTransclusion();
+
+                               if ( $text === false || $text === null ) {
+                                       $text = false;
+                                       break;
+                               }
                        } elseif ( $title->getNamespace() == NS_MEDIAWIKI ) {
                                global $wgContLang;
                                $message = wfMessage( $wgContLang->lcfirst( $title->getText() ) )->inContentLanguage();
@@ -3581,16 +3594,17 @@ class Parser {
                                        $text = false;
                                        break;
                                }
+                               $content = $message->content();
                                $text = $message->plain();
                        } else {
                                break;
                        }
-                       if ( $text === false ) {
+                       if ( !$content ) {
                                break;
                        }
                        # Redirect?
                        $finalTitle = $title;
-                       $title = Title::newFromRedirect( $text );
+                       $title = $content->getRedirectTarget();
                }
                return array(
                        'text' => $text,
@@ -5042,27 +5056,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
@@ -5179,7 +5188,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
@@ -5781,4 +5790,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;
+       }
 }