[MediaWiki-commits] [Gerrit] mediawiki...MinervaNeue[master]: Hygiene: Refactor Minerva history link generation

2017-11-27 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/392890 )

Change subject: Hygiene: Refactor Minerva history link generation
..


Hygiene: Refactor Minerva history link generation

* Create several sub functions to manage complexity of the history link
* Clean up MinervaTemplate to use data directly and remove isMainPage
template variable which is no longer being used.

Change-Id: I124aec9637f3635a335c58e559e578b2a56eb4c5
---
M includes/skins/MinervaTemplate.php
M includes/skins/SkinMinerva.php
M includes/skins/history.mustache
M includes/skins/minerva.mustache
4 files changed, 78 insertions(+), 70 deletions(-)

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



diff --git a/includes/skins/MinervaTemplate.php 
b/includes/skins/MinervaTemplate.php
index d747916..7726d05 100644
--- a/includes/skins/MinervaTemplate.php
+++ b/includes/skins/MinervaTemplate.php
@@ -107,18 +107,11 @@
protected function getHistoryLinkHtml( $data ) {
$action = Action::getActionName( RequestContext::getMain() );
if ( isset( $data['historyLink'] ) && $action === 'view' ) {
-   $historyLink = $data['historyLink'];
$args = [
'clockIconClass' => MinervaUI::iconClass( 
'clock-gray', 'before' ),
'arrowIconClass' => MinervaUI::iconClass(
'arrow-gray', 'element', 
'mw-ui-icon-small mf-mw-ui-icon-rotate-anti-clockwise indicator' ),
-   'isMainPage' => 
$this->getSkin()->getTitle()->isMainPage(),
-   'link' => $historyLink['href'],
-   'text' => $historyLink['text'],
-   'username' => $historyLink['data-user-name'],
-   'userGender' => 
$historyLink['data-user-gender'],
-   'timestamp' => $historyLink['data-timestamp']
-   ];
+   ] + $data['historyLink'];
$templateParser = new TemplateParser( __DIR__ );
return $templateParser->processTemplate( 'history', 
$args );
} else {
diff --git a/includes/skins/SkinMinerva.php b/includes/skins/SkinMinerva.php
index 4b7ccaa..d5e3d2e 100644
--- a/includes/skins/SkinMinerva.php
+++ b/includes/skins/SkinMinerva.php
@@ -718,16 +718,60 @@
}
 
/**
+* Get a history link which describes author and relative time of last 
edit
+* @param Title $title The Title object of the page being viewed
+* @param int $timestamp
+* @return array
+*/
+   protected function getRelativeHistoryLink( Title $title, $timestamp ) {
+   $user = $this->getUser();
+   $text = $this->msg(
+   'minerva-last-modified-date',
+   $this->getLanguage()->userDate( $timestamp, $user ),
+   $this->getLanguage()->userTime( $timestamp, $user )
+   )->parse();
+   return [
+   // Use $edit['timestamp'] (Unix format) instead of 
$timestamp (MW format)
+   'data-timestamp' => wfTimestamp( TS_UNIX, $timestamp ),
+   'href' => $this->getHistoryUrl( $title ),
+   'text' => $text,
+   ] + $this->getRevisionEditorData( $title );
+   }
+
+   /**
+* Get a history link which makes no reference to user or last edited 
time
+* @param Title $title The Title object of the page being viewed
+* @return array
+*/
+   protected function getGenericHistoryLink( Title $title ) {
+   $text = $this->msg( 'mobile-frontend-history' )->plain();
+   return [
+   'href' => $this->getHistoryUrl( $title ),
+   'text' => $text,
+   ];
+   }
+
+   /**
+* Get the URL for the history page for the given title using 
Special:History
+* when available.
+* @param Title $title The Title object of the page being viewed
+* @return string
+*/
+   protected function getHistoryUrl( Title $title ) {
+   return SpecialPageFactory::exists( 'History' ) ?
+   SpecialPage::getTitleFor( 'History', $title 
)->getLocalURL() :
+   $title->getLocalURL( [ 'action' => 'history' ] );
+   }
+
+   /**
 * Prepare the content for the 'last edited' message, e.g. 'Last edited 
on 30 August
 * 2013, at 23:31'. This message is different for the main page since 
main page
 * content is typically transcuded rather than edited directly.
 * @param Title $title The Title object of the page being viewed
-* @param 

[MediaWiki-commits] [Gerrit] mediawiki...MinervaNeue[master]: Hygiene: Refactor Minerva history link generation

2017-11-22 Thread Jdlrobson (Code Review)
Jdlrobson has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/392890 )

Change subject: Hygiene: Refactor Minerva history link generation
..

Hygiene: Refactor Minerva history link generation

* Create several sub functions to manage complexity of the history link
* Clean up MinervaTemplate to use data directly and remove isMainPage
template variable which is no longer being used.

Change-Id: I124aec9637f3635a335c58e559e578b2a56eb4c5
---
M includes/skins/MinervaTemplate.php
M includes/skins/SkinMinerva.php
M includes/skins/history.mustache
M includes/skins/minerva.mustache
4 files changed, 82 insertions(+), 67 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/skins/MinervaNeue 
refs/changes/90/392890/1

diff --git a/includes/skins/MinervaTemplate.php 
b/includes/skins/MinervaTemplate.php
index d747916..7726d05 100644
--- a/includes/skins/MinervaTemplate.php
+++ b/includes/skins/MinervaTemplate.php
@@ -107,18 +107,11 @@
protected function getHistoryLinkHtml( $data ) {
$action = Action::getActionName( RequestContext::getMain() );
if ( isset( $data['historyLink'] ) && $action === 'view' ) {
-   $historyLink = $data['historyLink'];
$args = [
'clockIconClass' => MinervaUI::iconClass( 
'clock-gray', 'before' ),
'arrowIconClass' => MinervaUI::iconClass(
'arrow-gray', 'element', 
'mw-ui-icon-small mf-mw-ui-icon-rotate-anti-clockwise indicator' ),
-   'isMainPage' => 
$this->getSkin()->getTitle()->isMainPage(),
-   'link' => $historyLink['href'],
-   'text' => $historyLink['text'],
-   'username' => $historyLink['data-user-name'],
-   'userGender' => 
$historyLink['data-user-gender'],
-   'timestamp' => $historyLink['data-timestamp']
-   ];
+   ] + $data['historyLink'];
$templateParser = new TemplateParser( __DIR__ );
return $templateParser->processTemplate( 'history', 
$args );
} else {
diff --git a/includes/skins/SkinMinerva.php b/includes/skins/SkinMinerva.php
index 4b7ccaa..0eb5e34 100644
--- a/includes/skins/SkinMinerva.php
+++ b/includes/skins/SkinMinerva.php
@@ -718,16 +718,63 @@
}
 
/**
+* Get a history link which describes author and relative time of last 
edit
+* @param Title $title The Title object of the page being viewed
+* @param integer $timestamp
+* @return string
+*/
+   protected function getRelativeHistoryLink( Title $title, $timestamp ) {
+   $user = $this->getUser();
+   $text = $this->msg(
+   'minerva-last-modified-date',
+   $this->getLanguage()->userDate( $timestamp, $user ),
+   $this->getLanguage()->userTime( $timestamp, $user )
+   )->parse();
+   return [
+   // Use $edit['timestamp'] (Unix format) instead of 
$timestamp (MW format)
+   'data-timestamp' => wfTimestamp( TS_UNIX, $timestamp ),
+   'href' => $this->getHistoryUrl( $title ),
+   'text' => $text,
+   ] + $this->getRevisionEditorData( $title );
+   }
+
+   /**
+* Get a history link which makes no reference to user or last edited 
time
+* @param Title $title The Title object of the page being viewed
+* @param integer $timestamp
+* @return string
+*/
+   protected function getGenericHistoryLink( Title $title, $timestamp ) {
+   $text = $this->msg( 'mobile-frontend-history' )->plain();
+   return [
+   'href' => $this->getHistoryUrl( $title ),
+   'text' => $text,
+   ];
+   }
+
+   /**
+* Get the URL for the history page for the given title using 
Special:History
+* when available.
+* @param Title $title The Title object of the page being viewed
+* @return string
+*/
+   protected function getHistoryUrl( Title $title ) {
+   if ( SpecialPageFactory::exists( 'History' ) ) {
+   return SpecialPage::getTitleFor( 'History', $title 
)->getLocalURL();
+   } else {
+   return $title->getLocalURL( [ 'action' => 'history' ] );
+   }
+   }
+
+   /**
 * Prepare the content for the 'last edited' message, e.g. 'Last edited 
on 30 August
 * 2013, at 23:31'. This message is different for the main page since 
main page
 * content is typically transcud