jenkins-bot has submitted this change and it was merged.
Change subject: Flag to disable main page transformations
......................................................................
Flag to disable main page transformations
Change-Id: Ie3b1b5f1e2c563756c128c84e76d44fd528c06c4
---
M MobileFrontend.php
M includes/MobileFormatter.php
M includes/api/ApiMobileView.php
M includes/api/ApiParseExtender.php
4 files changed, 18 insertions(+), 8 deletions(-)
Approvals:
Jdlrobson: Looks good to me, approved
jenkins-bot: Verified
diff --git a/MobileFrontend.php b/MobileFrontend.php
index 4f8debf..cc96685 100644
--- a/MobileFrontend.php
+++ b/MobileFrontend.php
@@ -589,3 +589,9 @@
* wgMFDescription variable
*/
$wgMFUseWikibaseDescription = false;
+
+/**
+ * If set to true, main page HTML will receive special massaging that removes
everything
+ * but a few select pieces.
+ */
+$wgMFSpecialCaseMainPage = true;
diff --git a/includes/MobileFormatter.php b/includes/MobileFormatter.php
index 36d56c4..c5cf544 100644
--- a/includes/MobileFormatter.php
+++ b/includes/MobileFormatter.php
@@ -65,10 +65,11 @@
* @return MobileFormatter
*/
public static function newFromContext( $context, $html ) {
+ global $wgMFSpecialCaseMainPage;
wfProfileIn( __METHOD__ );
$title = $context->getTitle();
- $isMainPage = $title->isMainPage();
+ $isMainPage = $title->isMainPage() && $wgMFSpecialCaseMainPage;
$isFilePage = $title->inNamespace( NS_FILE );
$isSpecialPage = $title->isSpecialPage();
@@ -127,7 +128,7 @@
private function doRemoveImages() {
$doc = $this->getDoc();
$domElemsToReplace = array();
- foreach( $doc->getElementsByTagName( 'img' ) as $element ) {
+ foreach ( $doc->getElementsByTagName( 'img' ) as $element ) {
$domElemsToReplace[] = $element;
}
/** @var $element DOMElement */
@@ -210,7 +211,7 @@
$id = $element->getAttribute( 'id' );
if ( !in_array( $id, $commonAttributes ) ) {
$sectionTitle = $element->hasAttribute(
'title' ) ? $element->getAttribute( 'title' ) : '';
- if( $sectionTitle !== '' ) {
+ if ( $sectionTitle !== '' ) {
$element->removeAttribute(
'title' );
$h2UnknownMobileSection =
$mainPage->createElement( 'h2', htmlspecialchars( $sectionTitle ) );
@@ -260,7 +261,7 @@
*/
protected function findTopHeading( $html ) {
$tags = array( 'h1', 'h2', 'h3', 'h4', 'h5', 'h6' );
- foreach( $tags as $tag ) {
+ foreach ( $tags as $tag ) {
if ( strpos( $html, '<' . $tag ) !== false ) {
return $tag;
}
diff --git a/includes/api/ApiMobileView.php b/includes/api/ApiMobileView.php
index 6868f3f..4b17f42 100644
--- a/includes/api/ApiMobileView.php
+++ b/includes/api/ApiMobileView.php
@@ -422,7 +422,8 @@
* @return array
*/
private function getData( Title $title, $noImages ) {
- global $wgMemc, $wgUseTidy, $wgMFTidyMobileViewSections,
$wgMFMinCachedPageSize;
+ global $wgMemc, $wgUseTidy, $wgMFTidyMobileViewSections,
$wgMFMinCachedPageSize,
+ $wgMFSpecialCaseMainPage;
wfProfileIn( __METHOD__ );
$wp = $this->makeWikiPage( $title );
@@ -486,7 +487,7 @@
$mf = new MobileFormatter( MobileFormatter::wrapHTML(
$html ), $title );
$mf->setRemoveMedia( $noImages );
$mf->filterContent();
- $mf->setIsMainPage( $this->mainPage );
+ $mf->setIsMainPage( $this->mainPage &&
$wgMFSpecialCaseMainPage );
$html = $mf->getText();
}
wfProfileOut( __METHOD__ . '-MobileFormatter' );
@@ -544,7 +545,7 @@
// Page id
$data['id'] = $wp->getId();
$user = User::newFromId( $wp->getUser() );
- if( !$user->isAnon() ) {
+ if ( !$user->isAnon() ) {
$data['lastmodifiedby'] = array(
'name' => $wp->getUserText(),
'gender' => $user->getOption( 'gender' ),
diff --git a/includes/api/ApiParseExtender.php
b/includes/api/ApiParseExtender.php
index 425783c..dd3ee2f 100644
--- a/includes/api/ApiParseExtender.php
+++ b/includes/api/ApiParseExtender.php
@@ -62,6 +62,8 @@
* @return bool
*/
public static function onAPIAfterExecute( ApiBase &$module ) {
+ global $wgMFSpecialCaseMainPage;
+
if ( $module->getModuleName() == 'parse' ) {
wfProfileIn( __METHOD__ );
$data = $module->getResultData();
@@ -75,7 +77,7 @@
$html = MobileFormatter::wrapHTML(
$data['parse']['text']['*'] );
$mf = new MobileFormatter( $html, $title );
$mf->setRemoveMedia( $params['noimages'] );
- $mf->setIsMainPage( $params['mainpage'] );
+ $mf->setIsMainPage( $params['mainpage'] &&
$wgMFSpecialCaseMainPage );
$mf->enableExpandableSections(
!$params['mainpage'] );
// HACK: need a nice way to request a TOC- and
edit link-free HTML in the first place
$mf->remove( array( '.toc', 'mw-editsection' )
);
--
To view, visit https://gerrit.wikimedia.org/r/180349
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie3b1b5f1e2c563756c128c84e76d44fd528c06c4
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: MaxSem <[email protected]>
Gerrit-Reviewer: Awjrichards <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits