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] );
65 $title = $this->titleFactory->newFromText( $value );
69 $this->
failure(
'badtitle', $name, $value, $settings, $options );
70 } elseif ( $mustExist && !$title->exists() ) {
72 $this->
failure(
'missingtitle', $name, $value, $settings, $options );
75 if ( $returnObject ) {
76 return $title->getTitleValue();
78 return $title->getPrefixedText();
83 public function stringifyValue( $name, $value, array $settings, array $options ) {
85 return $this->titleFactory->newFromLinkTarget( $value )->getPrefixedText();
87 return parent::stringifyValue( $name, $value, $settings, $options );
91 public function checkSettings(
string $name, $settings, array $options, array $ret ): array {
92 $ret = parent::
checkSettings( $name, $settings, $options, $ret );
94 $ret[
'allowedKeys'] = array_merge( $ret[
'allowedKeys'], [
95 self::PARAM_MUST_EXIST, self::PARAM_RETURN_OBJECT,
98 if ( !is_bool( $settings[self::PARAM_MUST_EXIST] ??
false ) ) {
100 . gettype( $settings[self::PARAM_MUST_EXIST] );
103 if ( !is_bool( $settings[self::PARAM_RETURN_OBJECT] ??
false ) ) {
105 . gettype( $settings[self::PARAM_RETURN_OBJECT] );
108 if ( !empty( $settings[ParamValidator::PARAM_ISMULTI] ) &&
109 !empty( $settings[self::PARAM_RETURN_OBJECT] ) &&
111 ( $settings[ParamValidator::PARAM_ISMULTI_LIMIT1] ?? 100 ) > 10 ||
112 ( $settings[ParamValidator::PARAM_ISMULTI_LIMIT2] ?? 100 ) > 10
115 $ret[
'issues'][] =
'Multi-valued title-type parameters with PARAM_RETURN_OBJECT '
116 .
'should set low values (<= 10) for PARAM_ISMULTI_LIMIT1 and PARAM_ISMULTI_LIMIT2.'
117 .
' (Note that "<= 10" is arbitrary. If something hits this, we can investigate a real limit '
118 .
'once we have a real use case to look at.)';
125 public function getParamInfo( $name, array $settings, array $options ) {
126 $info = parent::getParamInfo( $name, $settings, $options );
128 $info[
'mustExist'] = !empty( $settings[self::PARAM_MUST_EXIST] );
134 public function getHelpInfo( $name, array $settings, array $options ) {
135 $info = parent::getParamInfo( $name, $settings, $options );
137 $info[ParamValidator::PARAM_TYPE] = MessageValue::new(
'paramvalidator-help-type-title' );
139 $mustExist = !empty( $settings[self::PARAM_MUST_EXIST] );
140 $info[self::PARAM_MUST_EXIST] = $mustExist
141 ? MessageValue::new(
'paramvalidator-help-type-title-must-exist' )
142 : MessageValue::new(
'paramvalidator-help-type-title-no-must-exist' );