Pwirth has uploaded a new change for review.

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

Change subject: [WIP] BSApiExtJSStoreFileBackend
......................................................................

[WIP] BSApiExtJSStoreFileBackend

* Added BSApiExtJSStoreFileBackend
* Improvemnts to BSApiExtJSStoreBase

Change-Id: Iaee62adc811e20f9ad7b8ebcc600119f103a070d
---
M BlueSpiceFoundation.php
M includes/AutoLoader.php
M includes/api/BSApiExtJSStoreBase.php
A includes/api/BSApiExtJSStoreFileBackend.php
4 files changed, 96 insertions(+), 2 deletions(-)


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

diff --git a/BlueSpiceFoundation.php b/BlueSpiceFoundation.php
index 68fe925..9d38948 100644
--- a/BlueSpiceFoundation.php
+++ b/BlueSpiceFoundation.php
@@ -65,6 +65,8 @@
 $wgAjaxExportList[] = 'BsCommonAJAXInterface::getFileUrl';
 $wgAjaxExportList[] = 'BsCore::ajaxBSPing';
 
+$wgAPIModules['extjsstorefilebackend'] = 'BSApiExtJSStoreFileBackend';
+
 //I18N MW1.23+
 $wgMessagesDirs['BlueSpice'] = __DIR__ . '/i18n/core';
 $wgMessagesDirs['BlueSpiceCredits'] = __DIR__ . '/i18n/credits';
diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php
index ffadfb5..a79257d 100644
--- a/includes/AutoLoader.php
+++ b/includes/AutoLoader.php
@@ -55,6 +55,7 @@
 $GLOBALS['wgAutoloadClasses']['BSApiBase'] = __DIR__."/api/BSApiBase.php";
 $GLOBALS['wgAutoloadClasses']['BSApiTasksBase'] = 
__DIR__."/api/BSApiTasksBase.php";
 $GLOBALS['wgAutoloadClasses']['BSApiExtJSStoreBase'] = 
__DIR__."/api/BSApiExtJSStoreBase.php";
+$GLOBALS['wgAutoloadClasses']['BSApiExtJSStoreFileBackend'] = 
__DIR__."/api/BSApiExtJSStoreFileBackend.php";
 
 //adapter
 $GLOBALS['wgAutoloadClasses']['BsExtensionMW'] = 
__DIR__."/ExtensionMW.class.php";
diff --git a/includes/api/BSApiExtJSStoreBase.php 
b/includes/api/BSApiExtJSStoreBase.php
index 9e40541..95ce37f 100644
--- a/includes/api/BSApiExtJSStoreBase.php
+++ b/includes/api/BSApiExtJSStoreBase.php
@@ -176,7 +176,10 @@
         * @return array
         */
        public function postProcessData( $aData ) {
-               wfRunHooks( 'BSApiExtJSStoreBaseBeforePostProcessData', array( 
$this, &$aData ) );
+               if( !wfRunHooks( 'BSApiExtJSStoreBaseBeforePostProcessData', 
array( $this, &$aData ) ) ) {
+                       return $aData;
+               }
+
                $aProcessedData = array();
 
                //First, apply filter
@@ -267,7 +270,8 @@
        public function trimData($aProcessedData) {
                $iStart = $this->getParameter('start');
                $iEnd = $this->getParameter('limit') + $iStart;
-               if( $iEnd >= $this->iFinalDataSetCount ) {
+
+               if( $iEnd >= $this->iFinalDataSetCount || $iEnd === 0 ) {
                        $iEnd = $this->iFinalDataSetCount - 1;
                }
 
diff --git a/includes/api/BSApiExtJSStoreFileBackend.php 
b/includes/api/BSApiExtJSStoreFileBackend.php
new file mode 100644
index 0000000..41119fb
--- /dev/null
+++ b/includes/api/BSApiExtJSStoreFileBackend.php
@@ -0,0 +1,87 @@
+<?php
+
+class BSApiExtJSStoreFileBackend extends BSApiExtJSStoreBase {
+
+       public function makeData() {
+               $oDbr = wfGetDB( DB_SLAVE );
+               $oImgRes = $oDbr->select(
+                       array( 'image', 'page' ),
+                       '*',
+                       array( 'page_namespace' => NS_FILE, 'page_title = 
img_name' ),
+                       __METHOD__
+               );
+
+               $aReturn = array();
+               foreach($oImgRes as $oRow) {
+                       $oTitle = Title::makeTitleSafe( NS_FILE, 
$oRow->page_title );
+                       if( !is_object( $oTitle ) || !$img = wfFindFile( 
$oTitle ) ) {
+                               continue;
+                       }
+
+                       $oImg = wfFindFile( $oTitle );
+                       $sThumb = $oImg->createThumb( 48, 48 );
+                       if( BsExtensionManager::isContextActive( 
'MW::SecureFileStore::Active' ) ) {
+                               $sThumb = SecureFileStore::secureStuff( 
$sThumb, true );
+                       }
+                       $oRow->img_metadata = unserialize( $oRow->img_metadata 
);
+
+                       $oResCat = $oDbr->select(
+                               array( 'categorylinks'),
+                               array( 'cl_to'),
+                               array( 'cl_from' => $oTitle->getArticleID() ),
+                               __METHOD__
+                       );
+
+                       $aCategories = array();
+                       foreach( $oResCat as $oCat ) {
+                               $aCategories[] = $oCat->cl_to;
+                       }
+
+                       $aReturn[] = (object) array_merge(
+                               (array) $oRow,
+                               array( 'img_thumbnail' => $sThumb ),
+                               array( 'categories' => $aCategories )
+                       );
+               }
+               return $aReturn;
+
+               //wfRunHooks( 'BSInsertFileGetFilesBeforeQuery', array( 
&$aConds, &$aNameFilters ) );
+       }
+
+       public function filterCallback( $aDataSet ) {
+               $aFilter = $this->getParameter('filter');
+               foreach( $aFilter as $oFilter ) {
+                       if( $oFilter->type != 'categories' ) {
+                               continue;
+                       }
+                       if( !$this->filterCategories($oFilter, $aDataSet) ) {
+                               return false;
+                       }
+               }
+               return parent::filterCallback($aDataSet);
+       }
+
+       public function filterCategories($oFilter, $aDataSet) {
+               $aFieldValue = $aDataSet->{$oFilter->field};
+               $aFilterValue = $oFilter->value;
+
+               switch( $oFilter->comparison ) {
+                       case 'ct':
+                               foreach($aFilterValue as $sValue) {
+                                       if( in_array($sValue, $aFieldValue) ) {
+                                               continue;
+                                       }
+                                       return false;
+                               }
+                               return true;
+                       case 'nct':
+                               foreach($aFilterValue as $sValue) {
+                                       if( !in_array($sValue, $aFieldValue) ) {
+                                               continue;
+                                       }
+                                       return false;
+                               }
+                               return true;
+               }
+       }
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iaee62adc811e20f9ad7b8ebcc600119f103a070d
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