(bug 23002) Imagelinks table not updated after imagemove. The actual bug was inconsis...
[lhc/web/wiklou.git] / includes / parser / Parser.php
index 3dcfe42..1f780fb 100644 (file)
@@ -114,7 +114,7 @@ class Parser {
 
        # Cleared with clearState():
        /**
-        * @var OutputPage
+        * @var ParserOutput
         */
        var $mOutput;
        var $mAutonumber, $mDTopen;
@@ -182,7 +182,7 @@ class Parser {
         */
        function __destruct() {
                if ( isset( $this->mLinkHolders ) ) {
-                       $this->mLinkHolders->__destruct();
+                       unset( $this->mLinkHolders );
                }
                foreach ( $this as $name => $value ) {
                        unset( $this->$name );
@@ -682,10 +682,8 @@ class Parser {
         * @param $matches Out parameter, Array: extracted tags
         * @param $uniq_prefix
         * @return String: stripped text
-        *
-        * @static
         */
-       public function extractTagsAndParams( $elements, $text, &$matches, $uniq_prefix = '' ) {
+       public static function extractTagsAndParams( $elements, $text, &$matches, $uniq_prefix = '' ) {
                static $n = 1;
                $stripped = '';
                $matches = array();
@@ -754,41 +752,6 @@ class Parser {
                return $this->mStripList;
        }
 
-       /**
-        * @deprecated use replaceVariables
-        */
-       function strip( $text, $state, $stripcomments = false , $dontstrip = array() ) {
-               return $text;
-       }
-
-       /**
-        * Restores pre, math, and other extensions removed by strip()
-        *
-        * always call unstripNoWiki() after this one
-        * @private
-        * @deprecated use $this->mStripState->unstrip()
-        */
-       function unstrip( $text, $state ) {
-               return $state->unstripGeneral( $text );
-       }
-
-       /**
-        * Always call this after unstrip() to preserve the order
-        *
-        * @private
-        * @deprecated use $this->mStripState->unstrip()
-        */
-       function unstripNoWiki( $text, $state ) {
-               return $state->unstripNoWiki( $text );
-       }
-
-       /**
-        * @deprecated use $this->mStripState->unstripBoth()
-        */
-       function unstripForHTML( $text ) {
-               return $this->mStripState->unstripBoth( $text );
-       }
-
        /**
         * Add an item to the strip state
         * Returns the unique tag which must be inserted into the stripped text
@@ -803,15 +766,6 @@ class Parser {
                return $rnd;
        }
 
-       /**
-        * Interface with html tidy
-        * @deprecated Use MWTidy::tidy()
-        */
-       public static function tidy( $text ) {
-               wfDeprecated( __METHOD__ );
-               return MWTidy::tidy( $text );
-       }
-
        /**
         * parse the wiki syntax used to render tables
         *
@@ -988,7 +942,6 @@ class Parser {
                return $out;
        }
 
-
        /**
         * Helper function for doTableStuff() separating the contents of cells from
         * attributes. Particularly useful as there's a possible bug and this action 
@@ -1088,7 +1041,7 @@ class Parser {
                        }
                        $return .= "\n</tr>";
 
-                       if ( ( !isset( $table[$i + 1] ) && !$simple ) || ( isset( $table[$i + 1] ) && ( $table[$i]['type'] != $table[$i + 1]['type'] ) ) ) {
+                       if ( ( !isset( $table[$i + 1] ) && !$simple ) || ( isset( $table[$i + 1] ) && isset( $table[$i + 1]['type'] ) && $table[$i]['type'] != $table[$i + 1]['type'] ) ) {
                                $return .= '</' . $table[$i]['type'] . '>';
                        }
                        $lastSection = $table[$i]['type'];
@@ -1620,7 +1573,6 @@ class Parser {
                return $attribs;
        }
 
-
        /**
         * Replace unusual URL escape codes with their equivalent characters
         *
@@ -2047,18 +1999,6 @@ class Parser {
                return $holders;
        }
 
-       /**
-        * Make a link placeholder. The text returned can be later resolved to a real link with
-        * replaceLinkHolders(). This is done for two reasons: firstly to avoid further
-        * parsing of interwiki links, and secondly to allow all existence checks and
-        * article length checks (for stub links) to be bundled into a single query.
-        *
-        * @deprecated
-        */
-       function makeLinkHolder( &$nt, $text = '', $query = array(), $trail = '', $prefix = '' ) {
-               return $this->mLinkHolders->makeHolder( $nt, $text, $query, $trail, $prefix );
-       }
-
        /**
         * Render a forced-blue link inline; protect against double expansion of
         * URLs if we're in a mode that prepends full URL prefixes to internal links.
@@ -2127,6 +2067,8 @@ class Parser {
        /**#@+
         * Used by doBlockLevels()
         * @private
+        *
+        * @return string
         */
        function closeParagraph() {
                $result = '';
@@ -2162,6 +2104,8 @@ class Parser {
         * These next three functions open, continue, and close the list
         * element appropriate to the prefix character passed into them.
         * @private
+        *
+        * @return string
         */
        function openList( $char ) {
                $result = $this->closeParagraph();
@@ -2186,6 +2130,8 @@ class Parser {
         * TODO: document
         * @param $char String
         * @private
+        *
+        * @return string
         */
        function nextItem( $char ) {
                if ( '*' === $char || '#' === $char ) {
@@ -2210,6 +2156,8 @@ class Parser {
         * TODO: document
         * @param $char String
         * @private
+        *
+        * @return string
         */
        function closeList( $char ) {
                if ( '*' === $char ) {
@@ -2585,6 +2533,9 @@ class Parser {
         * Return value of a magic variable (like PAGENAME)
         *
         * @private
+        *
+        * @param $index integer
+        * @param $frame PPFrame
         */
        function getVariableValue( $index, $frame=false ) {
                global $wgContLang, $wgSitename, $wgServer;
@@ -2933,6 +2884,8 @@ class Parser {
         * dependency requirements.
         *
         * @private
+        *
+        * @return PPNode
         */
        function preprocessToDom( $text, $flags = 0 ) {
                $dom = $this->getPreprocessor()->preprocessToObj( $text, $flags );
@@ -2941,6 +2894,8 @@ class Parser {
 
        /**
         * Return a three-element array: leading whitespace, string contents, trailing whitespace
+        *
+        * @return array
         */
        public static function splitWhitespace( $s ) {
                $ltrimmed = ltrim( $s );
@@ -2971,6 +2926,8 @@ class Parser {
         *        Providing arguments this way may be useful for extensions wishing to perform variable replacement explicitly.
         * @param $argsOnly Boolean: only do argument (triple-brace) expansion, not double-brace expansion
         * @private
+        *
+        * @return string
         */
        function replaceVariables( $text, $frame = false, $argsOnly = false ) {
                # Is there any text? Also, Prevent too big inclusions!
@@ -2994,7 +2951,11 @@ class Parser {
                return $text;
        }
 
-       # Clean up argument array - refactored in 1.9 so parserfunctions can use it, too.
+       /**
+        * Clean up argument array - refactored in 1.9 so parserfunctions can use it, too.
+        *
+        * @return array
+        */
        static function createAssocArgs( $args ) {
                $assocArgs = array();
                $index = 1;
@@ -3376,6 +3337,8 @@ class Parser {
        /**
         * Get the semi-parsed DOM representation of a template with a given title,
         * and its redirect destination title. Cached.
+        *
+        * @return array
         */
        function getTemplateDom( $title ) {
                $cacheTitle = $title;
@@ -3440,8 +3403,10 @@ class Parser {
        /**
         * Static function to get a template
         * Can be overridden via ParserOptions::setTemplateCallback().
+        *
+        * @return array
         */
-       static function statelessFetchTemplate( $title, $parser=false ) {
+       static function statelessFetchTemplate( $title, $parser = false ) {
                $text = $skip = false;
                $finalTitle = $title;
                $deps = array();
@@ -3543,8 +3508,6 @@ class Parser {
                # Register the file as a dependency...
                $this->mOutput->addImage( $title->getDBkey(), $time, $sha1 );
                if ( $file && !$title->equals( $file->getTitle() ) ) {
-                       # We fetched a rev from a different title; register it too...
-                       $this->mOutput->addImage( $file->getTitle()->getDBkey(), $time, $sha1 );
                        # Update fetched file title 
                        $title = $file->getTitle();
                }
@@ -3553,6 +3516,8 @@ class Parser {
 
        /**
         * Transclude an interwiki link.
+        *
+        * @return string
         */
        function interwikiTransclude( $title, $action ) {
                global $wgEnableScaryTranscluding;
@@ -3569,6 +3534,10 @@ class Parser {
                return $this->fetchScaryTemplateMaybeFromCache( $url );
        }
 
+       /**
+        * @param $url string
+        * @return Mixed|String
+        */
        function fetchScaryTemplateMaybeFromCache( $url ) {
                global $wgTranscludeCacheExpiry;
                $dbr = wfGetDB( DB_SLAVE );
@@ -3593,10 +3562,14 @@ class Parser {
                return $text;
        }
 
-
        /**
         * Triple brace replacement -- used for template arguments
         * @private
+        *
+        * @param $peice array
+        * @param $frame PPFrame
+        *
+        * @return array
         */
        function argSubstitution( $piece, $frame ) {
                wfProfileIn( __METHOD__ );
@@ -3650,6 +3623,8 @@ class Parser {
         *     inner      Contents of extension element
         *     noClose    Original text did not have a close tag
         * @param $frame PPFrame
+        *
+        * @return string
         */
        function extensionSubstitution( $params, $frame ) {
                $name = $frame->expand( $params['name'] );
@@ -4746,11 +4721,14 @@ class Parser {
                                // captions with multiple pipes (|) in it, until a more sensible grammar
                                // is defined for images in galleries
                                
+                               $matches[3] = $this->recursiveTagParse( trim( $matches[3] ) );
                                $altmatches = StringUtils::explode('|', $matches[3]);
-                               
+                               $magicWordAlt = MagicWord::get( 'img_alt' );
+
                                foreach ( $altmatches as $altmatch ) {
-                                       if ( substr( $altmatch, 0, 4 ) === 'alt=' ) {
-                                               $alt = $this->stripAltText( trim( substr( $altmatch, 4 ) ), false );
+                                       $match = $magicWordAlt->matchVariableStartToEnd( $altmatch );
+                                       if ( $match ) {
+                                               $alt = $this->stripAltText( $match, false );
                                        }
                                        else {
                                                // concatenate all other pipes
@@ -4761,9 +4739,7 @@ class Parser {
                                $label = substr( $label, 1 );
                        }
 
-                       $html = $this->recursiveTagParse( trim( $label ) );
-
-                       $ig->add( $title, $html, $alt );
+                       $ig->add( $title, $label, $alt );
                }
                return $ig->toHTML();
        }
@@ -5056,7 +5032,6 @@ class Parser {
         * @param $text String
         * @param $frame PPFrame
         * @return String
-        * @private
         */
        function attributeStripCallback( &$text, $frame = false ) {
                $text = $this->replaceVariables( $text, $frame );
@@ -5066,6 +5041,8 @@ class Parser {
 
        /**
         * Accessor
+        *
+        * @return array
         */
        function getTags() {
                return array_merge( array_keys( $this->mTransparentTagHooks ), array_keys( $this->mTagHooks ) );
@@ -5080,7 +5057,7 @@ class Parser {
        function replaceTransparentTags( $text ) {
                $matches = array();
                $elements = array_keys( $this->mTransparentTagHooks );
-               $text = $this->extractTagsAndParams( $elements, $text, $matches, $this->mUniqPrefix );
+               $text = self::extractTagsAndParams( $elements, $text, $matches, $this->mUniqPrefix );
 
                foreach ( $matches as $marker => $data ) {
                        list( $element, $content, $params, $tag ) = $data;
@@ -5234,10 +5211,10 @@ class Parser {
         * This function returns $oldtext after the content of the section
         * specified by $section has been replaced with $text.
         *
-        * @param $text String: former text of the article
+        * @param $oldtext String: former text of the article
         * @param $section Numeric: section identifier
         * @param $text String: replacing text
-        * #return String: modified text
+        * @return String: modified text
         */
        public function replaceSection( $oldtext, $section, $text ) {
                return $this->extractSections( $oldtext, $section, "replace", $text );
@@ -5255,7 +5232,7 @@ class Parser {
        /**
         * Get the revision object for $this->mRevisionId
         *
-        * @return either a Revision object or null
+        * @return Revision|null either a Revision object or null
         */
        protected function getRevisionObject() {
                if ( !is_null( $this->mRevisionObject ) ) {
@@ -5416,6 +5393,8 @@ class Parser {
 
        /**
         * strip/replaceVariables/unstrip for preprocessor regression testing
+        *
+        * @return string
         */
        function testSrvus( $text, $title, ParserOptions $options, $outputType = self::OT_HTML ) {
                if ( !$title instanceof Title ) {
@@ -5454,6 +5433,8 @@ class Parser {
         * This will call the callback function twice, with 'aaa' and 'bbb'. Those
         * two strings will be replaced with the value returned by the callback in
         * each case.
+        *
+        * @return string
         */
        function markerSkipCallback( $s, $callback ) {
                $i = 0;
@@ -5490,6 +5471,8 @@ class Parser {
         * array can later be loaded into another parser instance with
         * unserializeHalfParsedText(). The text can then be safely incorporated into
         * the return value of a parser hook.
+        *
+        * @return array
         */
        function serializeHalfParsedText( $text ) {
                wfProfileIn( __METHOD__ );
@@ -5538,7 +5521,9 @@ class Parser {
         * serializeHalfParsedText(), is compatible with the current version of the
         * parser.
         *
-        * @param $data Array.
+        * @param $data Array
+        *
+        * @return bool
         */
        function isValidHalfParsedText( $data ) {
                return isset( $data['version'] ) && $data['version'] == self::HALF_PARSED_VERSION;