Robert Vogel has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/394306 )

Change subject: BSFoundation: Added basic ArticlePreviewImage module
......................................................................


BSFoundation: Added basic ArticlePreviewImage module

Change-Id: I92b35f29d753a35907a5e949d08de7f9a6ba4f84
---
M extension.json
A resources/assets/article-preview-images/dummy.png
A src/DynamicFileDispatcher/ArticlePreviewImage.php
A src/DynamicFileDispatcher/ArticlePreviewImage/Image.php
M src/DynamicFileDispatcher/Factory.php
5 files changed, 109 insertions(+), 1 deletion(-)

Approvals:
  Robert Vogel: Verified; Looks good to me, approved



diff --git a/extension.json b/extension.json
index aca2f07..e800179 100644
--- a/extension.json
+++ b/extension.json
@@ -21,7 +21,8 @@
                                }
                        },
                        "DynamicFileRegistry": {
-                               "userprofileimage": 
"\\BlueSpice\\DynamicFileDispatcher\\UserProfileImage"
+                               "userprofileimage": 
"\\BlueSpice\\DynamicFileDispatcher\\UserProfileImage",
+                               "articlepreviewimage": 
"\\BlueSpice\\DynamicFileDispatcher\\ArticlePreviewImage"
                        },
                        "EntityRegistry": {}
                }
diff --git a/resources/assets/article-preview-images/dummy.png 
b/resources/assets/article-preview-images/dummy.png
new file mode 100644
index 0000000..048b952
--- /dev/null
+++ b/resources/assets/article-preview-images/dummy.png
Binary files differ
diff --git a/src/DynamicFileDispatcher/ArticlePreviewImage.php 
b/src/DynamicFileDispatcher/ArticlePreviewImage.php
new file mode 100644
index 0000000..192a6d5
--- /dev/null
+++ b/src/DynamicFileDispatcher/ArticlePreviewImage.php
@@ -0,0 +1,49 @@
+<?php
+
+namespace BlueSpice\DynamicFileDispatcher;
+
+class ArticlePreviewImage extends Module {
+       const TITLETEXT = 'titletext';
+       const WIDTH = 'width';
+       const HEIGHT = 'height';
+
+       public function getParamDefinition() {
+               return array_merge( parent::getParamDefinition(), [
+                       static::TITLETEXT => [
+                               Params::PARAM_TYPE => Params::TYPE_STRING,
+                               Params::PARAM_DEFAULT => '',
+                       ],
+                       static::WIDTH => [
+                               Params::PARAM_TYPE => Params::TYPE_INT,
+                               Params::PARAM_DEFAULT => 40, //TODO: config
+                       ],
+                       static::HEIGHT => [
+                               Params::PARAM_TYPE => Params::TYPE_INT,
+                               Params::PARAM_DEFAULT => 40, //TODO: config
+                       ],
+               ]);
+       }
+
+       /**
+        *
+        * @param Params $params
+        */
+       protected function extractParams( $params ) {
+               parent::extractParams( $params );
+               if( !\Title::newFromText( $this->params[static::TITLETEXT] ) ) {
+                       throw new \MWException(
+                               "Invalid titletext: 
{$this->params[static::TITLETEXT]}"
+                       );
+               }
+       }
+
+       /**
+        * @return File
+        */
+       public function getFile() {
+               return new 
\BlueSpice\DynamicFileDispatcher\ArticlePreviewImage\Image(
+                       $this,
+                       \Title::newFromText( $this->params[static::TITLETEXT] )
+               );
+       }
+}
\ No newline at end of file
diff --git a/src/DynamicFileDispatcher/ArticlePreviewImage/Image.php 
b/src/DynamicFileDispatcher/ArticlePreviewImage/Image.php
new file mode 100644
index 0000000..85e0dc5
--- /dev/null
+++ b/src/DynamicFileDispatcher/ArticlePreviewImage/Image.php
@@ -0,0 +1,50 @@
+<?php
+
+namespace BlueSpice\DynamicFileDispatcher\ArticlePreviewImage;
+use \BlueSpice\DynamicFileDispatcher\Module;
+
+class Image extends \BlueSpice\DynamicFileDispatcher\File {
+
+       /**
+        *
+        * @var \Title
+        */
+       protected $title = null;
+
+       /**
+        *
+        * @param Module $dfd
+        * @param \Title $title
+        */
+       public function __construct( Module $dfd, \Title $title ) {
+               parent::__construct( $dfd );
+               $this->title = $title;
+       }
+
+       protected function getSourcePath() {
+               return $GLOBALS['wgExtensionDirectory']
+                       
."/BlueSpiceFoundation/resources/assets/article-preview-images/dummy.png";
+       }
+
+       /**
+        * Sets the headers for given \WebResponse
+        * @param \WebResponse $response
+        * @return void
+        */
+       public function setHeaders( \WebResponse $response ) {
+               $response->header(
+                       'Content-type: '.$this->getMimeType(),
+                       true
+               );
+
+               $path = \BsFileSystemHelper::normalizePath(
+                       $this->getSourcePath()
+               );
+
+               readfile( $path );
+       }
+
+       public function getMimeType() {
+               return 'image/png';
+       }
+}
\ No newline at end of file
diff --git a/src/DynamicFileDispatcher/Factory.php 
b/src/DynamicFileDispatcher/Factory.php
index fc054a5..5b64577 100644
--- a/src/DynamicFileDispatcher/Factory.php
+++ b/src/DynamicFileDispatcher/Factory.php
@@ -77,6 +77,14 @@
                $this->modules = $extRegistry->getAttribute(
                        'BlueSpiceFoundationDynamicFileRegistry'
                );
+               foreach( $this->modules as $key => $module ) {
+                       if( !is_array( $module ) ) {
+                               continue;
+                       }
+                       //Attributes get merged together instead of 
overwritten, so just take the
+                       //last one
+                       $this->modules[$key] = end( $module );
+               }
 
                return $this->modules;
        }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I92b35f29d753a35907a5e949d08de7f9a6ba4f84
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/BlueSpiceFoundation
Gerrit-Branch: master
Gerrit-Owner: Pwirth <wi...@hallowelt.biz>
Gerrit-Reviewer: Ljonka <l.verhovs...@gmail.com>
Gerrit-Reviewer: Mglaser <gla...@hallowelt.biz>
Gerrit-Reviewer: Robert Vogel <vo...@hallowelt.biz>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to