Tweichart has uploaded a new change for review.

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

Change subject: added userhelper
......................................................................

added userhelper

* added method getUserByRight
* moved getUserDisplayName from core, is now deprecated

Change-Id: I40a7bb9569a25b2411dcd70b67c5271915316cea
---
M includes/AutoLoader.php
M includes/Core.class.php
A includes/utility/UserHelper.class.php
3 files changed, 74 insertions(+), 17 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BlueSpiceFoundation 
refs/changes/36/203036/1

diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php
index 03fbc59..3ef2e1b 100644
--- a/includes/AutoLoader.php
+++ b/includes/AutoLoader.php
@@ -77,6 +77,7 @@
 $GLOBALS['wgAutoloadClasses']['BsFormatConverter'] = 
__DIR__."/utility/FormatConverter.class.php";
 $GLOBALS['wgAutoloadClasses']['BsFileSystemHelper'] = 
__DIR__."/utility/FileSystemHelper.class.php";
 $GLOBALS['wgAutoloadClasses']['BsGroupHelper'] = 
__DIR__."/utility/GroupHelper.class.php";
+$GLOBALS['wgAutoloadClasses']['BsUserHelper'] = 
__DIR__."/utility/UserHelper.class.php";
 $GLOBALS['wgAutoloadClasses']['BsLinkProvider'] = 
__DIR__."/utility/LinkProvider.class.php";
 $GLOBALS['wgAutoloadClasses']['BsNamespaceHelper'] = 
__DIR__."/utility/NamespaceHelper.class.php";
 $GLOBALS['wgAutoloadClasses']['BsPageContentProvider'] = 
__DIR__."/utility/PageContentProvider.class.php";
diff --git a/includes/Core.class.php b/includes/Core.class.php
index 77a3ab9..554dab0 100644
--- a/includes/Core.class.php
+++ b/includes/Core.class.php
@@ -383,24 +383,13 @@
                return $output;
        }
 
+       /**
+        * @deprecated since version 2.23.2
+        * @param User $oUser
+        * @return String
+        */
        public static function getUserDisplayName( $oUser = null ) {
-               wfProfileIn( 'BS::'.__METHOD__ );
-               global $wgUser;
-               if ( $oUser === null ) {
-                       $oUser = $wgUser;
-               }
-               if ( !( $oUser instanceof User ) ) {
-                       wfProfileOut( 'BS::'.__METHOD__ );
-                       return false;
-               }
-               $sRealname = $oUser->getRealName();
-               if ( $sRealname ) {
-                       wfProfileOut( 'BS::'.__METHOD__ );
-                       return $sRealname;
-               } else {
-                       wfProfileOut( 'BS::'.__METHOD__ );
-                       return $oUser->getName();
-               }
+               return BsUserHelper::getUserDisplayName($oUser);
        }
 
                /**
diff --git a/includes/utility/UserHelper.class.php 
b/includes/utility/UserHelper.class.php
new file mode 100644
index 0000000..620a43a
--- /dev/null
+++ b/includes/utility/UserHelper.class.php
@@ -0,0 +1,67 @@
+<?php
+
+class BsUserHelper {
+
+       /**
+        * Returns an array of user ids of users in the given group
+        * @param String $sRight
+        * @param Int $iLimit
+        * @param Int $iOffset
+        * @return array array of user ids
+        */
+       public static function getUserByRight( $sRight, $iLimit = 0, $iOffset = 
0 ) {
+               wfProfileIn( 'BS::' . __METHOD__ );
+               $aReturn = array();
+               $aGroups = BsGroupHelper::getGroupsByRight( $sRight );
+               if ( count( $aGroups ) < 1 ) {
+                       wfProfileOut( 'BS::' . __METHOD__ );
+                       return $aReturn;
+               }
+               $oDBr = wfGetDB( DB_SLAVE );
+               $sGroups = "";
+               foreach ( $aGroups as $key => $sGroup ) {
+                       if ( $key != 0 ) {
+                               $sGroups .= ",";
+                       }
+                       $sGroups .= "'" . $sGroup . "'";
+               }
+               $sCond = array( 'ug_group IN (' . $sGroups . ')' );
+               $sOptions = $iLimit == 0 ? "" : " LIMIT " . $iLimit;
+               $sOptions .= $iOffset == 0 ? "" : " OFFSET " . $iLimit;
+               $oRes = $oDBr->select( 'user_groups', array( 
'DISTINCT(ug_user)' ), $sCond, __METHOD__, $sOptions );
+               if ( !$oRes ) {
+                       wfProfileOut( 'BS::' . __METHOD__ );
+                       return $aReturn;
+               }
+               while ( $oRow = $oRes->fetchObject() ) {
+                       $aReturn [] = (int) $oRow->ug_user;
+               }
+               wfProfileOut( 'BS::' . __METHOD__ );
+               return $aReturn;
+       }
+
+       /**
+        * Returns the displayed name for the given user
+        * @param User $oUser
+        * @return mixed username, else false
+        */
+       public static function getUserDisplayName( $oUser = null ) {
+               wfProfileIn( 'BS::' . __METHOD__ );
+               if ( $oUser === null ) {
+                       $oUser = RequestContext::getMain()->getUser();
+               }
+               if ( !( $oUser instanceof User ) ) {
+                       wfProfileOut( 'BS::' . __METHOD__ );
+                       return false;
+               }
+               $sRealname = $oUser->getRealName();
+               if ( $sRealname ) {
+                       wfProfileOut( 'BS::' . __METHOD__ );
+                       return $sRealname;
+               } else {
+                       wfProfileOut( 'BS::' . __METHOD__ );
+                       return $oUser->getName();
+               }
+       }
+
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I40a7bb9569a25b2411dcd70b67c5271915316cea
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BlueSpiceFoundation
Gerrit-Branch: master
Gerrit-Owner: Tweichart <weich...@hallowelt.biz>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to