r64751 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r64750‎ | r64751 | r64752 >
Date:15:53, 8 April 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Added special page for saving submitted stories as per Priyanka Dhanda's suggestion.
Modified paths:
  • /trunk/extensions/Storyboard/Storyboard.i18n.php (modified) (history)
  • /trunk/extensions/Storyboard/Storyboard.php (modified) (history)
  • /trunk/extensions/Storyboard/specials/StorySubmission (added) (history)
  • /trunk/extensions/Storyboard/specials/StorySubmission/StorySubmission_body.php (added) (history)
  • /trunk/extensions/Storyboard/storyboard.sql (modified) (history)
  • /trunk/extensions/Storyboard/tags/Storysubmission/Storysubmission_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Storyboard/storyboard.sql
@@ -18,7 +18,6 @@
1919 story_image_hidden TINYINT NOT NULL default '0'
2020 ) /*$wgDBTableOptions*/;
2121
 22+CREATE UNIQUE INDEX story_title ON /*$wgDBprefix*/storyboard (story_title);
2223 CREATE INDEX story_published_modified ON /*$wgDBprefix*/storyboard (story_is_published, story_modified);
23 -CREATE INDEX story_modified_id ON /*$wgDBprefix*/storyboard (story_modified, story_id);
24 -CREATE INDEX story_title ON /*$wgDBprefix*/storyboard (story_title);
25 -ALTER TABLE /*$wgDBprefix*/storyboard ADD UNIQUE (story_title)
\ No newline at end of file
 24+CREATE INDEX story_modified_id ON /*$wgDBprefix*/storyboard (story_modified, story_id);
\ No newline at end of file
Index: trunk/extensions/Storyboard/Storyboard.i18n.php
@@ -38,6 +38,9 @@
3939 'storyboard-authorcontact' => 'Author contact information',
4040 'storyboard-thestory' => 'The story',
4141
 42+ // Special:StorySubmission
 43+ 'storyboard-submissioncomplete' => 'Submission complete',
 44+
4245 // Story review
4346 'storyreview' => 'Story review',
4447 'storyboard-publish' => 'Publish',
Index: trunk/extensions/Storyboard/tags/Storysubmission/Storysubmission_body.php
@@ -33,11 +33,7 @@
3434
3535 global $wgRequest, $wgUser;
3636
37 - if ( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'wpStoryEditToken' ) ) ) {
38 - $output = self::doSubmissionAndGetResult();
39 - } else {
40 - $output = self::getFrom( $parser, $args );
41 - }
 37+ $output = self::getFrom( $parser, $args );
4238
4339 wfProfileOut( __METHOD__ );
4440
@@ -76,8 +72,6 @@
7773 $maxLen = array_key_exists( 'maxlength', $args ) && is_int( $args['maxlength'] ) ? $args['maxlength'] : $egStoryboardMaxStoryLen;
7874 $minLen = array_key_exists( 'minlength', $args ) && is_int( $args['minlength'] ) ? $args['minlength'] : $egStoryboardMinStoryLen;
7975
80 - $submissionUrl = $parser->getTitle()->getLocalURL( 'action=purge' );
81 -
8276 $formBody = "<table width='$width'>";
8377
8478 $defaultName = '';
@@ -151,6 +145,8 @@
152146
153147 $formBody .= Html::hidden( 'lang', $args['language'] );
154148
 149+ $submissionUrl = SpecialPage::getTitleFor( 'StorySubmission' )->getFullURL();
 150+
155151 return Html::rawElement(
156152 'form',
157153 array(
@@ -164,40 +160,6 @@
165161 );
166162 }
167163
168 - /**
169 - * Store the submitted story in the database, and return a page telling the user his story has been submitted.
170 - */
171 - private static function doSubmissionAndGetResult() {
172 - global $wgRequest, $wgUser;
173 -
174 - $dbw = wfGetDB( DB_MASTER );
175164
176 - $title = $wgRequest->getText( 'storytitle' );
177 -
178 - $story = array(
179 - 'story_lang_code' => $wgRequest->getText( 'lang' ),
180 - 'story_author_name' => $wgRequest->getText( 'name' ),
181 - 'story_author_location' => $wgRequest->getText( 'location' ),
182 - 'story_author_occupation' => $wgRequest->getText( 'occupation' ),
183 - 'story_author_contact' => $wgRequest->getText( 'contact' ),
184 - 'story_title' => $title,
185 - 'story_text' => $wgRequest->getText( 'storytext' ),
186 - 'story_created' => $dbw->timestamp( time() ),
187 - 'story_modified' => $dbw->timestamp( time() ),
188 - );
189 -
190 - // If the user is logged in, also store his user id.
191 - if ( $wgUser->isLoggedIn() ) {
192 - $story[ 'story_author_id' ] = $wgUser->getId();
193 - }
194 -
195 - // TODO: email confirmation would be nice
196 -
197 - $dbw->insert( 'storyboard', $story );
198 -
199 - $storyboardLink = ''; // TODO: create html link to the page containing stories.
200 -
201 - return wfMsgExt( 'storyboard-createdsucessfully', 'parsemag', $storyboardLink );
202 - }
203165
204166 }
\ No newline at end of file
Index: trunk/extensions/Storyboard/specials/StorySubmission/StorySubmission_body.php
@@ -0,0 +1,75 @@
 2+<?php
 3+/**
 4+ * File holding the SpecialStorySubmission class defining a special page to save submitted stories and display a success message.
 5+ *
 6+ * @file StorySubmission_body.php
 7+ * @ingroup Storyboard
 8+ * @ingroup SpecialPage
 9+ *
 10+ * @author Jeroen De Dauw
 11+ */
 12+
 13+if ( !defined( 'MEDIAWIKI' ) ) {
 14+ die( 'Not an entry point.' );
 15+}
 16+
 17+class SpecialStorySubmission extends UnlistedSpecialPage {
 18+
 19+ public function __construct() {
 20+ parent::__construct( 'StorySubmission' );
 21+ }
 22+
 23+ public function execute( $title ) {
 24+ global $wgOut, $wgRequest, $wgUser;
 25+
 26+ if ( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'wpStoryEditToken' ) ) ) {
 27+ $this->saveStory();
 28+ $this->displayResult();
 29+ } else {
 30+ $wgOut->returnToMain();
 31+ }
 32+ }
 33+
 34+ /**
 35+ * Store the submitted story in the database, and return a page telling the user his story has been submitted.
 36+ */
 37+ private function saveStory() {
 38+ global $wgRequest, $wgUser;
 39+
 40+ $dbw = wfGetDB( DB_MASTER );
 41+
 42+ $title = $wgRequest->getText( 'storytitle' );
 43+
 44+ $story = array(
 45+ 'story_lang_code' => $wgRequest->getText( 'lang' ),
 46+ 'story_author_name' => $wgRequest->getText( 'name' ),
 47+ 'story_author_location' => $wgRequest->getText( 'location' ),
 48+ 'story_author_occupation' => $wgRequest->getText( 'occupation' ),
 49+ 'story_author_contact' => $wgRequest->getText( 'contact' ),
 50+ 'story_title' => $title,
 51+ 'story_text' => $wgRequest->getText( 'storytext' ),
 52+ 'story_created' => $dbw->timestamp( time() ),
 53+ 'story_modified' => $dbw->timestamp( time() ),
 54+ );
 55+
 56+ // If the user is logged in, also store his user id.
 57+ if ( $wgUser->isLoggedIn() ) {
 58+ $story[ 'story_author_id' ] = $wgUser->getId();
 59+ }
 60+
 61+ // TODO: email confirmation would be nice
 62+
 63+ $dbw->insert( 'storyboard', $story );
 64+ }
 65+
 66+ private function displayResult() {
 67+ global $wgOut;
 68+
 69+ $wgOut->setPageTitle( wfMsg( 'storyboard-submissioncomplete' ) );
 70+
 71+ $storyboardLink = ''; // TODO: create html link to the page containing stories.
 72+
 73+ $wgOut->addWikiText( wfMsgExt( 'storyboard-createdsucessfully', 'parsemag', $storyboardLink ) );
 74+ }
 75+
 76+}
\ No newline at end of file
Property changes on: trunk/extensions/Storyboard/specials/StorySubmission/StorySubmission_body.php
___________________________________________________________________
Name: svn:eol-style
177 + native
Index: trunk/extensions/Storyboard/Storyboard.php
@@ -43,6 +43,7 @@
4444 // Load classes
4545 $wgAutoloadClasses['StoryboardUtils'] = $egStoryboardDir . 'Storyboard_Utils.php';
4646 $wgAutoloadClasses['SpecialStory'] = $egStoryboardDir . 'specials/Story/Story_body.php';
 47+$wgAutoloadClasses['SpecialStorySubmission'] = $egStoryboardDir . 'specials/StorySubmission/StorySubmission_body.php';
4748 $wgAutoloadClasses['SpecialStoryReview'] = $egStoryboardDir . 'specials/StoryReview/StoryReview_body.php';
4849 $wgAutoloadClasses['TagStoryboard'] = $egStoryboardDir . 'tags/Storyboard/Storyboard_body.php';
4950 $wgAutoloadClasses['TagStorysubmission'] = $egStoryboardDir . 'tags/Storysubmission/Storysubmission_body.php';
@@ -52,6 +53,7 @@
5354 $wgSpecialPageGroups['StoryReview'] = 'contribution';
5455 $wgSpecialPages['Story'] = 'SpecialStory';
5556 $wgSpecialPageGroups['Story'] = 'contribution';
 57+$wgSpecialPages['StorySubmission'] = 'SpecialStorySubmission';
5658
5759 // API
5860 $wgAutoloadClasses['ApiStoryExists'] = "{$egStoryboardDir}api/ApiStoryExists.php";

Status & tagging log