ItSpiderman has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/404488 )
Change subject: Add SMW properties to BSBookmaker MassAdd options ...................................................................... Add SMW properties to BSBookmaker MassAdd options Now pages can be mass added to book in BookmakerUI based on SMW properties. Change-Id: I272ec176718377131940f5eec46e10acac0fa552 ERM: #8210 --- M extension.json M includes/BSSMWConnectorHooks.php A includes/BSSMWPropertyPageProvider.php A includes/api/ApiBookshelfSMWPropertyStore.php M resources/ext.BSSMWConnector.BookshelfUI.js 5 files changed, 137 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BlueSpiceSMWConnector refs/changes/88/404488/1 diff --git a/extension.json b/extension.json index 1bfcdc1..5e2abbb 100644 --- a/extension.json +++ b/extension.json @@ -17,7 +17,12 @@ "BSPropertyRegistry": "includes/BSPropertyRegistry.php", "BSDefinitionReader": "includes/BSDefinitionReader.php", "BSExtraPropertyAnnotator": "includes/BSExtraPropertyAnnotator.php", - "BSSMWCPageTemplates": "includes/BSSMWCPageTemplates.php" + "BSSMWCPageTemplates": "includes/BSSMWCPageTemplates.php", + "BSSMWPropertyPageProvider": "includes/BSSMWPropertyPageProvider.php", + "ApiBookshelfSMWPropertyStore": "includes/api/ApiBookshelfSMWPropertyStore.php" + }, + "APIModules": { + "bs-bookshelf-smw-property-store": "ApiBookshelfSMWPropertyStore" }, "MessagesDirs": { "BSSMWConnectorHooks": "i18n" @@ -48,6 +53,10 @@ "ext.BSSMWConnector.BookshelfUI": { "scripts": [ "ext.BSSMWConnector.BookshelfUI.js" + ], + "dependencies": [ + "ext.bluespice", + "ext.bluespice.extjs" ] }, "ext.BSSMWConnector": { @@ -86,6 +95,9 @@ ] } }, + "ExtensionFunctions": [ + "BSSMWPropertyPageProvider::register" + ], "load_composer_autoloader": true, "manifest_version": 1 } diff --git a/includes/BSSMWConnectorHooks.php b/includes/BSSMWConnectorHooks.php index 7a72174..c28b7fe 100644 --- a/includes/BSSMWConnectorHooks.php +++ b/includes/BSSMWConnectorHooks.php @@ -12,6 +12,10 @@ public static function onBeforePageDisplay( $out, $skin ) { $out->addModuleStyles( 'ext.BSSMWConnector.styles' ); + if( $out->getTitle()->isSpecial( 'BookshelfBookUI' ) ) { + $out->addModules( 'ext.BSSMWConnector.BookshelfUI' ); + } + if( !$out->getTitle()->isSpecial( 'FormEdit') && $out->getRequest()->getVal('action', 'view') !== 'formedit' ) { return true; } diff --git a/includes/BSSMWPropertyPageProvider.php b/includes/BSSMWPropertyPageProvider.php new file mode 100644 index 0000000..32f2edf --- /dev/null +++ b/includes/BSSMWPropertyPageProvider.php @@ -0,0 +1,37 @@ +<?php + +class BSSMWPropertyPageProvider { + public static function register() { + if( class_exists ( "MassAddPageProvider" ) ) { + $massAddPageProvider = MassAddPageProvider::getInstance(); + $massAddPageProvider->registerHandler( 'smwproperty', 'BSSMWPropertyPageProvider::getPages' ); + } + } + + public static function getPages( $root ) { + $root = (int) $root; + $dbr = wfGetDB( DB_SLAVE ); + $res = $dbr->select( + array( 'smw_object_ids', 'smw_di_wikipage' ), + array( 'smw_title', 'smw_namespace' ), + array( "smw_id = s_id AND p_id = $root" ) + ); + + $pagesRes = []; + foreach( $res as $row ) { + $title = Title::newFromText( $row->smw_title, $row->smw_namespace ); + if( !( $title instanceof Title ) || !$title->exists() ) { + continue; + } + $pagesRes[] = array( + 'page_id' => $title->getArticleId(), + 'page_title' => $title->getText(), + 'page_namespace' => $title->getNamespace(), + 'prefixed_text' => $title->getPrefixedText() + ); + } + + return $pagesRes; + } +} + diff --git a/includes/api/ApiBookshelfSMWPropertyStore.php b/includes/api/ApiBookshelfSMWPropertyStore.php new file mode 100644 index 0000000..62fa39e --- /dev/null +++ b/includes/api/ApiBookshelfSMWPropertyStore.php @@ -0,0 +1,36 @@ +<?php + +class ApiBookshelfSMWPropertyStore extends BSApiExtJSStoreBase { + + protected function makeData( $query = '' ) { + $result = new stdClass(); + + $properties = array(); + $dbr = wfGetDB( DB_SLAVE ); + + $dummyTitle = Title::newFromText( "Property:Dummy" ); + if( !( $dummyTitle instanceof Title ) ) { + return []; + } + $namespace = $dummyTitle->getNamespace(); + + $res = $dbr->select( + array( 'smw_object_ids' ), + array( 'smw_title', 'smw_id' ), + array( "smw_namespace = $namespace AND smw_title LIKE '%$query%'" ) + ); + + foreach ( $res as $row ) { + $propertyData = new stdClass(); + + $propertyData->prop_id = (int)$row->smw_id; + $propertyData->prop_title = $row->smw_title; + + $properties[ $row->smw_title ] = $propertyData; + } + ksort( $properties ); + $properties = array_values( $properties ); + + return $properties; + } +} \ No newline at end of file diff --git a/resources/ext.BSSMWConnector.BookshelfUI.js b/resources/ext.BSSMWConnector.BookshelfUI.js index e69de29..2a85b15 100644 --- a/resources/ext.BSSMWConnector.BookshelfUI.js +++ b/resources/ext.BSSMWConnector.BookshelfUI.js @@ -0,0 +1,47 @@ +( function( mw, jQuery, BS ) { + mw.hook( 'ext.bookshelfui.addmass.create' ).add( function( item ){ + Ext.define( 'SMWProperty', { + extend: 'Ext.data.Model', + fields: [ + { name: 'prop_id', type: 'int' }, + { name: 'prop_title', type: 'string' } + ] + } ); + var store = Ext.create( 'Ext.data.Store', { + proxy: { + type: 'ajax', + url: mw.util.wikiScript('api'), + extraParams: { + format: 'json', + action: 'bs-bookshelf-smw-property-store' + }, + reader: { + type: 'json', + root: 'results', + idProperty: 'id', + totalProperty: 'total' + } + }, + autoLoad: true, + remoteSort: true, + sortInfo: { + field: 'id', + direction: 'ASC' + }, + model: 'SMWProperty' + }); + + var cbSMWProperty = Ext.create( 'Ext.form.field.ComboBox', { + displayField: 'prop_title', + valueField: 'prop_id', + allowBlank: false, + forceSelection: true, + store: store, + hidden: true, + fieldLabel: mw.message('bs-bookshelfui-dlg-choosesmwprop-label').plain(), + labelAlign: 'right', + }); + + item.registerItem( 'smwproperty', 'bs-bookshelfui-type-smwprop', cbSMWProperty ); + }); +})( mediaWiki, jQuery, blueSpice ); \ No newline at end of file -- To view, visit https://gerrit.wikimedia.org/r/404488 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I272ec176718377131940f5eec46e10acac0fa552 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/BlueSpiceSMWConnector Gerrit-Branch: master Gerrit-Owner: ItSpiderman <d.savulje...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits