r114304 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114303‎ | r114304 | r114305 >
Date:20:27, 20 March 2012
Author:maxsem
Status:ok
Tags:
Comment:
Fixed converted sections being cached instead of unconverted, renamed section format none --> plain
Modified paths:
  • /trunk/extensions/MobileFrontend/api/ApiQueryExtracts.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MobileFrontend/api/ApiQueryExtracts.php
@@ -47,6 +47,9 @@
4848 }
4949 $text = $this->getExtract( $t );
5050 $text = $this->truncate( $text );
 51+ if ( $this->params['plaintext'] ) {
 52+ $text = $this->doSections( $text );
 53+ }
5154
5255 if ( $isXml ) {
5356 $fit = $result->addValue( array( 'query', 'pages', $id ), 'extract', array( '*' => $text ) );
@@ -283,6 +286,32 @@
284287 return $text;
285288 }
286289
 290+ private function doSections( $text ) {
 291+ $text = preg_replace_callback(
 292+ "/" . self::SECTION_MARKER_START . '(\d)'. self::SECTION_MARKER_END . "(.*?)$/m",
 293+ array( $this, 'sectionCallback' ),
 294+ $text
 295+ );
 296+ return $text;
 297+ }
 298+
 299+ private function sectionCallback( $matches ) {
 300+ if ( $this->params['sectionformat'] == 'raw' ) {
 301+ return $matches[0];
 302+ }
 303+ $func = __CLASS__ . "::doSection_{$this->params['sectionformat']}";
 304+ return call_user_func( $func, $matches[1], trim( $matches[2] ) );
 305+ }
 306+
 307+ private static function doSection_wiki( $level, $text ) {
 308+ $bars = str_repeat( '=', $level );
 309+ return "\n$bars $text $bars";
 310+ }
 311+
 312+ private static function doSection_plain( $level, $text ) {
 313+ return "\n$text";
 314+ }
 315+
287316 public function getAllowedParams() {
288317 return array(
289318 'chars' => array(
@@ -321,9 +350,9 @@
322351 'plaintext' => 'Return extracts as plaintext instead of limited HTML',
323352 'sectionformat' => array(
324353 'How to format sections in plaintext mode:',
325 - ' none - No formatting',
 354+ ' plain - No formatting',
326355 ' wiki - Wikitext-style formatting == like this ==',
327 - " raw - Return in this module's internal representation (secton titles prefixed with <ASCII 1><ASCII 2><section level><ASCII 2><ASCII 1>",
 356+ " raw - This module's internal representation (secton titles prefixed with <ASCII 1><ASCII 2><section level><ASCII 2><ASCII 1>",
328357 ),
329358 'continue' => 'When more results are available, use this to continue',
330359 );
@@ -360,7 +389,7 @@
361390 private $sectionFormat;
362391
363392 public static $sectionFormats = array(
364 - 'none',
 393+ 'plain',
365394 'wiki',
366395 'raw',
367396 );
@@ -388,11 +417,6 @@
389418 $text = html_entity_decode( $text );
390419 $text = str_replace( "\r", "\n", $text ); // for Windows
391420 $text = preg_replace( "/\n{3,}/", "\n\n", $text ); // normalise newlines
392 - $text = preg_replace_callback(
393 - "/" . ApiQueryExtracts::SECTION_MARKER_START . '(\d)'. ApiQueryExtracts::SECTION_MARKER_END . "(.*?)$/m",
394 - array( $this, 'sectionCallback' ),
395 - $text
396 - );
397421 }
398422 return $text;
399423 }
@@ -406,21 +430,4 @@
407431 }
408432 return $html;
409433 }
410 -
411 - private function sectionCallback( $matches ) {
412 - if ( $this->sectionFormat == 'raw' ) {
413 - return $matches[0];
414 - }
415 - $func = "ExtractFormatter::doSection_{$this->sectionFormat}";
416 - return call_user_func( $func, $matches[1], trim( $matches[2] ) );
417 - }
418 -
419 - private static function doSection_wiki( $level, $text ) {
420 - $bars = str_repeat( '=', $level );
421 - return "\n$bars $text $bars";
422 - }
423 -
424 - private static function doSection_none( $level, $text ) {
425 - return "\n$text";
426 - }
427434 }
\ No newline at end of file

Status & tagging log