https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113902
Revision: 113902
Author: maxsem
Date: 2012-03-15 10:04:15 +0000 (Thu, 15 Mar 2012)
Log Message:
-----------
Refactoring
Modified Paths:
--------------
trunk/extensions/MobileFrontend/HtmlFormatter.php
trunk/extensions/MobileFrontend/api/ApiQueryExcerpts.php
Modified: trunk/extensions/MobileFrontend/HtmlFormatter.php
===================================================================
--- trunk/extensions/MobileFrontend/HtmlFormatter.php 2012-03-15 10:03:46 UTC
(rev 113901)
+++ trunk/extensions/MobileFrontend/HtmlFormatter.php 2012-03-15 10:04:15 UTC
(rev 113902)
@@ -85,6 +85,13 @@
}
/**
+ * Instructs the formatter to flatten all tags
+ */
+ public function flattenAllTags() {
+ $this->flatten( '[?!]?[a-z0-9]+' );
+ }
+
+ /**
* Sets whether red links should be flattened
* @param bool $flag
*/
Modified: trunk/extensions/MobileFrontend/api/ApiQueryExcerpts.php
===================================================================
--- trunk/extensions/MobileFrontend/api/ApiQueryExcerpts.php 2012-03-15
10:03:46 UTC (rev 113901)
+++ trunk/extensions/MobileFrontend/api/ApiQueryExcerpts.php 2012-03-15
10:04:15 UTC (rev 113902)
@@ -119,12 +119,16 @@
}
}
// in case of cache miss, render just the needed section
- $apiMain = new ApiMain( new FauxRequest(
- array( 'page' => $page->getTitle()->getPrefixedText(),
'section' => 0, 'prop' => 'text' ) )
+ $api = new ApiMain( new FauxRequest(
+ array(
+ 'action' => 'parse',
+ 'page' => $page->getTitle()->getPrefixedText(),
+ 'section' => 0,
+ 'prop' => 'text'
+ ) )
);
- $apiParse = new ApiParse( $apiMain, 'parse' );
- $apiParse->execute();
- $data = $apiParse->getResultData();
+ $api->execute();
+ $data = $api->getResultData();
wfProfileOut( __METHOD__ );
return $data['parse']['text']['*'];
}
@@ -138,18 +142,18 @@
*/
private function convertText( $text, Title $title, $plainText ) {
wfProfileIn( __METHOD__ );
- $mf = new MobileFormatter( MobileFormatter::wrapHTML( $text,
false ), $title, 'XHTML' );
- $mf->removeImages();
- $mf->remove( array( 'table', 'div', 'sup.reference',
'span.coordinates',
+ $fmt = new HtmlFormatter( HtmlFormatter::wrapHTML( $text, false
), $title, 'XHTML' );
+ $fmt->removeImages();
+ $fmt->remove( array( 'table', 'div', 'sup.reference',
'span.coordinates',
'span.geo-multi-punct', 'span.geo-nondefault',
'.noexcerpt', '.error' )
);
if ( $plainText ) {
- $mf->flatten( '[?!]?[a-z0-9]+' );
+ $fmt->flattenAllTags();
} else {
- $mf->flatten( array( 'span', 'a' ) );
+ $fmt->flatten( array( 'span', 'a' ) );
}
- $mf->filterContent();
- $text = $mf->getText();
+ $fmt->filterContent();
+ $text = $fmt->getText();
if ( $plainText ) {
$text = html_entity_decode( $text );
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs