[MediaWiki-commits] [Gerrit] mediawiki...CollaborationKit[master]: Move title validation for Special:CreateCollaborationHub to ...
Brian Wolff has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/332114 ) Change subject: Move title validation for Special:CreateCollaborationHub to that field .. Move title validation for Special:CreateCollaborationHub to that field This will make the error be output directly on the field in question. Additionally, add validation checks for wrong namespace. Change-Id: I1e35786a982905bb8a43292368dab7e42c61c100 --- M i18n/en.json M i18n/qqq.json M includes/SpecialCreateCollaborationHub.php 3 files changed, 51 insertions(+), 9 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CollaborationKit refs/changes/14/332114/1 diff --git a/i18n/en.json b/i18n/en.json index 311394b..5517edd 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -120,5 +120,6 @@ "collaborationkit-green3": "Khaki", "collaborationkit-black": "Black", "collaborationkit-column-active": "Active members", - "collaborationkit-column-inactive": "Inactive members" + "collaborationkit-column-inactive": "Inactive members", + "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}}" } diff --git a/i18n/qqq.json b/i18n/qqq.json index 4a9d86c..10011f9 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -120,5 +120,6 @@ "collaborationkit-green3": "Color label", "collaborationkit-black": "Color label", "collaborationkit-column-active": "Column header for the list of active members of a collaboration hub project", - "collaborationkit-column-inactive": "Column header for the list of members of a project who are no longer active on wiki." + "collaborationkit-column-inactive": "Column header for the list of members of a project who are no longer active on wiki.", + "collaborationkit-createhub-wrongnamespace": "Error message from Special:CreateCollaborationHub if the title specified is not allowed to be used with the CollaborationHubContent content model. Normally this means that the title is in the wrong namespace. $1 - Number of namespaces that CollaborationHub is allowed on. $2 - Comma separated list of namespace names that are allowed to be used." } diff --git a/includes/SpecialCreateCollaborationHub.php b/includes/SpecialCreateCollaborationHub.php index fd101ef..9633186 100644 --- a/includes/SpecialCreateCollaborationHub.php +++ b/includes/SpecialCreateCollaborationHub.php @@ -37,6 +37,8 @@ 'type' => 'text', 'cssclass' => 'mw-ck-title-input', 'label-message' => 'collaborationkit-createhub-title', + 'validation-callback' => [ $this, 'titleValidate' ], + 'required' => true ], // Display name can be different from page title 'display_name' => [ @@ -97,6 +99,40 @@ } /** +* 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. + $allowedNSConfig = $this->getConfig()->get( 'CollaborationListAllowedNamespaces' ); + $allowedNS = array_keys( array_filter( $allowedNSConfig ) ); + $lang = $this->getLanguage(); + $textNS = array_map( [ $lang, 'getFormattedNsText' ], $allowedNS ); +var_dump( $textNS, $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. * @param $mapping array * @return array @@ -116,14 +152,18 @@ public function onSubmit( array $data
[MediaWiki-commits] [Gerrit] mediawiki...CollaborationKit[master]: Move title validation for Special:CreateCollaborationHub to ...
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/332114 ) Change subject: Move title validation for Special:CreateCollaborationHub to that field .. Move title validation for Special:CreateCollaborationHub to that field This will make the error be output directly on the field in question. Additionally, add validation checks for wrong namespace. Change-Id: I1e35786a982905bb8a43292368dab7e42c61c100 --- M i18n/en.json M i18n/qqq.json M includes/SpecialCreateCollaborationHub.php 3 files changed, 50 insertions(+), 9 deletions(-) Approvals: Brian Wolff: Looks good to me, approved jenkins-bot: Verified diff --git a/i18n/en.json b/i18n/en.json index 311394b..dba6474 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -120,5 +120,6 @@ "collaborationkit-green3": "Khaki", "collaborationkit-black": "Black", "collaborationkit-column-active": "Active members", - "collaborationkit-column-inactive": "Inactive members" + "collaborationkit-column-inactive": "Inactive members", + "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}}." } diff --git a/i18n/qqq.json b/i18n/qqq.json index 4a9d86c..10011f9 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -120,5 +120,6 @@ "collaborationkit-green3": "Color label", "collaborationkit-black": "Color label", "collaborationkit-column-active": "Column header for the list of active members of a collaboration hub project", - "collaborationkit-column-inactive": "Column header for the list of members of a project who are no longer active on wiki." + "collaborationkit-column-inactive": "Column header for the list of members of a project who are no longer active on wiki.", + "collaborationkit-createhub-wrongnamespace": "Error message from Special:CreateCollaborationHub if the title specified is not allowed to be used with the CollaborationHubContent content model. Normally this means that the title is in the wrong namespace. $1 - Number of namespaces that CollaborationHub is allowed on. $2 - Comma separated list of namespace names that are allowed to be used." } diff --git a/includes/SpecialCreateCollaborationHub.php b/includes/SpecialCreateCollaborationHub.php index fd101ef..612acd1 100644 --- a/includes/SpecialCreateCollaborationHub.php +++ b/includes/SpecialCreateCollaborationHub.php @@ -37,6 +37,8 @@ 'type' => 'text', 'cssclass' => 'mw-ck-title-input', 'label-message' => 'collaborationkit-createhub-title', + 'validation-callback' => [ $this, 'titleValidate' ], + 'required' => true ], // Display name can be different from page title 'display_name' => [ @@ -97,6 +99,39 @@ } /** +* 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. * @param $mapping array * @return array @@ -116,14 +151,18 @@ public function onSubmit( array $data ) { $title = Title::newFromText( $data['tit