jenkins-bot has submitted this change and it was merged.

Change subject: Shift code from Template to Skins
......................................................................


Shift code from Template to Skins

Stop using prepareData and prepareBannerData
Logic belongs in the Skin class. Template class should be dumb.

Change-Id: I73bc0387fb92fd66fe6389e6f09788b0f44c941d
---
M includes/skins/MinervaTemplate.php
M includes/skins/MobileTemplate.php
M includes/skins/SkinMinerva.php
M includes/skins/SkinMobile.php
M includes/skins/SkinMobileBase.php
5 files changed, 118 insertions(+), 147 deletions(-)

Approvals:
  MaxSem: Verified; Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/skins/MinervaTemplate.php 
b/includes/skins/MinervaTemplate.php
index c5be660..50ba236 100644
--- a/includes/skins/MinervaTemplate.php
+++ b/includes/skins/MinervaTemplate.php
@@ -1,66 +1,7 @@
 <?php
 class MinervaTemplate extends BaseTemplate {
-       public function getSearchPlaceholderText() {
-               return wfMessage( 'mobile-frontend-placeholder' )->escaped();
-       }
-
-       private function prepareCommonData() {
-               // set defaults
-               if ( !isset( $this->data['postbodytext'] ) ) {
-                       $this->set( 'postbodytext', '' ); // not set in desktop 
skin
-               }
-               $searchBox = $this->makeSearchInput(
-                       array(
-                               'id' => 'searchInput',
-                               'class' => 'search',
-                               'autocomplete' => 'off',
-                               'placeholder' => 
$this->getSearchPlaceholderText(),
-                       )
-               );
-               $script = $this->data['wgScript'];
-               $searchButton = $this->makeSearchButton( 'go', array( 'class' 
=> 'searchSubmit' ) );
-               $header = <<<HTML
-<form action="{$script}" class="search-box">
-       {$searchBox}
-       {$searchButton}
-</form>
-HTML;
-               $this->set( 'header', $header );
-
-               // menu button
-               $url = SpecialPage::getTitleFor( 'MobileMenu' )->getLocalUrl() 
. '#mw-mf-page-left';
-               $this->set( 'menuButton',
-                       Html::element( 'a', array(
-                       'title' => wfMessage( 
'mobile-frontend-main-menu-button-tooltip' ),
-                       'href' => $url,
-                       'id'=> 'mw-mf-main-menu-button',
-                       ) )
-               );
-       }
-
-       public function prepareData() {
-               $this->set( 'prebodytext', '<h1>' . $this->data[ 'title' ] . 
'</h1>' );
-       }
-
-       private function prepareBannerData() {
-               global $wgMFEnableSiteNotice;
-               $banners = '';
-               if ( isset( $this->data['zeroRatedBanner'] ) ) { // FIXME: Add 
hook and move to Zero extension?
-                       $banners .= $this->data['zeroRatedBanner'];
-               }
-               if ( isset( $this->data['notice'] ) ) {
-                       $banners .= $this->data['notice'];
-               }
-               if ( $wgMFEnableSiteNotice ) {
-                       $banners .= '<div id="siteNotice"></div>';
-               }
-               $this->set( 'banners', $banners );
-       }
-
        public function execute() {
-               $this->prepareCommonData();
-               $this->prepareData();
-               $this->prepareBannerData();
+               $this->getSkin()->prepareData( $this );
                wfRunHooks( 'MinervaPreRender', array( $this ) );
                $this->render( $this->data );
        }
@@ -139,6 +80,7 @@
        }
 
        protected function render( $data ) { // FIXME: replace with template 
engines
+               $isSpecialPage = $this->getSkin()->getTitle()->isSpecialPage();
                $languages = $this->getLanguages();
                $variants = $this->getLanguageVariants();
                $languageData = array(
@@ -173,7 +115,18 @@
                                <div class="header">
                                <?php
                                        echo $this->html( 'menuButton' );
-                                       echo $this->html( 'header' );
+                                       if ( $isSpecialPage ) {
+                                               echo $data['specialPageHeader'];
+                                       } else {
+                                               ?>
+                                               <form action="<?php echo 
$data['wgScript'] ?>" class="search-box">
+                                               <?php
+                                               echo $this->makeSearchInput( 
$data['searchBox'] );
+                                               echo $this->makeSearchButton( 
'go', array( 'class' => 'searchSubmit' ) );
+                                               ?>
+                                               </form>
+                                               <?php
+                                       }
                                ?>
                                        <ul id="mw-mf-menu-page">
                                                <?php
@@ -186,7 +139,10 @@
                                <div class='show' id='content_wrapper'>
                                        <div id="content" class="content">
                                                <?php
-                                                       echo 
$data['prebodytext'];
+                                                       if ( !$isSpecialPage ) {
+                                                               echo 
$data['prebodytext'];
+                                                               echo 
$data['talklink'];
+                                                       }
                                                        echo $data[ 'bodytext' 
];
                                                        echo 
$this->renderLanguages( $languageData );
                                                        echo 
$data['postbodytext'];
diff --git a/includes/skins/MobileTemplate.php 
b/includes/skins/MobileTemplate.php
index 689283d..6385bfd 100644
--- a/includes/skins/MobileTemplate.php
+++ b/includes/skins/MobileTemplate.php
@@ -1,47 +1,11 @@
 <?php
 
 class MobileTemplate extends MinervaTemplate {
-       public function getMode() {
-               $context = MobileContext::singleton();
-               if ( $context->isAlphaGroupMember() ) {
-                       return 'alpha';
-               } else if ( $context->isBetaGroupMember() ) {
-                       return 'beta';
-               } else {
-                       return 'stable';
-               }
-       }
-
-       public function getSearchPlaceholderText() {
-               $mode = $this->getMode();
-               if ( $mode === 'alpha' ) {
-                       return wfMessage( 'mobile-frontend-placeholder-alpha' 
)->escaped();
-               } else if ( $mode === 'beta' ) {
-                       return wfMessage( 'mobile-frontend-placeholder-beta' 
)->escaped();
-               } else {
-                       return wfMessage( 'mobile-frontend-placeholder' 
)->escaped();
-               }
-       }
-
        /**
         * Constructor
         */
        public function __construct() {
                parent::__construct();
-       }
-
-       public function prepareData() {
-               global $wgExtensionAssetsPath;
-               $data = $this->data;
-
-               wfProfileIn( __METHOD__ );
-               $this->setRef( 'wgExtensionAssetsPath', $wgExtensionAssetsPath 
);
-
-               $this->set( 'bottomscripts', $data['bottomScripts'] );
-               if ( isset( $data['specialPageHeader'] ) ) {
-                       $this->set( 'header', $data['specialPageHeader'] );
-               }
-               wfProfileOut( __METHOD__ );
        }
 
        public function getPersonalTools() {
diff --git a/includes/skins/SkinMinerva.php b/includes/skins/SkinMinerva.php
index 6b0b4d9..6916181 100644
--- a/includes/skins/SkinMinerva.php
+++ b/includes/skins/SkinMinerva.php
@@ -24,6 +24,57 @@
                $out->addJsConfigVars( $this->getSkinConfigVariables() );
        }
 
+       public function prepareData( BaseTemplate $tpl ) {
+               $title = $this->getTitle();
+               $user = $this->getUser();
+               $out = $this->getOutput();
+               if ( $title->isSpecial( 'Userlogin' ) ) {
+                       $pageHeading = $this->getLoginPageHeading();
+               } else if ( $title->isMainPage() ) {
+                       $pageHeading = $user->isLoggedIn() ?
+                               wfMessage( 
'mobile-frontend-logged-in-homepage-notification', $user->getName() )->text() : 
'';
+               } else {
+                       $pageHeading = $out->getPageTitle();
+               }
+
+               $htmlHeader = $out->getProperty( 'mobile.htmlHeader' );
+               if ( $title->isSpecialPage() ) {
+                       if ( !$htmlHeader ) {
+                               $htmlHeader = Html::element( 'h1', array(), 
$pageHeading );
+                       }
+                       $tpl->set( 'specialPageHeader', $htmlHeader );
+               } else {
+                       $preBodyText = Html::rawElement( 'h1', array( 'id' => 
'section_0' ), $pageHeading );
+                       $tpl->set( 'prebodytext', $preBodyText );
+               }
+               if ( !isset( $tpl->data['talklink'] ) ) {
+                       $tpl->set( 'talklink', '' );
+               }
+
+               // set defaults
+               if ( !isset( $this->data['postbodytext'] ) ) {
+                       $tpl->set( 'postbodytext', '' ); // not currently set 
in desktop skin
+               }
+
+               $searchBox = array(
+                       'id' => 'searchInput',
+                       'class' => 'search',
+                       'autocomplete' => 'off',
+                       'placeholder' =>  wfMessage( 
'mobile-frontend-placeholder' )->escaped(),
+               );
+               $tpl->set( 'searchBox', $searchBox );
+
+               // menu button
+               $url = SpecialPage::getTitleFor( 'MobileMenu' )->getLocalUrl() 
. '#mw-mf-page-left';
+               $tpl->set( 'menuButton',
+                       Html::element( 'a', array(
+                       'title' => wfMessage( 
'mobile-frontend-main-menu-button-tooltip' ),
+                       'href' => $url,
+                       'id'=> 'mw-mf-main-menu-button',
+                       ) )
+               );
+       }
+
        /**
         * Returns array of config variables that should be added only to this 
skin for use in javascript
         * @return Array
diff --git a/includes/skins/SkinMobile.php b/includes/skins/SkinMobile.php
index f8a2e45..68a8cd7 100644
--- a/includes/skins/SkinMobile.php
+++ b/includes/skins/SkinMobile.php
@@ -164,52 +164,35 @@
                $isSpecialPage = $title->isSpecialPage();
                $isMainPage = $title->isMainPage();
                $user = $this->getUser();
-               $userLogin = $title->isSpecial( 'Userlogin' );
                $out = $this->getOutput();
                $ctx = MobileContext::singleton();
                $inAlpha = $ctx->isAlphaGroupMember();
 
-               if ( $userLogin ) {
-                       $pageHeading = $this->getLoginPageHeading();
-               } else {
-                       $pageHeading = $out->getPageTitle();
-               }
-
-               $preBodyText = '';
                $postBodyText = '';
                if ( !$isSpecialPage ) {
-                       $headingOptions = array();
-                       if ( $isMainPage ) {
-                               $pageHeading = $user->isLoggedIn() ?
-                                       wfMessage( 
'mobile-frontend-logged-in-homepage-notification', $user->getName() )->text() : 
'';
-                       } else {
-                               $headingOptions = array( 'id' => 'section_0' );
-                       }
-                       // prepend heading to articles
-                       if ( $pageHeading ) {
-                               $preBodyText = Html::rawElement( 'h1', 
$headingOptions, $pageHeading );
-                               // talk page link for logged in alpha users
-                               if ( $inAlpha && $user->isLoggedIn() && 
!$title->isTalkPage() ) {
-                                       $talkTitle = $title->getTalkPage();
-                                       if ( $talkTitle->getArticleID() ) {
-                                               $dbr = wfGetDB( DB_SLAVE );
-                                               $numTopics = $dbr->selectField( 
'page_props', 'pp_value',
-                                                       array( 'pp_page' => 
$talkTitle->getArticleID(), 'pp_propname' => 'page_top_level_section_count' ),
-                                                       __METHOD__
-                                               );
-                                       } else {
-                                               $numTopics = 0;
-                                       }
-                                       if ( $numTopics ) {
-                                               $talkLabel = 
$this->getLanguage()->formatNum( $numTopics );
-                                       } else {
-                                               $talkLabel = wfMessage( 
'mobile-frontend-talk-overlay-header' );
-                                       }
-                                       // @todo: Redlink support when we have 
good editing
-                                       $preBodyText .= Html::element( 'a',
-                                               array( 'href' => 
$talkTitle->getLocalURL(), 'id' => 'talk' ),
-                                               $talkLabel );
+
+                       // talk page link for logged in alpha users
+                       if ( $inAlpha && $user->isLoggedIn() && 
!$title->isTalkPage() ) {
+                               $talkTitle = $title->getTalkPage();
+                               if ( $talkTitle->getArticleID() ) {
+                                       $dbr = wfGetDB( DB_SLAVE );
+                                       $numTopics = $dbr->selectField( 
'page_props', 'pp_value',
+                                               array( 'pp_page' => 
$talkTitle->getArticleID(), 'pp_propname' => 'page_top_level_section_count' ),
+                                               __METHOD__
+                                       );
+                               } else {
+                                       $numTopics = 0;
                                }
+                               if ( $numTopics ) {
+                                       $talkLabel = 
$this->getLanguage()->formatNum( $numTopics );
+                               } else {
+                                       $talkLabel = wfMessage( 
'mobile-frontend-talk-overlay-header' );
+                               }
+                               // @todo: Redlink support when we have good 
editing
+                               $talkLink = Html::element( 'a',
+                                       array( 'href' => 
$talkTitle->getLocalURL(), 'id' => 'talk' ),
+                                       $talkLabel );
+                               $tpl->set( 'talklink', $talkLink );
                        }
 
                        // add last modified timestamp
@@ -227,15 +210,6 @@
                        ), $lastModified );
                }
 
-               $htmlHeader = $this->getOutput()->getProperty( 
'mobile.htmlHeader' );
-               if ( $isSpecialPage ) {
-                       if ( !$htmlHeader ) {
-                               $htmlHeader = Html::element( 'h1', array(), 
$pageHeading );
-                       }
-                       $tpl->set( 'specialPageHeader', $htmlHeader );
-               }
-
-               $tpl->set( 'prebodytext', $preBodyText );
                $tpl->set( 'postbodytext', $postBodyText );
        }
 
@@ -282,7 +256,7 @@
                );
                $bottomScripts .= $out->getBottomScripts();
 
-               $tpl->set( 'bottomScripts', $bottomScripts );
+               $tpl->set( 'bottomscripts', $bottomScripts );
                return $tpl;
        }
 
diff --git a/includes/skins/SkinMobileBase.php 
b/includes/skins/SkinMobileBase.php
index b62e2d8..d95735d 100644
--- a/includes/skins/SkinMobileBase.php
+++ b/includes/skins/SkinMobileBase.php
@@ -10,6 +10,32 @@
        /** @var array of classes that should be present on the body tag */
        private $pageClassNames = array();
 
+       public function prepareData( BaseTemplate $tpl ) {
+               global $wgMFEnableSiteNotice;
+               parent::prepareData( $tpl );
+               $context = MobileContext::singleton();
+               $search = $tpl->data['searchBox'];
+               if ( $context->isAlphaGroupMember() ) {
+                       $search['placeholder'] = wfMessage( 
'mobile-frontend-placeholder-alpha' )->escaped();
+               } else if ( $context->isBetaGroupMember() ) {
+                       $search['placeholder'] = wfMessage( 
'mobile-frontend-placeholder-beta' )->escaped();
+               }
+               $tpl->set( 'searchBox', $search );
+
+               $banners = '';
+               // FIXME: Move to Zero extension MinervaPreRender hook
+               if ( isset( $tpl->data['zeroRatedBanner'] ) ) {
+                       $banners .= $tpl->data['zeroRatedBanner'];
+               }
+               if ( isset( $tpl->data['notice'] ) ) {
+                       $banners .= $tpl->data['notice'];
+               }
+               if ( $wgMFEnableSiteNotice ) {
+                       $banners .= '<div id="siteNotice"></div>';
+               }
+               $tpl->set( 'banners', $banners );
+       }
+
        public function getSkinConfigVariables() {
                global $wgCookiePath;
                $ctx = MobileContext::singleton();

-- 
To view, visit https://gerrit.wikimedia.org/r/64634
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I73bc0387fb92fd66fe6389e6f09788b0f44c941d
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
Gerrit-Reviewer: Dr0ptp4kt <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: Yurik <[email protected]>
Gerrit-Reviewer: awjrichards <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to