Jdlrobson has uploaded a new change for review.
https://gerrit.wikimedia.org/r/64634
Change subject: Shift code from Template to Skins
......................................................................
Shift code from Template to Skins
Stop using prepareData and leave a note on prepareBannerData
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, 105 insertions(+), 131 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend
refs/changes/34/64634/1
diff --git a/includes/skins/MinervaTemplate.php
b/includes/skins/MinervaTemplate.php
index c5be660..d675807 100644
--- a/includes/skins/MinervaTemplate.php
+++ b/includes/skins/MinervaTemplate.php
@@ -1,47 +1,6 @@
<?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>' );
- }
-
+ // FIXME: Remove. Use SkinMinerva:prepareData instead.
private function prepareBannerData() {
global $wgMFEnableSiteNotice;
$banners = '';
@@ -58,8 +17,7 @@
}
public function execute() {
- $this->prepareCommonData();
- $this->prepareData();
+ $this->getSkin()->prepareData( $this );
$this->prepareBannerData();
wfRunHooks( 'MinervaPreRender', array( $this ) );
$this->render( $this->data );
@@ -139,6 +97,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 +132,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 +156,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..a1cd179 100644
--- a/includes/skins/SkinMobileBase.php
+++ b/includes/skins/SkinMobileBase.php
@@ -10,6 +10,18 @@
/** @var array of classes that should be present on the body tag */
private $pageClassNames = array();
+ public function prepareData( BaseTemplate $tpl ) {
+ 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 );
+ }
+
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: newchange
Gerrit-Change-Id: I73bc0387fb92fd66fe6389e6f09788b0f44c941d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits