Index: trunk/extensions/Storyboard/specials/Story/Story_body.php |
— | — | @@ -193,7 +193,7 @@ |
194 | 194 | * TODO: Fix the validation for the story title |
195 | 195 | */ |
196 | 196 | private function showStoryForm( $story ) { |
197 | | - global $wgOut, $wgLang, $wgRequest, $wgUser, $wgJsMimeType; |
| 197 | + global $wgOut, $wgLang, $wgRequest, $wgUser, $wgJsMimeType, $wgScriptPath; |
198 | 198 | global $egStoryboardScriptPath, $egStorysubmissionWidth, $egStoryboardMaxStoryLen, $egStoryboardMinStoryLen; |
199 | 199 | |
200 | 200 | $wgOut->setPageTitle( $story->story_title ); |
— | — | @@ -285,7 +285,9 @@ |
286 | 286 | 'class' => 'required email' |
287 | 287 | ) |
288 | 288 | ) . '</td></tr>'; |
289 | | - |
| 289 | + |
| 290 | + // TODO: further fix this |
| 291 | + // Need to extend the validator plugin to work with api results, and also send over the current srory id to exclude it. |
290 | 292 | $formBody .= '<tr>' . |
291 | 293 | '<td width="100%"><label for="storytitle">' . |
292 | 294 | htmlspecialchars( wfMsg( 'storyboard-storytitle' ) ) . |
— | — | @@ -299,7 +301,8 @@ |
300 | 302 | 'maxlength' => 255, |
301 | 303 | 'minlength' => 2, |
302 | 304 | 'id' => 'storytitle', |
303 | | - 'class' => 'required storytitle' |
| 305 | + 'class' => 'required storytitle', |
| 306 | + 'remote' => "$wgScriptPath/api.php?format=json&action=storyexists" |
304 | 307 | ) |
305 | 308 | ) . '</td></tr>'; |
306 | 309 | |
— | — | @@ -381,25 +384,14 @@ |
382 | 385 | jQuery(document).ready(function(){ |
383 | 386 | jQuery("#storyform").validate(); |
384 | 387 | }); |
385 | | -jQuery( "#storyform" ).validate({ |
386 | | - rules: { |
| 388 | +jQuery("#storyform").validate({ |
| 389 | + messages: { |
387 | 390 | storytitle: { |
388 | | - required: true, |
389 | | - remote: wgScriptPath + '/api.php?action=storyexists&storyname=' + '' // TODO |
| 391 | + required: " ", |
| 392 | + remote: jQuery.validator.format("{0} is already taken, please choose a different title.") |
390 | 393 | } |
391 | | - }, |
392 | | - messages: { |
393 | | - storytitle: "This story title already exists" // TODO: i18n |
394 | | - }, |
395 | | - success: function( label ) { |
396 | | - label.addClass( "valid" ).text( "Valid story title!" ) |
397 | | - }, |
398 | | - submitHandler: function() { |
399 | | - |
400 | | - }, |
401 | | - onkeyup: false |
| 394 | + } |
402 | 395 | }); |
403 | | - |
404 | 396 | EOT |
405 | 397 | ); |
406 | 398 | } |
Index: trunk/extensions/Storyboard/api/ApiStoryExists.php |
— | — | @@ -42,21 +42,24 @@ |
43 | 43 | public function execute() { |
44 | 44 | $params = $this->extractRequestParams(); |
45 | 45 | |
46 | | - if ( !isset( $params['storyname'] ) ) { |
47 | | - $this->dieUsageMsg( array( 'missingparam', 'storyname' ) ); |
| 46 | + if ( !isset( $params['storytitle'] ) ) { |
| 47 | + $this->dieUsageMsg( array( 'missingparam', 'storytitle' ) ); |
48 | 48 | } |
49 | | - |
| 49 | + |
50 | 50 | $dbr = wfGetDB( DB_SLAVE ); |
51 | 51 | |
52 | 52 | $story = $dbr->selectRow( |
53 | 53 | 'storyboard', |
54 | 54 | array( 'story_id' ), |
55 | | - array( 'story_title' => str_replace( '_', ' ', $params['storyname'] ) ) |
| 55 | + array( 'story_title' => str_replace( array( '_', '+' ), ' ', $params['storytitle'] ) ) |
56 | 56 | ); |
57 | 57 | |
58 | 58 | $result = array( |
59 | 59 | 'exists' => $story != false |
60 | 60 | ); |
| 61 | + |
| 62 | + // Just return true or false untill a better solution here is found. |
| 63 | + die( $story == false ? 'true' : 'false' ); |
61 | 64 | |
62 | 65 | $this->getResult()->setIndexedTagName( $result, 'story' ); |
63 | 66 | $this->getResult()->addValue( null, $this->getModuleName(), $result ); |
— | — | @@ -64,7 +67,7 @@ |
65 | 68 | |
66 | 69 | public function getAllowedParams() { |
67 | 70 | return array( |
68 | | - 'storyname' => array( |
| 71 | + 'storytitle' => array( |
69 | 72 | ApiBase :: PARAM_TYPE => 'string', |
70 | 73 | ), |
71 | 74 | ); |
— | — | @@ -72,7 +75,7 @@ |
73 | 76 | |
74 | 77 | public function getParamDescription() { |
75 | 78 | return array( |
76 | | - 'storyname' => 'The name of the story to check for.' |
| 79 | + 'storytitle' => 'The name of the story to check for.' |
77 | 80 | ); |
78 | 81 | } |
79 | 82 | |
— | — | @@ -84,13 +87,13 @@ |
85 | 88 | |
86 | 89 | public function getPossibleErrors() { |
87 | 90 | return array_merge( parent::getPossibleErrors(), array( |
88 | | - array( 'missingparam', 'storyname' ), |
| 91 | + array( 'missingparam', 'storytitle' ), |
89 | 92 | ) ); |
90 | 93 | } |
91 | 94 | |
92 | 95 | protected function getExamples() { |
93 | 96 | return array( |
94 | | - 'api.php?action=storyexists&storyname=oHai there!', |
| 97 | + 'api.php?action=storyexists&storytitle=oHai there!', |
95 | 98 | ); |
96 | 99 | } |
97 | 100 | |