MaxSem has uploaded a new change for review.

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


Change subject: POC: Mustache in UserProfile
......................................................................

POC: Mustache in UserProfile

Change-Id: I98ad3e2af811508d2e9a41fc18835bf85097606a
---
M MobileFrontend.php
M includes/specials/SpecialUserProfile.php
2 files changed, 119 insertions(+), 63 deletions(-)


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

diff --git a/MobileFrontend.php b/MobileFrontend.php
index f883ea4..71daad4 100644
--- a/MobileFrontend.php
+++ b/MobileFrontend.php
@@ -22,6 +22,9 @@
        die( -1 );
 }
 
+require_once( 'Mustache/Autoloader.php' );
+Mustache_Autoloader::register();
+
 // Define the extension; allows us make sure the extension is used correctly
 define( 'MOBILEFRONTEND', 'MobileFrontend' );
 
diff --git a/includes/specials/SpecialUserProfile.php 
b/includes/specials/SpecialUserProfile.php
index e6745ba..e7f225c 100644
--- a/includes/specials/SpecialUserProfile.php
+++ b/includes/specials/SpecialUserProfile.php
@@ -29,8 +29,22 @@
         */
        private $editable = false;
 
+       /**
+        * @var Mustache_Engine
+        */
+       private $mustache;
+
        public function __construct() {
                parent::__construct( 'UserProfile' );
+       }
+
+       protected function templater() {
+               if ( !$this->mustache ) {
+                       $this->mustache = new Mustache_Engine( array(
+                               //'cache' => wfTempDir(),
+                       ) );
+               }
+               return $this->mustache;
        }
 
        protected function getDaysAgo( MWTimestamp $ts ) {
@@ -57,17 +71,27 @@
                $ts = new MWTimestamp( $file->getTimestamp() );
                $daysAgo = $this->getDaysAgo( $ts );
                $page = new MobilePage( $title, $file );
-               $img = Html::openElement( 'div', array( 'class' => 'card' ) ) .
-                       Html::openElement( 'a', array( 'class' => 'container 
image', 'href' => $title->getLocalUrl() ) ) .
-                       $page->getMediumThumbnailHtml() .
-                       Html::openElement( 'div', array( 'class' => 'caption' ) 
) .
-                       $this->msg( 
'mobile-frontend-profile-last-upload-caption' )
-                               ->numParams( $daysAgo ) // $1
-                               ->params( $this->targetUser->getName() ) // $2
-                               ->parse() .
-                       Html::closeElement( 'div' ) .
-                       Html::closeElement( 'a' ) .
-                       Html::closeElement( 'div' );
+               $img = $this->templater()->render(
+<<<TWIG
+<div class="card">
+       <a class="container image" href="{{ url }}">
+               {{{ thumb }}}
+               <div class="caption">
+                       {{{ caption }}}
+               </div>
+       </a>
+</div>
+TWIG
+                       ,
+                       array(
+                               'url' => $title->getLocalUrl(),
+                               'thumb' => $page->getMediumThumbnailHtml(),
+                               'caption' => $this->msg( 
'mobile-frontend-profile-last-upload-caption' )
+                                       ->numParams( $daysAgo ) // $1
+                                       ->params( $this->targetUser->getName() 
) // $2
+                                       ->parse(),
+                       )
+               );
                wfProfileOut( __METHOD__ );
                return $img;
        }
@@ -80,7 +104,6 @@
         *
         */
        protected function getUserSummary() {
-               $user = $this->getUser();
                $out = '';
                if ( $this->editable || $this->userDescription ) {
                        $out = Html::openElement( 'div', array( 'class' => 
'user-description-container' ) );
@@ -115,18 +138,27 @@
                        $user = $thank['user'];
                        $title = $thank['title'];
                        $page = new MobilePage( $title );
-                       $html = Html::openElement( 'div', array( 'class' => 
'card' ) )
-                               . Html::openElement( 'div', array( 'class' => 
'container' ) )
-                               . $page->getMediumThumbnailHtml()
-                               . Html::openElement( 'div', array( 'class' => 
'caption' ) )
-                               . $this->msg( 
'mobile-frontend-profile-last-thanked',
-                                       $user,
-                                       $title->getFullText(),
-                                       $this->targetUser
-                               )->parse()
-                               . '</div>'
-                               . '</div>'
-                               . '</div>';
+                       $html = $this->templater()->render(
+<<<TWIG
+<div class="card">
+       <div class="container">
+               {{{ thumb }}}
+               <div class="caption">
+                       {{{ thanked }}}
+               </div>
+       </div>
+</div>
+TWIG
+                               ,
+                               array(
+                                       'thumb' => 
$page->getMediumThumbnailHtml(),
+                                       'thanked' => $this->msg( 
'mobile-frontend-profile-last-thanked',
+                                                       $user,
+                                                       $title->getFullText(),
+                                                       $this->targetUser
+                                               )->parse(),
+                               )
+                       );
                }
                wfProfileOut( __METHOD__ );
                return $html;
@@ -142,20 +174,28 @@
                $rev = $this->userInfo->getLastEdit();
                if ( $rev ) {
                        $daysAgo = $this->getDaysAgo( new MWTimestamp( 
wfTimestamp( TS_UNIX, $rev->getTimestamp() ) ) );
-                       $imageHtml = '';
                        $page = new MobilePage( $rev->getTitle() );
-                       $html = Html::openElement( 'div', array( 'class' => 
'card' ) )
-                               . Html::openElement( 'div', array( 'class' => 
'container image' ) )
-                               . $page->getMediumThumbnailHtml()
-                               . Html::openElement( 'div', array( 'class' => 
'caption' ) )
-                               . $this->msg( 
'mobile-frontend-profile-last-edit',
-                                       $rev->getTitle(),
-                                       $daysAgo,
-                                       $this->targetUser->getName()
-                               )->parse()
-                               . '</div>'
-                               . '</div>'
-                               . '</div>';
+                       $html = $this->templater()->render(
+<<<TWIG
+<div class="card">
+       <div class="container image">
+               {{{ thumb }}}
+               <div class="caption">
+                       {{{ lastEdit }}}
+               </div>
+       </div>
+</div>
+TWIG
+                               ,
+                               array(
+                                       'thumb' => 
$page->getMediumThumbnailHtml(),
+                                       'lastEdit' => $this->msg( 
'mobile-frontend-profile-last-edit',
+                                                       $rev->getTitle(),
+                                                       $daysAgo,
+                                                       
$this->targetUser->getName()
+                                               )->parse(),
+                               )
+                       );
                } else {
                        $html = '';
                }
@@ -204,23 +244,29 @@
                        $uploadCount = 500;
                }
 
-               return Html::openElement( 'div', array( 'class' => 'footer' ) )
-                       . Html::openElement( 'div' )
-                       . $this->msg( $msg, $this->targetUser->getName() )->
-                               numParams( $units, $editCount, $uploadCount 
)->parse()
-                       . Html::closeElement( 'div' )
-                       . Html::openElement( 'div' )
-                       . Linker::link( $this->targetUser->getUserPage(),
-                               $this->msg( 
'mobile-frontend-profile-userpage-link' )->escaped()
+               return $this->templater()->render(
+                       <<<TWIG
+<div class="footer">
+       <div>{{{ joined }}}</div>
+       <div>{{{ userpage }}}</div>
+       {{{ talklink }}}
+</div>
+TWIG
+                       ,
+                       array(
+                               'joined' => $this->msg( $msg, 
$this->targetUser->getName() )->
+                                               numParams( $units, $editCount, 
$uploadCount )->parse(),
+                               'userpage' => Linker::link( 
$this->targetUser->getUserPage(),
+                                               $this->msg( 
'mobile-frontend-profile-userpage-link' )->escaped()
+                                       ),
+                               'talklink' => $this->getTalkLink(),
                        )
-                       . Html::closeElement( 'div' )
-                       . $this->getTalkLink();
+               );
        }
 
        public function executeWhenAvailable( $par ) {
                wfProfileIn( __METHOD__ );
                $out = $this->getOutput();
-               $request = $this->getRequest();
                $this->addModules();
                $out->addModuleStyles( 'mobile.special.styles' );
                $out->setProperty( 'unstyledContent', true );
@@ -251,21 +297,28 @@
                                $this->userDescription = 
$this->getLanguage()->truncate( $this->getWikiPageText( $userDescPageTitle ),
                                        self::MAX_DESCRIPTION_CHARS );
 
-                               $html = Html::element( 'h1', array(), 
$this->targetUser->getName() )
-                                       . Html::openElement( 'div', array( 
'class' => 'profile content' ) )
-                                       . $this->getUserSummary();
-
-                               if ( $activityHtml ) {
-                                       $html .= Html::openElement( 'div', 
array( 'class' => 'card-container' ) )
-                                               . Html::openElement( 'h2' )
-                                               . $this->msg( 
'mobile-frontend-profile-activity-heading' )
-                                               . Html::closeElement( 'h2' )
-                                               . $activityHtml
-                                               . Html::closeElement( 'div' );
-                               }
-                               $html .= $this->getUserFooterHtml()
-                                       . Html::closeElement( 'div' );
-
+                               $html = $this->templater()->render(
+<<<TWIG
+<h1>{{ userName }}</h1>
+<div class="profile content">
+{{{ userSummary }}}
+{{# activity }}
+       <div class="card-container">
+               <h2>{{ activityHeading }}</h2>
+               {{{ activity }}}
+       </div>
+{{/ activity }}
+{{{ footer }}}
+TWIG
+                                       ,
+                                       array(
+                                               'userName' => 
$this->targetUser->getName(),
+                                               'userSummary' => 
$this->getUserSummary(),
+                                               'activity' => $activityHtml,
+                                               'activityHeading' => 
$this->msg( 'mobile-frontend-profile-activity-heading' )->text(),
+                                               'footer' => 
$this->getUserFooterHtml(),
+                                       )
+                               );
                        } else {
                                $html = $this->getHtmlNoUser();
                        }

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

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

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

Reply via email to