Pwirth has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/383149 )

Change subject: [WIP] New base class for BlueSpice extensions
......................................................................

[WIP] New base class for BlueSpice extensions

Change-Id: I216b91dd668f69d61ed6d39727436c9ae2225b7a
---
M includes/ExtensionMW.class.php
M includes/ExtensionManager.class.php
A src/Context.php
A src/Extension.php
4 files changed, 205 insertions(+), 65 deletions(-)


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

diff --git a/includes/ExtensionMW.class.php b/includes/ExtensionMW.class.php
index 3e4cc82..7835153 100644
--- a/includes/ExtensionMW.class.php
+++ b/includes/ExtensionMW.class.php
@@ -1,19 +1,14 @@
 <?php
 
-abstract class BsExtensionMW extends ContextSource {
+use BlueSpice\Extension;
+
+abstract class BsExtensionMW extends Extension {
 
        //<editor-fold desc="Former BsExtension implementation">
        protected $mExtensionFile = null;
        protected $mExtensionType = null;
 
        protected $mInfo = null;
-       protected $mExtensionKey = null;
-
-       protected $mResourcePath = null;
-
-       protected $sName = '';
-       protected $sStatus = '';
-       protected $sPackage = '';
 
        /**
         *
@@ -22,8 +17,6 @@
        protected $mCore = null;
 
        protected $aStandardContext = array( '*', '*', '*' );
-
-       protected function initExt() {}
 
        /**
         * Save a reference to current adapter instance.
@@ -61,16 +54,6 @@
                        'status' => $this->sStatus,
                        'package' => $this->sPackage,
                );
-       }
-
-       // TODO MRG (01.09.10 01:57): Kommentar
-       public function getName() {
-               return $this->sName;
-       }
-
-       // TODO MRG (01.09.10 01:57): Kommentar
-       public function getExtensionKey() {
-               return $this->mExtensionKey;
        }
 
        /**
@@ -119,6 +102,7 @@
         * @param string $hook name of the hook to register to
         * @param string $method (optional) name of method register to
         * @param bool $bExecuteFirst set this method to be first to be 
executed when hook triggered
+        * @deprecated since version 3.31.0
         */
        public function setHook( $hook, $method = false, $bExecuteFirst = false 
) {
                global $wgHooks;
@@ -139,46 +123,4 @@
                }
        }
 
-       /**
-        * Returns the resource path for the current extension
-        * @global string $IP
-        * @global string $wgScriptPath
-        * @return string
-        */
-       public function getResourcePath() {
-               return $this->mResourcePath;
-       }
-
-       /**
-        * Returns the image path for the current extension
-        * @param boolean $bResources Whether or not the image directory is 
located inside the resources directory
-        * @return string
-        */
-       public function getImagePath( $bResources = false ) {
-               if ( $bResources ) {
-                       return $this->getResourcePath().'/images/';
-               }
-               return dirname( $this->getResourcePath() ).'/images/';
-       }
-
-       /**
-        * Returns the cache key for this particlular extension
-        * @param string $sSubKey
-        * @return string
-        */
-       public function getCacheKey( $sSubKey = 'default' ) {
-               return BsCacheHelper::getCacheKey(
-                       'BlueSpice',
-                       $this->getName(),
-                       $sSubKey
-               );
-       }
-
-       /**
-        * Returns an array of tag extension definitions
-        * @return array
-        */
-       public function makeTagExtensionDefinitions() {
-               return array();
-       }
 }
diff --git a/includes/ExtensionManager.class.php 
b/includes/ExtensionManager.class.php
index 466c2e2..004d33b 100644
--- a/includes/ExtensionManager.class.php
+++ b/includes/ExtensionManager.class.php
@@ -146,7 +146,7 @@
                return self::$prRunningExtensions;
        }
 
-       protected static function makeExtensionConfig( $sExtName = "", $aConfig 
= array() ) {
+       protected static function makeExtensionDefinition( $sExtName = "", 
$aConfig = array() ) {
                global $bsgBlueSpiceExtInfo;
                if( !isset( $aConfig['className'] ) ) {
                        $aConfig['className'] = $sExtName;
@@ -193,7 +193,7 @@
 
                foreach( $GLOBALS['bsgExtensions'] as $sExtName => $aConfig ) {
                        self::$prRegisteredExtensions[$sExtName]
-                               = self::makeExtensionConfig( $sExtName, 
$aConfig );
+                               = self::makeExtensionDefinition( $sExtName, 
$aConfig );
                }
 
                foreach ( self::$prRegisteredExtensions as $sExtName => 
$aConfig ) {
@@ -205,7 +205,11 @@
                                );
                        }
 
-                       self::$prRunningExtensions[$sExtName] = new 
$sClassName();
+                       self::$prRunningExtensions[$sExtName] = new $sClassName(
+                               RequestContext::getMain(),
+                               \MediaWiki\MediaWikiServices::getInstance()
+                                       ->getConfigFactory()->makeConfig( 'bsg' 
)
+                       );
                        self::$prRunningExtensions[$sExtName]->setCore( $oCore 
);
                        self::$prRunningExtensions[$sExtName]->setup( 
$sExtName, $aConfig );
                }
diff --git a/src/Context.php b/src/Context.php
new file mode 100644
index 0000000..d6d29d9
--- /dev/null
+++ b/src/Context.php
@@ -0,0 +1,83 @@
+<?php
+namespace BlueSpice;
+
+abstract class Context implements \IContextSource {
+
+       /**
+        *
+        * @var \IContextSource
+        */
+       protected $context = null;
+
+       /**
+        *
+        * @var \Config
+        */
+       protected $config = null;
+
+       public function __construct( \IContextSource $context, \Config $config 
) {
+               $this->context = $context;
+               $this->config = $config;
+       }
+
+       public function canUseWikiPage() {
+               return $this->context->canUserWikiPage();
+       }
+
+       public function exportSession() {
+               return $this->context->exportSession();
+       }
+
+       public function getConfig() {
+               return $this->config;
+       }
+
+       public function getLanguage() {
+               return $this->context->getLanguage();
+       }
+
+       public function getOutput() {
+               return $this->context->getOutput();
+       }
+
+       public function getRequest() {
+               return $this->context->getRequest();
+       }
+
+       public function getSkin() {
+               return $this->context->getSkin();
+       }
+
+       /**
+        * Get the stats object
+        *
+        * @deprecated since 1.27 use a StatsdDataFactory from 
MediaWikiServices (preferably injected)
+        *
+        * @since 1.25
+        * @return IBufferingStatsdDataFactory
+        */
+       public function getStats() {
+               return $this->context->getStats();
+       }
+
+       public function getTiming() {
+               return $this->context->getTiming();
+       }
+
+       public function getTitle() {
+               return $this->context->getTitle();
+       }
+
+       public function getUser() {
+               return $this->context->getUser();
+       }
+
+       public function getWikiPage() {
+               return $this->context->getWikiPage();
+       }
+
+       public function msg( $key ) {
+               return $this->context->msg( $key );
+       }
+
+}
diff --git a/src/Extension.php b/src/Extension.php
new file mode 100644
index 0000000..155c6ad
--- /dev/null
+++ b/src/Extension.php
@@ -0,0 +1,111 @@
+<?php
+namespace BlueSpice;
+
+abstract class Extension extends Context {
+
+       protected $mExtensionKey = null;
+       protected $mResourcePath = null;
+
+       protected $sName = '';
+       protected $sStatus = '';
+       protected $sPackage = '';
+
+       protected function initExt() {}
+
+       public static function getInstance() {
+               return \BsExtensionManager::getExtension( $this->sName );
+       }
+
+       public function __construct( \IContextSource $context, \Config $config 
) {
+               parent::__construct( $context, $config );
+       }
+
+       /**
+        * returns the extension informations as an array
+        * @return array
+        */
+       public function getInfo() {
+               $aExtensions = ExtensionRegistry::getInstance()->getAllThings();
+               if( empty( $aExtensions[$this->sName] ) ) {
+                       return array(
+                               'status' => $this->sStatus,
+                               'package' => $this->sPackage,
+                       );
+               }
+               return $aExtensions[$this->sName] + array(
+                       'status' => $this->sStatus,
+                       'package' => $this->sPackage,
+               );
+       }
+
+       /**
+        * Initializes the extension.
+        */
+       public function setup( $sExtName = "", $aConfig = array() ) {
+               wfProfileIn( 'Performance: ' . __METHOD__ );
+
+               $this->mResourcePath = $GLOBALS['wgScriptPath']."/extensions"
+                       .$aConfig['extPath'].'/resources';
+
+               $this->sPackage = $aConfig['package'];
+               $this->sStatus = $aConfig['status'];
+               $this->mExtensionKey = "MW::$sExtName";
+               $this->sName = $sExtName;
+               $this->initExt();
+
+               wfProfileOut( 'Performance: ' . __METHOD__ );
+       }
+
+       /**
+        * Returns the resource path for the current extension
+        * @global string $IP
+        * @global string $wgScriptPath
+        * @return string
+        */
+       public function getResourcePath() {
+               return $this->mResourcePath;
+       }
+
+       // TODO MRG (01.09.10 01:57): Kommentar
+       public function getName() {
+               return $this->sName;
+       }
+
+       // TODO MRG (01.09.10 01:57): Kommentar
+       public function getExtensionKey() {
+               return $this->mExtensionKey;
+       }
+
+       /**
+        * Returns the image path for the current extension
+        * @param boolean $bResources Whether or not the image directory is 
located inside the resources directory
+        * @return string
+        */
+       public function getImagePath( $bResources = false ) {
+               if ( $bResources ) {
+                       return $this->getResourcePath().'/images/';
+               }
+               return dirname( $this->getResourcePath() ).'/images/';
+       }
+
+       /**
+        * Returns the cache key for this particlular extension
+        * @param string $sSubKey
+        * @return string
+        */
+       public function getCacheKey( $sSubKey = 'default' ) {
+               return \BsCacheHelper::getCacheKey(
+                       'BlueSpice',
+                       $this->getName(),
+                       $sSubKey
+               );
+       }
+
+       /**
+        * Returns an array of tag extension definitions
+        * @return array
+        */
+       public function makeTagExtensionDefinitions() {
+               return array();
+       }
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I216b91dd668f69d61ed6d39727436c9ae2225b7a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BlueSpiceFoundation
Gerrit-Branch: master
Gerrit-Owner: Pwirth <wi...@hallowelt.biz>

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

Reply via email to