r39373 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r39372‎ | r39373 | r39374 >
Date:23:33, 14 August 2008
Author:brion
Status:old
Tags:
Comment:
* 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)
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/Linker.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Linker.php
@@ -1184,46 +1184,58 @@
11851185 * @todo Document the $local parameter.
11861186 */
11871187 private function formatAutocomments( $comment, $title = null, $local = false ) {
1188 - $match = array();
1189 - while (preg_match('!(.*)/\*\s*(.*?)\s*\*/(.*)!', $comment,$match)) {
1190 - $pre=$match[1];
1191 - $auto=$match[2];
1192 - $post=$match[3];
1193 - $link='';
1194 - if( $title ) {
1195 - $section = $auto;
 1188+ // Bah!
 1189+ $this->autocommentTitle = $title;
 1190+ $this->autocommentLocal = $local;
 1191+ $comment = preg_replace_callback(
 1192+ '!(.*?)/\*\s*(.*?)\s*\*/(.*?)!',
 1193+ array( $this, 'formatAutocommentsCallback' ),
 1194+ $comment );
 1195+ unset( $this->autocommentTitle );
 1196+ unset( $this->autocommentLocal );
 1197+ return $comment;
 1198+ }
 1199+
 1200+ private function formatAutocommentsCallback( $match ) {
 1201+ $title = $this->autocommentTitle;
 1202+ $local = $this->autocommentLocal;
 1203+
 1204+ $pre=$match[1];
 1205+ $auto=$match[2];
 1206+ $post=$match[3];
 1207+ $link='';
 1208+ if( $title ) {
 1209+ $section = $auto;
11961210
1197 - # Generate a valid anchor name from the section title.
1198 - # Hackish, but should generally work - we strip wiki
1199 - # syntax, including the magic [[: that is used to
1200 - # "link rather than show" in case of images and
1201 - # interlanguage links.
1202 - $section = str_replace( '[[:', '', $section );
1203 - $section = str_replace( '[[', '', $section );
1204 - $section = str_replace( ']]', '', $section );
1205 - if ( $local ) {
1206 - $sectionTitle = Title::newFromText( '#' . $section );
1207 - } else {
1208 - $sectionTitle = clone( $title );
1209 - $sectionTitle->mFragment = $section;
1210 - }
1211 - $link = $this->link( $sectionTitle,
1212 - wfMsgForContent( 'sectionlink' ), array(), array(),
1213 - 'noclasses' );
 1211+ # Generate a valid anchor name from the section title.
 1212+ # Hackish, but should generally work - we strip wiki
 1213+ # syntax, including the magic [[: that is used to
 1214+ # "link rather than show" in case of images and
 1215+ # interlanguage links.
 1216+ $section = str_replace( '[[:', '', $section );
 1217+ $section = str_replace( '[[', '', $section );
 1218+ $section = str_replace( ']]', '', $section );
 1219+ if ( $local ) {
 1220+ $sectionTitle = Title::newFromText( '#' . $section );
 1221+ } else {
 1222+ $sectionTitle = clone( $title );
 1223+ $sectionTitle->mFragment = $section;
12141224 }
1215 - $auto = $link . $auto;
1216 - if( $pre ) {
1217 - # written summary $presep autocomment (summary /* section */)
1218 - $auto = wfMsgExt( 'autocomment-prefix', array( 'escapenoentities', 'content' ) ) . $auto;
1219 - }
1220 - if( $post ) {
1221 - # autocomment $postsep written summary (/* section */ summary)
1222 - $auto .= wfMsgExt( 'colon-separator', array( 'escapenoentities', 'content' ) );
1223 - }
1224 - $auto = '<span class="autocomment">' . $auto . '</span>';
1225 - $comment = $pre . $auto . $post;
 1225+ $link = $this->link( $sectionTitle,
 1226+ wfMsgForContent( 'sectionlink' ), array(), array(),
 1227+ 'noclasses' );
12261228 }
1227 -
 1229+ $auto = $link . $auto;
 1230+ if( $pre ) {
 1231+ # written summary $presep autocomment (summary /* section */)
 1232+ $auto = wfMsgExt( 'autocomment-prefix', array( 'escapenoentities', 'content' ) ) . $auto;
 1233+ }
 1234+ if( $post ) {
 1235+ # autocomment $postsep written summary (/* section */ summary)
 1236+ $auto .= wfMsgExt( 'colon-separator', array( 'escapenoentities', 'content' ) );
 1237+ }
 1238+ $auto = '<span class="autocomment">' . $auto . '</span>';
 1239+ $comment = $pre . $auto . $post;
12281240 return $comment;
12291241 }
12301242
Index: trunk/phase3/RELEASE-NOTES
@@ -126,6 +126,8 @@
127127 * (bug 13770) Fixed incorrect detection of PHP's DOM module
128128 * (bug 14790) Export of category pages when using Category: prefix now actually
129129 gives results
 130+* Avoid recursive crazy expansions in section edit comments for pages which
 131+ contain '/*' in the title
130132
131133 === API changes in 1.14 ===
132134

Follow-up revisions

RevisionCommit summaryAuthorDate
r39594Fix regression from r39373: * marks were changed to *? , which broke the colo...rotem17:22, 18 August 2008

Status & tagging log