r99218 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99217‎ | r99218 | r99219 >
Date:17:03, 7 October 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
added regex o_O
Modified paths:
  • /trunk/extensions/Contest/Contest.i18n.php (modified) (history)
  • /trunk/extensions/Contest/specials/SpecialContestSubmission.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Contest/Contest.i18n.php
@@ -125,6 +125,8 @@
126126 'contest-signup-require-challenge' => 'You must select a challenge.',
127127 'contest-signup-invalid-cv' => 'You entered an invalid URL.',
128128
 129+ 'contest-submission-invalid-url' => 'This URL does not match one of the allowed formats.',
 130+
129131 // Special:ContestSubmission
130132 'contest-submission-submit' => 'Submit',
131133 'contest-submission-unknown' => 'There is no contest with the provided name.',
Index: trunk/extensions/Contest/specials/SpecialContestSubmission.php
@@ -273,5 +273,31 @@
274274
275275 return true;
276276 }
 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+ }
277303
278304 }

Status & tagging log