}
/**
- * 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
+ * @since 1.30
*/
- public static function canCreateTag( $tag, User $user = null ) {
- if ( !is_null( $user ) ) {
- if ( !$user->isAllowed( 'managechangetags' ) ) {
- return Status::newFatal( 'tags-manage-no-permission' );
- } elseif ( $user->isBlocked() ) {
- return Status::newFatal( 'tags-manage-blocked', $user->getName() );
- }
- }
-
+ public static function isTagNameValid( $tag ) {
// no empty tags
if ( $tag === '' ) {
return Status::newFatal( 'tags-create-no-name' );
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 ) ) {
+ if ( !$user->isAllowed( 'managechangetags' ) ) {
+ return Status::newFatal( 'tags-manage-no-permission' );
+ } elseif ( $user->isBlocked() ) {
+ return Status::newFatal( 'tags-manage-blocked', $user->getName() );
+ }
+ }
+
+ $status = self::isTagNameValid( $tag );
+ if ( !$status->isGood() ) {
+ return $status;
+ }
+
// does the tag already exist?
$tagUsage = self::tagUsageStatistics();
if ( isset( $tagUsage[$tag] ) || in_array( $tag, self::listDefinedTags() ) ) {