r63391 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r63390‎ | r63391 | r63392 >
Date:14:17, 8 March 2010
Author:jeroendedauw
Status:resolved (Comments)
Tags:
Comment:
Follow up to r63378 and r63377. Added stuff to storysubmission tag.
Modified paths:
  • /trunk/extensions/Storyboard/Storyboard.i18n.php (modified) (history)
  • /trunk/extensions/Storyboard/storyboard.sql (modified) (history)
  • /trunk/extensions/Storyboard/tags/Storysubmission/Storysubmission_body.php (modified) (history)
  • /trunk/extensions/Storyboard/tags/Storysubmission/storysubmission.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Storyboard/storyboard.sql
@@ -3,11 +3,11 @@
44 CREATE TABLE /*$wgDBprefix*/storyboard (
55 story_id INT(8) unsigned NOT NULL auto_increment PRIMARY KEY,
66 story_author_id INT unsigned NULL,
7 - story_author_name VARCHAR(100) NOT NULL,
8 - story_author_location VARCHAR(150) NOT NULL,
9 - story_author_occupation VARCHAR(100) NOT NULL,
10 - story_author_image VARCHAR(50) NULL, -- TODO: find out if this is an acceptible way to refer to an image
11 - story_hit_count INT(8) unsigned NOT NULL,
 7+ story_author_name VARCHAR(255) NOT NULL,
 8+ story_author_location VARCHAR(255) NOT NULL,
 9+ story_author_occupation VARCHAR(255) NOT NULL,
 10+ story_author_image VARCHAR(255) NULL, -- TODO: find out if this is an acceptible way to refer to an image
 11+ story_hit_count INT(8) unsigned NOT NULL, default '0',
1212 story_title VARCHAR(255) NOT NULL,
1313 story_text MEDIUMBLOB NOT NULL,
1414 story_modified CHAR(14) binary NOT NULL default '',
Index: trunk/extensions/Storyboard/Storyboard.i18n.php
@@ -34,6 +34,7 @@
3535 'storyboard-story' => "Your story",
3636 'storyboard-photo' => 'Have a photo of yourself? Why not share it?',
3737 'storyboard-contact' => 'Your E-mail address or telephone number',
 38+ 'storyboard-storytitle' => 'A short, descriptive title',
3839 'storyboard-agreement' => 'I agree with the publication of this story.',
3940 'storyboard-charsleft' => '($1 {{PLURAL:$1|character|characters}} left)',
4041 'storyboard-cannotbelonger' => 'Your story is <b>$1</b> {{PLURAL:$1|character|characters}} to long!',
Index: trunk/extensions/Storyboard/tags/Storysubmission/Storysubmission_body.php
@@ -40,9 +40,11 @@
4141 * @param $parser
4242 * @param array $args
4343 * @return HTML
 44+ *
 45+ * TODO: any sort of client side validation?
4446 */
4547 private static function getFrom( $parser, array $args ) {
46 - global $wgOut, $wgUser, $wgJsMimeType, $wgSc, $egStoryboardScriptPath, $egStorysubmissionWidth, $egStoryboardMaxStoryLen, $egStoryboardMinStoryLen;
 48+ global $wgOut, $wgUser, $wgJsMimeType, $egStoryboardScriptPath, $egStorysubmissionWidth, $egStoryboardMaxStoryLen, $egStoryboardMinStoryLen;
4749
4850 $wgOut->addStyle( $egStoryboardScriptPath . '/tags/Storysubmission/storysubmission.css' );
4951 $wgOut->addScriptFile( $egStoryboardScriptPath . '/tags/Storysubmission/storysubmission.js' );
@@ -57,6 +59,7 @@
5860
5961 $formBody = "<table width='$width'>";
6062
 63+ // TODO: if logged in, use real name as default, or username when not available
6164 $formBody .= '<tr>' .
6265 Html::element( 'td', array('width' => '100%'), wfMsg( 'storyboard-yourname' ) ) .
6366 '<td>' .
@@ -77,6 +80,11 @@
7881 Html::element( 'td', array('width' => '100%'), wfMsg( 'storyboard-contact' ) ) .
7982 '<td>' . Html::input('contact' ,'', 'text', array( 'size' => $fieldSize )
8083 ) . '</td></tr>';
 84+
 85+ $formBody .= '<tr>' .
 86+ Html::element( 'td', array('width' => '100%'), wfMsg( 'storyboard-storytitle' ) ) .
 87+ '<td>' . Html::input('storytitle' ,'', 'text', array( 'size' => $fieldSize )
 88+ ) . '</td></tr>';
8189
8290 $formBody .= '<tr><td colspan="2">' .
8391 wfMsg( 'storyboard-story' ) .
@@ -89,7 +97,8 @@
9098 Html::element(
9199 'textarea',
92100 array(
93 - 'id' => 'story',
 101+ 'id' => 'storytext',
 102+ 'name' => 'storytext',
94103 'rows' => 7,
95104 'onkeyup' => "stbValidateStory( this, $minLen, $maxLen, 'storysubmission-charlimitinfo', 'storysubmission-button' )",
96105 ),
@@ -111,7 +120,7 @@
112121
113122 $formBody .= Html::hidden( 'wpEditToken', $wgUser->editToken() );
114123
115 - $formHtml = Html::rawElement(
 124+ return Html::rawElement(
116125 'form',
117126 array(
118127 'id' => 'storyform',
@@ -122,11 +131,6 @@
123132 ),
124133 $formBody
125134 );
126 -
127 - // Disable the submission button when JS is enabled.
128 - $formJs = "<script type='$wgJsMimeType'>/*<![CDATA[*/ document.getElementById( 'storysubmission-button' ).disabled = true; /*]]>*/</script>";
129 -
130 - return $formHtml . $formJs;
131135 }
132136
133137 /**
@@ -136,7 +140,25 @@
137141 global $wgRequest, $wgUser;
138142
139143 $dbw = wfGetDB( DB_MASTER );
140 - $dbw->insert( 'storyboard' ); // TODO
 144+
 145+ // TODO: some sort of validation?
 146+
 147+ $story = array(
 148+ 'story_author_name' => $dbw->addQuotes( $wgRequest->getText( 'name' ) ),
 149+ 'story_author_location' => $dbw->addQuotes( $wgRequest->getText( 'location' ) ),
 150+ 'story_author_occupation' => $dbw->addQuotes( $wgRequest->getText( 'occupation' ) ),
 151+ 'story_title' => $dbw->addQuotes( $wgRequest->getText( 'storytitle' ) ),
 152+ 'story_text' => $dbw->addQuotes( $wgRequest->getText( 'storytext' ) ),
 153+ // TODO: add other fields
 154+ );
 155+
 156+ // TODO: Add user id to $story if user is logged in
 157+
 158+ $dbw->insert( 'storyboard', $story );
 159+
 160+ $responseHtml = ''; // TODO: create html response
 161+
 162+ return $responseHtml;
141163 }
142164
143165 }
\ No newline at end of file
Index: trunk/extensions/Storyboard/tags/Storysubmission/storysubmission.js
@@ -33,4 +33,8 @@
3434 alert( 'You need to agree to the publication of your story to submit it.' ); // TODO: i18n
3535 }
3636 return agreementValid;
37 -}
\ No newline at end of file
 37+}
 38+
 39+addOnloadHook( function() {
 40+ document.getElementById( 'storysubmission-button' ).disabled = true;
 41+} );
\ No newline at end of file

Follow-up revisions

RevisionCommit summaryAuthorDate
r63393Follow up to r63391jeroendedauw14:26, 8 March 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r63377Small improvement to Special:StoryReview permission check and added JS to dis...jeroendedauw23:59, 7 March 2010
r63378DB Table update and added edit token check to storysubmission formjeroendedauw00:25, 8 March 2010

Comments

#Comment by Catrope (talk | contribs)   14:23, 8 March 2010
+			'story_author_name' => $dbw->addQuotes( $wgRequest->getText( 'name' ) ),
+			'story_author_location' => $dbw->addQuotes( $wgRequest->getText( 'location' ) ),
+			'story_author_occupation' => $dbw->addQuotes( $wgRequest->getText( 'occupation' ) ),
+			'story_title' => $dbw->addQuotes( $wgRequest->getText( 'storytitle' ) ),
+			'story_text' => $dbw->addQuotes( $wgRequest->getText( 'storytext' ) ),
+			// TODO: add other fields
+		);
+		
+		// TODO: Add user id to $story if user is logged in
+		
+		$dbw->insert( 'storyboard', $story );

You don't need to use addQuotes() when using insert(); if you provide the row in array format like you're doing above, insert() will quote stuff automatically, and your usage of addQuotes() may lead to double-quoting.

Status & tagging log