r111220 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111219‎ | r111220 | r111221 >
Date:23:47, 10 February 2012
Author:danwe
Status:ok (Comments)
Tags:
Comment:
Missing files from r111215
Modified paths:
  • /trunk/extensions/Validator/includes/criteria/CriterionIsTitle.php (added) (history)
  • /trunk/extensions/Validator/includes/manipulations/ParamManipulationTitle.php (added) (history)

Diff [purge]

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
134 + 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
177 + native

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r111215New built-in parameter type 'Title' implementeddanwe23:17, 10 February 2012

Comments

#Comment by Jeroen De Dauw (talk | contribs)   23:54, 10 February 2012

Awesome. Thanks.

Really need to make the system work with stuff that are not classes... Having a class for one logic line is extremely silly :/

#Comment by Danwe (talk | contribs)   02:37, 11 February 2012

How about re-designing the 'Parameter' class in Validator 0.5, having inherited classes for each data type instead of handling them all internally. And then, instead of using extra criterion/manipulation for them, the basic logic for each type could be handled internally. Already had that thought a few times when working with Validator. Also, I think quite often we do something expensive in some ParameterCriterion, just to do the same again in ParameterManipulation, without caching it the first time. Mostly they come together anyway, so perhaps they could simply be put together in one class.

#Comment by Jeroen De Dauw (talk | contribs)   21:15, 11 February 2012

Yes, I agree with that. I already discussed this a while back with Van. See here for my thoughts: http://lists.wikimedia.org/pipermail/wikitech-l/2011-November/056436.html

I don't have time at this point to start this work, but if you feel like giving it a go, I'll be happy to help finishing it up if needed.

#Comment by Danwe (talk | contribs)   21:34, 11 February 2012

Perhaps I'll look into it at some point. But right now I am working on a new semantic extension and there is still the changes for the Maps extension I still have not implemented yet, as well as a couple of other things :/

#Comment by Jeroen De Dauw (talk | contribs)   21:46, 11 February 2012

Right. I know how that goes :)

Might be worth writing a GSoC proposal for...

Status & tagging log