44 private $titleFactory;
52 $this->titleFactory = $titleFactory;
59 public function validate( $name, $value, array $settings, array $options ) {
60 $mustExist = !empty( $settings[self::PARAM_MUST_EXIST] );
61 $returnObject = !empty( $settings[self::PARAM_RETURN_OBJECT] );
63 $title = $this->titleFactory->newFromText( $value );
67 $this->
failure(
'badtitle', $name, $value, $settings, $options );
68 } elseif ( $mustExist && !
$title->exists() ) {
70 $this->
failure(
'missingtitle', $name, $value, $settings, $options );
73 if ( $returnObject ) {
74 return $title->getTitleValue();
76 return $title->getPrefixedText();
81 public function stringifyValue( $name, $value, array $settings, array $options ) {
83 return $this->titleFactory->newFromLinkTarget( $value )->getPrefixedText();
85 return parent::stringifyValue( $name, $value, $settings, $options );
89 public function checkSettings(
string $name, $settings, array $options, array $ret ): array {
90 $ret = parent::
checkSettings( $name, $settings, $options, $ret );
92 $ret[
'allowedKeys'] = array_merge( $ret[
'allowedKeys'], [
93 self::PARAM_MUST_EXIST, self::PARAM_RETURN_OBJECT,
96 if ( !is_bool( $settings[self::PARAM_MUST_EXIST] ??
false ) ) {
98 . gettype( $settings[self::PARAM_MUST_EXIST] );
101 if ( !is_bool( $settings[self::PARAM_RETURN_OBJECT] ??
false ) ) {
103 . gettype( $settings[self::PARAM_RETURN_OBJECT] );
106 if ( !empty( $settings[ParamValidator::PARAM_ISMULTI] ) &&
107 !empty( $settings[self::PARAM_RETURN_OBJECT] ) &&
109 ( $settings[ParamValidator::PARAM_ISMULTI_LIMIT1] ?? 100 ) > 10 ||
110 ( $settings[ParamValidator::PARAM_ISMULTI_LIMIT2] ?? 100 ) > 10
113 $ret[
'issues'][] =
'Multi-valued title-type parameters with PARAM_RETURN_OBJECT '
114 .
'should set low values (<= 10) for PARAM_ISMULTI_LIMIT1 and PARAM_ISMULTI_LIMIT2.'
115 .
' (Note that "<= 10" is arbitrary. If something hits this, we can investigate a real limit '
116 .
'once we have a real use case to look at.)';
123 public function getParamInfo( $name, array $settings, array $options ) {
124 $info = parent::getParamInfo( $name, $settings, $options );
126 $info[
'mustExist'] = !empty( $settings[self::PARAM_MUST_EXIST] );
132 public function getHelpInfo( $name, array $settings, array $options ) {
133 $info = parent::getParamInfo( $name, $settings, $options );
135 $info[ParamValidator::PARAM_TYPE] = MessageValue::new(
'paramvalidator-help-type-title' );
137 $mustExist = !empty( $settings[self::PARAM_MUST_EXIST] );
138 $info[self::PARAM_MUST_EXIST] = $mustExist
139 ? MessageValue::new(
'paramvalidator-help-type-title-must-exist' )
140 : MessageValue::new(
'paramvalidator-help-type-title-no-must-exist' );