r62802 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62801‎ | r62802 | r62803 >
Date:01:50, 22 February 2010
Author:jeroendedauw
Status:resolved (Comments)
Tags:
Comment:
Added new db fields and very rough layout for story review page
Modified paths:
  • /trunk/extensions/Storyboard/Storyboard.i18n.php (modified) (history)
  • /trunk/extensions/Storyboard/Storyboard.php (modified) (history)
  • /trunk/extensions/Storyboard/Storyboard.sql (modified) (history)
  • /trunk/extensions/Storyboard/specials/StoryReview/StoryReview_body.php (modified) (history)
  • /trunk/extensions/Storyboard/tags/Storyboard/Storyboard_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Storyboard/specials/StoryReview/StoryReview_body.php
@@ -23,8 +23,10 @@
2424 public function execute( $language ) {
2525 global $wgUser;
2626 if ( $wgUser->isAllowed( 'storyreview' ) && !$wgUser->isBlocked() ) {
 27+ // If the user has the storyreview permission and is not blocked, show the regular output.
2728 $this->addOutput();
2829 } else {
 30+ // If the user is not authorized, show an error.
2931 global $wgOut;
3032 $wgOut->permissionRequired( 'storyreview' );
3133 }
@@ -32,6 +34,80 @@
3335
3436 private function addOutput() {
3537 global $wgOut;
 38+
 39+ $wgOut->setPageTitle(wfMsg('storyboard-storyreview'));
 40+
3641 $wgOut->includeJQuery();
 42+
 43+ // Get a slave db object to do read operations against.
 44+ $dbr = wfGetDB( DB_SLAVE );
 45+
 46+ // Create a query to retrieve information about all non hidden stories.
 47+ $stories = $dbr->select(
 48+ Storyboard_TABLE,
 49+ array(
 50+ 'story_id',
 51+ 'story_author_name',
 52+ 'story_title',
 53+ 'story_text',
 54+ 'story_is_published'
 55+ ),
 56+ 'story_is_hidden = 0'
 57+ );
 58+
 59+ // Arrays to hold the html segments for both the unreviewed and reviewed stories.
 60+ $unreviewed = array();
 61+ $reviewed = array();
 62+
 63+ // Loop through all stories, get their html segments, and store in the appropriate array.
 64+ while ($story = $dbr->fetchObject($stories)) {
 65+ if ($story->story_is_published) {
 66+ $reviewed = array_merge($reviewed, $this->getStorySegments($story));
 67+ }
 68+ else {
 69+ $unreviewed = array_merge($unreviewed, $this->getStorySegments($story));
 70+ }
 71+ }
 72+
 73+ // Create the page layout, and add the stories.
 74+ $htmlSegments = array();
 75+ $htmlSegments[] = '<h2>' . wfMsg('storyboard-unreviewed') . '</h2>';
 76+ $htmlSegments[] = '<table width="100%">';
 77+ $htmlSegments = array_merge($htmlSegments, $unreviewed);
 78+ $htmlSegments[] = '</table>';
 79+ $htmlSegments[] = '<h2>' . wfMsg('storyboard-reviewed') . '</h2>';
 80+ $htmlSegments[] = '<table width="100%">';
 81+ $htmlSegments = array_merge($htmlSegments, $reviewed);
 82+ $htmlSegments[] = '</table>';
 83+
 84+ // Join all the html segments and add the resulting string to the page.
 85+ $wgOut->addHTML(implode('', $htmlSegments));
3786 }
38 -}
 87+
 88+ /**
 89+ * Returns the html segments for a single story.
 90+ *
 91+ * TODO: add \n's to get cleaner html output
 92+ *
 93+ * @param $story
 94+ * @return array
 95+ */
 96+ private function getStorySegments($story) {
 97+ $segments = array();
 98+ $segments[] = '<tr><td><table width="100%" border="1"><tr><td rowspan="2" width="200px">';
 99+ $segments[] = '<img src="http://upload.wikimedia.org/wikipedia/mediawiki/9/99/SemanticMaps.png">'; // TODO: get cropped image here
 100+ $segments[] = '</td><td><b>';
 101+ $segments[] = $story->story_title;
 102+ $segments[] = '</b><br />';
 103+ $segments[] = $story->story_text;
 104+ $segments[] = '</td></tr><tr><td align="center" height="35">';
 105+ $segments[] = '<button type="button">'; // TODO: figure out how to best update db info (page submit with form or onclick with ajax call?)
 106+ $segments[] = wfMsg('storyboard-publish');
 107+ $segments[] = '</button> &nbsp;&nbsp;&nbsp; <button type="button">';
 108+ $segments[] = wfMsg('edit');
 109+ $segments[] = '</button> &nbsp;&nbsp;&nbsp; <button type="button">';
 110+ $segments[] = wfMsg('hide');
 111+ $segments[] = '</button></td></tr></table></td></tr>';
 112+ return $segments;
 113+ }
 114+}
\ No newline at end of file
Index: trunk/extensions/Storyboard/Storyboard.sql
@@ -3,10 +3,12 @@
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(255) NULL,
 7+ story_author_name VARCHAR(255) NULL,
88 story_hit_count INT(8) unsigned NOT NULL,
99 story_title VARCHAR(255) NOT NULL,
1010 story_text MEDIUMBLOB NULL,
1111 story_modified CHAR(14) binary NOT NULL default '',
12 - story_created CHAR(14) binary NOT NULL default ''
13 -) /*$wgDBTableOptions*/;
 12+ story_created CHAR(14) binary NOT NULL default '',
 13+ story_is_published TINYINT NOT NULL default '0',
 14+ story_is_hidden TINYINT NOT NULL default '0'
 15+) /*$wgDBTableOptions*/;
\ No newline at end of file
Index: trunk/extensions/Storyboard/Storyboard.i18n.php
@@ -21,6 +21,7 @@
2222 'right-storyreview' => 'Review, edit, publish, and hide stories',
2323
2424 // Story review
 25+ 'storyboard-storyreview' => 'Story review',
2526 'storyboard-publish' => 'Publish',
2627 'storyboard-reviewed' => 'Reviewed',
2728 'storyboard-unreviewed' => 'Unreviewed',
Index: trunk/extensions/Storyboard/Storyboard.php
@@ -23,6 +23,8 @@
2424
2525 define( 'Storyboard_VERSION', '0' );
2626
 27+define( 'Storyboard_TABLE', 'storyboard' );
 28+
2729 // TODO: try to get out the hardcoded path.
2830 $egStoryboardScriptPath = $wgScriptPath . '/extensions/Storyboard';
2931 $egStoryboardDir = dirname( __FILE__ ) . '/';
@@ -81,7 +83,7 @@
8284 'path' => __FILE__,
8385 'name' => wfMsg( 'storyboard-name' ),
8486 'version' => Storyboard_VERSION,
85 - 'author' => array( '[http://bn2vs.com Jeroen De Dauw]' ),
 87+ 'author' => array( '[http://www.mediawiki.org/wiki/User:Jeroen_De_Dauw Jeroen De Dauw]' ),
8688 'url' => 'http://www.mediawiki.org/wiki/Extension:Storyboard',
8789 'description' => wfMsg( 'storyboard-desc' ),
8890 'descriptionmsg' => 'storyboard-desc',
Index: trunk/extensions/Storyboard/tags/Storyboard/Storyboard_body.php
@@ -26,7 +26,6 @@
2727 <script type="$wgJsMimeType">var storyboardPath = '$egStoryboardScriptPath';</script>
2828 <div id="storyboard"></div>
2929 <script type="$wgJsMimeType"> /*<![CDATA[*/
30 - jQuery(document).ready(function(){ jQuery("p").click(function(){ jQuery(this).hide(); }); });
3130 var storyboard = new Storyboard();
3231 storyboard.loadAjax();
3332 /*]]>*/ </script>

Follow-up revisions

RevisionCommit summaryAuthorDate
r62854Cleanup r62802, r62835 use __METHOD__ for wfProfileIn() calls. Also drop no-o...demon22:30, 22 February 2010

Comments

#Comment by Catrope (talk | contribs)   19:09, 22 February 2010
+			'story_is_hidden = 0'

You can use array( 'story_is_hidden' => 0 ) here.

$htmlSegments = array();
+		$htmlSegments[] = '<h2>' . wfMsg('storyboard-unreviewed') . '</h2>';
+		$htmlSegments[] = '<table width="100%">';
+		$htmlSegments = array_merge($htmlSegments, $unreviewed);
+		$htmlSegments[] = '</table>';
+		$htmlSegments[] = '<h2>' . wfMsg('storyboard-reviewed') . '</h2>';
+		$htmlSegments[] = '<table width="100%">';
+		$htmlSegments = array_merge($htmlSegments, $reviewed);
+		$htmlSegments[] = '</table>';

Use the Xml:: functions to generate HTML. Also, the array thing doesn't really make sense IMO, simple concatenation (like $foo .= 'bar';) would be cleaner.

+		$segments[] = $story->story_title;
...
+		$segments[] = $story->story_text;

Please read http://www.mediawiki.org/wiki/Security_for_developers to discover just how dangerous this is. Please also read and follow http://www.mediawiki.org/wiki/Manual:Coding_conventions , but that's obviously less important than writing secure code.

#Comment by Jeroen De Dauw (talk | contribs)   20:22, 26 February 2010

All these issues should have been fixed.

#Comment by 😂 (talk | contribs)   22:32, 22 February 2010

Ugh meant r62830 and r62835, not 62802.

Status & tagging log