Pwirth has uploaded a new change for review.
https://gerrit.wikimedia.org/r/282348
Change subject: BSPing: Used API instead of AjaxExportList
......................................................................
BSPing: Used API instead of AjaxExportList
* works for now. Needs refactoring (also the hook handlers)
Change-Id: I0627f61855f9929df7bf493a3af04f543c107b94
---
M BlueSpiceFoundation.php
M i18n/api/en.json
M i18n/api/qqq.json
M includes/AutoLoader.php
M includes/Core.class.php
A includes/api/BSApiPingTasks.php
M resources/bluespice/bluespice.ping.js
7 files changed, 143 insertions(+), 59 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BlueSpiceFoundation
refs/changes/48/282348/1
diff --git a/BlueSpiceFoundation.php b/BlueSpiceFoundation.php
index bf6cdc7..364e8a2 100644
--- a/BlueSpiceFoundation.php
+++ b/BlueSpiceFoundation.php
@@ -64,7 +64,6 @@
$wgAjaxExportList[] = 'BsCommonAJAXInterface::getCategoryStoreData';
$wgAjaxExportList[] = 'BsCommonAJAXInterface::getAsyncCategoryTreeStoreData';
$wgAjaxExportList[] = 'BsCommonAJAXInterface::getFileUrl';
-$wgAjaxExportList[] = 'BsCore::ajaxBSPing';
$wgAPIModules['bs-filebackend-store'] = 'BSApiFileBackendStore';
$wgAPIModules['bs-user-store'] = 'BSApiUserStore';
@@ -73,6 +72,7 @@
$wgAPIModules['bs-wikipage-tasks'] = 'BSApiWikiPageTasks';
$wgAPIModules['bs-wikipage-store'] = 'BSApiWikiPageStore';
$wgAPIModules['bs-titlequery-store'] = 'BSApiTitleQueryStore';
+$wgAPIModules['bs-ping-tasks'] = 'BSApiPingTasks';
//I18N MW1.23+
$wgMessagesDirs['BlueSpice'] = __DIR__ . '/i18n/core';
diff --git a/i18n/api/en.json b/i18n/api/en.json
index b954ce6..6ec105f 100644
--- a/i18n/api/en.json
+++ b/i18n/api/en.json
@@ -32,5 +32,6 @@
"bs-wikipage-tasks-error-page-edit-not-allowed": "You are not allowed
to edit page '$1'.",
"bs-wikipage-tasks-error-categories-not-valid": "Invalid
{{PLURAL:$2|category|categories}}: $1",
"bs-wikipage-tasks-setcategories-success": "Categories have
successfully been set.",
- "apihelp-bs-wikipage-store-description": "Lists all wiki pages. Allows
sorting, filtering and pagination. Implements ExtJS Store parameters."
+ "apihelp-bs-wikipage-store-description": "Lists all wiki pages. Allows
sorting, filtering and pagination. Implements ExtJS Store parameters.",
+ "apihelp-bs-ping-tasks-description": "Ping task that provides
continuous exchange of data"
}
diff --git a/i18n/api/qqq.json b/i18n/api/qqq.json
index 2d9f30c..4fd34b5 100644
--- a/i18n/api/qqq.json
+++ b/i18n/api/qqq.json
@@ -32,5 +32,6 @@
"bs-wikipage-tasks-error-page-edit-not-allowed": "An error message that
occurs if a user is not allowed to edit page with name '$1'.\n\nParameters:\n*
$1 - a page title",
"bs-wikipage-tasks-error-categories-not-valid": "An error message that
tells if the category names in $1 are invalid.\n\nParameters:\n* $1 - a comma
seperated list of provided invalid category names\n* $2 - a positive number for
the plural rule",
"bs-wikipage-tasks-setcategories-success": "A success message that
indicated that the categories have successfully been set",
- "apihelp-bs-wikipage-store-description": "Describes the API endpoint
that list wiki pages"
+ "apihelp-bs-wikipage-store-description": "Describes the API endpoint
that list wiki pages",
+ "apihelp-bs-ping-tasks-description": "Describes the API endpoint that
provides the ping"
}
diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php
index f281935..20016dc 100644
--- a/includes/AutoLoader.php
+++ b/includes/AutoLoader.php
@@ -70,6 +70,7 @@
$GLOBALS['wgAutoloadClasses']['BSApiWikiPageTasks'] = __DIR__ .
'/api/BSApiWikiPageTasks.php';
$GLOBALS['wgAutoloadClasses']['BSApiWikiPageStore'] = __DIR__ .
'/api/BSApiWikiPageStore.php';
$GLOBALS['wgAutoloadClasses']['BSApiTitleQueryStore'] = __DIR__ .
'/api/BSApiTitleQueryStore.php';
+$GLOBALS['wgAutoloadClasses']['BSApiPingTasks'] = __DIR__ .
'/api/BSApiPingTasks.php';
//adapter
$GLOBALS['wgAutoloadClasses']['BsExtensionMW'] =
__DIR__."/ExtensionMW.class.php";
diff --git a/includes/Core.class.php b/includes/Core.class.php
index 5cc9ab1..f297907 100644
--- a/includes/Core.class.php
+++ b/includes/Core.class.php
@@ -667,50 +667,6 @@
}
/**
- * Handles requests to the BS-AJAX-PING-BUS (BSAPB)
- * TODO: Move to seperate class
- * @return String JSON encoded data
- */
- public static function ajaxBSPing() {
- $aResult = array(
- "success" => false,
- "errors" => array(),
- "message" => '',
- );
-
- $oRequest = RequestContext::getMain()->getRequest();
- $iArticleId = $oRequest->getInt( 'iArticleID', 0 );
- $iNamespace = $oRequest->getInt( 'iNamespace', 0 );
- $sTitle = $oRequest->getVal( 'sTitle', '' );
- $iRevision = $oRequest->getInt( 'iRevision', 0 );
- $aBSPingData = $oRequest->getArray( 'BsPingData', array() );
-
- $aResult['success'] = true;
- foreach ( $aBSPingData as $aSinglePing ) {
- if ( empty( $aSinglePing['sRef'] ) ) continue;
- if ( !$aResult['success'] ) break;
-
- if ( !isset( $aSinglePing['aData'] ) )
- $aSinglePing['aData'] = array();
-
- $aSingleResult = array(
- "success" => false,
- "errors" => array(),
- "message" => '',
- );
- //if hook returns false - overall success is false
- $aResult['success'] = wfRunHooks(
'BsAdapterAjaxPingResult',
- array( $aSinglePing['sRef'],
$aSinglePing['aData'],
- $iArticleId, $sTitle, $iNamespace,
$iRevision,
- &$aSingleResult )
- );
- $aResult[$aSinglePing['sRef']] = $aSingleResult;
- }
-
- return FormatJson::encode( $aResult );
- }
-
- /**
* Make the page being parsed have a dependency on $page via the
templatelinks table.
*
http://www.mediawiki.org/wiki/Manual:Tag_extensions#Regenerating_the_page_when_another_page_is_edited
* @param Parser $oParser
diff --git a/includes/api/BSApiPingTasks.php b/includes/api/BSApiPingTasks.php
new file mode 100644
index 0000000..a094536
--- /dev/null
+++ b/includes/api/BSApiPingTasks.php
@@ -0,0 +1,130 @@
+<?php
+/**
+ * Provides common tasks that can pe performed on a WikiPage.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * This file is part of BlueSpice for MediaWiki
+ * For further information visit http://www.blue-spice.org
+ *
+ * @author Robert Vogel <[email protected]>
+ * @package Bluespice_Foundation
+ * @copyright Copyright (C) 2016 Hallo Welt! - Medienwerkstatt GmbH, All
rights reserved.
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License v2 or
later
+ * @filesource
+ */
+
+/**
+ * TODO: Works for now but needs refactoring soon!
+ * Provides common tasks that can pe performed on a WikiPage
+ * @package BlueSpice_Foundation
+ */
+class BSApiPingTasks extends BSApiTasksBase {
+ protected $aTasks = array( 'ping' );
+
+ protected $aReadTasks = array( 'ping' );
+
+ /**
+ * Configures the global permission requirements
+ * @return array
+ */
+ protected function getRequiredPermissions() {
+ return array(
+ 'ping' => array( 'read' )
+ );
+ }
+
+ //public function
+
+ protected function task_ping( $oTaskData ) {
+ $oResponse = $this->makeStandardReturn();
+
+ //TODO: Params need very hard param processing!
+ $iArticleId = isset( $oTaskData->iArticleID )
+ ? (int) $oTaskData->iArticleID
+ : 0
+ ;
+ $iNamespace = isset( $oTaskData->iNamespace )
+ ? (int) $oTaskData->iNamespace
+ : 0
+ ;
+ $sTitle = isset( $oTaskData->sTitle )
+ ? (string) $oTaskData->sTitle
+ : ''
+ ;
+ $iRevision = isset( $oTaskData->iRevision )
+ ? (int) $oTaskData->iRevision
+ : 0
+ ;
+ $aBSPingData = isset( $oTaskData->BsPingData )
+ ? (array) $oTaskData->BsPingData
+ : array()
+ ;
+
+ $oResponse->success = true;
+ $oResponse->payload = array();
+ if( empty($aBSPingData) ) {
+ return $oResponse;
+ }
+
+ foreach( $aBSPingData as $oSinglePing ) {
+ if( !$oResponse->success ) {
+ break;
+ }
+ if( empty($oSinglePing) || empty($oSinglePing->sRef) ) {
+ continue;
+ }
+
+ //Workaround: Each hook handler expect an array
+ $aSinglePing = (array) $oSinglePing;
+ if( !isset($aSinglePing['aData']) ) {
+ $aSinglePing['aData'] = array();
+ } else {
+ //TODO: Each data set needs very hard param
processing too!
+ $aSinglePing['aData'] = (array)
$aSinglePing['aData'];
+ }
+ //Workaround: Each hook handler expect an array not an
object
+ foreach( $aSinglePing['aData'] as $iKey => $oData ) {
+ if( empty($oData) ) {
+ $aSinglePing['aData'][$iKey] = array();
+ continue;
+ }
+ if( !$oData instanceof stdClass ) {
+ continue;
+ }
+ $aSinglePing['aData'][$iKey] = (array) $oData;
+ }
+
+ $aSingleResult = array(
+ "success" => false,
+ "errors" => array(),
+ "message" => '',
+ );
+ //if hook returns false - overall success is false
+ $oResponse->success = wfRunHooks(
'BsAdapterAjaxPingResult', array(
+ $aSinglePing['sRef'],
+ $aSinglePing['aData'],
+ $iArticleId,
+ $sTitle,
+ $iNamespace,
+ $iRevision,
+ &$aSingleResult
+ ));
+ $oResponse->payload[$aSinglePing['sRef']] =
$aSingleResult;
+ }
+
+ return $oResponse;
+ }
+}
\ No newline at end of file
diff --git a/resources/bluespice/bluespice.ping.js
b/resources/bluespice/bluespice.ping.js
index 168b7f1..76e272e 100644
--- a/resources/bluespice/bluespice.ping.js
+++ b/resources/bluespice/bluespice.ping.js
@@ -26,20 +26,13 @@
aData:aListenersToGo[i].aData
});
}
-
- $.post(
- mw.config.get( "wgScriptPath" ) + '/index.php',
- {
- action:'ajax',
- rs:'BsCore::ajaxBSPing',
+ bs.api.tasks.exec( 'ping', 'ping', {
iArticleID: mw.config.get( "wgArticleId" ),
sTitle: mw.config.get( "wgTitle" ),
iNamespace: mw.config.get( "wgNamespaceNumber"
),
iRevision: mw.config.get( "wgCurRevisionId" ),
BsPingData: BsPingData
- },
- BSPing.pingCallback( aListenersToGo )
- );
+ }).done( BSPing.pingCallback( aListenersToGo ) );
},
registerListener: function( sRef, iInterval, aData, callback) {
if ( typeof sRef === "undefined" ) {
@@ -75,7 +68,6 @@
},
pingCallback : function( aListenersToGo ) {
return function( result ) {
- result = JSON.parse( result );
if ( result.success !== true ) {
return;
}
@@ -86,14 +78,17 @@
$(document).trigger('BSPingBeforeSingleCallback', [
this,
aListenersToGo[i].callback,
- result[aListenersToGo[i].sRef],
+
result.payload[aListenersToGo[i].sRef],
aListenersToGo[i],
skip
]);
if ( skip ) {
continue;
}
- aListenersToGo[i].callback(
result[aListenersToGo[i].sRef], aListenersToGo[i] );
+ aListenersToGo[i].callback(
+
result.payload[aListenersToGo[i].sRef],
+ aListenersToGo[i]
+ );
}
}
--
To view, visit https://gerrit.wikimedia.org/r/282348
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0627f61855f9929df7bf493a3af04f543c107b94
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BlueSpiceFoundation
Gerrit-Branch: master
Gerrit-Owner: Pwirth <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits