Index: trunk/extensions/Validator/includes/manipulations/ParamManipulationTitle.php |
— | — | @@ -0,0 +1,32 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Parameter manipulation converting the value to a wiki Title. |
| 6 | + * |
| 7 | + * @since 0.4.14 |
| 8 | + * |
| 9 | + * @file ParamManipulationTitle.php |
| 10 | + * @ingroup Validator |
| 11 | + * @ingroup ParameterManipulations |
| 12 | + * |
| 13 | + * @author Daniel Werner |
| 14 | + */ |
| 15 | +class ParamManipulationTitle extends ItemParameterManipulation { |
| 16 | + |
| 17 | + /** |
| 18 | + * Constructor. |
| 19 | + * |
| 20 | + * @since 0.4.14 |
| 21 | + */ |
| 22 | + public function __construct() { |
| 23 | + parent::__construct(); |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * @see ItemParameterManipulation::doManipulation |
| 28 | + */ |
| 29 | + public function doManipulation( &$value, Parameter $parameter, array &$parameters ) { |
| 30 | + $value = Title::newFromText( trim( $value ) ); |
| 31 | + } |
| 32 | + |
| 33 | +} |
Property changes on: trunk/extensions/Validator/includes/manipulations/ParamManipulationTitle.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 34 | + native |
Index: trunk/extensions/Validator/includes/criteria/CriterionIsTitle.php |
— | — | @@ -0,0 +1,75 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Parameter criterion stating that the value must be a Title valid within the wiki. |
| 6 | + * Optionally the Title also has to be an existing one within the wiki. |
| 7 | + * |
| 8 | + * @since 0.4.14 |
| 9 | + * |
| 10 | + * @file CriterionIsTitle.php |
| 11 | + * @ingroup Validator |
| 12 | + * @ingroup Criteria |
| 13 | + * |
| 14 | + * @author Daniel Werner |
| 15 | + */ |
| 16 | +class CriterionIsTitle extends ItemParameterCriterion { |
| 17 | + |
| 18 | + protected $hasToExist; |
| 19 | + |
| 20 | + /** |
| 21 | + * Constructor. |
| 22 | + * |
| 23 | + * @param bool $hasToExist if set to true, the title has to be an existing one. If false, the name |
| 24 | + * is just checked for validity within the wikis regulations. |
| 25 | + * |
| 26 | + * @since 0.4.14 |
| 27 | + */ |
| 28 | + public function __construct( $hasToExist = false ) { |
| 29 | + $this->hasToExist = $hasToExist; |
| 30 | + |
| 31 | + parent::__construct(); |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * @see ItemParameterCriterion::validate |
| 36 | + */ |
| 37 | + protected function doValidation( $value, Parameter $parameter, array $parameters ) { |
| 38 | + // create wiki Title from text input: |
| 39 | + $title = Title::newFromText( trim( $value ) ); |
| 40 | + |
| 41 | + if( $title === null ) { |
| 42 | + return false; |
| 43 | + } |
| 44 | + |
| 45 | + if( $this->hasToExist ) { |
| 46 | + return $title->isKnown(); |
| 47 | + } |
| 48 | + |
| 49 | + return true; |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * @see ItemParameterCriterion::getItemErrorMessage |
| 54 | + */ |
| 55 | + protected function getItemErrorMessage( Parameter $parameter ) { |
| 56 | + $msg = 'validator_error_must_be_' . ( |
| 57 | + $this->hasToExist |
| 58 | + ? 'existing_' |
| 59 | + : '' |
| 60 | + ) . 'title'; |
| 61 | + return wfMsgExt( $msg, 'parsemag', $parameter->getOriginalName() ); |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * @see ItemParameterCriterion::getFullListErrorMessage |
| 66 | + */ |
| 67 | + protected function getFullListErrorMessage( Parameter $parameter ) { |
| 68 | + $msg = 'validator_list_error_must_be_' . ( |
| 69 | + $this->hasToExist |
| 70 | + ? 'existing_' |
| 71 | + : '' |
| 72 | + ) . 'title'; |
| 73 | + return wfMsgExt( $msg, 'parsemag', $parameter->getOriginalName() ); |
| 74 | + } |
| 75 | + |
| 76 | +} |
Property changes on: trunk/extensions/Validator/includes/criteria/CriterionIsTitle.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 77 | + native |