Robert Vogel has uploaded a new change for review.

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

Change subject: [WiP] New WikiSupPageTreeStore
......................................................................

[WiP] New WikiSupPageTreeStore

This change provides an generic API store backend for tree-like access to
the wikis page structure

Change-Id: I0cd30618b5b897cc4fa0335ecea82a3077b6efe0
---
M BlueSpiceFoundation.php
M includes/AutoLoader.php
A includes/api/BSApiWikiSubPageTreeStore.php
3 files changed, 88 insertions(+), 0 deletions(-)


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

diff --git a/BlueSpiceFoundation.php b/BlueSpiceFoundation.php
index d25d882..4c7e510 100644
--- a/BlueSpiceFoundation.php
+++ b/BlueSpiceFoundation.php
@@ -72,6 +72,8 @@
 $wgAPIModules['bs-interwiki-store'] = 'BSApiInterwikiStore';
 $wgAPIModules['bs-wikipage-tasks'] = 'BSApiWikiPageTasks';
 $wgAPIModules['bs-titlequery-store'] = 'BSApiTitleQueryStore';
+$wgAPIModules['bs-wikisubpage-treestore'] = 'BSApiWikiSubPageTreeStore';
+
 
 //I18N MW1.23+
 $wgMessagesDirs['BlueSpice'] = __DIR__ . '/i18n/core';
diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php
index ff0c1b6..7a4cbb8 100644
--- a/includes/AutoLoader.php
+++ b/includes/AutoLoader.php
@@ -67,6 +67,7 @@
 $GLOBALS['wgAutoloadClasses']['BSApiInterwikiStore'] = __DIR__ . 
'/api/BSApiInterwikiStore.php';
 $GLOBALS['wgAutoloadClasses']['BSApiWikiPageTasks'] = __DIR__ . 
'/api/BSApiWikiPageTasks.php';
 $GLOBALS['wgAutoloadClasses']['BSApiTitleQueryStore'] = __DIR__ . 
'/api/BSApiTitleQueryStore.php';
+$GLOBALS['wgAutoloadClasses']['BSApiWikiSubPageTreeStore'] = __DIR__ . 
'/api/BSApiWikiSubPageTreeStore.php';
 
 //adapter
 $GLOBALS['wgAutoloadClasses']['BsExtensionMW'] = 
__DIR__."/ExtensionMW.class.php";
diff --git a/includes/api/BSApiWikiSubPageTreeStore.php 
b/includes/api/BSApiWikiSubPageTreeStore.php
new file mode 100644
index 0000000..4c53366
--- /dev/null
+++ b/includes/api/BSApiWikiSubPageTreeStore.php
@@ -0,0 +1,85 @@
+<?php
+
+class BSApiWikiSubPageTreeStore extends BSApiExtJSStoreBase {
+       protected $root = 'children';
+
+       public function makeData($sQuery = '') {
+               $aParams = $this->extractRequestParams( false );
+               $oParent= Title::newFromText( $aParams['node'] );
+
+               $res = $this->getDB()->select(
+                       'page',
+                       '*',
+                       array(
+                               'page_title '.$this->getDB()->buildLike(
+                                       $oParent->getDBkey() .'/' ,
+                                       $this->getDB()->anyString()
+                               ),
+                               'page_namespace' => $oParent->getNamespace()
+                       )
+               );
+
+               $aResult = array();
+               foreach( $res as $row ) {
+                       $oTitle = Title::newFromRow( $row );
+                       if( !$oTitle->userCan( 'read' ) ) {
+                               continue;
+                       }
+
+                       if( !$oTitle->getBaseTitle()->equals( $oParent ) ) {
+                               continue; //We want only direct children
+                       }
+
+                       $oDataSet = new stdClass();
+
+                       $oDataSet->text = $oTitle->getSubpageText();
+                       $oDataSet->page_link = Linker::link( $oTitle, 
$oTitle->getSubpageText() );
+                       $oDataSet->leaf = true;
+                       $oDataSet->expanded = true;
+                       $oDataSet->loaded = true;
+
+                       if( $oTitle->hasSubpages() ) {
+                               $oDataSet->leaf = false;
+                               $oDataSet->expanded = false;
+                               $oDataSet->loaded = false;
+                       }
+
+                       $aResult[] = $oDataSet;
+               }
+
+               /*if( $aParams['node'] && $aParams['node'] !== 'root' ) {
+                       $oTree = $this->findNodeByPath( $oTree, explode( '.', 
$aParams['node'] ) );
+               }
+               $aResult = array();
+               if( isset($oTree->children ) ) {
+                       foreach( $oTree->children as $oChild ) {
+                               if( !empty( $oChild->children ) ) {
+                                       $oChild->leaf = false;
+                                       $oChild->expanded = false;
+                                       $oChild->loaded = false;
+                               }
+                               else {
+                                       $oChild->leaf = true;
+                               }
+                               unset( $oChild->children );
+                               $aResult[] = $oChild;
+                       }
+               }*/
+
+               return $aResult;
+
+       }
+
+       public function sortData($aProcessedData) {
+               return $aProcessedData; //Otherwise there is a strange default 
sorting
+               //TODO: Implement reasonable sorting for tree
+       }
+
+       public function getAllowedParams() {
+               return parent::getAllowedParams() + array(
+                       'node' => array(
+                               ApiBase::PARAM_TYPE => 'string'
+                       )
+               );
+       }
+}
\ No newline at end of file

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

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

Reply via email to