Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Wikipedia: Mediawiki-CVS

SVN: [111220] trunk/extensions/Validator/includes

 

 

Wikipedia mediawiki-cvs RSS feed   Index | Next | Previous | View Threaded


danwe at svn

Feb 10, 2012, 3:47 PM

Post #1 of 1 (17 views)
Permalink
SVN: [111220] trunk/extensions/Validator/includes

https://www.mediawiki.org/wiki/Special:Code/MediaWiki/111220

Revision: 111220
Author: danwe
Date: 2012-02-10 23:47:20 +0000 (Fri, 10 Feb 2012)
Log Message:
-----------
Missing files from r111215

Added Paths:
-----------
trunk/extensions/Validator/includes/criteria/CriterionIsTitle.php
trunk/extensions/Validator/includes/manipulations/ParamManipulationTitle.php

Added: trunk/extensions/Validator/includes/criteria/CriterionIsTitle.php
===================================================================
--- trunk/extensions/Validator/includes/criteria/CriterionIsTitle.php (rev 0)
+++ trunk/extensions/Validator/includes/criteria/CriterionIsTitle.php 2012-02-10 23:47:20 UTC (rev 111220)
@@ -0,0 +1,75 @@
+<?php
+
+/**
+ * Parameter criterion stating that the value must be a Title valid within the wiki.
+ * Optionally the Title also has to be an existing one within the wiki.
+ *
+ * @since 0.4.14
+ *
+ * @file CriterionIsTitle.php
+ * @ingroup Validator
+ * @ingroup Criteria
+ *
+ * @author Daniel Werner
+ */
+class CriterionIsTitle extends ItemParameterCriterion {
+
+ protected $hasToExist;
+
+ /**
+ * Constructor.
+ *
+ * @param bool $hasToExist if set to true, the title has to be an existing one. If false, the name
+ * is just checked for validity within the wikis regulations.
+ *
+ * @since 0.4.14
+ */
+ public function __construct( $hasToExist = false ) {
+ $this->hasToExist = $hasToExist;
+
+ parent::__construct();
+ }
+
+ /**
+ * @see ItemParameterCriterion::validate
+ */
+ protected function doValidation( $value, Parameter $parameter, array $parameters ) {
+ // create wiki Title from text input:
+ $title = Title::newFromText( trim( $value ) );
+
+ if( $title === null ) {
+ return false;
+ }
+
+ if( $this->hasToExist ) {
+ return $title->isKnown();
+ }
+
+ return true;
+ }
+
+ /**
+ * @see ItemParameterCriterion::getItemErrorMessage
+ */
+ protected function getItemErrorMessage( Parameter $parameter ) {
+ $msg = 'validator_error_must_be_' . (
+ $this->hasToExist
+ ? 'existing_'
+ : ''
+ ) . 'title';
+ return wfMsgExt( $msg, 'parsemag', $parameter->getOriginalName() );
+ }
+
+ /**
+ * @see ItemParameterCriterion::getFullListErrorMessage
+ */
+ protected function getFullListErrorMessage( Parameter $parameter ) {
+ $msg = 'validator_list_error_must_be_' . (
+ $this->hasToExist
+ ? 'existing_'
+ : ''
+ ) . 'title';
+ return wfMsgExt( $msg, 'parsemag', $parameter->getOriginalName() );
+ }
+
+}


Property changes on: trunk/extensions/Validator/includes/criteria/CriterionIsTitle.php
___________________________________________________________________
Added: svn:eol-style
+ native

Added: trunk/extensions/Validator/includes/manipulations/ParamManipulationTitle.php
===================================================================
--- trunk/extensions/Validator/includes/manipulations/ParamManipulationTitle.php (rev 0)
+++ trunk/extensions/Validator/includes/manipulations/ParamManipulationTitle.php 2012-02-10 23:47:20 UTC (rev 111220)
@@ -0,0 +1,32 @@
+<?php
+
+/**
+ * Parameter manipulation converting the value to a wiki Title.
+ *
+ * @since 0.4.14
+ *
+ * @file ParamManipulationTitle.php
+ * @ingroup Validator
+ * @ingroup ParameterManipulations
+ *
+ * @author Daniel Werner
+ */
+class ParamManipulationTitle extends ItemParameterManipulation {
+
+ /**
+ * Constructor.
+ *
+ * @since 0.4.14
+ */
+ public function __construct() {
+ parent::__construct();
+ }
+
+ /**
+ * @see ItemParameterManipulation::doManipulation
+ */
+ public function doManipulation( &$value, Parameter $parameter, array &$parameters ) {
+ $value = Title::newFromText( trim( $value ) );
+ }
+
+}


Property changes on: trunk/extensions/Validator/includes/manipulations/ParamManipulationTitle.php
___________________________________________________________________
Added: svn:eol-style
+ native


_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS [at] lists
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Wikipedia mediawiki-cvs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.