Robert Vogel has uploaded a new change for review.
https://gerrit.wikimedia.org/r/278280
Change subject: [WiP] GenericTagExtensionHandler: Basic impl.
......................................................................
[WiP] GenericTagExtensionHandler: Basic impl.
This change adds a generic tag handler mechanism to BlueSpice.
It is based on ParamProcessor library
WORK IN PROGRESS - DO NOT MERGE!
Change-Id: I06ea08e5a1ad789806a7648bd4cf03b5b911e12f
---
M .gitignore
M BlueSpice.hooks.php
M composer.json
M includes/AutoLoader.php
M includes/CoreHooks.php
M includes/ExtensionMW.class.php
M includes/ExtensionManager.class.php
A includes/GenericTagExtensionHandler.php
8 files changed, 178 insertions(+), 0 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BlueSpiceFoundation
refs/changes/80/278280/1
diff --git a/.gitignore b/.gitignore
index 8980552..be67e62 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,6 @@
config/
node_modules/**
vendor/**
+
+composer.lock
+composer.phar
\ No newline at end of file
diff --git a/BlueSpice.hooks.php b/BlueSpice.hooks.php
index a6a621c..20018eb 100644
--- a/BlueSpice.hooks.php
+++ b/BlueSpice.hooks.php
@@ -12,6 +12,7 @@
$wgHooks['UploadVerification'][] = 'BsCoreHooks::onUploadVerification';
$wgHooks['SkinTemplateOutputPageBeforeExec'][] =
'BsCoreHooks::onSkinTemplateOutputPageBeforeExec';
$wgHooks['SkinAfterContent'][] = 'BsCoreHooks::onSkinAfterContent';
+$wgHooks['ParserFirstCallInit'][] = 'BsCoreHooks::onParserFirstCallInit';
$wgHooks['UserAddGroup'][] = 'BsGroupHelper::addTemporaryGroupToUserHelper';
// START cache invalidation hooks
diff --git a/composer.json b/composer.json
index fa64b11..99585af 100644
--- a/composer.json
+++ b/composer.json
@@ -15,6 +15,9 @@
"homepage": "http://www.hallowelt.com"
}
],
+ "require": {
+ "param-processor/param-processor": "~1.2"
+ }
"require-dev": {
"jakub-onderka/php-parallel-lint": "0.9.2"
},
diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php
index fb70072..4fc8d0a 100644
--- a/includes/AutoLoader.php
+++ b/includes/AutoLoader.php
@@ -37,6 +37,7 @@
$GLOBALS['wgAutoloadClasses']['BSDebug'] = __DIR__."/Debug.php";
$GLOBALS['wgAutoloadClasses']['BsException'] = __DIR__."/Exception.class.php";
$GLOBALS['wgAutoloadClasses']['BsExtensionManager'] =
__DIR__."/ExtensionManager.class.php";
+$GLOBALS['wgAutoloadClasses']['BsGenericTagExtensionHandler'] =
__DIR__."/GenericTagExtensionHandler.php";
$GLOBALS['wgAutoloadClasses']['BsMailer'] =
__DIR__."/Mailer.class.php";//Deprecated
$GLOBALS['wgAutoloadClasses']['BsXHRBaseResponse'] =
__DIR__."/XHRBaseResponse.class.php";
$GLOBALS['wgAutoloadClasses']['BsXHRJSONResponse'] =
__DIR__."/XHRBaseResponse.class.php";
diff --git a/includes/CoreHooks.php b/includes/CoreHooks.php
index 5d164a8..1a7fd2e 100755
--- a/includes/CoreHooks.php
+++ b/includes/CoreHooks.php
@@ -541,4 +541,17 @@
'content' => $oProfilePageSettingsView
);
}
+
+ /**
+ *
+ * @param Parser $parser
+ * @return boolean
+ */
+ public static function onParserFirstCallInit( $parser ) {
+ BsGenericTagExtensionHandler::setupHandlers(
+ BsExtensionManager::getRunningExtensions(),
+ $parser
+ );
+ return true;
+ }
}
diff --git a/includes/ExtensionMW.class.php b/includes/ExtensionMW.class.php
index 64a7f7f..f98369a 100644
--- a/includes/ExtensionMW.class.php
+++ b/includes/ExtensionMW.class.php
@@ -135,4 +135,12 @@
$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 8c86a69..64128f8 100644
--- a/includes/ExtensionManager.class.php
+++ b/includes/ExtensionManager.class.php
@@ -15,6 +15,10 @@
class BsExtensionManager {
protected static $prRegisteredExtensions = array();
+ /**
+ *
+ * @var BsExtensionMW[]
+ */
protected static $prRunningExtensions = array();
protected static $aContexts = array();
protected static $aActiveContexts = array();
@@ -68,15 +72,32 @@
wfProfileOut( 'Performance: ' . __METHOD__ );
}
+ /**
+ *
+ * @return array
+ * @deprecated since version 2.23
+ */
public static function getRegisteredExtenions() {
wfDeprecated( __METHOD__ );
return self::$prRegisteredExtensions;
}
+ /**
+ *
+ * @return array
+ */
public static function getRegisteredExtensions() {
return self::$prRegisteredExtensions;
}
+ /**
+ *
+ * @return BsExtensionMW[]
+ */
+ public static function getRunningExtensions() {
+ return self::$prRunningExtensions;
+ }
+
public static function includeExtensionFiles( $oCore ) {
wfProfileIn( 'Performance: ' . __METHOD__ );
global $IP;
diff --git a/includes/GenericTagExtensionHandler.php
b/includes/GenericTagExtensionHandler.php
new file mode 100644
index 0000000..e5e77fe
--- /dev/null
+++ b/includes/GenericTagExtensionHandler.php
@@ -0,0 +1,128 @@
+<?php
+
+class BsGenericTagExtensionHandler {
+
+ /**
+ *
+ * @var string
+ */
+ protected $sTagName = '';
+
+ /**
+ *
+ * @var array
+ */
+ protected $aTagDef = array();
+
+
+ public function __construct( $sTagName, $aTagDef ) {
+ $this->sTagName = $sTagName;
+ $this->aTagDef = $this->extendTagDefinition( $aTagDef );
+ }
+
+ /**
+ * @param BsExtensionMW[] $aExtensions
+ * @param Parser $parser
+ */
+ public static function setupHandlers( $aExtensions, $parser ) {
+ foreach( $aExtensions as $oExtension ) {
+ $aExtensionTags =
$oExtension->makeTagExtensionDefinitions();
+ foreach( $aExtensionTags as $sTagName => $aTagDef ) {
+ $oTagHandler = new self( $sTagName, $aTagDef );
+ $parser->setHook( $sTagName, array(
$oTagHandler, 'handle' ) );
+ }
+ }
+ }
+
+ /**
+ *
+ * @param string $input
+ * @param array $args
+ * @param Parser $parser
+ * @param PPFrame $frame
+ * @return string
+ * @throws MWException
+ */
+ public function handle( $input, array $args, Parser $parser, PPFrame
$frame ) {
+ if( $this->aTagDef['disableParserCache'] === true ) {
+ $parser->disableCache();
+ }
+
+ if( $this->aTagDef['expandInput'] === true ) {
+ $input = $parser->recursiveTagParse( $input );
+ }
+
+ $sElementName = 'div';
+ if( $this->aTagDef['inline'] === true ) {
+ $sElementName = 'span';
+ }
+
+ $aElementClasses = $this->aTagDef['classes'];
+ $aElementClasses[] = 'bs-tag';
+ $aElementClasses[] = $this->makeElementClassName();
+
+ $aAttributes = array();
+ if( $this->aTagDef['titleMsg'] !== null ) {
+ $aAttributes[ 'title' ] = wfMessage(
$this->aTagDef['titleMsg'] )->plain();
+ }
+
+ $sContent = '';
+ try{
+ $processedInput = $this->processInput( $input );
+ $processedArgs = $this->processArgs( $args );
+ $aAttributes['params'] = FormatJson::encode(
$processedArgs );
+
+ if( is_callable( $this->aTagDef['callback'] ) ) {
+ $sContent = call_user_func_array(
$this->aTagDef['callback'], array(
+ $processedInput, $processedArgs,
$parser, $frame
+ ) );
+ }
+ } catch (Exception $ex) {
+ $sContent = 'ERROR';
+ $aElementClasses[] = 'bs-tag-error';
+ }
+
+ $aAttributes['class'] = implode( ' ', $aElementClasses );
+
+ return Html::rawElement( $sElementName, $aAttributes, $sContent
);
+ }
+
+ protected function processInput( $input ) {
+ return $input;
+ }
+
+ protected function processArgs( $args ) {
+ return $args;
+ }
+
+ protected function extendTagDefinition( $aTagDef ) {
+ return array_merge(
+ $this->makeDefaultTagDefinition(),
+ $aTagDef
+ );
+ }
+
+ protected function makeDefaultTagDefinition() {
+ return array(
+ 'params' => array(),
+ 'disableParserCache' => false,
+ 'classes' => array(),
+ 'titleMsg' => null,
+ 'inline' => false,
+ 'expandInput' => true,
+ 'expandParamValues' => true,
+ 'callback' => null,
+ 'modules' => array(),
+ 'moduleStyles' => array()
+ );
+ }
+
+ protected function makeElementClassName() {
+ $sPrefix = 'bs-';
+ if( strpos( $this->sTagName, 'bs:' ) === 0 ) {
+ $sPrefix = '';
+ }
+ return str_replace( ':', '-', $sPrefix.$this->sTagName );
+ }
+
+}
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/278280
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I06ea08e5a1ad789806a7648bd4cf03b5b911e12f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BlueSpiceFoundation
Gerrit-Branch: master
Gerrit-Owner: Robert Vogel <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits