http://www.mediawiki.org/wiki/Special:Code/MediaWiki/72721
Revision: 72721
Author: jeroendedauw
Date: 2010-09-10 14:12:40 +0000 (Fri, 10 Sep 2010)
Log Message:
-----------
Changes for 0.4 - renamed some classes to be more consistent
Modified Paths:
--------------
trunk/extensions/Validator/Validator.php
trunk/extensions/Validator/Validator_Settings.php
trunk/extensions/Validator/includes/CriterionValidationResult.php
trunk/extensions/Validator/includes/ItemParameterCriterion.php
trunk/extensions/Validator/includes/Validator.php
trunk/extensions/Validator/includes/parserHooks/Validator_ListErrors.php
Added Paths:
-----------
trunk/extensions/Validator/includes/ValidationError.php
trunk/extensions/Validator/includes/ValidationErrorHandler.php
Removed Paths:
-------------
trunk/extensions/Validator/includes/Validator_Error.php
trunk/extensions/Validator/includes/Validator_ErrorHandler.php
Modified: trunk/extensions/Validator/Validator.php
===================================================================
--- trunk/extensions/Validator/Validator.php 2010-09-10 14:07:43 UTC (rev
72720)
+++ trunk/extensions/Validator/Validator.php 2010-09-10 14:12:40 UTC (rev
72721)
@@ -64,8 +64,8 @@
$wgAutoloadClasses['TopologicalSort'] = $incDir .
'TopologicalSort.php';
$wgAutoloadClasses['ValidationFormats'] = $incDir .
'ValidationFormats.php';
$wgAutoloadClasses['ValidationManager'] = $incDir .
'ValidationManager.php'; // TODO: remove
-$wgAutoloadClasses['ValidatorError'] = $incDir .
'Validator_Error.php';
-$wgAutoloadClasses['ValidatorErrorHandler'] = $incDir .
'Validator_ErrorHandler.php';
+$wgAutoloadClasses['ValidationError'] = $incDir .
'ValidationError.php';
+$wgAutoloadClasses['ValidationErrorHandler'] = $incDir .
'ValidationErrorHandler.php';
$wgAutoloadClasses['CriterionHasLength'] = $incDir .
'criteria/CriterionHasLength.php';
$wgAutoloadClasses['CriterionInArray'] = $incDir .
'criteria/CriterionInArray.php';
Modified: trunk/extensions/Validator/Validator_Settings.php
===================================================================
--- trunk/extensions/Validator/Validator_Settings.php 2010-09-10 14:07:43 UTC
(rev 72720)
+++ trunk/extensions/Validator/Validator_Settings.php 2010-09-10 14:12:40 UTC
(rev 72721)
@@ -26,9 +26,9 @@
# Validator_ERRORS_SHOW : Validator will make the best of the
input it got, but will show a list of all errors.
# Validator_ERRORS_STRICT : Validator will only show regular output when
there are no errors, if there are, a list of them will be shown.
$egErrorLevel = array(
- ValidatorError::SEVERITY_MINOR => Validator_ERRORS_LOG,
- ValidatorError::SEVERITY_LOW => Validator_ERRORS_LOG,
- ValidatorError::SEVERITY_NORMAL => Validator_ERRORS_WARN,
- ValidatorError::SEVERITY_HIGH => Validator_ERRORS_SHOW,
- ValidatorError::SEVERITY_CRITICAL => Validator_ERRORS_STRICT,
+ ValidationError::SEVERITY_MINOR => Validator_ERRORS_LOG,
+ ValidationError::SEVERITY_LOW => Validator_ERRORS_LOG,
+ ValidationError::SEVERITY_NORMAL => Validator_ERRORS_WARN,
+ ValidationError::SEVERITY_HIGH => Validator_ERRORS_SHOW,
+ ValidationError::SEVERITY_CRITICAL => Validator_ERRORS_STRICT,
);
\ No newline at end of file
Modified: trunk/extensions/Validator/includes/CriterionValidationResult.php
===================================================================
--- trunk/extensions/Validator/includes/CriterionValidationResult.php
2010-09-10 14:07:43 UTC (rev 72720)
+++ trunk/extensions/Validator/includes/CriterionValidationResult.php
2010-09-10 14:12:40 UTC (rev 72721)
@@ -42,7 +42,7 @@
*
* @param ValidationError $error
*/
- public function addError( ValidatorError $error ) {
+ public function addError( ValidationError $error ) {
$this->errors[] = $error;
}
Modified: trunk/extensions/Validator/includes/ItemParameterCriterion.php
===================================================================
--- trunk/extensions/Validator/includes/ItemParameterCriterion.php
2010-09-10 14:07:43 UTC (rev 72720)
+++ trunk/extensions/Validator/includes/ItemParameterCriterion.php
2010-09-10 14:12:40 UTC (rev 72721)
@@ -87,7 +87,7 @@
if ( $result->hasInvalidItems() ) {
$result->addError(
- new ValidatorError(
$this->getListErrorMessage( $result->getInvalidItems() ) )
+ new ValidationError(
$this->getListErrorMessage( $result->getInvalidItems() ) )
);
}
}
@@ -96,7 +96,7 @@
$this->getItemErrorMessage( $value );
$result->addError(
- new ValidatorError(
$this->getItemErrorMessage( $value ) )
+ new ValidationError(
$this->getItemErrorMessage( $value ) )
);
}
}
Copied: trunk/extensions/Validator/includes/ValidationError.php (from rev
72717, trunk/extensions/Validator/includes/Validator_Error.php)
===================================================================
--- trunk/extensions/Validator/includes/ValidationError.php
(rev 0)
+++ trunk/extensions/Validator/includes/ValidationError.php 2010-09-10
14:12:40 UTC (rev 72721)
@@ -0,0 +1,57 @@
+<?php
+
+/**
+ * Error class.
+ *
+ * @since 0.4
+ *
+ * @file Validator_Error.php
+ * @ingroup Validator
+ *
+ * @author Jeroen De Dauw
+ */
+class ValidationError {
+
+ const SEVERITY_MINOR = 0;
+ const SEVERITY_LOW = 1;
+ const SEVERITY_NORMAL = 2;
+ const SEVERITY_HIGH = 3;
+ const SEVERITY_CRITICAL = 4;
+
+ public $message;
+ public $severity;
+
+ /**
+ * List of 'tags' for the error. This is mainly ment for indicating an
error
+ * type, such as 'missing parameter' or 'invalid value', but allows for
multiple
+ * such indications.
+ *
+ * @since 0.4
+ *
+ * @var array
+ */
+ public $tags;
+
+ /**
+ * Where the error occured.
+ *
+ * @since 0.4
+ *
+ * @var mixed: string or false
+ */
+ public $element;
+
+ /**
+ * @since 0.4
+ *
+ * @param string $message
+ * @param integer $severity
+ */
+ public function __construct( $message, $severity =
self::SEVERITY_NORMAL, $element = false, array $tags = array() ) {
+ $this->message = $message;
+ $this->severity = $severity;
+ $this->element = $element;
+ $this->tags = $tags;
+ }
+
+}
\ No newline at end of file
Copied: trunk/extensions/Validator/includes/ValidationErrorHandler.php (from
rev 72717, trunk/extensions/Validator/includes/Validator_ErrorHandler.php)
===================================================================
--- trunk/extensions/Validator/includes/ValidationErrorHandler.php
(rev 0)
+++ trunk/extensions/Validator/includes/ValidationErrorHandler.php
2010-09-10 14:12:40 UTC (rev 72721)
@@ -0,0 +1,114 @@
+<?php
+
+/**
+ * Static class for error handling.
+ *
+ * @since 0.4
+ *
+ * @file Validator_ErrorHandler.php
+ * @ingroup Validator
+ *
+ * @author Jeroen De Dauw
+ */
+final class ValidationErrorHandler {
+
+ /**
+ * @since 0.4
+ *
+ * @var array of ValidationError
+ */
+ protected static $errors;
+
+ /**
+ * Adds a single ValidationError.
+ *
+ * @since 0.4
+ *
+ * @param string $errorMessage
+ * @param integer $severity
+ */
+ public static function addError( ValidationError $error ) {
+ self::$errors[$error->element ? $error->element : 'unknown'][]
= $error;
+ }
+
+ /**
+ * Adds a list of ValidationError.
+ *
+ * @since 0.4
+ *
+ * @param array $errors
+ */
+ public static function addErrors( array $errors ) {
+ foreach ( $errors as $error ) {
+ self::addError( $error );
+ }
+ }
+
+ /**
+ * Returns a list of errors in wikitext.
+ *
+ * @since 0.4
+ *
+ * @param integer $minSeverity
+ *
+ * @return string
+ */
+ public static function getErrorList( $minSeverity =
ValidationError::SEVERITY_MINOR ) {
+ $elementHtml = array();
+
+ if ( count( self::$errors ) == 0 ) {
+ return false;
+ }
+
+ $elements = array_keys( self::$errors );
+ natcasesort( $elements );
+
+ foreach ( $elements as $element ) {
+ $elementErrors = self::getErrorListForElement(
$element, $minSeverity );
+
+ if ( $elementErrors ) {
+ $elementHtml[] = $elementErrors;
+ }
+ }
+
+ // TODO: i18n
+ return "== Errors ==\n\n" . implode( "\n\n", $elementHtml );
+ }
+
+ /**
+ * Returns wikitext listing the errors for a single element.
+ *
+ * @since 0.4
+ *
+ * @param string $element
+ * @param integer $minSeverity
+ *
+ * @return string
+ */
+ public static function getErrorListForElement( $element, $minSeverity =
ValidationError::SEVERITY_MINOR ) {
+ $errors = array();
+
+ if ( array_key_exists( $element, self::$errors ) ) {
+ foreach ( self::$errors[$element] as $error ) {
+ if ( $error->severity >= $minSeverity ) {
+ $errors[] = $error;
+ }
+ }
+ }
+
+ if ( count( $errors ) > 0 ) {
+ $lines = array();
+
+ foreach ( $errors as $error ) {
+ // TODO: switch on severity
+ $lines[] = "* $error->message";
+ }
+
+ return "=== $element ===\n\n" . implode( "\n", $lines );
+ }
+ else {
+ return false;
+ }
+ }
+
+}
\ No newline at end of file
Modified: trunk/extensions/Validator/includes/Validator.php
===================================================================
--- trunk/extensions/Validator/includes/Validator.php 2010-09-10 14:07:43 UTC
(rev 72720)
+++ trunk/extensions/Validator/includes/Validator.php 2010-09-10 14:12:40 UTC
(rev 72721)
@@ -42,7 +42,7 @@
protected $parameters;
/**
- * List of ValidatorError.
+ * List of ValidationError.
*
* @since 0.4
*
@@ -209,9 +209,9 @@
* @param mixed $tags string or array
* @param integer $severity
*/
- protected function registerNewError( $message, $tags = array(),
$severity = ValidatorError::SEVERITY_NORMAL ) {
+ protected function registerNewError( $message, $tags = array(),
$severity = ValidationError::SEVERITY_NORMAL ) {
$this->registerError(
- new ValidatorError(
+ new ValidationError(
$message,
$severity,
$this->element,
@@ -227,9 +227,9 @@
*
* @param ValidationError $error
*/
- protected function registerError( ValidatorError $error ) {
+ protected function registerError( ValidationError $error ) {
$this->errors[] = $error;
- ValidatorErrorHandler::addError( $error );
+ ValidationErrorHandler::addError( $error );
}
/**
@@ -351,7 +351,7 @@
/**
* Returns the errors.
*
- * @return array of ValidatorError
+ * @return array of ValidationError
*/
public function getErrors() {
return $this->errors;
@@ -376,7 +376,7 @@
$has = false;
foreach ( $this->errors as $error ) {
- if ( $error->severity >=
ValidatorError::SEVERITY_CRITICAL ) {
+ if ( $error->severity >=
ValidationError::SEVERITY_CRITICAL ) {
$has = true;
break;
}
Deleted: trunk/extensions/Validator/includes/Validator_Error.php
===================================================================
--- trunk/extensions/Validator/includes/Validator_Error.php 2010-09-10
14:07:43 UTC (rev 72720)
+++ trunk/extensions/Validator/includes/Validator_Error.php 2010-09-10
14:12:40 UTC (rev 72721)
@@ -1,57 +0,0 @@
-<?php
-
-/**
- * Error class.
- *
- * @since 0.4
- *
- * @file Validator_Error.php
- * @ingroup Validator
- *
- * @author Jeroen De Dauw
- */
-class ValidatorError {
-
- const SEVERITY_MINOR = 0;
- const SEVERITY_LOW = 1;
- const SEVERITY_NORMAL = 2;
- const SEVERITY_HIGH = 3;
- const SEVERITY_CRITICAL = 4;
-
- public $message;
- public $severity;
-
- /**
- * List of 'tags' for the error. This is mainly ment for indicating an
error
- * type, such as 'missing parameter' or 'invalid value', but allows for
multiple
- * such indications.
- *
- * @since 0.4
- *
- * @var array
- */
- public $tags;
-
- /**
- * Where the error occured.
- *
- * @since 0.4
- *
- * @var mixed: string or false
- */
- public $element;
-
- /**
- * @since 0.4
- *
- * @param string $message
- * @param integer $severity
- */
- public function __construct( $message, $severity =
ValidatorError::SEVERITY_NORMAL, $element = false, array $tags = array() ) {
- $this->message = $message;
- $this->severity = $severity;
- $this->element = $element;
- $this->tags = $tags;
- }
-
-}
\ No newline at end of file
Deleted: trunk/extensions/Validator/includes/Validator_ErrorHandler.php
===================================================================
--- trunk/extensions/Validator/includes/Validator_ErrorHandler.php
2010-09-10 14:07:43 UTC (rev 72720)
+++ trunk/extensions/Validator/includes/Validator_ErrorHandler.php
2010-09-10 14:12:40 UTC (rev 72721)
@@ -1,114 +0,0 @@
-<?php
-
-/**
- * Static class for error handling.
- *
- * @since 0.4
- *
- * @file Validator_ErrorHandler.php
- * @ingroup Validator
- *
- * @author Jeroen De Dauw
- */
-final class ValidatorErrorHandler {
-
- /**
- * @since 0.4
- *
- * @var array of ValidatorError
- */
- protected static $errors;
-
- /**
- * Adds a single ValidatorError.
- *
- * @since 0.4
- *
- * @param string $errorMessage
- * @param integer $severity
- */
- public static function addError( ValidatorError $error ) {
- self::$errors[$error->element ? $error->element : 'unknown'][]
= $error;
- }
-
- /**
- * Adds a list of ValidatorError.
- *
- * @since 0.4
- *
- * @param array $errors
- */
- public static function addErrors( array $errors ) {
- foreach ( $errors as $error ) {
- self::addError( $error );
- }
- }
-
- /**
- * Returns a list of errors in wikitext.
- *
- * @since 0.4
- *
- * @param integer $minSeverity
- *
- * @return string
- */
- public static function getErrorList( $minSeverity =
ValidatorError::SEVERITY_MINOR ) {
- $elementHtml = array();
-
- if ( count( self::$errors ) == 0 ) {
- return false;
- }
-
- $elements = array_keys( self::$errors );
- natcasesort( $elements );
-
- foreach ( $elements as $element ) {
- $elementErrors = self::getErrorListForElement(
$element, $minSeverity );
-
- if ( $elementErrors ) {
- $elementHtml[] = $elementErrors;
- }
- }
-
- // TODO: i18n
- return "== Errors ==\n\n" . implode( "\n\n", $elementHtml );
- }
-
- /**
- * Returns wikitext listing the errors for a single element.
- *
- * @since 0.4
- *
- * @param string $element
- * @param integer $minSeverity
- *
- * @return string
- */
- public static function getErrorListForElement( $element, $minSeverity =
ValidatorError::SEVERITY_MINOR ) {
- $errors = array();
-
- if ( array_key_exists( $element, self::$errors ) ) {
- foreach ( self::$errors[$element] as $error ) {
- if ( $error->severity >= $minSeverity ) {
- $errors[] = $error;
- }
- }
- }
-
- if ( count( $errors ) > 0 ) {
- $lines = array();
-
- foreach ( $errors as $error ) {
- // TODO: switch on severity
- $lines[] = "* $error->message";
- }
-
- return "=== $element ===\n\n" . implode( "\n", $lines );
- }
- else {
- return false;
- }
- }
-
-}
\ No newline at end of file
Modified:
trunk/extensions/Validator/includes/parserHooks/Validator_ListErrors.php
===================================================================
--- trunk/extensions/Validator/includes/parserHooks/Validator_ListErrors.php
2010-09-10 14:07:43 UTC (rev 72720)
+++ trunk/extensions/Validator/includes/parserHooks/Validator_ListErrors.php
2010-09-10 14:12:40 UTC (rev 72721)
@@ -14,18 +14,18 @@
/**
* Array to map the possible values for the 'minseverity' parameter
- * to their equivalent in the ValidatorError::SEVERITY_ enum.
+ * to their equivalent in the ValidationError::SEVERITY_ enum.
*
* @since 0.4
*
* @var array
*/
protected static $severityMap = array(
- 'minor' => ValidatorError::SEVERITY_MINOR,
- 'low' => ValidatorError::SEVERITY_LOW,
- 'normal' => ValidatorError::SEVERITY_NORMAL,
- 'high' => ValidatorError::SEVERITY_HIGH,
- 'critical' => ValidatorError::SEVERITY_CRITICAL,
+ 'minor' => ValidationError::SEVERITY_MINOR,
+ 'low' => ValidationError::SEVERITY_LOW,
+ 'normal' => ValidationError::SEVERITY_NORMAL,
+ 'high' => ValidationError::SEVERITY_HIGH,
+ 'critical' => ValidationError::SEVERITY_CRITICAL,
);
/**
@@ -102,7 +102,7 @@
* @return string
*/
public function render( array $parameters ) {
- $errorList = ValidatorErrorHandler::getErrorList(
self::$severityMap[$parameters['minseverity']] );
+ $errorList = ValidationErrorHandler::getErrorList(
self::$severityMap[$parameters['minseverity']] );
if ( $errorList ) {
return $this->parser->recursiveTagParse( $errorList );
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs