Jdlrobson has uploaded a new change for review.

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


Change subject: Alpha: UserProfile special page (first pass)
......................................................................

Alpha: UserProfile special page (first pass)

Remember Maryana this is what happens when you let Jon spend too
long on a plane.

TODO:
 * Add some design love

Change-Id: I59ed57fcd2c75788f42d6d306cba81719c964204
---
M MobileFrontend.i18n.php
M MobileFrontend.php
M includes/MobileFrontend.hooks.php
M includes/specials/SpecialMobileDiff.php
A includes/specials/SpecialUserProfile.php
5 files changed, 209 insertions(+), 5 deletions(-)


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

diff --git a/MobileFrontend.i18n.php b/MobileFrontend.i18n.php
index 5ca829f..3607c21 100644
--- a/MobileFrontend.i18n.php
+++ b/MobileFrontend.i18n.php
@@ -282,6 +282,25 @@
        'mobile-frontend-talk-reply-success' => 'Your reply was successfully 
saved to the talk page.',
        'mobile-frontend-talk-reply-info' => 'Note your reply will be 
automatically signed with your username.',
        'mobile-frontend-talk-reply' => 'Reply',
+
+       // Special:UserProfile
+       'mobile-frontend-profile-title' => 'User Profile',
+       'mobile-frontend-profile-edit-timestamp' => '$1 at $2',
+       'mobile-frontend-profile-edits' => '$1 edits',
+       'mobile-frontend-profile-activity' => '$1 edits per day',
+       'mobile-frontend-profile-registered' => 'Member since $1 ($2 days)',
+       'mobile-frontend-profile-userpage' => 'View user page',
+       'mobile-frontend-profile-usertalk' => 'View talk page',
+       'mobile-frontend-profile-noargs' => 'Please provide a username to view 
a profile.',
+       'mobile-frontend-profile-yours' => 'Visit your profile page',
+       'mobile-frontend-profile-heading-group' => 'Roles',
+       'mobile-frontend-profile-heading-registered' => 'Registered',
+       'mobile-frontend-profile-heading-editcount' => 'Edit count',
+       'mobile-frontend-profile-heading-activity' => 'Activity',
+       'mobile-frontend-profile-heading-rc' => 'Most recent edits',
+       'mobile-frontend-profile-heading-up' => 'Most recent uploads',
+       'mobile-frontend-profile-norecent' => 'No recent edits',
+       'mobile-frontend-profile-nogroups' => 'Normal user',
 );
 
 /** Message documentation (Message documentation)
@@ -732,6 +751,23 @@
        'mobile-frontend-talk-reply-info' => 'Inform the user their talk reply 
will be automatically signed.',
        'mobile-frontend-talk-reply' => 'Reply heading.
 {{Identical|Reply}}',
+       'mobile-frontend-profile-title' => 'Title of the Special:UserProfile 
page',
+       'mobile-frontend-profile-edit-timestamp' => 'Time of recent edit $1 is 
date, $2 is time.',
+       'mobile-frontend-profile-edits' => 'Edit count. $1 is number of edits.',
+       'mobile-frontend-profile-activity' => 'Edit rate per day. $1 is number 
of edits per day.',
+       'mobile-frontend-profile-registered' => 'Says how long user has been 
registered, $1 is date, $2 is number of days.',
+       'mobile-frontend-profile-userpage' => 'Label for link to user page.',
+       'mobile-frontend-profile-usertalk' => 'Label for link to user talk 
page.',
+       'mobile-frontend-profile-noargs' => 'Message shown when no parameter 
given to page asking them to provide one.',
+       'mobile-frontend-profile-yours' => 'Label for link to current user 
profile if known when no parameter given.',
+       'mobile-frontend-profile-heading-group' => 'Heading for user roles.',
+       'mobile-frontend-profile-heading-registered' => 'Heading for user 
registration.',
+       'mobile-frontend-profile-heading-editcount' => 'Heading for edit count',
+       'mobile-frontend-profile-heading-activity' => 'Heading for edit rate / 
activity.',
+       'mobile-frontend-profile-heading-rc' => 'Heading for most recent edits 
by user.',
+       'mobile-frontend-profile-heading-up' => 'Heading for most recent 
uploads by user.',
+       'mobile-frontend-profile-norecent' => 'Message shown when an edit has 
not edited.',
+       'mobile-frontend-profile-nogroups' => 'Shown when a user belongs to no 
user groups.',
 );
 
 /** Achinese (Acèh)
diff --git a/MobileFrontend.php b/MobileFrontend.php
index 6a68aec..09b9a7b 100644
--- a/MobileFrontend.php
+++ b/MobileFrontend.php
@@ -56,6 +56,7 @@
        'MobileSiteModule' => 'modules/MobileSiteModule',
 
        'SpecialUploads' => 'specials/SpecialUploads',
+       'SpecialUserProfile' => 'specials/SpecialUserProfile',
        'SpecialMobileUserlogin' => 'specials/SpecialMobileUserlogin',
        'SpecialMobileDiff' => 'specials/SpecialMobileDiff',
        'SpecialMobileOptions' => 'specials/SpecialMobileOptions',
diff --git a/includes/MobileFrontend.hooks.php 
b/includes/MobileFrontend.hooks.php
index 2be5bbc..93b8609 100644
--- a/includes/MobileFrontend.hooks.php
+++ b/includes/MobileFrontend.hooks.php
@@ -256,12 +256,16 @@
         * @return boolean hook return value
         */
        public static function onSpecialPage_initList( &$list ) {
-               if ( MobileContext::singleton()->shouldDisplayMobileView() ) {
+               $ctx = MobileContext::singleton();
+               if ( $ctx->shouldDisplayMobileView() ) {
                        // Replace the standard watchlist view with our custom 
one
                        $list['Watchlist'] = 'SpecialMobileWatchlist';
                        // FIXME: Make uploads work on desktop
                        $list['Uploads'] = 'SpecialUploads';
                        $list['Userlogin'] = 'SpecialMobileUserlogin';
+                       if ( $ctx->isAlphaGroupMember() ) {
+                               $list['UserProfile'] = 'SpecialUserProfile';
+                       }
                }
                return true;
        }
diff --git a/includes/specials/SpecialMobileDiff.php 
b/includes/specials/SpecialMobileDiff.php
index d403175..8d46fcd 100644
--- a/includes/specials/SpecialMobileDiff.php
+++ b/includes/specials/SpecialMobileDiff.php
@@ -212,7 +212,7 @@
                                        Linker::link( $user->getUserPage(), 
htmlspecialchars( $user->getName() ) ) .
                                '</div>' .
                                '<div class="mw-mf-roles">' .
-                                       $this->listGroups( $user ) .
+                                       self::listGroups( $user, 
$this->getLanguage() ) .
                                '</div>' .
                                '<div class="mw-mf-edit-count">' .
                                        $this->msg( 
'mobile-frontend-diffview-editcount', $this->getLanguage()->formatNum( $edits ) 
)->parse() .
@@ -236,19 +236,20 @@
                );
        }
 
-       function listGroups( User $user ) {
+       // FIXME: Move to a generic UserProfile class
+       public static function listGroups( User $user, $lang ) {
                # Get groups to which the user belongs
                $userGroups = $user->getGroups();
                $userMembers = array();
                foreach ( $userGroups as $n => $ug ) {
                        $memberName = User::getGroupMember( $ug, 
$user->getName() );
                        if ( $n == 0 ) {
-                               $memberName = $this->getLanguage()->ucfirst( 
$memberName );
+                               $memberName = $lang->ucfirst( $memberName );
                        }
                        $userMembers[] = User::makeGroupLinkHTML( $ug, 
$memberName );
                }
 
-               return $this->getLanguage()->commaList( $userMembers );
+               return $lang->commaList( $userMembers );
        }
 
        public static function getMobileUrlFromDesktop() {
diff --git a/includes/specials/SpecialUserProfile.php 
b/includes/specials/SpecialUserProfile.php
new file mode 100644
index 0000000..a4c2900
--- /dev/null
+++ b/includes/specials/SpecialUserProfile.php
@@ -0,0 +1,162 @@
+<?php
+
+class SpecialUserProfile extends UnlistedSpecialMobilePage {
+
+       public function __construct() {
+               parent::__construct( 'UserProfile' );
+       }
+
+       protected function getListHtml( $tag, $attrs, $items ) {
+               $html = Html::openElement( $tag, $attrs );
+               if ( $tag == 'dl' ) {
+                       foreach( $items as $def ) {
+                               $defTag = 'dt';
+                               foreach( $def as $item ) {
+                                       $html .= Html::openElement( $defTag );
+                                       $html .= $item;
+                                       $html .= Html::closeElement( $defTag );
+                                       $defTag = 'dd';
+                               }
+                       }
+               } else {
+                       foreach( $items as $item ) {
+                               $html .= Html::openElement( 'li' );
+                               $html .= $item;
+                               $html .= Html::closeElement( 'li' );
+                       }
+               }
+               $html .= Html::closeElement( 'ul' );
+               return $html;
+       }
+
+       protected function getRecentEdits( $user ) {
+               $dbr = wfGetDB( DB_SLAVE );
+               $where = array(
+                       'rc_user_text' => $user->getName(),
+               );
+               $constraints = array( 'LIMIT' => 5, 'ORDER BY' => 'rc_timestamp 
desc' );
+               $res = $dbr->select( 'recentchanges', 
'rc_title,rc_cur_id,rc_namespace, rc_cur_time', $where, __METHOD__, 
$constraints );
+               $rc = array();
+               foreach( $res as $rev ) {
+                       $attrs = array(
+                               'href' => SpecialPage::getTitleFor( 
'MobileDiff', $rev->rc_cur_id )->getLocalURL(),
+                       );
+                       $ts = $rev->rc_cur_time;
+                       $date = $this->getLanguage()->userDate( $ts, $user );
+                       $time = $this->getLanguage()->userTime( $ts, $user );
+                       $rc[] =
+                               Html::element( 'a', $attrs, Title::newFromText( 
$rev->rc_title, $rev->rc_namespace )->getPrefixedText() ) .
+                               // FIXME: lazy hack
+                               ' ' .
+                               Html::element( 'span', array( 'class' => 
'modified', 'timestamp' => $ts ),
+                                       wfMessage( 
'mobile-frontend-profile-edit-timestamp', $date, $time ) );
+               }
+
+               return $rc;
+       }
+
+       protected function getRecentUploads( $user, $limit=1 ) {
+               global $wgMFPhotoUploadWiki, $wgConf;
+
+               if ( !$wgMFPhotoUploadWiki ) {
+                       $dbr = wfGetDB( DB_SLAVE );
+               } elseif (
+                               $wgMFPhotoUploadWiki &&
+                               !in_array( $wgMFPhotoUploadWiki, 
$wgConf->getLocalDatabases() )
+                       ) {
+                       // early return if the database is invalid
+                       return false;
+               } else {
+                       $dbr = wfGetDB( DB_SLAVE, array(), $wgMFPhotoUploadWiki 
);
+               }
+
+               $dbr->ignoreErrors( true );
+               $where = array( 'img_user_text' => $user->getName() );
+               $constraints = array( 'LIMIT' => $limit, 'ORDER BY' => 
'img_timestamp desc' );
+               $res = $dbr->select( 'image', 'img_name', $where, __METHOD__, 
$constraints );
+               $count = 0;
+               $uploads = array();
+               foreach( $res as $row ) {
+                       $name = $row->img_name;
+                       $file = wfLocalFile( $name );
+                       $uploads[] = $file->transform( array( 'width' => 320, 
'height' => 320 ) )->toHtml();
+                       $count += 1;
+               }
+               return count( $uploads ) === 0 ? false : $uploads;
+       }
+
+       protected function getUserPageLinks( $user ) {
+               return $this->getListHtml( 'ul', array( 'class' => 'hlist' ),
+                       array(
+                               Html::element( 'a', array( 'href' => 
$user->getUserPage()->getLocalUrl() ), wfMessage( 
'mobile-frontend-profile-userpage' ) ),
+                               Html::element( 'a', array( 'href' => 
$user->getTalkPage()->getLocalUrl() ), wfMessage( 
'mobile-frontend-profile-usertalk' ) )
+                       )
+               );
+       }
+
+       protected function getUserActivity( $user ) {
+               $lang = $this->getLanguage();
+               $registered = $user->getRegistration();
+               $timestamp = wfTimestamp( TS_UNIX, $registered );
+               $editCount = $user->getEditCount();
+               $today = wfTimestamp( TS_UNIX, date( 'YmdHis') );
+               $days = round( ( $today - $timestamp ) / ( 24 * 60 * 60 ) );
+               if ( $days <= 0 ) {
+                       $days = 1;
+               }
+
+               $msg = wfMessage( 'mobile-frontend-profile-registered',
+                               $lang->userDate( $timestamp, $user ), $days
+                       )->parse();
+
+               // render list
+               $rc = $this->getRecentEdits( $user );
+               $groups = SpecialMobileDiff::listGroups( $user, $lang );
+               $items = array(
+                       array( wfMessage( 
'mobile-frontend-profile-heading-group' ),
+                               $groups ? $groups : wfMessage( 
'mobile-frontend-profile-nogroups' ) ),
+                       array( wfMessage( 
'mobile-frontend-profile-heading-registered' ), $msg ),
+                       array( wfMessage( 
'mobile-frontend-profile-heading-editcount' ),
+                               Html::element( 'a',
+                                       array( 'href' => 
SpecialPage::getTitleFor( 'Contributions', $user->getName() )->getLocalURL() ),
+                                       wfMessage( 
'mobile-frontend-profile-edits', $editCount ) ) ),
+                       array( wfMessage( 
'mobile-frontend-profile-heading-activity' ),
+                               wfMessage( 'mobile-frontend-profile-activity', 
round( $editCount / $days ) ) ),
+                       array_merge( array( wfMessage( 
'mobile-frontend-profile-heading-rc' ) ),
+                               count( $rc ) > 0 ? $rc : array( wfMessage( 
'mobile-frontend-profile-norecent' ) ) ),
+               );
+               $uploads = $this->getRecentUploads( $user );
+               if ( $uploads ) {
+                       $items[] = array_merge( array( 'Recent uploads' ), 
$uploads ); 
+               }
+               return $this->getListHtml( 'dl', array(), $items );
+       }
+
+       protected function getUserPage( $username ) {
+               $user = User::newFromName( $username );
+               $html = Html::element( 'h2', array(), $username );
+
+               $html .= $this->getUserPageLinks( $user );
+               $html .= $this->getUserActivity( $user );
+
+               return $html;
+       }
+
+       public function execute( $par = '' ) {
+               $out = $this->getOutput();
+               $out->setPageTitle( wfMessage( 'mobile-frontend-profile-title' 
) );
+               if ( $par ) {
+                       $html = $this->getUserPage( $par );
+               } else {
+                       $html = Html::element( 'p', array(), wfMessage( 
'mobile-frontend-profile-noargs' ) );
+                       $user = $out->getUser();
+                       if ( $user->isLoggedIn() ) {
+                               $profileUrl = SpecialPage::getTitleFor( 
$this->getName(), $user->getName() )->getLocalURL();
+                               $html .= Html::openElement( 'p', array() );
+                               $html .= Html::element( 'a', array( 'href' => 
$profileUrl ), wfMessage( 'mobile-frontend-profile-yours' ) );
+                               $html .= Html::closeElement( 'p', array() );
+                       }
+               }
+               $out->addHtml( $html );
+       }
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I59ed57fcd2c75788f42d6d306cba81719c964204
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

Reply via email to