jenkins-bot has submitted this change and it was merged.
Change subject: Hygiene: The big skin cleanup
......................................................................
Hygiene: The big skin cleanup
By exposing a way to add to template data in core
a lot of our skin code disappears magically
Note: Toggling does not work in the desktop version of
the Minerva skin. This is a known problem and being addressed
separately.
Change-Id: I43fc26bf334753b189e20921f142bade7658ac31
Dependency: I0a9a7f10ea6a2e9c90c2a83e7c5f7fa56fa0fb93
---
M includes/skins/MinervaTemplate.php
M includes/skins/SkinMinerva.php
M includes/skins/SkinMobile.php
M includes/skins/SkinMobileAlpha.php
M includes/skins/SkinMobileBeta.php
5 files changed, 94 insertions(+), 101 deletions(-)
Approvals:
Awjrichards: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/skins/MinervaTemplate.php
b/includes/skins/MinervaTemplate.php
index 0dbd3e9..e09ded2 100644
--- a/includes/skins/MinervaTemplate.php
+++ b/includes/skins/MinervaTemplate.php
@@ -10,10 +10,7 @@
}
public function execute() {
- $skin = $this->getSkin();
- $title = $skin->getTitle();
- $this->isSpecialPage = $title->isSpecialPage();
- $skin->prepareData( $this );
+ $this->isSpecialPage =
$this->getSkin()->getTitle()->isSpecialPage();
wfRunHooks( 'MinervaPreRender', array( $this ) );
$this->render( $this->data );
}
@@ -41,8 +38,9 @@
protected function renderLanguages() {
$languages = $this->getLanguages();
$variants = $this->getLanguageVariants();
- $languagesCount = count( $languages );
- $variantsCount = count( $variants );
+ // stupid php: count( false ) returns 1
+ $languagesCount = is_array( $languages ) ? count( $languages )
: 0;
+ $variantsCount = is_array( $variants ) ? count( $variants ) : 0;
if ( $languagesCount > 0 || $variantsCount > 1 ) {
$heading = wfMessage(
'mobile-frontend-language-article-heading' )->text();
diff --git a/includes/skins/SkinMinerva.php b/includes/skins/SkinMinerva.php
index bb43e7e..69d365d 100644
--- a/includes/skins/SkinMinerva.php
+++ b/includes/skins/SkinMinerva.php
@@ -14,6 +14,62 @@
/** @var array of classes that should be present on the body tag */
private $pageClassNames = array();
+ protected function prepareQuickTemplate( OutputPage $out = null ) {
+ global $wgAppleTouchIcon;
+ wfProfileIn( __METHOD__ );
+ $tpl = parent::prepareQuickTemplate( $out );
+ // add head items
+ if ( $wgAppleTouchIcon !== false ) {
+ $out->addHeadItem( 'touchicon',
+ Html::element( 'link', array( 'rel' =>
'apple-touch-icon', 'href' => $wgAppleTouchIcon ) )
+ );
+ }
+ $out->addHeadItem( 'viewport',
+ Html::element( 'meta', array( 'name' => 'viewport',
'content' => 'initial-scale=1.0, user-scalable=yes, minimum-scale=0.25,
maximum-scale=1.6' ) )
+ );
+ // hide chrome on bookmarked sites
+ $out->addHeadItem( 'apple-mobile-web-app-capable',
+ Html::element( 'meta', array( 'name' =>
'apple-mobile-web-app-capable', 'content' => 'yes' ) )
+ );
+ $out->addHeadItem( 'loadingscript', Html::inlineScript(
+ "document.documentElement.className += ' page-loading';"
+ ) );
+
+ $tpl->set( 'unstyledContent', $out->getProperty(
'unstyledContent' ) );
+
+ $this->preparePageContent( $tpl );
+ $this->prepareHeaderAndFooter( $tpl );
+ $this->prepareSearch( $tpl );
+ $this->prepareMenuButton( $tpl );
+ $this->prepareBanners( $tpl );
+ $this->prepareSiteLinks( $tpl );
+ $this->prepareWarnings( $tpl );
+ $this->preparePageActions( $tpl );
+ $this->prepareUserButton( $tpl );
+ $this->prepareDiscoveryTools( $tpl );
+ $this->preparePersonalTools( $tpl );
+ wfProfileOut( __METHOD__ );
+ return $tpl;
+ }
+
+ /**
+ * Prepares the header and the content of a page
+ * Stores in QuickTemplate prebodytext, postbodytext keys
+ * @param QuickTemplate
+ */
+ protected function preparePageContent( QuickTemplate $tpl ) {
+ $title = $this->getTitle();
+
+ // If it's a talk page, add a link to the main namespace page
+ if ( $title->isTalkPage() ) {
+ $tpl->set( 'subject-page', Linker::link(
+ $title->getSubjectPage(),
+ wfMessage( 'mobile-frontend-talk-back-to-page',
$title->getText() ),
+ array( 'class' => 'return-link' )
+ ) );
+ }
+ }
+
/**
* @param string $className: valid class name
*/
@@ -293,8 +349,7 @@
return wfMessage( 'mobile-frontend-placeholder' )->text();
}
- public function prepareData( BaseTemplate $tpl ) {
- global $wgMFEnableSiteNotice;
+ protected function prepareHeaderAndFooter( BaseTemplate $tpl ) {
$title = $this->getTitle();
$user = $this->getUser();
$out = $this->getOutput();
@@ -328,7 +383,9 @@
if ( !isset( $tpl->data['postbodytext'] ) ) {
$tpl->set( 'postbodytext', '' ); // not currently set
in desktop skin
}
+ }
+ protected function prepareSearch( BaseTemplate $tpl ) {
$searchBox = array(
'id' => 'searchInput',
'class' => 'search',
@@ -338,7 +395,9 @@
'placeholder' => $this->getSearchPlaceHolderText(),
);
$tpl->set( 'searchBox', $searchBox );
+ }
+ protected function prepareMenuButton( BaseTemplate $tpl ) {
// menu button
$url = SpecialPage::getTitleFor( 'MobileMenu' )->getLocalUrl()
. '#mw-mf-page-left';
$tpl->set( 'menuButton',
@@ -348,12 +407,18 @@
'id'=> 'mw-mf-main-menu-button',
) )
);
+ }
+ protected function prepareBanners( BaseTemplate $tpl ) {
+ global $wgMFEnableSiteNotice;
$banners = array();
if ( $wgMFEnableSiteNotice ) {
$banners[] = '<div id="siteNotice"></div>';
}
$tpl->set( 'banners', $banners );
+ }
+
+ protected function prepareSiteLinks( BaseTemplate $tpl ) {
$aboutPageTitleText = $this->msg( 'aboutpage'
)->inContentLanguage()->text();
$disclaimerPageTitleText = $this->msg( 'disclaimerpage'
)->inContentLanguage()->text();
$urls = array();
@@ -372,12 +437,19 @@
);
}
$tpl->set( 'site_urls', $urls );
- $tpl->set( 'page_actions', array() );
+ }
+
+ protected function prepareWarnings( BaseTemplate $tpl ) {
+ $out = $this->getOutput();
if ( $out->getRequest()->getText( 'oldid' ) ) {
$subtitle = $out->getSubtitle();
$tpl->set( '_old_revision_warning',
Html::openElement( 'div', array( 'class' =>
'alert warning' ) ) . $subtitle . Html::closeElement( 'div' ) );
}
+ }
+
+ protected function preparePageActions( BaseTemplate $tpl ) {
+ $title = $this->getTitle();
// Reuse template data variable from SkinTemplate to construct
page menu
$menu = array();
$namespaces = $tpl->data['content_navigation']['namespaces'];
@@ -423,11 +495,6 @@
}
$tpl->set( 'page_actions', $menu );
- $this->prepareUserButton( $tpl );
-
- $tpl->set( 'unstyledContent', $out->getProperty(
'unstyledContent' ) );
- $this->prepareDiscoveryTools( $tpl );
- $this->preparePersonalTools( $tpl );
}
/**
diff --git a/includes/skins/SkinMobile.php b/includes/skins/SkinMobile.php
index 70376b8..77b0ccd 100644
--- a/includes/skins/SkinMobile.php
+++ b/includes/skins/SkinMobile.php
@@ -1,7 +1,7 @@
<?php
// FIXME: kill the need for this file (SkinMinerva instead)
/**
- * SkinMobile: Extends Minerva with mobile specific code
+ * SkinMobile: Extends Minerva with mobile specific code that constructs the
footer and 'mobilizes' urls
*/
class SkinMobile extends SkinMinerva {
@@ -33,7 +33,7 @@
if ( !$out ) {
$out = $this->getOutput();
}
- if ( $wgMFNoindexPages ) {
+ if ( $out && $wgMFNoindexPages ) {
$out->setRobotPolicy( 'noindex,nofollow' );
}
@@ -43,22 +43,7 @@
$this->hookOptions = $options;
}
}
- $html = ExtMobileFrontend::DOMParse( $out );
-
- wfProfileIn( __METHOD__ . '-tpl' );
- $tpl = $this->prepareTemplate();
- $tpl->set( 'headelement', $out->headElement( $this ) );
- $tpl->set( 'bodytext', $html );
- $tpl->set( 'reporttime', wfReportTime() );
- $tpl->execute();
- wfProfileOut( __METHOD__ . '-tpl' );
-
- wfProfileOut( __METHOD__ );
- }
-
- public function prepareData( BaseTemplate $tpl ) {
- parent::prepareData( $tpl );
- $this->applyCustomisations( $tpl );
+ parent::outputPage( $out );
}
public function getSkinConfigVariables() {
@@ -101,55 +86,14 @@
wfRunHooks( 'EnableMobileModules', array( $out,
$this->getMode() ) );
}
- protected function prepareTemplate() {
- global $wgAppleTouchIcon;
-
+ protected function prepareQuickTemplate( OutputPage $out = null ) {
wfProfileIn( __METHOD__ );
- $tpl = $this->setupTemplate( $this->template );
- $out = $this->getOutput();
-
- $tpl->setRef( 'skin', $this );
- $tpl->set( 'wgScript', wfScript() );
-
- $this->initPage( $this->getOutput() );
- $this->loggedin = $this->getUser()->isLoggedIn();
- $content_navigation = $this->buildContentNavigationUrls();
- $tpl->setRef( 'content_navigation', $content_navigation );
- $tpl->set( 'language_urls', $this->mobilizeUrls(
$this->getLanguages() ) );
-
- // add head items
- if ( $wgAppleTouchIcon !== false ) {
- $out->addHeadItem( 'touchicon',
- Html::element( 'link', array( 'rel' =>
'apple-touch-icon', 'href' => $wgAppleTouchIcon ) )
- );
- }
- $out->addHeadItem( 'canonical',
- Html::element( 'link', array( 'href' =>
$this->getTitle()->getCanonicalURL(), 'rel' => 'canonical' ) )
- );
- $out->addHeadItem( 'viewport',
- Html::element( 'meta', array( 'name' => 'viewport',
'content' => 'initial-scale=1.0, user-scalable=yes, minimum-scale=0.25,
maximum-scale=1.6' ) )
- );
- // hide chrome on bookmarked sites
- $out->addHeadItem( 'apple-mobile-web-app-capable',
- Html::element( 'meta', array( 'name' =>
'apple-mobile-web-app-capable', 'content' => 'yes' ) )
- );
- $out->addHeadItem( 'loadingscript', Html::inlineScript(
- "document.documentElement.className += ' page-loading';"
- ) );
-
- $tpl->set( 'pagetitle', $out->getHTMLTitle() );
-
- $this->prepareTemplatePageContent( $tpl );
- $this->prepareFooterLinks( $tpl );
-
$out->setTarget( 'mobile' );
-
- $bottomScripts = Html::inlineScript(
- "document.documentElement.className =
document.documentElement.className.replace( 'page-loading', '' );"
- );
- $bottomScripts .= $out->getBottomScripts();
- $tpl->set( 'bottomscripts', $bottomScripts );
-
+ $html = ExtMobileFrontend::DOMParse( $out );
+ $tpl = parent::prepareQuickTemplate( $out );
+ $tpl->set( 'bodytext', $html );
+ $this->applyCustomisations( $tpl );
+ $this->prepareFooterLinks( $tpl );
wfProfileOut( __METHOD__ );
return $tpl;
}
@@ -288,24 +232,6 @@
return $this->mobileContext->getMobileUrl( $loginUrl,
$wgSecureLogin );
}
return SpecialPage::getTitleFor( 'Userlogin' )->getLocalURL(
$query );
- }
-
- /**
- * Prepares the header and the content of a page
- * Stores in QuickTemplate prebodytext, postbodytext keys
- * @param QuickTemplate
- */
- function prepareTemplatePageContent( QuickTemplate $tpl ) {
- $title = $this->getTitle();
-
- // If it's a talk page, add a link to the main namespace page
- if ( $title->isTalkPage() ) {
- $tpl->set( 'subject-page', Linker::link(
- $title->getSubjectPage(),
- wfMessage( 'mobile-frontend-talk-back-to-page',
$title->getText() ),
- array( 'class' => 'return-link' )
- ) );
- }
}
/**
diff --git a/includes/skins/SkinMobileAlpha.php
b/includes/skins/SkinMobileAlpha.php
index 0f816a1..23178c2 100644
--- a/includes/skins/SkinMobileAlpha.php
+++ b/includes/skins/SkinMobileAlpha.php
@@ -14,9 +14,10 @@
return $modules;
}
- public function prepareData( BaseTemplate $tpl ) {
- parent::prepareData( $tpl );
+ protected function prepareQuickTemplate( OutputPage $out = null ) {
+ $tpl = parent::prepareQuickTemplate( $out );
$this->prepareTalkLabel( $tpl );
+ return $tpl;
}
protected function prepareTalkLabel( BaseTemplate $tpl ) {
diff --git a/includes/skins/SkinMobileBeta.php
b/includes/skins/SkinMobileBeta.php
index a4862a5..0f300a2 100644
--- a/includes/skins/SkinMobileBeta.php
+++ b/includes/skins/SkinMobileBeta.php
@@ -24,10 +24,11 @@
return $styles;
}
- public function prepareData( BaseTemplate $tpl ) {
- parent::prepareData( $tpl );
+ protected function prepareQuickTemplate( OutputPage $out = null ) {
+ $tpl = parent::prepareQuickTemplate( $out );
// Move last modified link to top as long as it is not the main
page
$tpl->set( '_lastModifiedAbove',
!$this->getTitle()->isMainPage() );
+ return $tpl;
}
protected function getHistoryLink( Title $title ) {
--
To view, visit https://gerrit.wikimedia.org/r/94247
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I43fc26bf334753b189e20921f142bade7658ac31
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
Gerrit-Reviewer: Awjrichards <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits