[MediaWiki-commits] [Gerrit] mediawiki...MinervaNeue[master]: Render add discussion button in PHP not JS

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

Change subject: Render add discussion button in PHP not JS
..


Render add discussion button in PHP not JS

The talk page JavaScript progressively enhances an
existing button in the page.

Remove the frontend logic and rely entirely on whether
the button is in the page or not.

Additional change:
* The browser tests incorrectly suggest a user needs
5 edits to be able to use the talk feature. This is not
true. They just need to be logged in. Update that logic.

Bug: T167728
Change-Id: Iacedea30bdd0775b3d785db5b143abafd7a18b39
---
M includes/skins/SkinMinerva.php
M resources/skins.minerva.talk/init.js
M skin.json
M tests/browser/features/talk.feature
4 files changed, 53 insertions(+), 44 deletions(-)

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



diff --git a/includes/skins/SkinMinerva.php b/includes/skins/SkinMinerva.php
index 22459c1..10fa820 100644
--- a/includes/skins/SkinMinerva.php
+++ b/includes/skins/SkinMinerva.php
@@ -991,14 +991,24 @@
 * Returns an array with details for a talk button.
 * @param Title $talkTitle Title object of the talk page
 * @param array $talkButton Array with data of desktop talk button
+* @param bool $addSection (optional) when added the talk button will 
render
+*  as an add topic button. Defaults to false.
 * @return array
 */
-   protected function getTalkButton( $talkTitle, $talkButton ) {
+   protected function getTalkButton( $talkTitle, $talkButton, $addSection 
= false ) {
+   if ( $addSection ) {
+   $params = [ 'action' => 'edit', 'section' => 'new' ];
+   $className = 'talk continue add';
+   } else {
+   $params = [];
+   $className = 'talk';
+   }
+
return [
'attributes' => [
-   'href' => $talkTitle->getLinkURL(),
+   'href' => $talkTitle->getLinkURL( $params ),
'data-title' => $talkTitle->getFullText(),
-   'class' => 'talk',
+   'class' => $className,
],
'label' => $talkButton['text'],
];
@@ -1037,10 +1047,16 @@
// FIXME [core]: This seems unnecessary..
$subjectId = $title->getNamespaceKey( '' );
$talkId = $subjectId === 'main' ? 'talk' : 
"{$subjectId}_talk";
-   if ( isset( $namespaces[$talkId] ) && 
!$title->isTalkPage() ) {
+
+   if ( isset( $namespaces[$talkId] ) ) {
$talkButton = $namespaces[$talkId];
$talkTitle = $title->getTalkPage();
-   $buttons['talk'] = $this->getTalkButton( 
$talkTitle, $talkButton );
+   if ( $title->isTalkPage() ) {
+   $talkButton['text'] = wfMessage( 
'minerva-talk-add-topic' );
+   $buttons['talk'] = 
$this->getTalkButton( $title, $talkButton, true );
+   } else {
+   $buttons['talk'] = 
$this->getTalkButton( $talkTitle, $talkButton );
+   }
}
}
 
@@ -1265,8 +1281,7 @@
protected function isTalkAllowed() {
$title = $this->getTitle();
return $this->isAllowedPageAction( 'talk' ) &&
-   !$title->isTalkPage() &&
-   $title->canHaveTalkPage() &&
+   ( $title->isTalkPage() || $title->canHaveTalkPage() ) &&
$this->getUser()->isLoggedIn();
}
 
diff --git a/resources/skins.minerva.talk/init.js 
b/resources/skins.minerva.talk/init.js
index 7d8c1d7..c55846b 100644
--- a/resources/skins.minerva.talk/init.js
+++ b/resources/skins.minerva.talk/init.js
@@ -1,15 +1,13 @@
 ( function ( M, $ ) {
var loader = M.require( 'mobile.startup/rlModuleLoader' ),
LoadingOverlay = M.require( 'mobile.startup/LoadingOverlay' ),
-   user = M.require( 'mobile.startup/user' ),
-   Button = M.require( 'mobile.startup/Button' ),
$talk = $( '.talk' ),
// use the plain return value here - T128273
title = $talk.attr( 'data-title' ),
-   page = M.getCurrentPage(),
overlayManager = M.require( 
'skins.minerva.scripts/overlayManager' ),
skin = M.require( 'skins.minerva.scripts/skin' ),
-   pageTitle, talkTitle;
+   inTalkNamespace = fa

[MediaWiki-commits] [Gerrit] mediawiki...MinervaNeue[master]: Render add discussion button in PHP not JS

2017-09-28 Thread Jdlrobson (Code Review)
Jdlrobson has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/381315 )

Change subject: Render add discussion button in PHP not JS
..

Render add discussion button in PHP not JS

The talk page JavaScript progressively enhances an
existing button in the page.

Remove the frontend logic and rely entirely on whether
the button is in the page or not.

This was previously done in the client due to the requirement
to only show to users with 5 or more edits, but now the logic
only considers whether they are logged in.

Update tests to reflect that.

Bug: T167728
Change-Id: Iacedea30bdd0775b3d785db5b143abafd7a18b39
---
M includes/skins/SkinMinerva.php
M resources/skins.minerva.talk/init.js
M skin.json
M tests/browser/features/talk.feature
4 files changed, 49 insertions(+), 37 deletions(-)


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

diff --git a/includes/skins/SkinMinerva.php b/includes/skins/SkinMinerva.php
index 2214508..1ca3301 100644
--- a/includes/skins/SkinMinerva.php
+++ b/includes/skins/SkinMinerva.php
@@ -993,12 +993,20 @@
 * @param array $talkButton Array with data of desktop talk button
 * @return array
 */
-   protected function getTalkButton( $talkTitle, $talkButton ) {
+   protected function getTalkButton( $talkTitle, $talkButton, $addSection 
= false ) {
+   if ( $addSection ) {
+   $params = [ 'action' => 'edit', 'section' => 'new' ];
+   $className = 'talk continue add';
+   } else {
+   $params = [];
+   $className = 'talk';
+   }
+
return [
'attributes' => [
-   'href' => $talkTitle->getLinkURL(),
+   'href' => $talkTitle->getLinkURL( $params ),
'data-title' => $talkTitle->getFullText(),
-   'class' => 'talk',
+   'class' => $className,
],
'label' => $talkButton['text'],
];
@@ -1037,10 +1045,16 @@
// FIXME [core]: This seems unnecessary..
$subjectId = $title->getNamespaceKey( '' );
$talkId = $subjectId === 'main' ? 'talk' : 
"{$subjectId}_talk";
-   if ( isset( $namespaces[$talkId] ) && 
!$title->isTalkPage() ) {
+
+   if ( isset( $namespaces[$talkId] ) ) {
$talkButton = $namespaces[$talkId];
$talkTitle = $title->getTalkPage();
-   $buttons['talk'] = $this->getTalkButton( 
$talkTitle, $talkButton );
+   if ( $title->isTalkPage() ) {
+   $talkButton['text'] = wfMessage( 
'minerva-talk-add-topic' );
+   $buttons['talk'] = 
$this->getTalkButton( $title, $talkButton, true );
+   } else {
+   $buttons['talk'] = 
$this->getTalkButton( $talkTitle, $talkButton );
+   }
}
}
 
@@ -1264,8 +1278,7 @@
protected function isTalkAllowed() {
$title = $this->getTitle();
return $this->isAllowedPageAction( 'talk' ) &&
-   !$title->isTalkPage() &&
-   $title->canHaveTalkPage() &&
+   ( $title->isTalkPage() || $title->canHaveTalkPage() ) &&
$this->getUser()->isLoggedIn();
}
 
diff --git a/resources/skins.minerva.talk/init.js 
b/resources/skins.minerva.talk/init.js
index 7d8c1d7..c55846b 100644
--- a/resources/skins.minerva.talk/init.js
+++ b/resources/skins.minerva.talk/init.js
@@ -1,15 +1,13 @@
 ( function ( M, $ ) {
var loader = M.require( 'mobile.startup/rlModuleLoader' ),
LoadingOverlay = M.require( 'mobile.startup/LoadingOverlay' ),
-   user = M.require( 'mobile.startup/user' ),
-   Button = M.require( 'mobile.startup/Button' ),
$talk = $( '.talk' ),
// use the plain return value here - T128273
title = $talk.attr( 'data-title' ),
-   page = M.getCurrentPage(),
overlayManager = M.require( 
'skins.minerva.scripts/overlayManager' ),
skin = M.require( 'skins.minerva.scripts/skin' ),
-   pageTitle, talkTitle;
+   inTalkNamespace = false,
+   pageTitle, talkTitle, talkNs, pageNs;
 
// if there's no title for any reason, don't do anything
if ( !title ) {
@@ -25,12 +23,15 @@
// The method to get associated namespaces will change later (m