MediaWiki master
TagsDef.php
Go to the documentation of this file.
1<?php
2
4
11
23class TagsDef extends EnumDef {
24
25 private ChangeTagsStore $changeTagsStore;
26
27 public function __construct( Callbacks $callbacks, ChangeTagsStore $changeTagsStore ) {
28 parent::__construct( $callbacks );
29 $this->changeTagsStore = $changeTagsStore;
30 }
31
33 public function validate( $name, $value, array $settings, array $options ) {
34 $this->failIfNotString( $name, $value, $settings, $options );
35
36 // Validate the full list of tags at once, because the caller will
37 // *probably* stop at the first exception thrown.
38 if ( isset( $options['values-list'] ) ) {
39 $ret = $value;
40 $tagsStatus = ChangeTags::canAddTagsAccompanyingChange( $options['values-list'] );
41 } else {
42 // The 'tags' type always returns an array.
43 $ret = [ $value ];
44 $tagsStatus = ChangeTags::canAddTagsAccompanyingChange( $ret );
45 }
46
47 if ( !$tagsStatus->isGood() ) {
48 $msg = $tagsStatus->getMessage();
49 $data = [];
50 if ( $tagsStatus->value ) {
51 // Specific tags are not allowed.
52 $data['disallowedtags'] = $tagsStatus->value;
53 // @codeCoverageIgnoreStart
54 } else {
55 // All are disallowed, I guess
56 $data['disallowedtags'] = $settings['values-list'] ?? $ret;
57 }
58 // @codeCoverageIgnoreEnd
59
60 // Only throw if $value is among the disallowed tags
61 if ( in_array( $value, $data['disallowedtags'], true ) ) {
62 throw new ValidationException(
63 DataMessageValue::new( $msg->getKey(), $msg->getParams(), 'badtags', $data ),
64 $name, $value, $settings
65 );
66 }
67 }
68
69 return $ret;
70 }
71
73 public function getEnumValues( $name, array $settings, array $options ) {
74 return $this->changeTagsStore->listExplicitlyDefinedTags();
75 }
76
77}
Read-write access to the change_tags table.
Recent changes tagging.
Type definition for tags type.
Definition TagsDef.php:23
__construct(Callbacks $callbacks, ChangeTagsStore $changeTagsStore)
Definition TagsDef.php:27
getEnumValues( $name, array $settings, array $options)
Get the values for enum-like parameters.This is primarily intended for documentation and implementati...
Definition TagsDef.php:73
validate( $name, $value, array $settings, array $options)
Validate the value.When ParamValidator is processing a multi-valued parameter, this will be called on...
Definition TagsDef.php:33
Value object representing a message for i18n with alternative machine-readable data.
Type definition for enumeration types.
Definition EnumDef.php:32
failIfNotString(string $name, $value, array $settings, array $options)
Fails if $value is not a string.
Definition TypeDef.php:68
Interface defining callbacks needed by ParamValidator.
Definition Callbacks.php:21