MediaWiki REL1_39
TagsDef.php
Go to the documentation of this file.
1<?php
2
4
5use ChangeTags;
6use MediaWiki\Message\Converter as MessageConverter;
11
23class TagsDef extends EnumDef {
24
26 private $messageConverter;
27
28 public function __construct( Callbacks $callbacks ) {
29 parent::__construct( $callbacks );
30 $this->messageConverter = new MessageConverter();
31 }
32
33 public function validate( $name, $value, array $settings, array $options ) {
34 // Validate the full list of tags at once, because the caller will
35 // *probably* stop at the first exception thrown.
36 if ( isset( $options['values-list'] ) ) {
37 $ret = $value;
38 $tagsStatus = ChangeTags::canAddTagsAccompanyingChange( $options['values-list'] );
39 } else {
40 // The 'tags' type always returns an array.
41 $ret = [ $value ];
42 $tagsStatus = ChangeTags::canAddTagsAccompanyingChange( $ret );
43 }
44
45 if ( !$tagsStatus->isGood() ) {
46 $msg = $this->messageConverter->convertMessage( $tagsStatus->getMessage() );
47 $data = [];
48 if ( $tagsStatus->value ) {
49 // Specific tags are not allowed.
50 $data['disallowedtags'] = $tagsStatus->value;
51 // @codeCoverageIgnoreStart
52 } else {
53 // All are disallowed, I guess
54 $data['disallowedtags'] = $settings['values-list'] ?? $ret;
55 }
56 // @codeCoverageIgnoreEnd
57
58 // Only throw if $value is among the disallowed tags
59 if ( in_array( $value, $data['disallowedtags'], true ) ) {
60 throw new ValidationException(
61 DataMessageValue::new( $msg->getKey(), $msg->getParams(), 'badtags', $data ),
62 $name, $value, $settings
63 );
64 }
65 }
66
67 return $ret;
68 }
69
70 public function getEnumValues( $name, array $settings, array $options ) {
72 }
73
74}
static canAddTagsAccompanyingChange(array $tags, Authority $performer=null, $checkBlock=true)
Is it OK to allow the user to apply all the specified tags at the same time as they edit/make the cha...
static listExplicitlyDefinedTags()
Lists tags explicitly defined in the change_tag_def table of the database.
Converter between Message and MessageValue.
Definition Converter.php:18
Type definition for tags type.
Definition TagsDef.php:23
__construct(Callbacks $callbacks)
Definition TagsDef.php:28
getEnumValues( $name, array $settings, array $options)
Get the values for enum-like parameters.
Definition TagsDef.php:70
validate( $name, $value, array $settings, array $options)
Validate the value.
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
Interface defining callbacks needed by ParamValidator.
Definition Callbacks.php:21