Robert Vogel has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/398659 )

Change subject: Refactored UserMiniProfile and UserProfileImage DFD-Module
......................................................................

Refactored UserMiniProfile and UserProfileImage DFD-Module

* Moved user setting to Extension:BlueSpiceAvatars
* Therefore BSF only handles "anon" and "default"

Change-Id: I4958c75cc66b5c9c863e0471ca3c5fe511dad0b1
---
M includes/outputhandler/views/view.UserMiniProfile.php
M src/DynamicFileDispatcher/UserProfileImage.php
A src/DynamicFileDispatcher/UserProfileImage/AnonImage.php
A src/DynamicFileDispatcher/UserProfileImage/DefaultImage.php
D src/DynamicFileDispatcher/UserProfileImage/Image.php
D src/DynamicFileDispatcher/UserProfileImage/ImageExternal.php
6 files changed, 72 insertions(+), 209 deletions(-)


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

diff --git a/includes/outputhandler/views/view.UserMiniProfile.php 
b/includes/outputhandler/views/view.UserMiniProfile.php
index 5bc65b1..5c67d6b 100644
--- a/includes/outputhandler/views/view.UserMiniProfile.php
+++ b/includes/outputhandler/views/view.UserMiniProfile.php
@@ -1,7 +1,8 @@
 <?php
 
-use MediaWiki\MediaWikiServices;
 use BlueSpice\DynamicFileDispatcher\Params;
+use BlueSpice\Services;
+use BlueSpice\DynamicFileDispatcher\UserProfileImage;
 /**
  * This class provides a miniprofile for users.
  * @package BlueSpice_AdapterMW
@@ -31,15 +32,14 @@
                        : $this->aDefaultClasses;
 
                $params = array_merge( $this->mOptions, [
-                       Params::MODULE => 'userprofileimage',
-                       'username' => $this->mOptions['user']->getName(),
+                       Params::MODULE => UserProfileImage::MODULE_NAME,
+                       UserProfileImage::USERNAME => 
$this->mOptions['user']->getName(),
+                       UserProfileImage::WIDTH => 
(int)$this->mOptions['width'],
+                       UserProfileImage::HEIGHT => 
(int)$this->mOptions['height']
                ]);
-               $dfdUrlBuilder = MediaWikiServices::getInstance()->getService(
-                       'BSDynamicFileDispatcherUrlBuilder'
-               );
-               $url = $dfdUrlBuilder->build(
-                       new Params( $params )
-               );
+
+               $dfdUrlBuilder = 
Services::getInstance()->getBSDynamicFileDispatcherUrlBuilder();
+               $url = $dfdUrlBuilder->build( new Params( $params ) );
 
                $aOut = array();
                $aOut[] = '<div class="'.  implode( ' ', $aClasses ).'" 
title="'.$this->mOptions['userdisplayname'].'">';
@@ -101,69 +101,6 @@
                        );
                }
 
-               if( empty( $this->mOptions['userimagesrc'] ) ) {
-                       $this->mOptions['userimagesrc'] = 
$GLOBALS['wgScriptPath']
-                               
."/extensions/BlueSpiceFoundation/resources/bluespice/images/bs-user-default-image.png";
-               }
-
-               if ( $oUser->isAnon() ) {
-                       $this->mOptions['userimagesrc'] = 
$GLOBALS['wgScriptPath']
-                               
."/extensions/BlueSpiceFoundation/resources/bluespice/images/bs-user-anon-image.png";
-                       $this->mOptions['linktargethref'] = '';
-               } else {
-                       $sUserImageName = BsConfig::getVarForUser( 
'MW::UserImage', $oUser );
-                       if ( !empty( $sUserImageName ) ) { //Image given as a 
url
-
-                               if ( $sUserImageName{0} == '/' ) {
-                                       //relative url from own system given
-                                       $this->mOptions['userimagesrc'] = 
$sUserImageName;
-                               } elseif ( $this->isExternalUrl( 
$sUserImageName ) ) {
-                                       $aParsedUrl = wfParseUrl( 
$sUserImageName );
-                                       //external url
-                                       //TODO: Fix, when system is call via 
https:// and the given
-                                       //url is http:// the browser will block 
the image
-                                       $bAllowedProtocoll = in_array(
-                                               
$aParsedUrl['scheme'].$aParsedUrl['delimiter'],
-                                               $wgUrlProtocols
-                                       );
-                                       if( $bAllowedProtocoll ) {
-                                               $sQuery = isset( 
$aParsedUrl['query'] ) ?
-                                                       
"?{$aParsedUrl['query']}"
-                                                       : ''
-                                               ;
-                                               $this->mOptions['userimagesrc'] 
=
-                                                       $aParsedUrl['scheme']
-                                                       
.$aParsedUrl['delimiter']
-                                                       .$aParsedUrl['host']
-                                                       .$aParsedUrl['path']
-                                                       .$sQuery
-                                               ;
-                                       }
-                               } else {
-                                       $this->setOptionsFromRepoFile( 
$sUserImageName );
-                               }
-                       } else {
-                               //MW default File:<username>
-                               $oUserImageFile = 
RepoGroup::singleton()->findFile(
-                                       Title::newFromText( $sUserImageName, 
NS_FILE )
-                               );
-                               $oUserThumbnail = false;
-                               if ( $oUserImageFile !== false ) {
-                                       $oUserThumbnail = 
$oUserImageFile->transform(
-                                               array(
-                                                       'width' => 
$this->mOptions['width'],
-                                                       'height' => 
$this->mOptions['height']
-                                               )
-                                       );
-                               }
-                               if ( $oUserThumbnail !== false ) {
-                                       $this->mOptions['userimagesrc'] = 
$oUserThumbnail->getUrl();
-                                       $this->mOptions['width'] = 
$oUserThumbnail->getWidth();
-                                       $this->mOptions['height'] = 
$oUserThumbnail->getHeight();
-                               }
-                       }
-               }
-
                Hooks::run( 'UserMiniProfileAfterInit', array( $this ) );
                $this->bIsInit = true;
        }
@@ -178,26 +115,5 @@
 
        public function getOptions() {
                return $this->mOptions;
-       }
-
-       protected function isExternalUrl( $sMaybeExternalUrl ) {
-               return substr( $sMaybeExternalUrl, 0, 4 ) == "http";
-       }
-
-       protected function setOptionsFromRepoFile( $sUserImageName ) {
-               $oUserImageFile = wfFindFile( $sUserImageName );
-               if( $oUserImageFile ) {
-                       $oUserThumbnail = $oUserImageFile->transform(
-                               array(
-                                       'width' => $this->mOptions['width'],
-                                       'height' => $this->mOptions['height']
-                               )
-                       );
-                       if ( $oUserThumbnail ) {
-                               $this->mOptions['userimagesrc'] = 
$oUserThumbnail->getUrl();
-                               $this->mOptions['width'] = 
$oUserThumbnail->getWidth();
-                               $this->mOptions['height'] = 
$oUserThumbnail->getHeight();
-                       }
-               }
        }
 }
\ No newline at end of file
diff --git a/src/DynamicFileDispatcher/UserProfileImage.php 
b/src/DynamicFileDispatcher/UserProfileImage.php
index 0dc9161..5e37624 100644
--- a/src/DynamicFileDispatcher/UserProfileImage.php
+++ b/src/DynamicFileDispatcher/UserProfileImage.php
@@ -2,10 +2,20 @@
 
 namespace BlueSpice\DynamicFileDispatcher;
 
+use BlueSpice\DynamicFileDispatcher\UserProfileImage\AnonImage;
+use BlueSpice\DynamicFileDispatcher\UserProfileImage\DefaultImage;
+
 class UserProfileImage extends Module {
+       const MODULE_NAME = 'userprofileimage';
        const USERNAME = 'username';
        const WIDTH = 'width';
        const HEIGHT = 'height';
+
+       /**
+        *
+        * @var \User
+        */
+       protected $user = null;
 
        public function getParamDefinition() {
                return array_merge( parent::getParamDefinition(), [
@@ -37,39 +47,14 @@
                }
        }
 
-       protected function getImageSource() {
-               //This is temporay code until the UserMiniProfile gets a rewrite
-               $miniprofile = \BsCore::getInstance()->getUserMiniProfile(
-                       \User::newFromName( $this->params[static::USERNAME] ),
-                       [
-                               'width' => $this->params[static::WIDTH],
-                               'height' => $this->params[static::HEIGHT],
-                       ]
-               );
-               $options = $miniprofile->getOptions();
-               return $options['userimagesrc'];
-       }
-
-       protected function isExternalUrl( $sMaybeExternalUrl ) {
-               return substr( $sMaybeExternalUrl, 0, 4 ) == "http";
-       }
-
        /**
         * @return File
         */
        public function getFile() {
-               $imgSrc = $this->getImageSource();
-               if( $this->isExternalUrl( $imgSrc ) ) {
-                       return new 
\BlueSpice\DynamicFileDispatcher\UserProfileImage\ImageExternal(
-                               $this,
-                               $imgSrc,
-                               \User::newFromName( 
$this->params[static::USERNAME] )
-                       );
+               $this->user = \User::newFromName( 
$this->params[static::USERNAME] );
+               if( $this->user->isAnon() ) {
+                       return new AnonImage( $this );
                }
-               return new 
\BlueSpice\DynamicFileDispatcher\UserProfileImage\Image(
-                       $this,
-                       $imgSrc,
-                       \User::newFromName( $this->params[static::USERNAME] )
-               );
+               return new DefaultImage( $this );
        }
-}
\ No newline at end of file
+}
diff --git a/src/DynamicFileDispatcher/UserProfileImage/AnonImage.php 
b/src/DynamicFileDispatcher/UserProfileImage/AnonImage.php
new file mode 100644
index 0000000..7e520e5
--- /dev/null
+++ b/src/DynamicFileDispatcher/UserProfileImage/AnonImage.php
@@ -0,0 +1,24 @@
+<?php
+
+namespace BlueSpice\DynamicFileDispatcher\UserProfileImage;
+use \BlueSpice\DynamicFileDispatcher\Module;
+
+class AnonImage extends \BlueSpice\DynamicFileDispatcher\File {
+
+       /**
+        * Sets the headers for given \WebResponse
+        * @param \WebResponse $response
+        * @return void
+        */
+       public function setHeaders( \WebResponse $response ) {
+               $response->header( 'Content-type: '.$this->getMimeType(), true 
);
+
+               $IP = $GLOBALS['IP'];
+
+               readfile( 
"$IP/extensions/BlueSpiceFoundation/resources/bluespice/images/bs-user-anon-image.png"
 );
+       }
+
+       public function getMimeType() {
+               return 'image/png';
+       }
+}
\ No newline at end of file
diff --git a/src/DynamicFileDispatcher/UserProfileImage/DefaultImage.php 
b/src/DynamicFileDispatcher/UserProfileImage/DefaultImage.php
new file mode 100644
index 0000000..c631314
--- /dev/null
+++ b/src/DynamicFileDispatcher/UserProfileImage/DefaultImage.php
@@ -0,0 +1,24 @@
+<?php
+
+namespace BlueSpice\DynamicFileDispatcher\UserProfileImage;
+use \BlueSpice\DynamicFileDispatcher\Module;
+
+class DefaultImage extends \BlueSpice\DynamicFileDispatcher\File {
+
+       /**
+        * Sets the headers for given \WebResponse
+        * @param \WebResponse $response
+        * @return void
+        */
+       public function setHeaders( \WebResponse $response ) {
+               $response->header( 'Content-type: '.$this->getMimeType(), true 
);
+
+               $IP = $GLOBALS['IP'];
+
+               readfile( 
"$IP/extensions/BlueSpiceFoundation/resources/bluespice/images/bs-user-default-image.png"
 );
+       }
+
+       public function getMimeType() {
+               return 'image/png';
+       }
+}
\ No newline at end of file
diff --git a/src/DynamicFileDispatcher/UserProfileImage/Image.php 
b/src/DynamicFileDispatcher/UserProfileImage/Image.php
deleted file mode 100644
index 28d9ab2..0000000
--- a/src/DynamicFileDispatcher/UserProfileImage/Image.php
+++ /dev/null
@@ -1,64 +0,0 @@
-<?php
-
-namespace BlueSpice\DynamicFileDispatcher\UserProfileImage;
-use \BlueSpice\DynamicFileDispatcher\Module;
-
-class Image extends \BlueSpice\DynamicFileDispatcher\File {
-       /**
-        *
-        * @var string
-        */
-       protected $src = '';
-
-       /**
-        *
-        * @var \User
-        */
-       protected $user = null;
-
-       /**
-        *
-        * @param Module $dfd
-        * @param sring $src
-        * @param \User $user
-        */
-       public function __construct( Module $dfd, $src, $user ) {
-               parent::__construct( $dfd );
-               $this->src = $src;
-               $this->user = $user;
-       }
-
-       /**
-        * Sets the headers for given \WebResponse
-        * @param \WebResponse $response
-        * @return void
-        */
-       public function setHeaders( \WebResponse $response ) {
-               $response->header(
-                       'Content-type: '.$this->getMimeType(),
-                       true
-               );
-               //This is temporay code until the UserMiniProfile gets a rewrite
-               $path = $GLOBALS['IP'];
-               $scriptPath = $this->dfd->getConfig()->get( 'ScriptPath' );
-               if( $scriptPath && $scriptPath != "" ) {
-                       $countDirs = substr_count( $scriptPath, '/' );
-                       $i = 0;
-                       while( $i < $countDirs ) {
-                               $path = dirname( $path );
-                               $i++;
-                       }
-               }
-               $path = str_replace(
-                       '/nsfr_img_auth.php/',
-                       '/images/',
-                       \BsFileSystemHelper::normalizePath( $path.$this->src )
-               );
-
-               readfile( $path );
-       }
-
-       public function getMimeType() {
-               return 'image/png';
-       }
-}
\ No newline at end of file
diff --git a/src/DynamicFileDispatcher/UserProfileImage/ImageExternal.php 
b/src/DynamicFileDispatcher/UserProfileImage/ImageExternal.php
deleted file mode 100644
index 1102dd2..0000000
--- a/src/DynamicFileDispatcher/UserProfileImage/ImageExternal.php
+++ /dev/null
@@ -1,22 +0,0 @@
-<?php
-
-namespace BlueSpice\DynamicFileDispatcher\UserProfileImage;
-
-class ImageExternal extends Image {
-
-       /**
-        * Sets the headers for given \WebResponse
-        * @param \WebResponse $response
-        * @return void
-        */
-       public function setHeaders( \WebResponse $response ) {
-               $this->dfd->getContext()->getRequest()->response()->header(
-                       "Location:$this->src",
-                       true
-               );
-       }
-
-       public function getMimeType() {
-               return '';
-       }
-}
\ No newline at end of file

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4958c75cc66b5c9c863e0471ca3c5fe511dad0b1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BlueSpiceFoundation
Gerrit-Branch: master
Gerrit-Owner: Robert Vogel <vo...@hallowelt.biz>

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

Reply via email to