Jdlrobson has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/349131 )
Change subject: POC: Provide a formatter that routes through live Wikipedia content ...................................................................... POC: Provide a formatter that routes through live Wikipedia content This will help us test on some real articles rather than having to import lots of articles. I'm going to use this for testing lazy loading images but I also wanted to show how the interface works... Change-Id: I4a1cbd2cbacba34f8b57b655472de9c4dde59db8 --- M extension.json A includes/LiveWikipediaContentFormatter.php 2 files changed, 37 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend refs/changes/31/349131/1 diff --git a/extension.json b/extension.json index 73b5a80..58e730d 100644 --- a/extension.json +++ b/extension.json @@ -58,6 +58,7 @@ "MobileFrontend\\WMFBaseDomainExtractor": "includes/WMFBaseDomainExtractor.php", "MobileContext": "includes/MobileContext.php", "IParserContentFormatter": "includes/IParserContentFormatter.php", + "LiveWikipediaContentFormatter": "includes/LiveWikipediaContentFormatter.php", "MobileFormatter": "includes/MobileFormatter.php", "MobileCollection": "includes/models/MobileCollection.php", "MobilePage": "includes/models/MobilePage.php", @@ -1737,7 +1738,7 @@ ] }, "config": { - "MFMobileFormatterClass": "MobileFormatter", + "MFMobileFormatterClass": "LiveWikipediaContentFormatter", "MFEnableXAnalyticsLogging": false, "MFAppPackageId": false, "MFAppScheme": "http", diff --git a/includes/LiveWikipediaContentFormatter.php b/includes/LiveWikipediaContentFormatter.php new file mode 100644 index 0000000..5e0acbc --- /dev/null +++ b/includes/LiveWikipediaContentFormatter.php @@ -0,0 +1,35 @@ +<?php +/** + * MobileFormatter.php + */ + +use HtmlFormatter\HtmlFormatter; + +/** + * When a page is missing looks for the HTML on Wikipedia instead + */ +class LiveWikipediaContentFormatter extends MobileFormatter { + /** + * @inheritdoc + */ + public static function newFromContext( MobileContext $context, $html, + $enableSections = false, $includeTOC = false + ) { + $title = $context->getTitle(); + if ( !$title->exists() ) { + $url = 'https://en.wikipedia.org/w/api.php?formatversion=2&format=json&action=parse&prop=text&page='; + $url .= $title->getPrefixedDBKey(); + + $resp = file_get_contents( $url, false ); + $json = json_decode( $resp ); + if ( isset( $json->{'parse'} ) ) { + $parse = $json->{'parse'}; + $html = $parse->{'text'}; + } + } + + $formatter = MobileFormatter::newFromContext( $context, $html, $enableSections, $includeTOC ); + $formatter->remove( [ '.toc', '.mw-editsection', '.navbox', '.nomobile' ] ); + return $formatter; + } +} -- To view, visit https://gerrit.wikimedia.org/r/349131 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I4a1cbd2cbacba34f8b57b655472de9c4dde59db8 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MobileFrontend Gerrit-Branch: master Gerrit-Owner: Jdlrobson <jrob...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits