Robert Vogel has uploaded a new change for review. https://gerrit.wikimedia.org/r/324696
Change subject: BSInsertCategory: Added integration for UploadPanel ...................................................................... BSInsertCategory: Added integration for UploadPanel Categories can now automatically be set to an upload panel Also: Fixed some bugs. NEEDS MERGE TO MASTER AND REL1_27 ATTENTION: The RL module definition is added in a seperate commit, in order to make cherry-pick to other branches easier Change-Id: I82e9366db74597fcfd1603fc72315b1722d7809f (cherry picked from commit cf110cc65b2c5fb9cd4fb18d8169c20531c4fdf8) --- M InsertCategory/InsertCategory.class.php M InsertCategory/i18n/de.json M InsertCategory/i18n/en.json M InsertCategory/i18n/qqq.json M InsertCategory/resources/bluespice.insertCategory.js A InsertCategory/resources/bluespice.insertCategory.uploadPanelIntegration.js 6 files changed, 61 insertions(+), 13 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BlueSpiceExtensions refs/changes/96/324696/1 diff --git a/InsertCategory/InsertCategory.class.php b/InsertCategory/InsertCategory.class.php index 4749112..bac49fe 100644 --- a/InsertCategory/InsertCategory.class.php +++ b/InsertCategory/InsertCategory.class.php @@ -52,6 +52,7 @@ $this->setHook( 'VisualEditorConfig' ); BsConfig::registerVar( 'MW::InsertCategory::WithParents', false, BsConfig::LEVEL_PUBLIC | BsConfig::RENDER_AS_JAVASCRIPT | BsConfig::TYPE_BOOL, 'bs-insertcategory-pref-withparents', 'toggle' ); + BsConfig::registerVar( 'MW::InsertCategory::UploadPanelIntegration', false, BsConfig::LEVEL_PUBLIC | BsConfig::RENDER_AS_JAVASCRIPT | BsConfig::TYPE_BOOL, 'bs-insertcategory-pref-uploadpanelintegration', 'toggle' ); wfProfileOut( 'BS::' . __METHOD__ ); } @@ -84,6 +85,9 @@ $out->addModuleStyles('ext.bluespice.insertcategory.styles'); $out->addModules( 'ext.bluespice.insertcategory' ); $out->addJsConfigVars( 'BSInsertCategoryWithParents', BsConfig::get( 'MW::InsertCategory::WithParents' ) ); + if( BsConfig::get( 'MW::InsertCategory::UploadPanelIntegration' ) ) { + $out->addModules( 'ext.bluespice.insertCategory.uploadPanelIntegration' ); + } return true; } diff --git a/InsertCategory/i18n/de.json b/InsertCategory/i18n/de.json index 971cf6e..3254d42 100644 --- a/InsertCategory/i18n/de.json +++ b/InsertCategory/i18n/de.json @@ -10,6 +10,7 @@ "bs-insertcategory-insertcat": "Kategorie einfügen", "prefs-insertcategory": "Kategorie einfügen", "bs-insertcategory-pref-withparents": "Kategorie mit ihren übergeordneten Kategorien einfügen", + "bs-insertcategory-pref-uploadpanelintegration": "Kategorien einer Seite im Hochladedialog voreinstellen", "bs-insertcategory-title": "Kategorie einfügen", "bs-insertcategory-cat-label": "Zugewiesen:", "bs-insertcategory-success": "Die Kategorie wurde hinzugefügt", diff --git a/InsertCategory/i18n/en.json b/InsertCategory/i18n/en.json index c3a986f..16fdadd 100644 --- a/InsertCategory/i18n/en.json +++ b/InsertCategory/i18n/en.json @@ -8,6 +8,7 @@ "bs-insertcategory-insertcat": "Insert category", "prefs-insertcategory": "Insert category", "bs-insertcategory-pref-withparents": "Insert category with its parents", + "bs-insertcategory-pref-uploadpanelintegration": "Set page categories as default in upload dialog", "bs-insertcategory-title": "Insert category", "bs-insertcategory-cat-label": "Assigned:", "bs-insertcategory-success": "The category was added", diff --git a/InsertCategory/i18n/qqq.json b/InsertCategory/i18n/qqq.json index 33d3e4d..349ec29 100644 --- a/InsertCategory/i18n/qqq.json +++ b/InsertCategory/i18n/qqq.json @@ -9,6 +9,7 @@ "bs-insertcategory-insertcat": "Used as text for the link to insert category.\n{{Identical|Insert category}}", "prefs-insertcategory": "Used in [{{canonicalurl:Special:WikiAdmin|mode=Preferences}} Special:WikiAdmin?mode=Preferences], headline for insert category section.\n{{Identical|Insert category}}", "bs-insertcategory-pref-withparents": "Option in [{{canonicalurl:Special:WikiAdmin|mode=Preferences}} Special:WikiAdmin?mode=Preferences], checkbox label for insert category with its parents", + "bs-insertcategory-pref-uploadpanelintegration": "Option in [{{canonicalurl:Special:WikiAdmin|mode=Preferences}} Special:WikiAdmin?mode=Preferences], checkbox label for integration with upload panel component", "bs-insertcategory-title": "Window title for insert category.\n{{Identical|Insert category}}", "bs-insertcategory-cat-label": "Label for the \"Assigned categories\" box.", "bs-insertcategory-success": "Text for add category successful", diff --git a/InsertCategory/resources/bluespice.insertCategory.js b/InsertCategory/resources/bluespice.insertCategory.js index 1f5da3f..8084c49 100644 --- a/InsertCategory/resources/bluespice.insertCategory.js +++ b/InsertCategory/resources/bluespice.insertCategory.js @@ -92,7 +92,7 @@ return false; }); -var BsInsertCategoryViewHelper = { +window.BsInsertCategoryViewHelper = { getCategories: function() { return mw.config.get("wgCategories"); }, @@ -141,17 +141,16 @@ } }; -var BsInsertCategoryWikiEditorHelper = { +window.BsInsertCategoryWikiEditorHelper = { getCategories: function() { var text = $('#wpTextbox1').val(); - // this doesn't work: bsInsertCategoryCategoryNamespaceName TODO:Localize - var myregexp = new RegExp('\\[\\['+ bs.util.getNamespaceText( bs.ns.NS_CATEGORY ) +':(.+?)\\]\\]', 'g'); + var myregexp = new RegExp('\\[\\[(Category|'+ bs.util.getNamespaceText( bs.ns.NS_CATEGORY ) +'):(.+?)\\]\\]', 'g'); var match; var terms = []; match = myregexp.exec(text); while( match !== null ) { - terms.push( match[1] ); + terms.push( match[2] ); match = myregexp.exec(text); } @@ -169,23 +168,20 @@ }); $('#wpTextbox1').val( text + tags ); - - //BsCore.restoreSelection(tags, 'append'); - //BsCore.restoreScrollPosition(); } }; -var BsInsertCategoryWysiwygEditorHelper = { +window.BsInsertCategoryWysiwygEditorHelper = { getCategories: function() { var text = tinyMCE.activeEditor.getContent(); // this doesn't work: bsInsertCategoryCategoryNamespaceName TODO:Localize - var myregexp = new RegExp('\\[\\['+bs.util.getNamespaceText( bs.ns.NS_CATEGORY )+':(.+?)\\]\\]', 'g'); + var myregexp = new RegExp('\\[\\[(Category|'+bs.util.getNamespaceText( bs.ns.NS_CATEGORY )+'):(.+?)\\]\\]', 'g'); var match; var terms = []; match = myregexp.exec(text); while( match !== null ) { - terms.push( match[1] ); + terms.push( match[2] ); match = myregexp.exec(text); } @@ -193,7 +189,7 @@ }, setCategories: function( categories ) { - var regexCat = new RegExp('(<br \/>)*\\[\\['+bs.util.getNamespaceText( bs.ns.NS_CATEGORY )+':..*?\\]\\]', 'ig'); ///(<br \/>)*\[\['+bs.util.getNamespaceText( bs.ns.NS_CATEGORY )+':(.+?)\]\]/ig; + var regexCat = new RegExp('(<br \/>)*\\[\\[(Category|'+bs.util.getNamespaceText( bs.ns.NS_CATEGORY )+'):..*?\\]\\]', 'ig'); ///(<br \/>)*\[\['+bs.util.getNamespaceText( bs.ns.NS_CATEGORY )+':(.+?)\]\]/ig; var tags = ''; var text = tinyMCE.activeEditor.getContent(); text = text.replace(regexCat, ""); @@ -204,4 +200,4 @@ tinyMCE.activeEditor.setContent( text + tags ); } -}; +}; \ No newline at end of file diff --git a/InsertCategory/resources/bluespice.insertCategory.uploadPanelIntegration.js b/InsertCategory/resources/bluespice.insertCategory.uploadPanelIntegration.js new file mode 100644 index 0000000..453a502 --- /dev/null +++ b/InsertCategory/resources/bluespice.insertCategory.uploadPanelIntegration.js @@ -0,0 +1,45 @@ +(function( mw, $, bs, d ){ + $(d).on( 'BSUploadPanelInitComponent', function( e, sender, panelItems, detailsItems ) { + if( !sender.bsCategories ) { + return; + } + + /** + * If the upload panel is in a window, it might be closed and reopened (e.g. in edit mode). In that case, it is not + * enough to set the categories on init time, but we have to set them every time the window with the panel opens, + * as the categories might have changed in the meantime. + */ + sender.on( 'afterrender', function() { + var window = sender.up( 'window' ); + if( !window ) { + return; + } + + window.on( 'show', function() { + sender.bsCategories.setValue( fetchCategories() ); + }, sender ); + }); + + sender.bsCategories.setValue( fetchCategories() ); + } ); + + /** + * There are three possible sources for categories of a page: + * 1. In WikiText edit mode we can grab all the explicitly set categories from '#wpTextbox1' + * 2. In BlueSpiceVisualEditor edit mode we can grab the explicitly set categories from 'tinyMCE.activeEditor' + * 3. In view mode we can get explicitly _and_ implicitly set categories by accessing 'wgCategories' variable + */ + function fetchCategories () { + var categories = mw.config.get( 'wgCategories', [] ); + var action = mw.config.get( 'wgAction' ); + if( action === 'edit' ) { + categories = BsInsertCategoryWikiEditorHelper.getCategories(); + + if( tinyMCE && tinyMCE.activeEditor ) { + categories = BsInsertCategoryWysiwygEditorHelper.getCategories(); + } + } + + return categories; + } +}( mediaWiki, jQuery, blueSpice, document )); \ No newline at end of file -- To view, visit https://gerrit.wikimedia.org/r/324696 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I82e9366db74597fcfd1603fc72315b1722d7809f Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/BlueSpiceExtensions Gerrit-Branch: REL1_27 Gerrit-Owner: Robert Vogel <vo...@hallowelt.biz> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits