r82576 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82575‎ | r82576 | r82577 >
Date:21:37, 21 February 2011
Author:catrope
Status:ok
Tags:
Comment:
Modified paths:
  • /branches/wmf/1.17wmf1/extensions/DoubleWiki/DoubleWiki_body.php (modified) (history)
  • /branches/wmf/1.17wmf1/extensions/ProofreadPage/ProofreadPage_body.php (modified) (history)
  • /branches/wmf/1.17wmf1/extensions/WikiEditor/modules/ext.wikiEditor.toolbar.js (modified) (history)
  • /branches/wmf/1.17wmf1/includes/ImageGallery.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/Sanitizer.php (modified) (history)
  • /branches/wmf/1.17wmf1/languages/LanguageConverter.php (modified) (history)
  • /branches/wmf/1.17wmf1/languages/messages/MessagesSh.php (modified) (history)
  • /branches/wmf/1.17wmf1/languages/messages/MessagesSl.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.17wmf1/extensions/DoubleWiki/DoubleWiki_body.php
@@ -36,7 +36,7 @@
3737 * Read the list of matched phrases and add tags to the html output.
3838 */
3939 function addMatchingTags ( &$text, $lang ) {
40 - $pattern = "/<div id=\"align-$lang\" style=\"display:none;\"><pre>(.*?)<\/pre>/is";
 40+ $pattern = "/<div id=\"align-$lang\" style=\"display:none;\">\n*<pre>(.*?)<\/pre>\n*<\/div>/is";
4141 $m = array();
4242 if ( ! preg_match( $pattern, $text, $m ) ) {
4343 return;
Index: branches/wmf/1.17wmf1/extensions/WikiEditor/modules/ext.wikiEditor.toolbar.js
@@ -647,9 +647,7 @@
648648 "\u05d0", "\u05d1", "\u05d2", "\u05d3", "\u05d4", "\u05d5", "\u05d6", "\u05d7", "\u05d8",
649649 "\u05d9", "\u05db", "\u05da", "\u05dc", "\u05de", "\u05dd", "\u05e0", "\u05df", "\u05e1",
650650 "\u05e2", "\u05e4", "\u05e3", "\u05e6", "\u05e5", "\u05e7", "\u05e8", "\u05e9", "\u05ea",
651 - "\u05f3", "\u05f4", "\u05f0", "\u05f1", "\u05f2", "\u05d0", "\u05d3", "\u05d4", "\u05d5",
652 - "\u05d6", "\u05d7", "\u05d8", "\u05d9", "\u05da", "\u05db", "\u05dc", "\u05dd", "\u05de",
653 - "\u05df", "\u05e0", "\u05e1", "\u05e2", "\u05e3", "\u05e4", "\u05be", "\u05f3", "\u05f4",
 651+ "\u05f3", "\u05f4", "\u05f0", "\u05f1", "\u05f2", "\u05be",
654652 [ "\u05b0\u25cc", "\u05b0" ], [ "\u05b1\u25cc", "\u05b1" ], [ "\u05b2\u25cc", "\u05b2" ],
655653 [ "\u05b3\u25cc", "\u05b3" ], [ "\u05b4\u25cc", "\u05b4" ], [ "\u05b5\u25cc", "\u05b5" ],
656654 [ "\u05b6\u25cc", "\u05b6" ], [ "\u05b7\u25cc", "\u05b7" ], [ "\u05b8\u25cc", "\u05b8" ],
Index: branches/wmf/1.17wmf1/extensions/ProofreadPage/ProofreadPage_body.php
@@ -945,7 +945,7 @@
946946 }
947947
948948 // wrap the output in a div, to prevent the parser from inserting pararaphs
949 - $out = "<div>$out</div>";
 949+ $out = "<div>\n$out\n</div>";
950950 $out = $parser->recursiveTagParse( $out );
951951 return $out;
952952 }
Property changes on: branches/wmf/1.17wmf1/extensions/ProofreadPage/ProofreadPage_body.php
___________________________________________________________________
Modified: svn:mergeinfo
953953 Merged /trunk/extensions/ProofreadPage/ProofreadPage_body.php:r82475,82480,82547,82550,82552,82554-82555,82565
954954 Merged /trunk/phase3/extensions/ProofreadPage/ProofreadPage_body.php:r82475,82480,82538,82547,82550,82552,82554-82555,82565
Index: branches/wmf/1.17wmf1/includes/Sanitizer.php
@@ -40,7 +40,7 @@
4141 * Allows some... latitude.
4242 * Used in Sanitizer::fixTagAttributes and Sanitizer::decodeTagAttributes
4343 */
44 -$attribFirst = '[:A-Z_a-z]';
 44+$attribFirst = '[:A-Z_a-z0-9]';
4545 $attrib = '[:A-Z_a-z-.0-9]';
4646 $space = '[\x09\x0a\x0d\x20]';
4747 define( 'MW_ATTRIBS_REGEX',
Index: branches/wmf/1.17wmf1/includes/ImageGallery.php
@@ -227,7 +227,8 @@
228228
229229 if ( $this->mPerRow > 0 ) {
230230 $maxwidth = $this->mPerRow * ( $this->mWidths + 50 );
231 - $this->mAttribs['style'] = "max-width: {$maxwidth}px;_width: {$maxwidth}px;";
 231+ $oldStyle = isset( $this->mAttribs['style'] ) ? $this->mAttribs['style'] : "";
 232+ $this->mAttribs['style'] = "max-width: {$maxwidth}px;_width: {$maxwidth}px;" . $oldStyle;
232233 }
233234
234235 $attribs = Sanitizer::mergeAttributes(
Index: branches/wmf/1.17wmf1/languages/LanguageConverter.php
@@ -300,34 +300,6 @@
301301 }
302302
303303 /**
304 - * Caption convert, base on preg_replace_callback.
305 - *
306 - * To convert text in "title" or "alt", like '<img alt="text" ... '
307 - * or '<span title="text" ... '
308 - *
309 - * @return String like ' alt="yyyy"' or ' title="yyyy"'
310 - */
311 - protected function captionConvert( $matches ) {
312 - // TODO: cache the preferred variant in every autoConvert() process,
313 - // this helps improve performance in a way.
314 - $toVariant = $this->getPreferredVariant();
315 - $title = $matches[1];
316 - $text = $matches[2];
317 -
318 - // we convert captions except URL
319 - if ( !strpos( $text, '://' ) ) {
320 - $text = $this->translate( $text, $toVariant );
321 - }
322 -
323 - // remove HTML tags to prevent disrupting the layout
324 - $text = preg_replace( '/<[^>]+>/', '', $text );
325 - // escape HTML special chars to prevent disrupting the layout
326 - $text = htmlspecialchars( $text );
327 -
328 - return " {$title}=\"{$text}\"";
329 - }
330 -
331 - /**
332304 * Dictionary-based conversion.
333305 * This function would not parse the conversion rules.
334306 * If you want to parse rules, try to use convert() or
@@ -374,41 +346,75 @@
375347
376348 $reg = '/' . $codefix . $scriptfix . $prefix .
377349 '<[^>]+>|&[a-zA-Z#][a-z0-9]+;' . $marker . $htmlfix . '/s';
 350+ $startPos = 0;
 351+ $sourceBlob = '';
 352+ $literalBlob = '';
378353
379 - $matches = preg_split( $reg, $text, - 1, PREG_SPLIT_OFFSET_CAPTURE );
 354+ // Guard against delimiter nulls in the input
 355+ $text = str_replace( "\000", '', $text );
380356
381 - $m = array_shift( $matches );
 357+ while ( $startPos < strlen( $text ) ) {
 358+ if ( preg_match( $reg, $text, $markupMatches, PREG_OFFSET_CAPTURE, $startPos ) ) {
 359+ $elementPos = $markupMatches[0][1];
 360+ $element = $markupMatches[0][0];
 361+ } else {
 362+ $elementPos = strlen( $text );
 363+ $element = '';
 364+ }
382365
383 - $ret = $this->translate( $m[0], $toVariant );
384 - $mstart = $m[1] + strlen( $m[0] );
 366+ // Queue the part before the markup for translation in a batch
 367+ $sourceBlob .= substr( $text, $startPos, $elementPos - $startPos ) . "\000";
385368
386 - // enable convertsion of '<img alt="xxxx" ... '
387 - // or '<span title="xxxx" ... '
388 - $captionpattern = '/\s(title|alt)\s*=\s*"([\s\S]*?)"/';
 369+ // Advance to the next position
 370+ $startPos = $elementPos + strlen( $element );
389371
390 - $trtext = '';
391 - $trtextmark = "\0";
392 - $notrtext = array();
393 - foreach ( $matches as $m ) {
394 - $mark = substr( $text, $mstart, $m[1] - $mstart );
395 - $mark = preg_replace_callback( $captionpattern,
396 - array( &$this, 'captionConvert' ),
397 - $mark );
398 - // Let's convert the trtext only once,
399 - // it would give us more performance improvement
400 - $notrtext[] = $mark;
401 - $trtext .= $m[0] . $trtextmark;
402 - $mstart = $m[1] + strlen( $m[0] );
 372+ // Translate any alt or title attributes inside the matched element
 373+ if ( $element !== '' && preg_match( '/^(<[^>\s]*)\s([^>]*)(.*)$/', $element,
 374+ $elementMatches ) )
 375+ {
 376+ $attrs = Sanitizer::decodeTagAttributes( $elementMatches[2] );
 377+ $changed = false;
 378+ foreach ( array( 'title', 'alt' ) as $attrName ) {
 379+ if ( !isset( $attrs[$attrName] ) ) {
 380+ continue;
 381+ }
 382+ $attr = $attrs[$attrName];
 383+ // Don't convert URLs
 384+ if ( !strpos( $attr, '://' ) ) {
 385+ $attr = $this->translate( $attr, $toVariant );
 386+ }
 387+
 388+ // Remove HTML tags to avoid disrupting the layout
 389+ $attr = preg_replace( '/<[^>]+>/', '', $attr );
 390+ if ( $attr !== $attrs[$attrName] ) {
 391+ $attrs[$attrName] = $attr;
 392+ $changed = true;
 393+ }
 394+ }
 395+ if ( $changed ) {
 396+ $element = $elementMatches[1] . Html::expandAttributes( $attrs ) .
 397+ $elementMatches[3];
 398+ }
 399+ }
 400+ $literalBlob .= $element . "\000";
403401 }
404 - $notrtext[] = '';
405 - $trtext = $this->translate( $trtext, $toVariant );
406 - $trtext = StringUtils::explode( $trtextmark, $trtext );
407 - foreach ( $trtext as $t ) {
408 - $ret .= array_shift( $notrtext );
409 - $ret .= $t;
 402+
 403+ // Do the main translation batch
 404+ $translatedBlob = $this->translate( $sourceBlob, $toVariant );
 405+
 406+ // Put the output back together
 407+ $translatedIter = StringUtils::explode( "\000", $translatedBlob );
 408+ $literalIter = StringUtils::explode( "\000", $literalBlob );
 409+ $output = '';
 410+ while ( $translatedIter->valid() && $literalIter->valid() ) {
 411+ $output .= $translatedIter->current();
 412+ $output .= $literalIter->current();
 413+ $translatedIter->next();
 414+ $literalIter->next();
410415 }
 416+
411417 wfProfileOut( __METHOD__ );
412 - return $ret;
 418+ return $output;
413419 }
414420
415421 /**
Property changes on: branches/wmf/1.17wmf1/languages/LanguageConverter.php
___________________________________________________________________
Modified: svn:mergeinfo
416422 Merged /trunk/phase3/languages/LanguageConverter.php:r82475,82480,82538,82547,82550,82552,82554-82555,82565
Index: branches/wmf/1.17wmf1/languages/messages/MessagesSh.php
@@ -26,6 +26,8 @@
2727 NS_CATEGORY_TALK => 'Razgovor_o_kategoriji',
2828 );
2929
 30+$linkTrail = '/^([a-zčćđžš]+)(.*)$/sDu';
 31+
3032 $messages = array(
3133 # User preference toggles
3234 'tog-underline' => 'Podvuci linkove:',
Index: branches/wmf/1.17wmf1/languages/messages/MessagesSl.php
@@ -152,6 +152,8 @@
153153 'url_query' => array( '0', 'POIZVEDBA', 'QUERY' ),
154154 );
155155
 156+$linkTrail = '/^([a-zčćđžš]+)(.*)$/sDu';
 157+
156158 $datePreferences = array(
157159 'default',
158160 'dmy short',

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r82475Relaxed the allowed format of parser tag attributes as per bug 27539. One sid...sean_colombo19:25, 19 February 2011
r82480(Bug 27539) Allow attributes beginning with a digit in wiktext tag parameters....platonides20:16, 19 February 2011
r82538Gallery's perrow was overwriting the original style= attribute.hartman21:31, 20 February 2011
r82547Add basic linktrail to SH and SLreedy13:33, 21 February 2011
r82550Rewrote LanguageConverter::autoConvert() to make it use preg_match() with an ...tstarling14:17, 21 February 2011
r82552close div forgotten in r82513; match new lines too.thomasv14:48, 21 February 2011
r82554WikiEditor: removed duplicate Hebrew characters. Reported on IRC by Yair Rand.maxsem15:35, 21 February 2011
r82555prevent unwanted paragraph creationthomasv15:36, 21 February 2011
r82565Per Hashar on r82547, u modifier needed on regexesreedy19:02, 21 February 2011

Status & tagging log