From: Brion Vibber Date: Thu, 14 Aug 2008 23:33:02 +0000 (+0000) Subject: * Avoid recursive crazy expansions in section edit comments for pages which contain... X-Git-Tag: 1.31.0-rc.0~45894 X-Git-Url: http://git.cyclocoop.org/%40spipnet%40?a=commitdiff_plain;h=bc64b21e6a87c64dedf2433922288e53b5db9607;p=lhc%2Fweb%2Fwiklou.git * Avoid recursive crazy expansions in section edit comments for pages which contain '/*' in the title 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) --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index f6441a0a3a..575141a901 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 === diff --git a/includes/Linker.php b/includes/Linker.php index 6ddf33125a..7a7cb17265 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -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 = '' . $auto . ''; - $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 = '' . $auto . ''; + $comment = $pre . $auto . $post; return $comment; }