[MediaWiki-commits] [Gerrit] mediawiki...BlueSpiceExtensions[master]: StateBar: Now uses API instead of ajax call

2016-08-16 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: StateBar: Now uses API instead of ajax call
..


StateBar: Now uses API instead of ajax call

Converted ajax call to API.

Change-Id: Ib8228d6995b19a6205b66008f027d5a5ad01222b
---
M StateBar/StateBar.class.php
M StateBar/StateBar.setup.php
M StateBar/i18n/en.json
M StateBar/i18n/qqq.json
A StateBar/includes/api/BSApiStateBarTasks.php
M StateBar/resources/bluespice.StateBar.js
6 files changed, 104 insertions(+), 89 deletions(-)

Approvals:
  Robert Vogel: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/StateBar/StateBar.class.php b/StateBar/StateBar.class.php
index c0dcf3c..91ff5c0 100644
--- a/StateBar/StateBar.class.php
+++ b/StateBar/StateBar.class.php
@@ -90,7 +90,7 @@
/**
 * Registers StateBar sort variables
 */
-   private function registerSortVars() {
+   public function registerSortVars() {
wfRunHooks( 'BSStateBarAddSortTopVars', array( 
&$this->aSortTopVars ) );
 
$aDefaultSortTopVars = array(
@@ -150,59 +150,6 @@
}
 
/**
-* AJAX interface for BlueSpice SateBar body views
-* @return string The JSON formatted response
-*/
-   public static function ajaxCollectBodyViews() {
-   global $wgUser;
-   $aResult = array(
-   "success" => false,
-   "views" => array(),
-   "message" => '',
-   );
-
-   $iArticleID = RequestContext::getMain()->getRequest()->getInt( 
'articleID', 0 );
-   if( $iArticleID === 0 ) {
-   $aResult['message'] = 
wfMessage("bs-statebar-ajax-nobodyviews")->plain();
-   return FormatJson::encode($aResult);
-   }
-
-   $oStateBar = BsExtensionManager::getExtension( 'StateBar' );
-   $oStateBar->registerSortVars();
-
-   $oTitle = $oStateBar->checkContext(
-   Title::newFromID( $iArticleID ),
-   true //because you already have the possible redirected 
title!
-//also prevents from get wrong data in 
redirect redirect
-   );
-   if( is_null($oTitle) ) {
-   $aResult['message'] = 
wfMessage("bs-statebar-ajax-nobodyviews")->plain();
-   return json_encode( $aResult );
-   }
-
-   $aBodyViews = array();
-   wfRunHooks( 'BSStateBarBeforeBodyViewAdd', array( $oStateBar, 
&$aBodyViews, $wgUser, $oTitle ) );
-   if( empty($aBodyViews) ) {
-   $aResult['success'] = true;
-   $aResult['message'] = 
wfMessage('bs-statebar-ajax-nobodyviews')->plain();
-   return json_encode( $aResult );
-   }
-
-   $aSortBodyVars = BsConfig::get('MW::StateBar::SortBodyVars');
-   if( !empty($aSortBodyVars) ) {
-   $aBodyViews = $oStateBar->reorderViews( $aBodyViews, 
$aSortBodyVars );
-   }
-
-   //execute all views to an array with numeric index
-   $aExecutedBodyViews = array();
-   foreach( $aBodyViews as $oView ) $aExecutedBodyViews[] = 
$oView->execute();
-
-   $aResult['views'] = $aExecutedBodyViews;
-   $aResult['success'] = true;
-   return FormatJson::encode( $aResult );
-   }
-
-   /**
 * Inject tags into InsertMagic
 * @param Object $oResponse reference
 * $param String $type
@@ -243,7 +190,7 @@
 * @param bool $bRedirect
 * @return Title - null when context check fails
 */
-   private function checkContext( $oTitle, $bRedirect = false ) {
+   public function checkContext( $oTitle, $bRedirect = false ) {
if ( is_null( $oTitle ) ) return null;
if ( $oTitle->exists() === false ) return null;
if ( $oTitle->getNamespace() === NS_SPECIAL ) return null;
diff --git a/StateBar/StateBar.setup.php b/StateBar/StateBar.setup.php
index 44308a1..b8610ca 100644
--- a/StateBar/StateBar.setup.php
+++ b/StateBar/StateBar.setup.php
@@ -27,4 +27,6 @@
 $wgAutoloadClasses['ViewStateBarTopElement'] = 
__DIR__.'/views/view.StateBarTopElement.php';
 $wgAutoloadClasses['ViewStateBarBodyElement'] = 
__DIR__.'/views/view.StateBarBodyElement.php';
 
-$wgAjaxExportList[] = 'StateBar::ajaxCollectBodyViews';
+$wgAutoloadClasses['BSApiStateBarTasks'] = __DIR__ . 
'/includes/api/BSApiStateBarTasks.php';
+
+$wgAPIModules['bs-statebar-tasks'] = 'BSApiStateBarTasks';
diff --git a/StateBar/i18n/en.json b/StateBar/i18n/en.json
index 9f23807..d638229 100644
--- a/StateBar/i18n/en.json
+++ b/StateBar/i18n/en.json
@@ -12,5 +12,6 @@
"bs-statebar-viewtoggler": "DETAILS",

[MediaWiki-commits] [Gerrit] mediawiki...BlueSpiceExtensions[master]: StateBar: Now uses API instead of ajax call

2016-08-14 Thread Mglaser (Code Review)
Mglaser has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/304747

Change subject: StateBar: Now uses API instead of ajax call
..

StateBar: Now uses API instead of ajax call

Converted ajax call to API.

Change-Id: Ib8228d6995b19a6205b66008f027d5a5ad01222b
---
M StateBar/StateBar.class.php
M StateBar/StateBar.setup.php
M StateBar/i18n/en.json
M StateBar/i18n/qqq.json
A StateBar/includes/api/BSApiStateBarTasks.php
M StateBar/resources/bluespice.StateBar.js
6 files changed, 104 insertions(+), 89 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BlueSpiceExtensions 
refs/changes/47/304747/1

diff --git a/StateBar/StateBar.class.php b/StateBar/StateBar.class.php
index c0dcf3c..91ff5c0 100644
--- a/StateBar/StateBar.class.php
+++ b/StateBar/StateBar.class.php
@@ -90,7 +90,7 @@
/**
 * Registers StateBar sort variables
 */
-   private function registerSortVars() {
+   public function registerSortVars() {
wfRunHooks( 'BSStateBarAddSortTopVars', array( 
&$this->aSortTopVars ) );
 
$aDefaultSortTopVars = array(
@@ -150,59 +150,6 @@
}
 
/**
-* AJAX interface for BlueSpice SateBar body views
-* @return string The JSON formatted response
-*/
-   public static function ajaxCollectBodyViews() {
-   global $wgUser;
-   $aResult = array(
-   "success" => false,
-   "views" => array(),
-   "message" => '',
-   );
-
-   $iArticleID = RequestContext::getMain()->getRequest()->getInt( 
'articleID', 0 );
-   if( $iArticleID === 0 ) {
-   $aResult['message'] = 
wfMessage("bs-statebar-ajax-nobodyviews")->plain();
-   return FormatJson::encode($aResult);
-   }
-
-   $oStateBar = BsExtensionManager::getExtension( 'StateBar' );
-   $oStateBar->registerSortVars();
-
-   $oTitle = $oStateBar->checkContext(
-   Title::newFromID( $iArticleID ),
-   true //because you already have the possible redirected 
title!
-//also prevents from get wrong data in 
redirect redirect
-   );
-   if( is_null($oTitle) ) {
-   $aResult['message'] = 
wfMessage("bs-statebar-ajax-nobodyviews")->plain();
-   return json_encode( $aResult );
-   }
-
-   $aBodyViews = array();
-   wfRunHooks( 'BSStateBarBeforeBodyViewAdd', array( $oStateBar, 
&$aBodyViews, $wgUser, $oTitle ) );
-   if( empty($aBodyViews) ) {
-   $aResult['success'] = true;
-   $aResult['message'] = 
wfMessage('bs-statebar-ajax-nobodyviews')->plain();
-   return json_encode( $aResult );
-   }
-
-   $aSortBodyVars = BsConfig::get('MW::StateBar::SortBodyVars');
-   if( !empty($aSortBodyVars) ) {
-   $aBodyViews = $oStateBar->reorderViews( $aBodyViews, 
$aSortBodyVars );
-   }
-
-   //execute all views to an array with numeric index
-   $aExecutedBodyViews = array();
-   foreach( $aBodyViews as $oView ) $aExecutedBodyViews[] = 
$oView->execute();
-
-   $aResult['views'] = $aExecutedBodyViews;
-   $aResult['success'] = true;
-   return FormatJson::encode( $aResult );
-   }
-
-   /**
 * Inject tags into InsertMagic
 * @param Object $oResponse reference
 * $param String $type
@@ -243,7 +190,7 @@
 * @param bool $bRedirect
 * @return Title - null when context check fails
 */
-   private function checkContext( $oTitle, $bRedirect = false ) {
+   public function checkContext( $oTitle, $bRedirect = false ) {
if ( is_null( $oTitle ) ) return null;
if ( $oTitle->exists() === false ) return null;
if ( $oTitle->getNamespace() === NS_SPECIAL ) return null;
diff --git a/StateBar/StateBar.setup.php b/StateBar/StateBar.setup.php
index 44308a1..b8610ca 100644
--- a/StateBar/StateBar.setup.php
+++ b/StateBar/StateBar.setup.php
@@ -27,4 +27,6 @@
 $wgAutoloadClasses['ViewStateBarTopElement'] = 
__DIR__.'/views/view.StateBarTopElement.php';
 $wgAutoloadClasses['ViewStateBarBodyElement'] = 
__DIR__.'/views/view.StateBarBodyElement.php';
 
-$wgAjaxExportList[] = 'StateBar::ajaxCollectBodyViews';
+$wgAutoloadClasses['BSApiStateBarTasks'] = __DIR__ . 
'/includes/api/BSApiStateBarTasks.php';
+
+$wgAPIModules['bs-statebar-tasks'] = 'BSApiStateBarTasks';
diff --git a/StateBar/i18n/en.json b/StateBar/i18n/en.json
index 9f23807..d638229 100644
--- a/StateBar/i18n/en.json
+++ b/StateBar/i18n/en.json
@@ -12,5 +12,6