Mglaser has uploaded a new change for review.
https://gerrit.wikimedia.org/r/287651
Change subject: Dashboard: Added custom widget
......................................................................
Dashboard: Added custom widget
A custom widget can now be used. It displays any given wiki article
in the widget. This can be used to create customized widgets with
arbitrary content.
This is a rebased version of change 286759
Change-Id: Ib3eaeffd36fccf2d14dde7c6fa725f441b9e766f
---
M Dashboards/Dashboards.class.php
M Dashboards/Dashboards.setup.php
M Dashboards/i18n/en.json
M Dashboards/i18n/qqq.json
M Dashboards/includes/api/BSApiDashboardStore.php
M Dashboards/includes/api/BSApiDashboardTasks.php
A Dashboards/includes/api/BSApiDashboardWidgetsTasks.php
M Dashboards/resources/BS.Dashboards/PortletCatalog.js
A Dashboards/resources/BS.Dashboards/WikiPagePortlet.js
A Dashboards/resources/BS.Dashboards/WikiPagePortletConfig.js
10 files changed, 187 insertions(+), 15 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BlueSpiceExtensions
refs/changes/51/287651/1
diff --git a/Dashboards/Dashboards.class.php b/Dashboards/Dashboards.class.php
index 06164ff..fc107f5 100644
--- a/Dashboards/Dashboards.class.php
+++ b/Dashboards/Dashboards.class.php
@@ -211,6 +211,12 @@
'title' => wfMessage(
'bs-dashboard-userportlet-calendar-title' )->plain()
)
);
+ $aPortalConfig[0][] = array(
+ 'type' => 'BS.Dashboards.WikiPagePortlet',
+ 'config' => array(
+ 'title' => wfMessage(
'bs-dashboard-userportlet-wikipage-title' )->plain()
+ )
+ );
return true;
}
@@ -229,6 +235,14 @@
'title' => wfMessage(
'bs-dashboard-userportlet-calendar-title' )->plain(),
'description' => wfMessage(
'bs-dashboard-userportlet-calendar-description' )->plain()
);
+ $aPortlets[] = array(
+ 'type' => 'BS.Dashboards.WikiPagePortlet',
+ 'config' => array(
+ 'title' => wfMessage(
'bs-dashboard-userportlet-wikipage-title' )->plain(),
+ ),
+ 'title' => wfMessage(
'bs-dashboard-userportlet-wikipage-title' )->plain(),
+ 'description' => wfMessage(
'bs-dashboard-userportlet-wikipage-description' )->plain()
+ );
return true;
}
}
\ No newline at end of file
diff --git a/Dashboards/Dashboards.setup.php b/Dashboards/Dashboards.setup.php
index fea42bc..15869e1 100644
--- a/Dashboards/Dashboards.setup.php
+++ b/Dashboards/Dashboards.setup.php
@@ -13,12 +13,14 @@
$wgAutoloadClasses['SpecialUserDashboard'] =
__DIR__.'/includes/specials/SpecialUserDashboard.php';
$GLOBALS['wgAutoloadClasses']['BSApiDashboardTasks'] = __DIR__ .
'/includes/api/BSApiDashboardTasks.php';
$GLOBALS['wgAutoloadClasses']['BSApiDashboardStore'] = __DIR__ .
'/includes/api/BSApiDashboardStore.php';
+$GLOBALS['wgAutoloadClasses']['BSApiDashboardWidgetsTasks'] = __DIR__ .
'/includes/api/BSApiDashboardWidgetsTasks.php';
$wgSpecialPages['AdminDashboard'] = 'SpecialAdminDashboard';
$wgSpecialPages['UserDashboard'] = 'SpecialUserDashboard';
$wgAPIModules['bs-dashboards-tasks'] = 'BSApiDashboardTasks';
$wgAPIModules['bs-dashboards-store'] = 'BSApiDashboardStore';
+$wgAPIModules['bs-dashboards-widgets-tasks'] = 'BSApiDashboardWidgetsTasks';
$wgHooks['LoadExtensionSchemaUpdates'][] = 'Dashboards::getSchemaUpdates';
$wgHooks['BSDashboardsUserDashboardPortalPortlets'][] =
'Dashboards::onBSDashboardsUserDashboardPortalPortlets';
@@ -50,7 +52,8 @@
'messages' => array(
'bs-dashboards-addportlet',
'bs-dashboards-portlets',
- 'bs-extjs-rssfeeder-rss-title'
+ 'bs-extjs-rssfeeder-rss-title',
+ 'bs-dashboard-userportlet-wikipage-wiki-article'
)
) + $aResourceModuleTemplate;
diff --git a/Dashboards/i18n/en.json b/Dashboards/i18n/en.json
index 50a1e5c..b897fa3 100644
--- a/Dashboards/i18n/en.json
+++ b/Dashboards/i18n/en.json
@@ -14,6 +14,11 @@
"userdashboard": "User dashboard",
"bs-dashboard-userportlet-calendar-title": "Calendar",
"bs-dashboard-userportlet-calendar-description": "Calendar",
+ "bs-dashboard-userportlet-wikipage-title": "WikiPage",
+ "bs-dashboard-userportlet-wikipage-description": "Use a wiki page to
define the widget",
+ "bs-dashboard-userportlet-wikipage-wiki-article": "Wiki page",
+ "apihelp-bs-dashboard-task-param-dc": "Cache control parameter. Used by
ExtJS.",
"apihelp-bs-dashboards-store-description": "Lists all available
portlets",
- "apihelp-bs-dashboards-tasks-description": "Saves dashboard
configuration"
+ "apihelp-bs-dashboards-tasks-description": "Saves dashboard
configuration",
+ "apihelp-bs-dashboards-widgets-tasks-description": "Returns content for
some dashboard widgets"
}
diff --git a/Dashboards/i18n/qqq.json b/Dashboards/i18n/qqq.json
index c24e6b5..0885c23 100644
--- a/Dashboards/i18n/qqq.json
+++ b/Dashboards/i18n/qqq.json
@@ -16,7 +16,12 @@
"admindashboard": "Special page name for admin dashboard.\n\n\"admin\"
is short for administrator.\n\nSee also:\n* {{msg-mw|Userdashboard}}",
"userdashboard": "Special page name for user dashboard.\n\nSee also:\n*
{{msg-mw|Admindashboard}}",
"bs-dashboard-userportlet-calendar-title": "Portlet title for
calendar\n{{Identical|Calendar}}",
- "bs-dashboard-userportlet-calendar-description": "portlet description
for calendar\n{{Identical|Calendar}}",
+ "bs-dashboard-userportlet-calendar-description": "Portlet description
for calendar\n{{Identical|Calendar}}",
+ "bs-dashboard-userportlet-wikipage-title": "Portlet title for wikipage
widget",
+ "bs-dashboard-userportlet-wikipage-description": "Portlet description
for wikipage widget",
+ "bs-dashboard-userportlet-wikipage-wiki-article": "Label for wiki
article parameter used in config dialog",
+ "apihelp-bs-dashboard-task-param-dc": "Label for cache control
parameter in api call",
"apihelp-bs-dashboards-store-description": "Describes the API endpoint
that lists available portlets",
- "apihelp-bs-dashboards-tasks-description": "Describes the API endpoint
that saves dashboard configuration"
+ "apihelp-bs-dashboards-tasks-description": "Describes the API endpoint
that saves dashboard configuration",
+ "apihelp-bs-dashboards-widgets-tasks-description": "Describes the API
endpoint that returns content for some dashboard widgets"
}
diff --git a/Dashboards/includes/api/BSApiDashboardStore.php
b/Dashboards/includes/api/BSApiDashboardStore.php
index e04e90e..68e5322 100644
--- a/Dashboards/includes/api/BSApiDashboardStore.php
+++ b/Dashboards/includes/api/BSApiDashboardStore.php
@@ -40,16 +40,24 @@
$aReturnArray = array_merge( $aReturnArray, $aPortlets );
- return $aReturnArray;
+ // make sure to return objects, not arrays
+ $aReturnObjects = array();
+ foreach ( $aReturnArray as $aReturn ) {
+ $aReturnObjects[] = (object)$aReturn;
+ }
+
+ return $aReturnObjects;
}
public function filterCallback( $aDataSet ) {
- $oFilter = $this->getParameter( 'filter' );
+ $aFilter = $this->getParameter( 'filter' );
- if( $oFilter->type == 'group' ) {
- $bFilterApplies = $this->filterGroup( $oFilter,
$aDataSet );
- if( !$bFilterApplies ) {
- return false;
+ foreach ( $aFilter as $oFilter ) {
+ if( $oFilter->type == 'group' ) {
+ $bFilterApplies = $this->filterGroup( $oFilter,
$aDataSet );
+ if( !$bFilterApplies ) {
+ return false;
+ }
}
}
@@ -60,10 +68,10 @@
if( !is_string( $oFilter->value ) ) {
return true; //TODO: Warning
}
- $sFieldValue = $aDataSet['groups'];
+ $sFieldValue = $aDataSet->groups;
$sFilterValue = $oFilter->value;
- return in_array( $oFilter->value, $aDataSet['groups'] );
+ return in_array( $oFilter->value, $aDataSet->groups );
}
}
\ No newline at end of file
diff --git a/Dashboards/includes/api/BSApiDashboardTasks.php
b/Dashboards/includes/api/BSApiDashboardTasks.php
index 626c759..0a0f1a9 100644
--- a/Dashboards/includes/api/BSApiDashboardTasks.php
+++ b/Dashboards/includes/api/BSApiDashboardTasks.php
@@ -81,4 +81,4 @@
return $oResponse;
}
-}
\ No newline at end of file
+}
diff --git a/Dashboards/includes/api/BSApiDashboardWidgetsTasks.php
b/Dashboards/includes/api/BSApiDashboardWidgetsTasks.php
new file mode 100644
index 0000000..9ea3d0c
--- /dev/null
+++ b/Dashboards/includes/api/BSApiDashboardWidgetsTasks.php
@@ -0,0 +1,61 @@
+<?php
+
+class BSApiDashboardWidgetsTasks extends BSApiTasksBase {
+
+ protected $aTasks = array(
+ 'wikipage'
+ );
+
+ protected function getRequiredTaskPermissions() {
+ return array(
+ 'wikipage' => array( 'read' )
+ );
+ }
+
+ public function task_wikipage( $oTaskData, $aParams ) {
+ $oResponse = $this->makeStandardReturn();
+
+ if ( !isset( $oTaskData->wikiArticle ) ) {
+ $oResponse->success = true;
+ $oResponse->payload = array( "html" => "" );
+ return $oResponse;
+ }
+
+ $oTitle = Title::newFromText( $oTaskData->wikiArticle );
+ if ( !$oTitle->userCan( 'read' ) ) {
+ $oResponse->success = false;
+ $oResponse->payload = array( "html" => wfMessage(
'bs-permissionerror' )->plain() );
+ return $oResponse;
+ }
+ $oWikiPage = WikiPage::factory( $oTitle );
+
+ $sHTML = $oWikiPage->getContent()->getParserOutput( $oTitle
)->getText();
+
+ $oResponse->success = true;
+ $oResponse->payload = array( "html" => $sHTML );
+ return $oResponse;
+ }
+
+ public function needsToken() {
+ return false;
+ }
+ /**
+ * Returns an array of allowed parameters
+ * @return array
+ */
+ protected function getAllowedParams() {
+ $paramList = parent::getAllowedParams();
+
+ return array_merge(
+ $paramList,
+ array(
+ '_dc' => array(
+ ApiBase::PARAM_TYPE => 'string',
+ ApiBase::PARAM_REQUIRED => false,
+ //TODO: Description
+ 10 /*ApiBase::PARAM_HELP_MSG*/ =>
'apihelp-bs-dashboard-task-param-dc',
+ )
+ )
+ );
+ }
+}
\ No newline at end of file
diff --git a/Dashboards/resources/BS.Dashboards/PortletCatalog.js
b/Dashboards/resources/BS.Dashboards/PortletCatalog.js
index 39f57aa..ad25b2d 100644
--- a/Dashboards/resources/BS.Dashboards/PortletCatalog.js
+++ b/Dashboards/resources/BS.Dashboards/PortletCatalog.js
@@ -11,12 +11,12 @@
proxy: {
type: 'ajax',
url: bs.api.makeUrl(
'bs-dashboards-store', {
- "filter": JSON.stringify({
+ "filter": JSON.stringify([{
"type": "group",
"comparison": "eq",
"value": mw.config.get(
'bsPortalConfigLocation' ),
"field": "group"
- })
+ }])
}),
reader: {
type: 'json',
diff --git a/Dashboards/resources/BS.Dashboards/WikiPagePortlet.js
b/Dashboards/resources/BS.Dashboards/WikiPagePortlet.js
new file mode 100644
index 0000000..2cfd06f
--- /dev/null
+++ b/Dashboards/resources/BS.Dashboards/WikiPagePortlet.js
@@ -0,0 +1,55 @@
+Ext.define('BS.Dashboards.WikiPagePortlet', {
+ extend: 'BS.portal.Portlet',
+ height: 300,
+
+ portletConfigClass : 'BS.Dashboards.WikiPagePortletConfig',
+
+ initComponent: function() {
+ //this.portletArticle
+ this.cContent = Ext.create('Ext.Component', {
+ loader: {
+ url: '',
+ target: this.cContent,
+ renderer: function( loader, response, active ) {
+ var responseObj = Ext.JSON.decode(
response.responseText );
+ loader.getTarget().update(
responseObj.payload.html );
+ return true;
+ }
+ },
+ autoScroll: true
+ });
+
+ this.loadContent();
+
+ this.items = [
+ this.cContent
+ ];
+ this.on( 'configchange', this.onConfigChange, this);
+ this.callParent( arguments );
+ },
+
+ getPortletConfig: function() {
+ var cfg = this.callParent( arguments );
+ cfg.wikiArticle = this.wikiArticle;
+ return cfg;
+ },
+ setPortletConfig: function( oConfig ) {
+ this.wikiArticle = oConfig.wikiArticle;
+ this.callParent( arguments );
+ },
+ onConfigChange: function( oConfig ) {
+ this.loadContent();
+ },
+ loadContent: function() {
+ var me = this;
+ bs.api.tasks.exec(
+ 'dashboards-widgets',
+ 'wikipage',
+ {
+ "wikiArticle": me.wikiArticle
+ }
+ ).done( function(response) {
+ me.cContent.update( response.payload.html );
+ });
+ }
+});
diff --git a/Dashboards/resources/BS.Dashboards/WikiPagePortletConfig.js
b/Dashboards/resources/BS.Dashboards/WikiPagePortletConfig.js
new file mode 100644
index 0000000..b5bbb41
--- /dev/null
+++ b/Dashboards/resources/BS.Dashboards/WikiPagePortletConfig.js
@@ -0,0 +1,21 @@
+Ext.define('BS.Dashboards.WikiPagePortletConfig', {
+ extend: 'BS.portal.PortletConfig',
+
+ afterInitComponent: function() {
+ this.tfArticle = Ext.create( 'Ext.form.TextField',{
+ fieldLabel: mw.message(
'bs-dashboard-userportlet-wikipage-wiki-article' ).plain(),
+ labelAlign: 'right'
+ });
+ this.items.push( this.tfArticle );
+ this.callParent( arguments );
+ },
+ setConfigControlValues: function( cfg ) {
+ this.tfArticle.setValue( cfg.wikiArticle );
+ this.callParent( arguments );
+ },
+ getConfigControlValues: function() {
+ var cfg = this.callParent( arguments );
+ cfg.wikiArticle = this.tfArticle.getValue();
+ return cfg;
+ }
+});
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/287651
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib3eaeffd36fccf2d14dde7c6fa725f441b9e766f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BlueSpiceExtensions
Gerrit-Branch: master
Gerrit-Owner: Mglaser <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits