Anomie has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/197314

Change subject: Factor out changetag name validation check
......................................................................

Factor out changetag name validation check

This way it can be called by AbuseFilter without also getting caught in
the "already exists" checks. And possibly it could also be used in the
future to validate input passed to ChangeTags::addTags()

Bug: T92956
Change-Id: Ic5d754323cbfd2c2b54c4df1245767946ebb1821
---
M includes/ChangeTags.php
1 file changed, 24 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/14/197314/1

diff --git a/includes/ChangeTags.php b/includes/ChangeTags.php
index d597d6d..10f89fd 100644
--- a/includes/ChangeTags.php
+++ b/includes/ChangeTags.php
@@ -492,19 +492,13 @@
        }
 
        /**
-        * Is it OK to allow the user to create this tag?
+        * Is the tag name valid?
         *
         * @param string $tag Tag that you are interested in creating
-        * @param User|null $user User whose permission you wish to check, or 
null if
-        * you don't care (e.g. maintenance scripts)
         * @return Status
         * @since 1.25
         */
-       public static function canCreateTag( $tag, User $user = null ) {
-               if ( !is_null( $user ) && !$user->isAllowed( 'managechangetags' 
) ) {
-                       return Status::newFatal( 'tags-manage-no-permission' );
-               }
-
+       public static function isTagNameValid( $tag ) {
                // no empty tags
                if ( $tag === '' ) {
                        return Status::newFatal( 'tags-create-no-name' );
@@ -522,6 +516,28 @@
                        return Status::newFatal( 
'tags-create-invalid-title-chars' );
                }
 
+               return Status::newGood();
+       }
+
+       /**
+        * Is it OK to allow the user to create this tag?
+        *
+        * @param string $tag Tag that you are interested in creating
+        * @param User|null $user User whose permission you wish to check, or 
null if
+        * you don't care (e.g. maintenance scripts)
+        * @return Status
+        * @since 1.25
+        */
+       public static function canCreateTag( $tag, User $user = null ) {
+               if ( !is_null( $user ) && !$user->isAllowed( 'managechangetags' 
) ) {
+                       return Status::newFatal( 'tags-manage-no-permission' );
+               }
+
+               $status = self::isTagNameValid( $tag );
+               if ( !$status->isGood() ) {
+                       return $status;
+               }
+
                // does the tag already exist?
                $tagUsage = self::tagUsageStatistics();
                if ( isset( $tagUsage[$tag] ) ) {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic5d754323cbfd2c2b54c4df1245767946ebb1821
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Anomie <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to