* Avoid recursive crazy expansions in section edit comments for pages which contain...
authorBrion Vibber <brion@users.mediawiki.org>
Thu, 14 Aug 2008 23:33:02 +0000 (23:33 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Thu, 14 Aug 2008 23:33:02 +0000 (23:33 +0000)
while( preg_match ) <- bad
preg_replace_callback <- good

Old method made insane expansions like this on 'Wikipedia:Translation/*/Lang/de':

(cur) (last)  2008-08-14T22:23:48 Carcharoth (Talk | contribs | block) (12,310 bytes) (- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - →/Lang/de#.2FLang.2Fde.23.2FLang.2Fde.23.2FLang.2Fde.23.2FLang.2Fde.23.2FLang.2Fde.23.2FLang.2Fde.23.2FLang.2Fde.23.2FLang.2Fde.23.2FLang.2Fde.23.2FLang[...and on for another 30k characters...]#Latest_translation_requests" title="Wikipedia:Translation/: Lang/de">→Latest translation requests: add request) (rollback | undo)

RELEASE-NOTES
includes/Linker.php

index f6441a0..575141a 100644 (file)
@@ -126,6 +126,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 13770) Fixed incorrect detection of PHP's DOM module
 * (bug 14790) Export of category pages when using Category: prefix now actually
   gives results
+* Avoid recursive crazy expansions in section edit comments for pages which
+  contain '/*' in the title
 
 === API changes in 1.14 ===
 
index 6ddf331..7a7cb17 100644 (file)
@@ -1184,46 +1184,58 @@ class Linker {
         * @todo Document the $local parameter.
         */
        private function formatAutocomments( $comment, $title = null, $local = false ) {
-               $match = array();
-               while (preg_match('!(.*)/\*\s*(.*?)\s*\*/(.*)!', $comment,$match)) {
-                       $pre=$match[1];
-                       $auto=$match[2];
-                       $post=$match[3];
-                       $link='';
-                       if( $title ) {
-                               $section = $auto;
-
-                               # Generate a valid anchor name from the section title.
-                               # Hackish, but should generally work - we strip wiki
-                               # syntax, including the magic [[: that is used to
-                               # "link rather than show" in case of images and
-                               # interlanguage links.
-                               $section = str_replace( '[[:', '', $section );
-                               $section = str_replace( '[[', '', $section );
-                               $section = str_replace( ']]', '', $section );
-                               if ( $local ) {
-                                       $sectionTitle = Title::newFromText( '#' . $section );
-                               } else {
-                                       $sectionTitle = clone( $title );
-                                       $sectionTitle->mFragment = $section;
-                               }
-                               $link = $this->link( $sectionTitle,
-                                       wfMsgForContent( 'sectionlink' ), array(), array(),
-                                       'noclasses' );
-                       }
-                       $auto = $link . $auto;
-                       if( $pre ) {
-                               # written summary $presep autocomment (summary /* section */)
-                               $auto = wfMsgExt( 'autocomment-prefix', array( 'escapenoentities', 'content' ) ) . $auto;
-                       }
-                       if( $post ) {
-                               # autocomment $postsep written summary (/* section */ summary)
-                               $auto .= wfMsgExt( 'colon-separator', array( 'escapenoentities', 'content' ) );
+               // Bah!
+               $this->autocommentTitle = $title;
+               $this->autocommentLocal = $local;
+               $comment = preg_replace_callback(
+                       '!(.*?)/\*\s*(.*?)\s*\*/(.*?)!',
+                       array( $this, 'formatAutocommentsCallback' ),
+                       $comment );
+               unset( $this->autocommentTitle );
+               unset( $this->autocommentLocal );
+               return $comment;
+       }
+       
+       private function formatAutocommentsCallback( $match ) {
+               $title = $this->autocommentTitle;
+               $local = $this->autocommentLocal;
+               
+               $pre=$match[1];
+               $auto=$match[2];
+               $post=$match[3];
+               $link='';
+               if( $title ) {
+                       $section = $auto;
+
+                       # Generate a valid anchor name from the section title.
+                       # Hackish, but should generally work - we strip wiki
+                       # syntax, including the magic [[: that is used to
+                       # "link rather than show" in case of images and
+                       # interlanguage links.
+                       $section = str_replace( '[[:', '', $section );
+                       $section = str_replace( '[[', '', $section );
+                       $section = str_replace( ']]', '', $section );
+                       if ( $local ) {
+                               $sectionTitle = Title::newFromText( '#' . $section );
+                       } else {
+                               $sectionTitle = clone( $title );
+                               $sectionTitle->mFragment = $section;
                        }
-                       $auto = '<span class="autocomment">' . $auto . '</span>';
-                       $comment = $pre . $auto . $post;
+                       $link = $this->link( $sectionTitle,
+                               wfMsgForContent( 'sectionlink' ), array(), array(),
+                               'noclasses' );
                }
-
+               $auto = $link . $auto;
+               if( $pre ) {
+                       # written summary $presep autocomment (summary /* section */)
+                       $auto = wfMsgExt( 'autocomment-prefix', array( 'escapenoentities', 'content' ) ) . $auto;
+               }
+               if( $post ) {
+                       # autocomment $postsep written summary (/* section */ summary)
+                       $auto .= wfMsgExt( 'colon-separator', array( 'escapenoentities', 'content' ) );
+               }
+               $auto = '<span class="autocomment">' . $auto . '</span>';
+               $comment = $pre . $auto . $post;
                return $comment;
        }