jenkins-bot has submitted this change and it was merged.

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
---
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(-)

Approvals:
  Robert Vogel: Looks good to me, approved
  Pwirth: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/InsertCategory/InsertCategory.class.php 
b/InsertCategory/InsertCategory.class.php
index 19f067a..2ea5edc 100644
--- a/InsertCategory/InsertCategory.class.php
+++ b/InsertCategory/InsertCategory.class.php
@@ -74,6 +74,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__ );
        }
@@ -106,6 +107,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 caaeef5..ebfd71f 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");
        },
@@ -149,17 +149,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);
                }
 
@@ -177,23 +176,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);
                }
 
@@ -201,7 +197,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, "");
@@ -212,4 +208,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/323123
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I82e9366db74597fcfd1603fc72315b1722d7809f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BlueSpiceExtensions
Gerrit-Branch: REL1_23
Gerrit-Owner: Robert Vogel <vo...@hallowelt.biz>
Gerrit-Reviewer: Dvogel hallowelt <daniel.vo...@hallowelt.com>
Gerrit-Reviewer: Ljonka <l.verhovs...@gmail.com>
Gerrit-Reviewer: Mglaser <gla...@hallowelt.biz>
Gerrit-Reviewer: Pwirth <wi...@hallowelt.biz>
Gerrit-Reviewer: Robert Vogel <vo...@hallowelt.biz>
Gerrit-Reviewer: Siebrand <siebr...@kitano.nl>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to