* Fixed a bug where moving a page would cause the following SQL error when
[lhc/web/wiklou.git] / includes / Parser.php
index 75810d5..abd62c6 100644 (file)
@@ -184,13 +184,6 @@ class Parser
 
                $text = $this->internalParse( $text );
 
-               $dashReplace = array(
-                       '/ - /' => " – ", # N dash
-                       '/(?<=[0-9])-(?=[0-9])/' => "&ndash;", # N dash between numbers
-                       '/ -- /' => "&nbsp;&mdash; " # M dash
-               );
-               $text = preg_replace( array_keys($dashReplace), array_values($dashReplace), $text );
-               
                
                $text = $this->unstrip( $text, $this->mStripState );
                
@@ -213,6 +206,13 @@ class Parser
 
                $this->replaceLinkHolders( $text );
 
+               $dashReplace = array(
+                       '/ - /' => "&nbsp;&ndash; ", # N dash
+                       '/(?<=[\d])-(?=[\d])/' => "&ndash;", # N dash between numbers
+                       '/ -- /' => "&nbsp;&mdash; " # M dash
+               );
+               $text = preg_replace( array_keys($dashReplace), array_values($dashReplace), $text );
+
                # the position of the convert() call should not be changed. it 
                # assumes that the links are all replaces and the only thing left 
                # is the <nowiki> mark.
@@ -971,6 +971,7 @@ class Parser
         * @access private
         */
        function replaceExternalLinks( $text ) {
+               global $wgContLang;
                $fname = 'Parser::replaceExternalLinks';
                wfProfileIn( $fname );
 
@@ -1213,7 +1214,11 @@ class Parser
                                # [[Image:Foo.jpg|[http://example.com desc]]] <- having three ] in a row fucks up,
                                # the real problem is with the $e1 regex
                                # See bug 1300.
-                               if (preg_match( "/^\](.*)/s", $m[3], $n ) ) {
+                               #
+                               # Still some problems for cases where the ] is meant to be outside punctuation,
+                               # and no image is in sight. See bug 2095.
+                               #
+                               if( $text !== '' && preg_match( "/^\](.*)/s", $m[3], $n ) ) {
                                        $text .= ']'; # so that replaceExternalLinks($text) works later
                                        $m[3] = $n[1];
                                }
@@ -1340,7 +1345,7 @@ class Parser
                                
                                if ( $ns == NS_CATEGORY ) {
                                        wfProfileIn( "$fname-category" );
-                                       $t = $nt->getText();
+                                       $t = $wgContLang->convert($nt->getText());
                                        $s = rtrim($s . "\n"); # bug 87
 
                                        $wgLinkCache->suspend(); # Don't save in links/brokenlinks
@@ -1356,6 +1361,7 @@ class Parser
                                        } else {
                                                $sortkey = $text;
                                        }
+                                       $sortkey = $wgContLang->convertCategoryKey( $sortkey );
                                        $wgLinkCache->addCategoryLinkObj( $nt, $sortkey );
                                        $this->mOutput->addCategoryLink( $t );
                                        
@@ -2030,13 +2036,9 @@ class Parser
                        $mwMsgnw =& MagicWord::get( MAG_MSGNW );
                        if ( $mwMsgnw->matchStartAndRemove( $part1 ) ) {
                                $nowiki = true;
-                       } else {
-                               # Remove obsolete MSG:
-                               $mwMsg =& MagicWord::get( MAG_MSG );
-                               $mwMsg->matchStartAndRemove( $part1 );
                        }
 
-                       # Check if it is an internal message
+                       # int: is the wikitext equivalent of wfMsg()
                        $mwInt =& MagicWord::get( MAG_INT );
                        if ( $mwInt->matchStartAndRemove( $part1 ) ) {
                                if ( $this->incrementIncludeCount( 'int:'.$part1 ) ) {
@@ -2044,6 +2046,15 @@ class Parser
                                        $found = true;
                                }
                        }
+
+                       # msg: is the wikitext equivalent of wfMsgForContent()
+                       $mwMsg =& MagicWord::get( MAG_MSG );
+                       if ( $mwMsg->matchStartAndRemove( $part1 ) ) {
+                               if ( $this->incrementIncludeCount( 'msg:'.$part1 ) ) {
+                                        $text = $linestart . wfMsgReal( $part1, $args, true, true );
+                                        $found = true;
+                               }
+                       }
                }
 
                # NS
@@ -3079,6 +3090,7 @@ class Parser
                                # remember to set an alignment, don't render immediately
                                $align = 'none';
                        } elseif ( $wgUseImageResize && ! is_null( $match = $mwWidth->matchVariableStartToEnd($val) ) ) {
+                               wfDebug( "MAG_IMG_WIDTH match: $match\n" );
                                # $match is the image width in pixels
                                if ( preg_match( '/^([0-9]*)x([0-9]*)$/', $match, $m ) ) {
                                        $width = intval( $m[1] );