Jdlrobson has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/368109 )
Change subject: DONOTMERGE: Remove main page special casing code ...................................................................... DONOTMERGE: Remove main page special casing code Change-Id: I1c23fce015fd058eff6766b95e85db1befe4b3eb --- M README.md M extension.json M includes/MobileFormatter.php M includes/api/ApiMobileView.php 4 files changed, 4 insertions(+), 155 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend refs/changes/09/368109/1 diff --git a/README.md b/README.md index 07b303d..ae0385b 100644 --- a/README.md +++ b/README.md @@ -213,19 +213,6 @@ * Type: `Array` * Default: `['h1', 'h2', 'h3', 'h4', 'h5', 'h6']` -#### $wgMFSpecialCaseMainPage - -If set to true, main page HTML will receive special massaging. - -See <https://m.mediawiki.org/wiki/Mobile_Gateway/Mobile_homepage_formatting> - -Use is discouraged as it leads to unnecessary technical debt and on the long -term the goal is to deprecate usage of this config variable. Use at your own -risk! - -* Type: `Boolean` -* Default: `false` - #### $wgMFMobileHeader Requests containing header with this name will be considered as coming from diff --git a/extension.json b/extension.json index e80cc56..d79b9b3 100644 --- a/extension.json +++ b/extension.json @@ -1281,7 +1281,6 @@ "h5", "h6" ], - "MFSpecialCaseMainPage": false, "MFMobileHeader": "X-Subdomain", "MFRemovableClasses": { "beta": [], diff --git a/includes/MobileFormatter.php b/includes/MobileFormatter.php index 53ab00d..8b5a34b 100644 --- a/includes/MobileFormatter.php +++ b/includes/MobileFormatter.php @@ -58,11 +58,6 @@ * @var boolean $expandableSections */ protected $expandableSections = false; - /** - * Whether actual page is the main page - * @var boolean $mainPage - */ - protected $mainPage = false; /** * Name of the transformation option @@ -107,18 +102,14 @@ IContentProvider $provider, $enableSections = false, $includeTOC = false ) { - $mfSpecialCaseMainPage = $context->getMFConfig()->get( 'MFSpecialCaseMainPage' ); $title = $context->getTitle(); - $isMainPage = $title->isMainPage() && $mfSpecialCaseMainPage; $isFilePage = $title->inNamespace( NS_FILE ); $isSpecialPage = $title->isSpecialPage(); $html = self::wrapHTML( $provider->getHTML() ); $formatter = new MobileFormatter( $html, $title ); - $formatter->enableExpandableSections( !$isMainPage && !$isSpecialPage ); - - $formatter->setIsMainPage( $isMainPage ); + $formatter->enableExpandableSections( !$isSpecialPage ); $formatter->enableExpandableSections( $enableSections ); $formatter->enableTOCPlaceholder( $includeTOC ); @@ -142,14 +133,6 @@ */ public function enableExpandableSections( $flag = true ) { $this->expandableSections = $flag; - } - - /** - * Change mainPage (is this the main page) to $value (standard: true) - * @param boolean $value - */ - public function setIsMainPage( $value = true ) { - $this->mainPage = $value; } /** @@ -191,7 +174,7 @@ self::SHOW_FIRST_PARAGRAPH_BEFORE_INFOBOX => $showFirstParagraphBeforeInfobox ]; // Sectionify the content and transform it if necessary per section - if ( !$this->mainPage && $this->expandableSections ) { + if ( $this->expandableSections ) { list( $headings, $subheadings ) = $this->getHeadings( $doc ); $this->makeHeadingsEditable( $subheadings ); $this->makeSections( $doc, $headings, $transformOptions ); @@ -547,10 +530,6 @@ * @return string Processed HTML */ public function getText( $element = null ) { - if ( $this->mainPage ) { - $element = $this->parseMainPage( $this->getDoc() ); - } - return parent::getText( $element ); } @@ -561,81 +540,6 @@ */ protected function msg( $key ) { return wfMessage( $key )->text(); - } - - /** - * Performs transformations specific to main page - * @param DOMDocument $mainPage Tree to process - * @return DOMElement|null - */ - protected function parseMainPage( DOMDocument $mainPage ) { - $featuredArticle = $mainPage->getElementById( 'mp-tfa' ); - $newsItems = $mainPage->getElementById( 'mp-itn' ); - $centralAuthImages = $mainPage->getElementById( 'central-auth-images' ); - - // Collect all the Main Page DOM elements that have an id starting with 'mf-' - $xpath = new DOMXpath( $mainPage ); - $elements = $xpath->query( '//*[starts-with(@id, "mf-")]' ); - - // These elements will be handled specially - $commonAttributes = [ 'mp-tfa', 'mp-itn' ]; - - // Start building the new Main Page content in the $content var - $content = $mainPage->createElement( 'div' ); - $content->setAttribute( 'id', 'mainpage' ); - - // If there is a featured article section, add it to the new Main Page content - if ( $featuredArticle ) { - $h2FeaturedArticle = $mainPage->createElement( - 'h2', - $this->msg( 'mobile-frontend-featured-article' ) - ); - $content->appendChild( $h2FeaturedArticle ); - $content->appendChild( $featuredArticle ); - } - - // If there is a news section, add it to the new Main Page content - if ( $newsItems ) { - $h2NewsItems = $mainPage->createElement( 'h2', $this->msg( 'mobile-frontend-news-items' ) ); - $content->appendChild( $h2NewsItems ); - $content->appendChild( $newsItems ); - } - - // Go through all the collected Main Page DOM elements and format them for mobile - /** @var $element DOMElement */ - foreach ( $elements as $element ) { - if ( $element->hasAttribute( 'id' ) ) { - $id = $element->getAttribute( 'id' ); - // Filter out elements processed specially - if ( !in_array( $id, $commonAttributes ) ) { - // Convert title attributes into h2 headers - $sectionTitle = $element->hasAttribute( 'title' ) ? $element->getAttribute( 'title' ) : ''; - if ( $sectionTitle !== '' ) { - $element->removeAttribute( 'title' ); - $h2UnknownMobileSection = - $mainPage->createElement( 'h2', htmlspecialchars( $sectionTitle ) ); - $content->appendChild( $h2UnknownMobileSection ); - } - $br = $mainPage->createElement( 'br' ); - $br->setAttribute( 'clear', 'all' ); - $content->appendChild( $element ); - $content->appendChild( $br ); - } - } - } - - // If no mobile-appropriate content has been assembled at this point, return null. - // This will cause HtmlFormatter to fall back to using the entire page. - if ( $content->childNodes->length == 0 ) { - return null; - } - - // If there are CentralAuth 1x1 images, preserve them unmodified - if ( $centralAuthImages ) { - $content->appendChild( $centralAuthImages ); - } - - return $content; } /** diff --git a/includes/api/ApiMobileView.php b/includes/api/ApiMobileView.php index c4e357c..fe8163a 100644 --- a/includes/api/ApiMobileView.php +++ b/includes/api/ApiMobileView.php @@ -17,8 +17,6 @@ private $followRedirects; /** @var boolean Saves whether sections have the header name or not */ private $noHeadings; - /** @var boolean Saves whether the requested page is the main page */ - private $mainPage; /** @var boolean Saves whether the output is formatted or not */ private $noTransform; /** @var boolean Saves whether page images should be added or not */ @@ -105,16 +103,6 @@ $namespace = $title->getNamespace(); $this->addXAnalyticsItem( 'ns', (string)$namespace ); - // See whether the actual page (or if enabled, the redirect target) is the main page - $this->mainPage = $this->isMainPage( $title ); - if ( $this->mainPage && $this->noHeadings ) { - $this->noHeadings = false; - if ( is_callable( [ $this, 'addWarning' ] ) ) { - $this->addWarning( 'apiwarn-mobilefrontend-ignoringnoheadings', 'ignoringnoheadings' ); - } else { - $this->setWarning( "``noheadings'' makes no sense on the main page, ignoring" ); - } - } if ( isset( $prop['normalizedtitle'] ) && $title->getPrefixedText() != $params['page'] ) { $resultObj->addValue( null, $moduleName, [ 'normalizedtitle' => $title->getPageLanguage()->convert( $title->getPrefixedText() ) ] @@ -165,17 +153,7 @@ } $result = []; $missingSections = []; - if ( $this->mainPage ) { - if ( $onlyRequestedSections ) { - $requestedSections = - self::getRequestedSectionIds( $params['sections'], $data, $missingSections ); - } else { - $requestedSections = [ 0 ]; - } - $resultObj->addValue( null, $moduleName, - [ 'mainpage' => true ] - ); - } elseif ( isset( $params['sections'] ) ) { + if ( isset( $params['sections'] ) ) { $requestedSections = self::getRequestedSectionIds( $params['sections'], $data, $missingSections ); } else { @@ -333,23 +311,6 @@ */ protected function findFile( $title, $options = [] ) { return wfFindFile( $title, $options ); - } - - /** - * Check if page is the main page after follow redirect when followRedirects is true. - * - * @param Title $title Title object to check - * @return boolean - */ - protected function isMainPage( $title ) { - if ( $title->isRedirect() && $this->followRedirects ) { - $wp = $this->makeWikiPage( $title ); - $target = $wp->getRedirectTarget(); - if ( $target ) { - return $target->isMainPage(); - } - } - return $title->isMainPage(); } /** @@ -547,7 +508,6 @@ private function getData( Title $title, $noImages, $oldid = null ) { $mfConfig = MobileContext::singleton()->getMFConfig(); $mfMinCachedPageSize = $mfConfig->get( 'MFMinCachedPageSize' ); - $mfSpecialCaseMainPage = $mfConfig->get( 'MFSpecialCaseMainPage' ); global $wgMemc; @@ -629,12 +589,11 @@ if ( !$this->noTransform ) { $mf = new MobileFormatter( MobileFormatter::wrapHTML( $html ), $title ); $mf->setRemoveMedia( $noImages ); - $mf->setIsMainPage( $this->mainPage && $mfSpecialCaseMainPage ); $mf->filterContent(); $html = $mf->getText(); } - if ( $this->mainPage || $this->file ) { + if ( $this->file ) { $data = [ 'sections' => [], 'text' => [ $html ], -- To view, visit https://gerrit.wikimedia.org/r/368109 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1c23fce015fd058eff6766b95e85db1befe4b3eb 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