Index: trunk/extensions/Contest/Contest.i18n.php |
— | — | @@ -125,6 +125,8 @@ |
126 | 126 | 'contest-signup-require-challenge' => 'You must select a challenge.', |
127 | 127 | 'contest-signup-invalid-cv' => 'You entered an invalid URL.', |
128 | 128 | |
| 129 | + 'contest-submission-invalid-url' => 'This URL does not match one of the allowed formats.', |
| 130 | + |
129 | 131 | // Special:ContestSubmission |
130 | 132 | 'contest-submission-submit' => 'Submit', |
131 | 133 | 'contest-submission-unknown' => 'There is no contest with the provided name.', |
Index: trunk/extensions/Contest/specials/SpecialContestSubmission.php |
— | — | @@ -273,5 +273,31 @@ |
274 | 274 | |
275 | 275 | return true; |
276 | 276 | } |
| 277 | + |
| 278 | + /** |
| 279 | + * HTMLForm field validation-callback for the submissiom field. |
| 280 | + * Warning: regexes used! o_O |
| 281 | + * |
| 282 | + * @since 0.1 |
| 283 | + * |
| 284 | + * @param $value String |
| 285 | + * @param $alldata Array |
| 286 | + * |
| 287 | + * @return true|string |
| 288 | + */ |
| 289 | + public function validateSubmissionField( $value, $alldata = null ) { |
| 290 | + $allowedPatterns = array( |
| 291 | + // GitHub URLs such as https://github.com/JeroenDeDauw/smwcon/tree/f9b26ec4ba1101b1f5d4ef76b7ae6ad3dabfb53b |
| 292 | + '@^https://github\.com/[a-zA-Z0-9-]+/[a-zA-Z0-9_-]+/tree/[a-zA-Z0-9]{40}$@i' |
| 293 | + ); |
| 294 | + |
| 295 | + foreach ( $allowedPatterns as $pattern ) { |
| 296 | + if ( preg_match( $pattern, $value ) ) { |
| 297 | + return true; |
| 298 | + } |
| 299 | + } |
| 300 | + |
| 301 | + return wfMsg( 'contest-submission-invalid-url' ); |
| 302 | + } |
277 | 303 | |
278 | 304 | } |