r46400 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r46399‎ | r46400 | r46401 >
Date:23:12, 27 January 2009
Author:brion
Status:ok
Tags:
Comment:
Revert r46068 " Enable language conversion in "alt" and "title" attributes."
Use of eval is strongly discouraged, on penalty of death. :) Needs to be redone using preg_replace_callback
Modified paths:
  • /trunk/phase3/languages/LanguageConverter.php (modified) (history)

Diff [purge]

Index: trunk/phase3/languages/LanguageConverter.php
@@ -199,24 +199,6 @@
200200 }
201201
202202 /**
203 - * caption convert, base on preg_replace
204 - *
205 - * to convert text in "title" or "alt", like '<img alt="text" ... '
206 - * or '<span title="text" ... '
207 - *
208 - * @param string $title the "title" or "alt" text
209 - * @param string $text the text to be converted
210 - * @param string $toVariant the target language code
211 - * @return string like ' alt="yyyy"' or ' title="yyyy"'
212 - */
213 - protected function captionConvert( $title, $text, $toVariant ) {
214 - // we convert captions except URL
215 - if( !strpos( $text, '://' ) )
216 - $text = $this->translate($text, $toVariant);
217 - return " $title=\"$text\"";
218 - }
219 -
220 - /**
221203 * dictionary-based conversion
222204 *
223205 * @param string $text the text to be converted
@@ -266,14 +248,8 @@
267249
268250 $ret = $this->translate($m[0], $toVariant);
269251 $mstart = $m[1]+strlen($m[0]);
270 -
271 - // enable convertsion of '<img alt="xxxx" ... ' or '<span title="xxxx" ... '
272 - $captionpattern = '/\s(title|alt)\s*=\s*"([\s\S]*?)"/e';
273 - $replacement = "\$this->captionConvert('\\1', '\\2', \$toVariant)";
274252 foreach($matches as $m) {
275 - $mark = substr($text, $mstart, $m[1]-$mstart);
276 - $mark = preg_replace($captionpattern, $replacement, $mark);
277 - $ret .= $mark;
 253+ $ret .= substr($text, $mstart, $m[1]-$mstart);
278254 $ret .= $this->translate($m[0], $toVariant);
279255 $mstart = $m[1] + strlen($m[0]);
280256 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r46068Enable language conversion...philip07:56, 23 January 2009

Status & tagging log