Index: trunk/extensions/Validator/includes/ValidationErrorHandler.php |
— | — | @@ -45,70 +45,14 @@ |
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
49 | | - * Returns a list of errors in wikitext. |
| 49 | + * Returns a list of all registered errors. |
50 | 50 | * |
51 | 51 | * @since 0.4 |
52 | 52 | * |
53 | | - * @param integer $minSeverity |
54 | | - * |
55 | | - * @return string |
| 53 | + * @return array of ValidationError |
56 | 54 | */ |
57 | | - public static function getErrorList( $minSeverity = ValidationError::SEVERITY_MINOR ) { |
58 | | - $elementHtml = array(); |
59 | | - |
60 | | - if ( count( self::$errors ) == 0 ) { |
61 | | - return false; |
62 | | - } |
63 | | - |
64 | | - $elements = array_keys( self::$errors ); |
65 | | - natcasesort( $elements ); |
66 | | - |
67 | | - foreach ( $elements as $element ) { |
68 | | - $elementErrors = self::getErrorListForElement( $element, $minSeverity ); |
69 | | - |
70 | | - if ( $elementErrors ) { |
71 | | - $elementHtml[] = $elementErrors; |
72 | | - } |
73 | | - } |
74 | | - |
75 | | - // TODO: i18n |
76 | | - return "== Errors ==\n\n" . implode( "\n\n", $elementHtml ); |
| 55 | + public static function getErrors() { |
| 56 | + return self::$errors; |
77 | 57 | } |
78 | 58 | |
79 | | - /** |
80 | | - * Returns wikitext listing the errors for a single element. |
81 | | - * |
82 | | - * @since 0.4 |
83 | | - * |
84 | | - * @param string $element |
85 | | - * @param integer $minSeverity |
86 | | - * |
87 | | - * @return string |
88 | | - */ |
89 | | - public static function getErrorListForElement( $element, $minSeverity = ValidationError::SEVERITY_MINOR ) { |
90 | | - $errors = array(); |
91 | | - |
92 | | - if ( array_key_exists( $element, self::$errors ) ) { |
93 | | - foreach ( self::$errors[$element] as $error ) { |
94 | | - if ( $error->severity >= $minSeverity ) { |
95 | | - $errors[] = $error; |
96 | | - } |
97 | | - } |
98 | | - } |
99 | | - |
100 | | - if ( count( $errors ) > 0 ) { |
101 | | - $lines = array(); |
102 | | - |
103 | | - foreach ( $errors as $error ) { |
104 | | - // TODO: switch on severity |
105 | | - $lines[] = "* $error->message"; |
106 | | - } |
107 | | - |
108 | | - return "=== $element ===\n\n" . implode( "\n", $lines ); |
109 | | - } |
110 | | - else { |
111 | | - return false; |
112 | | - } |
113 | | - } |
114 | | - |
115 | 59 | } |
\ No newline at end of file |
Index: trunk/extensions/Validator/includes/parserHooks/Validator_ListErrors.php |
— | — | @@ -69,12 +69,14 @@ |
70 | 70 | * @return array |
71 | 71 | */ |
72 | 72 | protected function getParameterInfo( $type ) { |
| 73 | + global $egValidatorErrListMin; |
| 74 | + |
73 | 75 | return array( |
74 | 76 | 'minseverity' => array( |
75 | 77 | 'criteria' => array( |
76 | 78 | 'in_array' => array_keys( self::$severityMap ) |
77 | 79 | ), |
78 | | - 'default' => 'minor' |
| 80 | + 'default' => $egValidatorErrListMin |
79 | 81 | ) |
80 | 82 | ); |
81 | 83 | } |
— | — | @@ -102,14 +104,103 @@ |
103 | 105 | * @return string |
104 | 106 | */ |
105 | 107 | public function render( array $parameters ) { |
106 | | - $errorList = ValidationErrorHandler::getErrorList( self::$severityMap[$parameters['minseverity']] ); |
| 108 | + $errorList = $this->getErrorList( |
| 109 | + ValidationErrorHandler::getErrors(), |
| 110 | + self::$severityMap[$parameters['minseverity']] |
| 111 | + ); |
107 | 112 | |
108 | | - if ( $errorList ) { |
109 | | - return $this->parser->recursiveTagParse( $errorList ); |
110 | | - } |
111 | | - else { |
| 113 | + return $this->parser->recursiveTagParse( $errorList ); |
| 114 | + } |
| 115 | + |
| 116 | + /** |
| 117 | + * Returns a list of errors in wikitext. |
| 118 | + * |
| 119 | + * @since 0.4 |
| 120 | + * |
| 121 | + * @param array $errors |
| 122 | + * @param integer $minSeverity |
| 123 | + * |
| 124 | + * @return string |
| 125 | + */ |
| 126 | + public function getErrorList( array $errors, $minSeverity = ValidationError::SEVERITY_MINOR ) { |
| 127 | + $elementHtml = array(); |
| 128 | + |
| 129 | + if ( count( $errors ) == 0 ) { |
112 | 130 | return ''; |
113 | 131 | } |
| 132 | + |
| 133 | + $elements = array_keys( $errors ); |
| 134 | + natcasesort( $elements ); |
| 135 | + |
| 136 | + foreach ( $elements as $element ) { |
| 137 | + $elementErrors = $this->getErrorListForElement( $errors[$element], $element, $minSeverity ); |
| 138 | + |
| 139 | + if ( $elementErrors ) { |
| 140 | + $elementHtml[] = $elementErrors; |
| 141 | + } |
| 142 | + } |
| 143 | + |
| 144 | + return count( $elementHtml ) > 0 ? |
| 145 | + '== ' . wfMsg( 'validator-listerrors-errors' ) . " ==\n\n" . implode( "\n\n", $elementHtml ) : ''; |
114 | 146 | } |
115 | 147 | |
| 148 | + /** |
| 149 | + * Returns wikitext listing the errors for a single element. |
| 150 | + * |
| 151 | + * @since 0.4 |
| 152 | + * |
| 153 | + * @param array $allErrors |
| 154 | + * @param string $element |
| 155 | + * @param integer $minSeverity |
| 156 | + * |
| 157 | + * @return mixed String or false |
| 158 | + */ |
| 159 | + public function getErrorListForElement( array $allErrors, $element, $minSeverity = ValidationError::SEVERITY_MINOR ) { |
| 160 | + $errors = array(); |
| 161 | + |
| 162 | + foreach ( $allErrors as $error ) { |
| 163 | + if ( $error->hasSeverity( $minSeverity ) ) { |
| 164 | + $errors[] = $error; |
| 165 | + } |
| 166 | + } |
| 167 | + |
| 168 | + if ( count( $errors ) > 0 ) { |
| 169 | + $lines = array(); |
| 170 | + |
| 171 | + foreach ( $errors as $error ) { |
| 172 | + // TODO: switch on severity |
| 173 | + $lines[] = '* ' . wfMsgExt( |
| 174 | + 'validator-listerrors-severity-message', |
| 175 | + 'parsemag', |
| 176 | + $this->getSeverityMessage( $error->getSeverity() ), |
| 177 | + $error->message |
| 178 | + ); |
| 179 | + } |
| 180 | + |
| 181 | + return "=== $element ===\n\n" . implode( "\n", $lines ); |
| 182 | + } |
| 183 | + else { |
| 184 | + return false; |
| 185 | + } |
| 186 | + } |
| 187 | + |
| 188 | + /** |
| 189 | + * Returns a message for a severity. |
| 190 | + * |
| 191 | + * @since 0.4 |
| 192 | + * |
| 193 | + * @param integer $severity |
| 194 | + * |
| 195 | + * @return string |
| 196 | + */ |
| 197 | + protected function getSeverityMessage( $severity ) { |
| 198 | + static $reverseMap = false; |
| 199 | + |
| 200 | + if ( $reverseMap === false ) { |
| 201 | + $reverseMap = array_flip( self::$severityMap ); |
| 202 | + } |
| 203 | + |
| 204 | + return wfMsg( 'validator-listerrors-' . $reverseMap[$severity] ); |
| 205 | + } |
| 206 | + |
116 | 207 | } |
\ No newline at end of file |
Index: trunk/extensions/Validator/includes/ParserHook.php |
— | — | @@ -284,9 +284,9 @@ |
285 | 285 | * @return string |
286 | 286 | */ |
287 | 287 | protected function renderFatalError( ValidationError $error ) { |
288 | | - return '<span class="errorbox">' . |
| 288 | + return '<div><span class="errorbox">' . |
289 | 289 | htmlspecialchars( wfMsgExt( 'validator-fatal-error', 'parsemag', $error->getMessage() ) ) . |
290 | | - '</span>'; |
| 290 | + '</span></div><br /><br />'; |
291 | 291 | } |
292 | 292 | |
293 | 293 | /** |
Index: trunk/extensions/Validator/Validator.i18n.php |
— | — | @@ -17,6 +17,7 @@ |
18 | 18 | $messages['en'] = array( |
19 | 19 | 'validator-desc' => 'Provides generic parameter handling support for other extensions', |
20 | 20 | |
| 21 | + // General |
21 | 22 | 'validator-warning' => "'''Warning:''' $1", |
22 | 23 | 'validator-error' => "'''Error:''' $1", |
23 | 24 | 'validator-fatal-error' => "Fatal error: $1", |
— | — | @@ -29,6 +30,15 @@ |
30 | 31 | 'validator_error_required_missing' => 'The required parameter "$1" is not provided.', |
31 | 32 | 'validator-error-override-argument' => 'Tried to override parameter $1 (value: $2) with value "$3"', |
32 | 33 | |
| 34 | + // Listerrors |
| 35 | + 'validator-listerrors-errors' => 'Errors', |
| 36 | + 'validator-listerrors-severity-message' => '($1) $2', // $1 = severity; $2 = message |
| 37 | + 'validator-listerrors-minor' => 'Minor', |
| 38 | + 'validator-listerrors-low' => 'Low', |
| 39 | + 'validator-listerrors-normal' => 'Normal', |
| 40 | + 'validator-listerrors-high' => 'High', |
| 41 | + 'validator-listerrors-fatal' => 'Fatal', |
| 42 | + |
33 | 43 | // Criteria errors for single values |
34 | 44 | 'validator_error_empty_argument' => 'Parameter $1 can not have an empty value.', |
35 | 45 | 'validator_error_must_be_number' => 'Parameter $1 can only be a number.', |
Index: trunk/extensions/Validator/Validator_Settings.php |
— | — | @@ -23,12 +23,14 @@ |
24 | 24 | |
25 | 25 | # Maps actions to error severity. |
26 | 26 | # ACTION_LOG will cause the error to be logged |
27 | | -# ACTION_WARN will cause a notice that there is an error to be shown |
28 | | -# ACTION_SHOW will cause an error message to be shown |
29 | | -# ACTION_DEMAND will cause an error and prevent rendering of the regular output |
| 27 | +# ACTION_WARN will cause a notice that there is an error to be shown inline |
| 28 | +# ACTION_SHOW will cause an error message to be shown inline |
| 29 | +# ACTION_DEMAND will cause an error message to be shown inline and prevent rendering of the regular output |
30 | 30 | $egErrorActions = array( |
31 | 31 | ValidationError::SEVERITY_MINOR => ValidationError::ACTION_LOG, |
32 | 32 | ValidationError::SEVERITY_LOW => ValidationError::ACTION_WARN, |
33 | 33 | ValidationError::SEVERITY_NORMAL => ValidationError::ACTION_SHOW, |
34 | 34 | ValidationError::SEVERITY_HIGH => ValidationError::ACTION_DEMAND, |
35 | | -); |
\ No newline at end of file |
| 35 | +); |
| 36 | + |
| 37 | +$egValidatorErrListMin = 'minor'; |
\ No newline at end of file |