r62753 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62752‎ | r62753 | r62754 >
Date:20:21, 20 February 2010
Author:jeroendedauw
Status:resolved (Comments)
Tags:
Comment:
Started implemntation of the <storyboard/> tag. Not in working order yet though.
Modified paths:
  • /trunk/extensions/Storyboard/Storyboard.pg.sql (added) (history)
  • /trunk/extensions/Storyboard/Storyboard.php (modified) (history)
  • /trunk/extensions/Storyboard/images (added) (history)
  • /trunk/extensions/Storyboard/images/Background.png (added) (history)
  • /trunk/extensions/Storyboard/images/Delicious.png (added) (history)
  • /trunk/extensions/Storyboard/images/Facebook.png (added) (history)
  • /trunk/extensions/Storyboard/images/Twitter.png (added) (history)
  • /trunk/extensions/Storyboard/images/ajax_loader.gif (added) (history)
  • /trunk/extensions/Storyboard/images/spacer_result.png (added) (history)
  • /trunk/extensions/Storyboard/specials/StoryReview (added) (history)
  • /trunk/extensions/Storyboard/specials/StoryReview/StoryReview_body.php (added) (history)
  • /trunk/extensions/Storyboard/specials/StoryReview_body.php (deleted) (history)
  • /trunk/extensions/Storyboard/tags/Storyboard (added) (history)
  • /trunk/extensions/Storyboard/tags/Storyboard/Stories.php (added) (history)
  • /trunk/extensions/Storyboard/tags/Storyboard/Storyboard.css (added) (history)
  • /trunk/extensions/Storyboard/tags/Storyboard/Storyboard.js (added) (history)
  • /trunk/extensions/Storyboard/tags/Storyboard/Storyboard_body.php (added) (history)
  • /trunk/extensions/Storyboard/tags/Storyboard_body.php (deleted) (history)
  • /trunk/extensions/Storyboard/tags/Storysubmission (added) (history)
  • /trunk/extensions/Storyboard/tags/Storysubmission/Storysubmission_body.php (added) (history)
  • /trunk/extensions/Storyboard/tags/Storysubmission_body.php (deleted) (history)

Diff [purge]

Index: trunk/extensions/Storyboard/specials/StoryReview_body.php
@@ -1,37 +0,0 @@
2 -<?php
3 -/**
4 - * File holding the SpecialStoryReview class that allows reviewers to moderate the submitted stories.
5 - *
6 - * @file StoryReview_body.php
7 - * @ingroup Storyboard
8 - *
9 - * @author Jeroen De Dauw
10 - */
11 -
12 -if ( !defined( 'MEDIAWIKI' ) ) {
13 - die( 'Not an entry point.' );
14 -}
15 -
16 -class SpecialStoryReview extends IncludableSpecialPage {
17 -
18 - public function __construct() {
19 - parent::__construct( 'StoryReview' );
20 -
21 - wfLoadExtensionMessages( 'Storyboard' );
22 - }
23 -
24 - public function execute( $language ) {
25 - global $wgUser;
26 - if ( $wgUser->isAllowed( 'storyreview' ) && !$wgUser->isBlocked() ) {
27 - $this->addOutput();
28 - } else {
29 - global $wgOut;
30 - $wgOut->permissionRequired( 'storyreview' );
31 - }
32 - }
33 -
34 - private function addOutput() {
35 - global $wgOut;
36 - $wgOut->includeJQuery();
37 - }
38 -}
Index: trunk/extensions/Storyboard/specials/StoryReview/StoryReview_body.php
@@ -0,0 +1,37 @@
 2+<?php
 3+/**
 4+ * File holding the SpecialStoryReview class that allows reviewers to moderate the submitted stories.
 5+ *
 6+ * @file StoryReview_body.php
 7+ * @ingroup Storyboard
 8+ *
 9+ * @author Jeroen De Dauw
 10+ */
 11+
 12+if ( !defined( 'MEDIAWIKI' ) ) {
 13+ die( 'Not an entry point.' );
 14+}
 15+
 16+class SpecialStoryReview extends IncludableSpecialPage {
 17+
 18+ public function __construct() {
 19+ parent::__construct( 'StoryReview' );
 20+
 21+ wfLoadExtensionMessages( 'Storyboard' );
 22+ }
 23+
 24+ public function execute( $language ) {
 25+ global $wgUser;
 26+ if ( $wgUser->isAllowed( 'storyreview' ) && !$wgUser->isBlocked() ) {
 27+ $this->addOutput();
 28+ } else {
 29+ global $wgOut;
 30+ $wgOut->permissionRequired( 'storyreview' );
 31+ }
 32+ }
 33+
 34+ private function addOutput() {
 35+ global $wgOut;
 36+ $wgOut->includeJQuery();
 37+ }
 38+}
Property changes on: trunk/extensions/Storyboard/specials/StoryReview/StoryReview_body.php
___________________________________________________________________
Added: svn:eol-style
139 + native
Index: trunk/extensions/Storyboard/images/Background.png
Cannot display: file marked as a binary type.
svn:mime-type = image/png
Property changes on: trunk/extensions/Storyboard/images/Background.png
___________________________________________________________________
Added: svn:mime-type
240 + image/png
Index: trunk/extensions/Storyboard/images/Delicious.png
Cannot display: file marked as a binary type.
svn:mime-type = image/png
Property changes on: trunk/extensions/Storyboard/images/Delicious.png
___________________________________________________________________
Added: svn:mime-type
341 + image/png
Index: trunk/extensions/Storyboard/images/Twitter.png
Cannot display: file marked as a binary type.
svn:mime-type = image/png
Property changes on: trunk/extensions/Storyboard/images/Twitter.png
___________________________________________________________________
Added: svn:mime-type
442 + image/png
Index: trunk/extensions/Storyboard/images/Facebook.png
Cannot display: file marked as a binary type.
svn:mime-type = image/png
Property changes on: trunk/extensions/Storyboard/images/Facebook.png
___________________________________________________________________
Added: svn:mime-type
543 + image/png
Index: trunk/extensions/Storyboard/images/ajax_loader.gif
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: trunk/extensions/Storyboard/images/ajax_loader.gif
___________________________________________________________________
Added: svn:mime-type
644 + application/octet-stream
Index: trunk/extensions/Storyboard/images/spacer_result.png
Cannot display: file marked as a binary type.
svn:mime-type = image/png
Property changes on: trunk/extensions/Storyboard/images/spacer_result.png
___________________________________________________________________
Added: svn:mime-type
745 + image/png
Index: trunk/extensions/Storyboard/Storyboard.pg.sql
@@ -0,0 +1,18 @@
 2+-- Postgres version of the database schema for the Storyboard extension.
 3+
 4+BEGIN;
 5+
 6+CREATE SEQUENCE story_id_seq;
 7+
 8+CREATE TABLE `storyboard` (
 9+ story_id INTEGER PRIMARY KEY DEFAULT nextval('story_id_seq'),
 10+ story_author_id INTEGER NULL,
 11+ story_author_name TEXT NULL,
 12+ story_hit_count INTEGER NOT NULL,
 13+ story_title TEXT NOT NULL,
 14+ story_text TEXT NULL,
 15+ story_modified TIMESTAMPTZ NULL DEFAULT now(),
 16+ story_created TIMESTAMPTZ NULL DEFAULT now(),
 17+);
 18+
 19+COMMIT;
\ No newline at end of file
Property changes on: trunk/extensions/Storyboard/Storyboard.pg.sql
___________________________________________________________________
Added: svn:eol-style
120 + native
Index: trunk/extensions/Storyboard/Storyboard.php
@@ -23,8 +23,10 @@
2424
2525 define( 'Storyboard_VERSION', '0' );
2626
 27+// TODO: try to get out the hardcoded path.
2728 $egStoryboardScriptPath = $wgScriptPath . '/extensions/Storyboard';
2829 $egStoryboardDir = dirname( __FILE__ ) . '/';
 30+$egStoryboardStyleVersion = $wgStyleVersion . '-' . Storyboard_VERSION;
2931
3032 // Include the settings file.
3133 require_once( $egStoryboardDir . 'Storyboard_Settings.php' );
@@ -37,13 +39,13 @@
3840 $wgExtensionAliasesFiles['Storyboard'] = $egStoryboardDir . 'Storyboard.alias.php';
3941
4042 // Load and register the StoryReview special page and register it's group.
41 -$wgAutoloadClasses['SpecialStoryReview'] = $egStoryboardDir . 'specials/StoryReview_body.php';
 43+$wgAutoloadClasses['SpecialStoryReview'] = $egStoryboardDir . 'specials/StoryReview/StoryReview_body.php';
4244 $wgSpecialPages['StoryReview'] = 'SpecialStoryReview';
4345 $wgSpecialPageGroups['StoryReview'] = 'contribution';
4446
4547 // Load the tag extension classes.
46 -$wgAutoloadClasses['TagStoryboard'] = $egStoryboardDir . 'tags/Storyboard_body.php';
47 -$wgAutoloadClasses['TagStorysubmission'] = $egStoryboardDir . 'tags/Storysubmission_body.php';
 48+$wgAutoloadClasses['TagStoryboard'] = $egStoryboardDir . 'tags/Storyboard/Storyboard_body.php';
 49+$wgAutoloadClasses['TagStorysubmission'] = $egStoryboardDir . 'tags/Storysubmission/Storysubmission_body.php';
4850
4951 // Register the tag extensions.
5052 // Avoid unstubbing $wgParser on setHook() too early on modern (1.12+) MW versions, as per r35980.
Index: trunk/extensions/Storyboard/tags/Storysubmission_body.php
@@ -1,22 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * File holding the rendering function for the Storysubmission tag.
6 - *
7 - * @file Storysubmission_body.php
8 - * @ingroup Storyboard
9 - *
10 - * @author Jeroen De Dauw
11 - */
12 -
13 -if ( !defined( 'MEDIAWIKI' ) ) {
14 - die( 'Not an entry point.' );
15 -}
16 -
17 -class TagStorysubmission {
18 -
19 - public static function render( $input, $args, $parser, $frame ) {
20 - return '';
21 - }
22 -
23 -}
\ No newline at end of file
Index: trunk/extensions/Storyboard/tags/Storyboard_body.php
@@ -1,25 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * File holding the rendering function for the Storyboard tag.
6 - *
7 - * @file Storyboard_body.php
8 - * @ingroup Storyboard
9 - *
10 - * @author Jeroen De Dauw
11 - */
12 -
13 -if ( !defined( 'MEDIAWIKI' ) ) {
14 - die( 'Not an entry point.' );
15 -}
16 -
17 -class TagStoryboard {
18 -
19 - public static function render( $input, $args, $parser, $frame ) {
20 - return '';
21 - }
22 -
23 -}
24 -
25 -
26 -
Index: trunk/extensions/Storyboard/tags/Storyboard/Storyboard.css
@@ -0,0 +1,93 @@
 2+/**
 3+ * Storyboard tag css.
 4+ *
 5+ * @file Storyboard.css
 6+ * @ingroup Storyboard
 7+ *
 8+ * @author Jeroen De Dauw
 9+ * @author Tha Devil (helpmij.nl)
 10+ */
 11+
 12+#storyboard
 13+{
 14+ margin-left: 31px;
 15+ width: 50%;
 16+ height: 300px;
 17+ overflow-y: scroll;
 18+ overflow-x: hidden;
 19+ font-family: Verdana;
 20+ font-size: 10px;
 21+}
 22+
 23+#storyboard-results
 24+{
 25+ background: url(extensions/Storyboard/images/Background.png) repeat-y;
 26+}
 27+
 28+.storyboard-result
 29+{
 30+ padding-bottom: 6px;
 31+ background: url(extensions/Storyboard/images/spacer_result.png) no-repeat bottom;
 32+}
 33+
 34+.storyboard-result .storyboard-header
 35+{
 36+ margin: 10px 0px 10px 15px;
 37+}
 38+
 39+.storyboard-result .storyboard-header .storyboard-title
 40+{
 41+ font: 16px "Lucida Sans", Verdana;
 42+ font-weight: bold;
 43+ width: 100px;
 44+ height: 21px;
 45+ overflow: hidden;
 46+ float: left;
 47+}
 48+
 49+.storyboard-result
 50+{
 51+ margin-left: 12px;
 52+ margin-right: 15px;
 53+}
 54+
 55+.storyboard-result
 56+{
 57+ float: left;
 58+ width: 146px;
 59+ height: 112px;
 60+ margin-left: 3px;
 61+ margin-right: 3px;
 62+ margin-top: 10px;
 63+ overflow: hidden;
 64+ text-align: center;
 65+}
 66+
 67+.storyboard-result
 68+{
 69+ display: none;
 70+}
 71+
 72+#storyboard-loading
 73+{
 74+ background-image: url(extensions/Storyboard/images/ajax_loader.gif);
 75+ width:31px;
 76+ height:31px;
 77+ margin:0 auto;
 78+ margin-top: 10px;
 79+}
 80+
 81+.storyboard-footer
 82+{
 83+ height: 40px;
 84+ padding-top: 20px;
 85+ margin-left: 15px;
 86+}
 87+
 88+.storyboard-sharing
 89+{
 90+ margin-left: 750px;
 91+ height: 30px;
 92+ width: 110px;
 93+ float: left;
 94+}
Property changes on: trunk/extensions/Storyboard/tags/Storyboard/Storyboard.css
___________________________________________________________________
Added: svn:eol-style
195 + native
Index: trunk/extensions/Storyboard/tags/Storyboard/Storyboard.js
@@ -0,0 +1,87 @@
 2+ /**
 3+ * Storyboard object.
 4+ *
 5+ * @file Storyboard.js
 6+ * @ingroup Storyboard
 7+ *
 8+ * @author Jeroen De Dauw
 9+ * @author Tha Devil (helpmij.nl)
 10+ */
 11+
 12+/**
 13+ * Constructor for the Storyboard object.
 14+ */
 15+function Storyboard() {
 16+ this.stories = [];
 17+
 18+ this.pageNumber = 0;
 19+ this.pageAmount = -1;
 20+
 21+ this.isLoading = false;
 22+}
 23+
 24+/**
 25+ * Scroll method.
 26+ * Checks if new stories should be loaded, and calls loadAjax when this is the case.
 27+ */
 28+Storyboard.prototype.scroll = function(event) {
 29+ var board = event.data[0];
 30+ var documentHeight = jQuery(document).height();
 31+ var top = jQuery("#storyboard").scrollTop();
 32+
 33+ var resultsHeight = 0;
 34+ jQuery("#storyboard .storyboard-result").each(function() {
 35+ resultsHeight += $(this).height();
 36+ });
 37+
 38+ var threshold = ( ( top / 2 ) + ( 0.01 * Math.pow(documentHeight, 2) ) ) / resultsHeight;
 39+ if (threshold > 0.6) threshold = 0.6;
 40+
 41+ if( top / resultsHeight >= threshold && !board.isLoading && board.pageNumber < board.pageAmount )
 42+ {
 43+ board.loadAjax();
 44+ }
 45+};
 46+
 47+/**
 48+ * LoadAjax method.
 49+ * Requests and loads new stories into the storyboard.
 50+ */
 51+Storyboard.prototype.loadAjax = function() {
 52+ alert('load');
 53+ var t = this;
 54+
 55+ this.isLoading = true;
 56+
 57+ jQuery("#storyboard").append(jQuery("<div />").attr("id","storyboard-loading"));
 58+
 59+ jQuery.getJSON(storyboardPath + '/tags/Storyboard/Stories.php?&number=' + t.currentPage + '', function(json) {
 60+
 61+ t.pageAmount = json.pageAmount;
 62+ t.stories.push(json);
 63+ t.isLoading = false;
 64+
 65+ jQuery("#storyboard-loading").remove();
 66+
 67+ t.display();
 68+ });
 69+};
 70+
 71+/**
 72+ * Display method.
 73+ * Creates the storyboard layout.
 74+ */
 75+Storyboard.prototype.display = function() {
 76+ alert('display');
 77+};
 78+
 79+/**
 80+ * Reload method.
 81+ * Removes all stories from the storyboard and loads a new batch of stories.
 82+ */
 83+Storyboard.prototype.reload = function() {
 84+ jQuery("#storyboard").html("");
 85+ this.stories = [];
 86+ this.pageNumber = 0;
 87+ this.loadAjax();
 88+};
\ No newline at end of file
Property changes on: trunk/extensions/Storyboard/tags/Storyboard/Storyboard.js
___________________________________________________________________
Added: svn:eol-style
189 + native
Index: trunk/extensions/Storyboard/tags/Storyboard/Storyboard_body.php
@@ -0,0 +1,41 @@
 2+<?php
 3+
 4+/**
 5+ * File holding the rendering function for the Storyboard tag.
 6+ *
 7+ * @file Storyboard_body.php
 8+ * @ingroup Storyboard
 9+ *
 10+ * @author Jeroen De Dauw
 11+ */
 12+
 13+if ( !defined( 'MEDIAWIKI' ) ) {
 14+ die( 'Not an entry point.' );
 15+}
 16+
 17+class TagStoryboard {
 18+
 19+ public static function render( $input, $args, $parser, $frame ) {
 20+ global $wgOut, $wgJsMimeType, $egStoryboardScriptPath;
 21+
 22+ $wgOut->addStyle($egStoryboardScriptPath . '/tags/Storyboard/Storyboard.css');
 23+ $wgOut->includeJQuery();
 24+ $wgOut->addScriptFile($egStoryboardScriptPath . '/tags/Storyboard/Storyboard.js');
 25+
 26+ $output = <<<END
 27+<script type="$wgJsMimeType">var storyboardPath = '$egStoryboardScriptPath';</script>
 28+<div id="storyboard"></div>
 29+<script type="$wgJsMimeType"> /*<![CDATA[*/
 30+ jQuery(document).ready(function(){ jQuery("p").click(function(){ jQuery(this).hide(); }); });
 31+ var storyboard = new Storyboard();
 32+ storyboard.loadAjax();
 33+/*]]>*/ </script>
 34+END;
 35+
 36+ return array($output, 'noparse' => 'true', 'isHTML' => 'true');
 37+ }
 38+
 39+}
 40+
 41+
 42+
Property changes on: trunk/extensions/Storyboard/tags/Storyboard/Storyboard_body.php
___________________________________________________________________
Added: svn:eol-style
143 + native
Index: trunk/extensions/Storyboard/tags/Storyboard/Stories.php
@@ -0,0 +1,11 @@
 2+<?php
 3+
 4+/**
 5+ * Webservice for fetching stories from the Storyboard extension.
 6+ *
 7+ * @file Stories.php
 8+ * @ingroup Storyboard
 9+ *
 10+ * @author Jeroen De Dauw
 11+ */
 12+
Property changes on: trunk/extensions/Storyboard/tags/Storyboard/Stories.php
___________________________________________________________________
Added: svn:eol-style
113 + native
Index: trunk/extensions/Storyboard/tags/Storysubmission/Storysubmission_body.php
@@ -0,0 +1,26 @@
 2+<?php
 3+
 4+/**
 5+ * File holding the rendering function for the Storysubmission tag.
 6+ *
 7+ * @file Storysubmission_body.php
 8+ * @ingroup Storyboard
 9+ *
 10+ * @author Jeroen De Dauw
 11+ */
 12+
 13+if ( !defined( 'MEDIAWIKI' ) ) {
 14+ die( 'Not an entry point.' );
 15+}
 16+
 17+class TagStorysubmission {
 18+
 19+ // http://www.mediawiki.org/wiki/Manual:Forms
 20+ // http://www.mediawiki.org/wiki/Manual:Hooks/UnknownAction
 21+ public static function render( $input, $args, $parser, $frame ) {
 22+ return <<<END
 23+
 24+END;
 25+ }
 26+
 27+}
\ No newline at end of file
Property changes on: trunk/extensions/Storyboard/tags/Storysubmission/Storysubmission_body.php
___________________________________________________________________
Added: svn:eol-style
128 + native

Comments

#Comment by Catrope (talk | contribs)   18:58, 22 February 2010

jQuery(document).ready(function(){ jQuery("p").click(function(){ jQuery(this).hide(); }); }); shouldn't be in the _body.php file, but in the .js file. I also suggest rewriting the .js file as a jQuery plugin, so it hardcodes #storyboard in one place only and won't need to use an ID for storyboard-loading (a class plus storing a jQuery reference using .data() should do). Also, wrap the code in (function($) { ... code here ... })(jQuery); so you can use $ instead of jQuery in your code without worrying about whether $ is defined globally.

The .css file contains multiple rules for the same selector in different parts of the file, sometimes even right after each other. You should merge all these for readability.

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

Thanks for the feedback :)

That one line should not be there at all actually, accidentally put it in the code. Part of the code in this commit (inc the css) is based on some other stuff, so it'll take me a while to clean it out completely.

#Comment by 😂 (talk | contribs)   01:52, 5 March 2010

Marking resolved, original issues have long since been fixed.

Status & tagging log