Tweichart has uploaded a new change for review.
https://gerrit.wikimedia.org/r/232901
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
Change-Id: I5c0d001d786d14a148d62655755844724864c071
---
M InsertCategory/InsertCategory.class.php
M InsertCategory/resources/BS.InsertCategory/Dialog.js
M InsertCategory/resources/bluespice.insertCategory.js
3 files changed, 68 insertions(+), 28 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BlueSpiceExtensions
refs/changes/01/232901/1
diff --git a/InsertCategory/InsertCategory.class.php
b/InsertCategory/InsertCategory.class.php
index 8c9a1c5..a5c11ef 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( 'insertCategoryWithParents',
BsConfig::get( 'MW::InsertCategory::WithParents' ) );
return true;
}
@@ -141,25 +142,34 @@
: 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();
+ $iNamespaceId = $oRequest->getVal( "page_ns", 0 );
+ $sPageName = $oRequest->getVal( "page_name", "" );
+ $oTitle = Title::newFromText( $sPageName, $iNamespaceId
);
+ }
+ $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..d2cf950 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( 'insertCategoryWithParents' ) ) {
+ 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;
@@ -70,6 +82,12 @@
});
sender.setValue( valuesToSet.join(','), true );
},
+ onBtnOKClick: function () {
+ if ( mw.config.get( "wgAction" ) !== "edit" ) {
+ BS.InsertCategory.Dialog.setLoading( true );
+ }
+ this.fireEvent( 'ok', this, this.getData() );
+ },
setData: function( data ) {
this.bsCategories.setValue( data );
},
diff --git a/InsertCategory/resources/bluespice.insertCategory.js
b/InsertCategory/resources/bluespice.insertCategory.js
index 1b79d52..821c54c 100644
--- a/InsertCategory/resources/bluespice.insertCategory.js
+++ b/InsertCategory/resources/bluespice.insertCategory.js
@@ -33,8 +33,10 @@
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.close();
});
BS.InsertCategory.Dialog.setData(
BsInsertCategoryWysiwygEditorHelper.getCategories()
@@ -53,10 +55,11 @@
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 );
+ }
+ } );
BS.InsertCategory.Dialog.setData(
BsInsertCategoryViewHelper.getCategories()
);
@@ -72,8 +75,10 @@
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.close();
});
BS.InsertCategory.Dialog.setData(
BsInsertCategoryWikiEditorHelper.getCategories()
@@ -96,18 +101,25 @@
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( "wgTitle" ),
+ page_ns: mw.config.get( "wgNamespaceNumber" ),
categories: categories.join(',')
}
});
+ },
+ onSetCategoriesOk: function () {
+ BS.InsertCategory.Dialog.setLoading( false );
+ 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: newchange
Gerrit-Change-Id: I5c0d001d786d14a148d62655755844724864c071
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BlueSpiceExtensions
Gerrit-Branch: master
Gerrit-Owner: Tweichart <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits