Phuedx has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/204490

Change subject: Beta: Add the "Tags" section
......................................................................

Beta: Add the "Tags" section

* Add a wgMFBrowseTags static list of tags, which is empty by default
* Add the MobileFrontend\Browse\TagService class that simply returns
  wgMFBrowseTags for every mainspace article
* Render the set of tags returned by the TagService using a Mustache template
* Try and keep everything isolated, i.e. namespaced, as this is a prototype

Bug: T94739

Change-Id: I27e78c22c217b3752894bb4ea2bcf3d8bbd9a436
---
M MobileFrontend.php
M i18n/en.json
M i18n/qqq.json
M includes/Resources.php
A includes/browse/TagService.php
M includes/config/Experimental.php
M includes/skins/MinervaTemplate.php
M includes/skins/MinervaTemplateBeta.php
M includes/skins/SkinMinervaBeta.php
A less/browse/tags.less
A templates/browse/tags.mustache
A tests/phpunit/browse/TagServiceTest.php
12 files changed, 198 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/90/204490/1

diff --git a/MobileFrontend.php b/MobileFrontend.php
index eb8acfe..a2f589d 100644
--- a/MobileFrontend.php
+++ b/MobileFrontend.php
@@ -100,6 +100,8 @@
        'UserLoginAndCreateTemplate' => 'skins/UserLoginAndCreateTemplate',
        'UserLoginMobileTemplate' => 'skins/UserLoginMobileTemplate',
        'UserAccountCreateMobileTemplate' => 
'skins/UserAccountCreateMobileTemplate',
+
+       'MobileFrontend\Browse\TagService' => 'browse/TagService',
 );
 
 foreach ( $autoloadClasses as $className => $classFilename ) {
diff --git a/i18n/en.json b/i18n/en.json
index 4d03f1d..2c2e6bd 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -408,5 +408,6 @@
        "mobile-frontend-days-ago": "$1 {{PLURAL:$1|day|days}} ago",
        "mobile-frontend-months-ago": "$1 {{PLURAL:$1|month|months}} ago",
        "mobile-frontend-years-ago": "$1 {{PLURAL:$1|year|years}} ago",
-       "mobile-frontend-console-recruit": "\\o/ Hey! This is open source 
software and we need volunteers to help us build this thing, make it better and 
fix any bugs that you might be seeing in this JavaScript console!\n\nYou can 
find our backlog @ https://phabricator.wikimedia.org/project/view/67/";
+       "mobile-frontend-console-recruit": "\\o/ Hey! This is open source 
software and we need volunteers to help us build this thing, make it better and 
fix any bugs that you might be seeing in this JavaScript console!\n\nYou can 
find our backlog @ https://phabricator.wikimedia.org/project/view/67/";,
+       "mobile-frontend-browse-tags-header": "Tags"
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 76b6e5e..e32bc86 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -436,5 +436,6 @@
        "mobile-frontend-days-ago": "Expression of duration of time passed in 
days.\nParameter:\n* $1 - number of days that have passed.",
        "mobile-frontend-months-ago": "Expression of duration of time passed in 
months.\nParameter:\n * $1 - number of months that have passed.",
        "mobile-frontend-years-ago": "Expression of duration of time passed in 
years.\nParameter:\n * $1 - number of years that have passed.",
-       "mobile-frontend-console-recruit": "Message that is displayed in the 
JavaScript console aimed at developers in an attempt to recruit volunteers. The 
\\o/ emoticon is a man with his arms in the air with the purpose of drawing 
attention to the message. If this doesn't translate into the destination 
language feel free to omit it or use something more applicable."
+       "mobile-frontend-console-recruit": "Message that is displayed in the 
JavaScript console aimed at developers in an attempt to recruit volunteers. The 
\\o/ emoticon is a man with his arms in the air with the purpose of drawing 
attention to the message. If this doesn't translate into the destination 
language feel free to omit it or use something more applicable.",
+       "mobile-frontend-browse-tags-header": "The header of the \"tags\" 
section of the page, which is part of the Browse experiment."
 }
diff --git a/includes/Resources.php b/includes/Resources.php
index 09729f0..09b59ba 100644
--- a/includes/Resources.php
+++ b/includes/Resources.php
@@ -132,6 +132,7 @@
                        'less/pageactions.beta.less',
                        'less/footer.beta.less',
                        'less/content/main.beta.less',
+                       'less/browse/tags.less',
                ),
        ),
        'skins.minerva.beta.images' => $wgMFResourceFileModuleBoilerplate + 
array(
diff --git a/includes/browse/TagService.php b/includes/browse/TagService.php
new file mode 100644
index 0000000..69fb7ac
--- /dev/null
+++ b/includes/browse/TagService.php
@@ -0,0 +1,33 @@
+<?php
+
+namespace MobileFrontend\Browse;
+
+use Title;
+
+/**
+ * Handles the retrieval of tags - in the context of the Browse experiment - 
for pages.
+ */
+class TagService
+{
+       private $tags;
+
+       public function __construct( array $tags ) {
+               $this->tags = $tags;
+       }
+
+       /**
+        * Gets the tags associated with the page.
+        *
+        * Only articles in mainspace can have tags.
+        *
+        * @param Title $title
+        * @return array
+        */
+       public function getTags( Title $title ) {
+               if ( !$title->inNamespace( NS_MAIN ) ) {
+                       return array();
+               }
+
+               return $this->tags;
+       }
+}
\ No newline at end of file
diff --git a/includes/config/Experimental.php b/includes/config/Experimental.php
index f06a1b8..77bd09a 100644
--- a/includes/config/Experimental.php
+++ b/includes/config/Experimental.php
@@ -13,3 +13,12 @@
  * Controls whether a message should be logged to the console to attempt to 
recruit volunteers.
  */
 $wgMFEnableJSConsoleRecruitment = false;
+
+/**
+ * A static list of tags for the Browse experiment.
+ *
+ * Currently the tags are "assigned" to every mainspace article.
+ *
+ * @var string[]
+ */
+$wgMFBrowseTags = array();
\ No newline at end of file
diff --git a/includes/skins/MinervaTemplate.php 
b/includes/skins/MinervaTemplate.php
index 4c2ec11..22c3f51 100644
--- a/includes/skins/MinervaTemplate.php
+++ b/includes/skins/MinervaTemplate.php
@@ -277,6 +277,7 @@
                                if ( isset( $data['subject-page'] ) ) {
                                        echo $data['subject-page'];
                                }
+                               $this->renderPostContent( $data );
                                $this->renderSecondaryActions();
                                $this->renderHistoryLinkBottom( $data );
                        ?>
@@ -315,6 +316,14 @@
        }
 
        /**
+        * Renders any content after the main content and before the secondary 
actions.
+        *
+        * @param array $data The data used to build the page
+        */
+       protected function renderPostContent( $data ) {
+       }
+
+       /**
         * Render wrapper for loading content
         * @param array $data Data used to build the page
         */
diff --git a/includes/skins/MinervaTemplateBeta.php 
b/includes/skins/MinervaTemplateBeta.php
index 972bda0..205c07c 100644
--- a/includes/skins/MinervaTemplateBeta.php
+++ b/includes/skins/MinervaTemplateBeta.php
@@ -73,4 +73,36 @@
                        <?php
                }
        }
+
+       protected function renderPostContent( $data ) {
+               echo $this->renderBrowseTags( $data );
+       }
+
+       /**
+        * Renders the tags assigned to the page as part of the Browse 
experiment.
+        *
+        * @param $data
+        * @return string
+        */
+       protected function renderBrowseTags( $data) {
+               if ( !isset( $data['browse_tags'] ) ) {
+                       return '';
+               }
+
+               // TODO: Create tag entity and view.
+               $tags = array_map( function ( $rawTag ) {
+                       return array(
+                               'msg' => $rawTag,
+                       );
+
+               }, $data['browse_tags'] );
+
+               // FIXME: This should be in MinervaTemplate#getTemplateParser.
+               $templateParser = new TemplateParser( __DIR__ . 
'/../../templates' );
+
+               return $templateParser->processTemplate( 'browse/tags', array(
+                       'headerMsg' => wfMessage( 
'mobile-frontend-browse-tags-header' )->text(),
+                       'tags' => $tags,
+               ) );
+       }
 }
diff --git a/includes/skins/SkinMinervaBeta.php 
b/includes/skins/SkinMinervaBeta.php
index 1e40856..2795318 100644
--- a/includes/skins/SkinMinervaBeta.php
+++ b/includes/skins/SkinMinervaBeta.php
@@ -3,6 +3,8 @@
  * SkinMinervaBeta.php
  */
 
+use MobileFrontend\Browse\TagService;
+
 /**
  * Beta-Implementation of stable class SkinMinerva
  */
@@ -186,4 +188,32 @@
                                Html::closeElement( 'div' ) );
                }
        }
+
+       protected function preparePageContent( BaseTemplate $tpl ) {
+               parent::preparePageContent( $tpl );
+
+               $title = $this->getTitle();
+               $browseTags = $this->getBrowseTags( $title );
+               $tpl->set( 'browse_tags', $browseTags );
+       }
+
+       /**
+        * Gets the tags assigned to the page as part of the Browse experiment.
+        *
+        * @param Title $title
+        * @return array
+        */
+       private function getBrowseTags( Title $title ) {
+               return $this->getBrowseTagService()
+                       ->getTags( $title );
+       }
+
+       /**
+        * @return MobileFrontend\Browse\TagService
+        */
+       private function getBrowseTagService() {
+               $tags = $this->getMFConfig()->get( 'MFBrowseTags' );
+
+               return new TagService( $tags );
+       }
 }
diff --git a/less/browse/tags.less b/less/browse/tags.less
new file mode 100644
index 0000000..3da8ce6
--- /dev/null
+++ b/less/browse/tags.less
@@ -0,0 +1,27 @@
+@import "minerva.variables";
+
+.browse-tags {
+       list-style: none;
+
+       .browse-tag {
+               display: inline-block;
+               margin-right: 1em;
+               background-color: @grayLightest;
+               color: @grayMediumDark;
+               padding: 0 0.75em;
+               border-radius: 0.2em;
+
+               &:first-letter {
+                       text-transform: lowercase;
+               }
+
+               a,
+               a:visited {
+                       color: @grayMediumDark;
+               }
+       }
+
+       .browse-tag:last-child {
+               margin-right: 0;
+       }
+}
\ No newline at end of file
diff --git a/templates/browse/tags.mustache b/templates/browse/tags.mustache
new file mode 100644
index 0000000..c9ebb46
--- /dev/null
+++ b/templates/browse/tags.mustache
@@ -0,0 +1,8 @@
+<aside>
+       <h4>{{headerMsg}}</h4>
+       <ul class="browse-tags">
+       {{#tags}}
+               <li class="browse-tag"><a href="#">{{msg}}</a></li>
+       {{/tags}}
+       </ul>
+</aside>
diff --git a/tests/phpunit/browse/TagServiceTest.php 
b/tests/phpunit/browse/TagServiceTest.php
new file mode 100644
index 0000000..cacf2e6
--- /dev/null
+++ b/tests/phpunit/browse/TagServiceTest.php
@@ -0,0 +1,43 @@
+<?php
+
+namespace Tests\MobileFrontend\Browse;
+
+use PHPUnit_Framework_TestCase;
+use MobileFrontend\Browse\TagService;
+use TitleValue;
+use Title;
+
+class TagServiceTest extends PHPUnit_Framework_TestCase {
+       private $tagService;
+       private $mainspaceTitle;
+
+       public function setUp() {
+               parent::setUp();
+
+               $this->tags = array(
+                       'Castles in Bavaria',
+                       'Landmarks in Germany',
+               );
+               $this->tagService = new TagService( $this->tags );
+
+       }
+
+       private function getTitleInNamespace( $namespace ) {
+               $titleValue = new TitleValue( $namespace, '65daysofstatic' );
+
+               return Title::newFromTitleValue( $titleValue );
+       }
+
+       public function test_a_title_outside_of_mainspace_shouldnt_have_tags() {
+               $title = $this->getTitleInNamespace( NS_TALK );
+
+               $this->assertEmpty( $this->tagService->getTags( $title ) );
+       }
+
+       public function 
test_any_title_in_mainspace_should_have_the_configured_tags() {
+               $title = $this->getTitleInNamespace( NS_MAIN );
+               $actualTags = $this->tagService->getTags( $title );
+
+               $this->assertEquals( $this->tags, $actualTags );
+       }
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I27e78c22c217b3752894bb4ea2bcf3d8bbd9a436
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Phuedx <[email protected]>

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

Reply via email to