Harej has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/336195 )

Change subject: Namespace selector for CreateCollaborationHub
......................................................................

Namespace selector for CreateCollaborationHub

Page is created in the namespace selected from the dropdown. I gutted the 
validation callback because I couldn't figure out how to get it to work with 
two pieces of input, so I just do title validation at a later stage.

The final product should *not* look like this. I know Isarra is working on the 
styling so I am deferring to her.

Bug: T155859
Change-Id: Ided3791360ebb127d96c380be015090e449a2115
---
M i18n/en.json
M i18n/qqq.json
M includes/SpecialCreateCollaborationHub.php
3 files changed, 33 insertions(+), 43 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CollaborationKit 
refs/changes/95/336195/1

diff --git a/i18n/en.json b/i18n/en.json
index c977116..1165642 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -9,7 +9,8 @@
        "collaborationkit-desc": "Tools for building WikiProjects and on-wiki 
collaborative workspaces",
        "createcollaborationhub": "Create new Collaboration Hub",
        "createhubfeature": "Create a new Collaboration Hub feature",
-       "collaborationkit-createhub-title": "Page title",
+       "collaborationkit-createhub-namespace": "Namespace",
+       "collaborationkit-createhub-title": "Hub name",
        "collaborationkit-createhub-invalidtitle": "The specified title is 
invalid.",
        "collaborationkit-createhub-exists": "A page already exists with the 
specified title.",
        "collaborationkit-createhub-nopermission": "You do not have permission 
to create a Collaboration Hub with this title",
@@ -118,7 +119,7 @@
        "collaborationkit-createhub-wrongnamespace": "This page name cannot be 
used as a Collaboration Hub. Collaboration Hubs can only be created in the 
{{PLURAL:$1|$2 namespace|following namespaces: $2}}.",
        "createcollaborationhub-text": "You are creating a new Collaboration 
Hub, a workspace for organizing a project. Once this page is created, you will 
be able to add features and make other edits.",
        "collaborationkit-createhub-title-help": "Where to create the 
Collaboration Hub",
-       "collaborationkit-createhub-title-placeholder": "Project:...",
+       "collaborationkit-createhub-title-placeholder": "My New Project",
        "collaborationkit-hubedit-displayname-help": "Used to refer to the 
project on other pages. Only needed if different from the page title.",
        "collaborationkit-hubedit-image-help": "An image or icon to represent 
the project",
        "collaborationkit-hubedit-introduction-placeholder": "Introduce your 
project here! Tell us what you want to do.",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 4a77816..4adf7ea 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -12,7 +12,8 @@
        "collaborationkit-desc": 
"{{desc|name=CollaborationKit|url=https://www.mediawiki.org/wiki/Extension:CollaborationKit}}";,
        "createcollaborationhub": "Header for Special:CreateCollaborationHub",
        "createhubfeature": "Header for Special:CreateHubFeature. Hubs are the 
WikiProject pages as a whole, and \"features\" are the sections inside them.",
-       "collaborationkit-createhub-title": "Label for target page title input 
on Special:CreateCollaborationHub\n{{Identical|Page title}}",
+       "collaborationkit-createhub-namespace": "Label for namespace of page 
title input on Special:CreateCollaborationHub",
+       "collaborationkit-createhub-title": "Label for target page title input 
(without namespace) on Special:CreateCollaborationHub",
        "collaborationkit-createhub-invalidtitle": "Error message for an 
invalid title",
        "collaborationkit-createhub-exists": "Error message for attempting to 
create a page that already exists",
        "collaborationkit-createhub-nopermission": "Error message for no 
permission to edit/create/whatever",
diff --git a/includes/SpecialCreateCollaborationHub.php 
b/includes/SpecialCreateCollaborationHub.php
index 4401229..aafb639 100644
--- a/includes/SpecialCreateCollaborationHub.php
+++ b/includes/SpecialCreateCollaborationHub.php
@@ -34,14 +34,28 @@
         * @return array
         */
        protected function getFormFields() {
+               $allowedNamespaces = $this->getConfig()->get( 
'CollaborationListAllowedNamespaces' );
+               $namespaceNames = $this->getLanguage()->getNamespaces();
+               $namespaceChoices = [];
+               foreach ( $allowedNamespaces as $nsIndex => $nsCanBeUsed ) {
+                       $namespaceChoices[ $namespaceNames[ $nsIndex ] ] = 
$nsIndex;
+               }
 
                $fields = [
                        // autofilled from how they got here, hopefully
+
+                       'namespace' => [
+                               'type' => 'select',
+                               'options' => $namespaceChoices,
+                               'cssclass' => 'mw-ck-namespace-input',
+                               'label-message' => 
'collaborationkit-createhub-namespace',
+                               'help-message' => 
'collaborationkit-createhub-namespace-help',
+                               'required' => true
+                       ],
                        'title' => [
                                'type' => 'text',
                                'cssclass' => 'mw-ck-title-input',
                                'label-message' => 
'collaborationkit-createhub-title',
-                               'validation-callback' => [ $this, 
'titleValidate' ],
                                'help-message' => 
'collaborationkit-createhub-title-help',
                                'placeholder-message' => 
'collaborationkit-createhub-title-placeholder',
                                'required' => true
@@ -61,6 +75,12 @@
                                'help-message' => 
'collaborationkit-hubedit-image-help'
                        ],
                ];
+
+               // Our preference is the Project namespace
+               if ( in_array( 4, $allowedNamespaces ) ) {
+                       $fields[ 'namespace' ][ 'default' ] = 4;
+               }
+
                // Colours for the hub styles
                $colours = [];
                foreach ( CollaborationHubContent::getThemeColours() as $colour 
) {
@@ -107,40 +127,7 @@
        }
 
        /**
-        * Callback to validate given title
-        *
-        * @param $value string The title value to test
-        * @return bool|string|Message True on success, or Message for error
-        */
-       public function titleValidate( $value ) {
-               $title = Title::newFromText( $value );
-               if ( !$title ) {
-                       return $this->msg( 
'collaborationkit-createhub-invalidtitle' );
-               }
-
-               // TODO: Add an option to import it to itself as target if the
-               // page already exists, archiving the existing page to a 
subpage (T136475)
-               if ( $title->exists() ) {
-                       return $this->msg( 'collaborationkit-createhub-exists' 
);
-               }
-
-               $handler = new CollaborationHubContentHandler();
-               if ( !$handler->canBeUsedOn( $title ) ) {
-                       // Most likely a namespace issue.
-                       $lang = $this->getLanguage();
-                       $allowedNSConfig = $this->getConfig()->get( 
'CollaborationListAllowedNamespaces' );
-                       $allowedNS = array_keys( array_filter( $allowedNSConfig 
) );
-                       $textNS = array_map( [ $lang, 'getFormattedNsText' ], 
$allowedNS );
-                       return $this->msg( 
'collaborationkit-createhub-wrongnamespace' )
-                               ->numParams( count( $textNS ) )
-                               ->params( $lang->commaList( $textNS ) );
-               }
-
-               return true;
-       }
-
-       /**
-        * Build and return the aossociative array for the content source field.
+        * Build and return the associative array for the content source field.
         * @param $mapping array
         * @return array
         */
@@ -157,9 +144,10 @@
         * @return Status
         */
        public function onSubmit( array $data ) {
-               $title = Title::newFromText( $data['title'] );
+               $namespaces = $this->getLanguage()->getNamespaces();
+               $pagename = $namespaces[ $data[ 'namespace' ] ] . ':' . 
$data['title'];
+               $title = Title::newFromText( $pagename );
                if ( !$title ) {
-                       // Should already be checked, but make extra sure.
                        return Status::newFatal( 
'collaborationkit-createhub-invalidtitle' );
                }
 
@@ -202,12 +190,12 @@
                }
                */
 
-               $title = Title::newFromText( $data['title'] );
+               $title = Title::newFromText( $pagename );
                if ( !$title ) {
                        return Status::newFatal( 
'collaborationkit-createhub-invalidtitle' );
                }
 
-               $memberListTitle = Title::newFromText( $data['title'] . '/' . 
$this->msg( 'collaborationkit-hub-pagetitle-members' ) );
+               $memberListTitle = Title::newFromText( $pagename . '/' . 
$this->msg( 'collaborationkit-hub-pagetitle-members' ) );
                if ( !$memberListTitle ) {
                        return Status::newFatal( 
'collaborationkit-createhub-invalidtitle' );
                }
@@ -221,7 +209,7 @@
                        return $memberResult;
                }
 
-               $announcementsTitle = Title::newFromText( $data['title'] . '/' 
. $this->msg( 'collaborationkit-hub-pagetitle-announcements' 
)->inContentLanguage()->plain() );
+               $announcementsTitle = Title::newFromText( $pagename . '/' . 
$this->msg( 'collaborationkit-hub-pagetitle-announcements' 
)->inContentLanguage()->plain() );
                if ( !$announcementsTitle ) {
                        return Status::newFatal( 
'collaborationkit-createhub-invalidtitle' );
                }

-- 
To view, visit https://gerrit.wikimedia.org/r/336195
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ided3791360ebb127d96c380be015090e449a2115
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CollaborationKit
Gerrit-Branch: master
Gerrit-Owner: Harej <jamesmh...@gmail.com>

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

Reply via email to