jenkins-bot has submitted this change and it was merged. Change subject: small improvements + settings fix ......................................................................
small improvements + settings fix * categories can now be added in view mode even if the page is not created yet * categoryselect window now stays open untill the request is finished * failure messages will be displayed by now * setting for adding parents re-implemented (window loading moved to foundation, see https://gerrit.wikimedia.org/r/233675) Change-Id: I5c0d001d786d14a148d62655755844724864c071 --- M InsertCategory/InsertCategory.class.php M InsertCategory/resources/BS.InsertCategory/Dialog.js M InsertCategory/resources/bluespice.insertCategory.js 3 files changed, 59 insertions(+), 29 deletions(-) Approvals: Robert Vogel: Looks good to me, approved jenkins-bot: Verified diff --git a/InsertCategory/InsertCategory.class.php b/InsertCategory/InsertCategory.class.php index 8c9a1c5..8f8a0f4 100644 --- a/InsertCategory/InsertCategory.class.php +++ b/InsertCategory/InsertCategory.class.php @@ -104,7 +104,8 @@ */ public static function onBeforePageDisplay( &$out, &$skin ) { $out->addModuleStyles('ext.bluespice.insertcategory.styles'); - $out->addModules('ext.bluespice.insertcategory'); + $out->addModules( 'ext.bluespice.insertcategory' ); + $out->addJsConfigVars( 'BSInsertCategoryWithParents', BsConfig::get( 'MW::InsertCategory::WithParents' ) ); return true; } @@ -141,25 +142,33 @@ : explode( ',', $sTags ); $oTitle = Title::newFromID( $iArticleId ); - if ( $oTitle->exists() ) { - $sCat = BsNamespaceHelper::getNamespaceName( NS_CATEGORY ); - $sText = BsPageContentProvider::getInstance()->getContentFromTitle( $oTitle, Revision::RAW ); + if ( is_null( $oTitle ) || !$oTitle->exists() ) { + $oRequest = RequestContext::getMain()->getRequest(); + $sPageName = $oRequest->getVal( "page_name", "" ); + $oTitle = Title::newFromText( $sPageName ); + } + $sCat = BsNamespaceHelper::getNamespaceName( NS_CATEGORY ); + $sText = BsPageContentProvider::getInstance()->getContentFromTitle( $oTitle, Revision::RAW ); - // Remove all before adding - $sPattern = '#^\[\['.$sCat.':.*?\]\]#im'; - $sText = preg_replace( $sPattern, '', $sText ); + // Remove all before adding + $sPattern = '#^\[\[' . $sCat . ':.*?\]\]#im'; + $sText = preg_replace( $sPattern, '', $sText ); - if ( !empty( $aTags ) ) { - foreach ( $aTags as $sTag ) { - $sText .= "\n[[".$sCat.":$sTag]]"; - } + if ( !empty( $aTags ) ) { + foreach ( $aTags as $sTag ) { + $sText .= "\n[[" . $sCat . ":$sTag]]"; } - - $oArticle = new Article( $oTitle ); - $oArticle->doEdit( $sText, '', EDIT_UPDATE | EDIT_MINOR ); } - return FormatJson::encode( array( 'success' => true ) ); + $oWikiPage = new WikiPage( $oTitle ); + $oUser = RequestContext::getMain()->getUser(); + $oContent = new WikitextContent( $sText ); + $oStatus = $oWikiPage->doEditContent( $oContent, "", 0, false, $oUser ); + if ( !$oStatus->isGood() ) { + return FormatJson::encode( array ( 'success' => false, 'msg' => $oStatus->getMessage() ) ); + } + + return FormatJson::encode( array ( 'success' => true ) ); } /** diff --git a/InsertCategory/resources/BS.InsertCategory/Dialog.js b/InsertCategory/resources/BS.InsertCategory/Dialog.js index 7d2f86b..9475322 100644 --- a/InsertCategory/resources/BS.InsertCategory/Dialog.js +++ b/InsertCategory/resources/BS.InsertCategory/Dialog.js @@ -56,7 +56,19 @@ }, onItemClick: function( tree, record, item, index, e, eOpts ) { this.isDirty = true; - this.bsCategories.addValue( [record.data.text] ); + if ( mw.config.get( 'BSInsertCategoryWithParents' ) ) { + this.addValuesFromRecord( record ); + } + else { + this.bsCategories.addValue( [ record.data.text ] ); + } + }, + addValuesFromRecord: function ( record ) { + //parentNode is null if there is no parent, internalId "src" is the root of the categories + if ( typeof ( record.parentNode ) !== "null" && record.parentNode.internalId !== "src" ) { + this.addValuesFromRecord( record.parentNode ); + } + this.bsCategories.addValue( [ record.data.text ] ); }, onSelect: function( sender, records) { this.isDirty = true; diff --git a/InsertCategory/resources/bluespice.insertCategory.js b/InsertCategory/resources/bluespice.insertCategory.js index 1b79d52..bf12770 100644 --- a/InsertCategory/resources/bluespice.insertCategory.js +++ b/InsertCategory/resources/bluespice.insertCategory.js @@ -33,8 +33,9 @@ Ext.require('BS.InsertCategory.Dialog', function(){ BS.InsertCategory.Dialog.clearListeners(); BS.InsertCategory.Dialog.on('ok', function(sender, data){ - if( BS.InsertCategory.Dialog.isDirty ) - BsInsertCategoryWysiwygEditorHelper.setCategories( data ); + if ( BS.InsertCategory.Dialog.isDirty ) { + BsInsertCategoryWysiwygEditorHelper.setCategories( data ); + } }); BS.InsertCategory.Dialog.setData( BsInsertCategoryWysiwygEditorHelper.getCategories() @@ -53,10 +54,12 @@ var me = this; Ext.require('BS.InsertCategory.Dialog', function(){ BS.InsertCategory.Dialog.clearListeners(); - BS.InsertCategory.Dialog.on('ok', function(sender, data){ - if( BS.InsertCategory.Dialog.isDirty ) - BsInsertCategoryViewHelper.setCategories( data ); - }); + BS.InsertCategory.Dialog.on( 'ok', function ( sender, data ) { + if ( BS.InsertCategory.Dialog.isDirty ) { + BsInsertCategoryViewHelper.setCategories( data ); + return false; + } + } ); BS.InsertCategory.Dialog.setData( BsInsertCategoryViewHelper.getCategories() ); @@ -72,8 +75,9 @@ Ext.require('BS.InsertCategory.Dialog', function(){ BS.InsertCategory.Dialog.clearListeners(); BS.InsertCategory.Dialog.on('ok', function(sender, data){ - if( BS.InsertCategory.Dialog.isDirty ) - BsInsertCategoryWikiEditorHelper.setCategories( data ); + if ( BS.InsertCategory.Dialog.isDirty ) { + BsInsertCategoryWikiEditorHelper.setCategories( data ); + } }); BS.InsertCategory.Dialog.setData( BsInsertCategoryWikiEditorHelper.getCategories() @@ -92,22 +96,27 @@ setCategories: function( categories ) { Ext.Ajax.request({ - url: bs.util.getAjaxDispatcherUrl( 'InsertCategory::addCategoriesToArticle', [ wgArticleId ] ), + url: bs.util.getAjaxDispatcherUrl( 'InsertCategory::addCategoriesToArticle', [ mw.config.get( "wgArticleId" ) ] ), success: function( response, opts ) { var obj = Ext.decode(response.responseText); if ( obj.success ) { - bs.util.alert( 'ICsuc', { textMsg: 'bs-insertcategory-success', titleMsg: 'bs-extjs-title-success' } ); - window.location.reload( true ); + bs.util.alert( 'ICsuc', { textMsg: 'bs-insertcategory-success', titleMsg: 'bs-extjs-title-success' }, { ok: BsInsertCategoryViewHelper.onSetCategoriesOk } ); } else { - bs.util.alert( 'ICsuc', { textMsg: 'bs-insertcategory-failure', titleMsg: 'bs-extjs-title-warning' } ); + bs.util.alert( 'ICsuc', { textMsg: obj.msg, titleMsg: 'bs-extjs-title-warning' }, { ok: BsInsertCategoryViewHelper.onSetCategoriesFailure } ); } }, failure: function() {}, params: { - page_name: wgPageName, + page_name: mw.config.get( "wgPageName" ), categories: categories.join(',') } }); + }, + onSetCategoriesOk: function () { + window.location.reload( true ); + }, + onSetCategoriesFailure: function () { + BS.InsertCategory.Dialog.setLoading( false ); } }; -- To view, visit https://gerrit.wikimedia.org/r/232901 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I5c0d001d786d14a148d62655755844724864c071 Gerrit-PatchSet: 5 Gerrit-Project: mediawiki/extensions/BlueSpiceExtensions Gerrit-Branch: master Gerrit-Owner: Tweichart <[email protected]> Gerrit-Reviewer: Mglaser <[email protected]> Gerrit-Reviewer: Pwirth <[email protected]> Gerrit-Reviewer: Robert Vogel <[email protected]> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
