r64900 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r64899‎ | r64900 | r64901 >
Date:20:59, 10 April 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Work on the title validation
Modified paths:
  • /trunk/extensions/Storyboard/api/ApiStoryExists.php (modified) (history)
  • /trunk/extensions/Storyboard/specials/Story/Story_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Storyboard/specials/Story/Story_body.php
@@ -193,7 +193,7 @@
194194 * TODO: Fix the validation for the story title
195195 */
196196 private function showStoryForm( $story ) {
197 - global $wgOut, $wgLang, $wgRequest, $wgUser, $wgJsMimeType;
 197+ global $wgOut, $wgLang, $wgRequest, $wgUser, $wgJsMimeType, $wgScriptPath;
198198 global $egStoryboardScriptPath, $egStorysubmissionWidth, $egStoryboardMaxStoryLen, $egStoryboardMinStoryLen;
199199
200200 $wgOut->setPageTitle( $story->story_title );
@@ -285,7 +285,9 @@
286286 'class' => 'required email'
287287 )
288288 ) . '</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.
290292 $formBody .= '<tr>' .
291293 '<td width="100%"><label for="storytitle">' .
292294 htmlspecialchars( wfMsg( 'storyboard-storytitle' ) ) .
@@ -299,7 +301,8 @@
300302 'maxlength' => 255,
301303 'minlength' => 2,
302304 'id' => 'storytitle',
303 - 'class' => 'required storytitle'
 305+ 'class' => 'required storytitle',
 306+ 'remote' => "$wgScriptPath/api.php?format=json&action=storyexists"
304307 )
305308 ) . '</td></tr>';
306309
@@ -381,25 +384,14 @@
382385 jQuery(document).ready(function(){
383386 jQuery("#storyform").validate();
384387 });
385 -jQuery( "#storyform" ).validate({
386 - rules: {
 388+jQuery("#storyform").validate({
 389+ messages: {
387390 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.")
390393 }
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+ }
402395 });
403 -
404396 EOT
405397 );
406398 }
Index: trunk/extensions/Storyboard/api/ApiStoryExists.php
@@ -42,21 +42,24 @@
4343 public function execute() {
4444 $params = $this->extractRequestParams();
4545
46 - if ( !isset( $params['storyname'] ) ) {
47 - $this->dieUsageMsg( array( 'missingparam', 'storyname' ) );
 46+ if ( !isset( $params['storytitle'] ) ) {
 47+ $this->dieUsageMsg( array( 'missingparam', 'storytitle' ) );
4848 }
49 -
 49+
5050 $dbr = wfGetDB( DB_SLAVE );
5151
5252 $story = $dbr->selectRow(
5353 'storyboard',
5454 array( 'story_id' ),
55 - array( 'story_title' => str_replace( '_', ' ', $params['storyname'] ) )
 55+ array( 'story_title' => str_replace( array( '_', '+' ), ' ', $params['storytitle'] ) )
5656 );
5757
5858 $result = array(
5959 'exists' => $story != false
6060 );
 61+
 62+ // Just return true or false untill a better solution here is found.
 63+ die( $story == false ? 'true' : 'false' );
6164
6265 $this->getResult()->setIndexedTagName( $result, 'story' );
6366 $this->getResult()->addValue( null, $this->getModuleName(), $result );
@@ -64,7 +67,7 @@
6568
6669 public function getAllowedParams() {
6770 return array(
68 - 'storyname' => array(
 71+ 'storytitle' => array(
6972 ApiBase :: PARAM_TYPE => 'string',
7073 ),
7174 );
@@ -72,7 +75,7 @@
7376
7477 public function getParamDescription() {
7578 return array(
76 - 'storyname' => 'The name of the story to check for.'
 79+ 'storytitle' => 'The name of the story to check for.'
7780 );
7881 }
7982
@@ -84,13 +87,13 @@
8588
8689 public function getPossibleErrors() {
8790 return array_merge( parent::getPossibleErrors(), array(
88 - array( 'missingparam', 'storyname' ),
 91+ array( 'missingparam', 'storytitle' ),
8992 ) );
9093 }
9194
9295 protected function getExamples() {
9396 return array(
94 - 'api.php?action=storyexists&storyname=oHai there!',
 97+ 'api.php?action=storyexists&storytitle=oHai there!',
9598 );
9699 }
97100

Status & tagging log