r64471 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r64470‎ | r64471 | r64472 >
Date:04:45, 1 April 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Finished up work on image manipulation (hide, show & delete) on Special:StoryReview.
Modified paths:
  • /trunk/extensions/Storyboard/specials/StoryReview/StoryReview_body.php (modified) (history)
  • /trunk/extensions/Storyboard/storyboard.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Storyboard/specials/StoryReview/StoryReview_body.php
@@ -56,6 +56,7 @@
5757 'story_title',
5858 'story_text',
5959 'story_is_published',
 60+ 'story_author_image',
6061 'story_image_hidden'
6162 ),
6263 array( 'story_is_hidden' => 0 )
@@ -96,33 +97,58 @@
9798 * @return string
9899 */
99100 private function getStorySegments( $story ) {
100 - $imageSrc = 'http://upload.wikimedia.org/wikipedia/mediawiki/9/99/SemanticMaps.png'; // TODO: get cropped image here
 101+ global $wgTitle;
101102
 103+ $editUrl = SpecialPage::getTitleFor( 'story', $story->story_title )->getFullURL('action=edit&returnto=' . $wgTitle->getPrefixedText() );
 104+ $editUrl = Xml::escapeJsString( $editUrl );
 105+
102106 $title = htmlspecialchars( $story->story_title );
103107 $text = htmlspecialchars( $story->story_text );
104108
105109 $publishAction = $story->story_is_published ? 'unpublish' : 'publish';
106 - // Uses storyboard-unpublish or storyboard-publish
107 - $publishMsg = htmlspecialchars( wfMsg( "storyboard-$publishAction" ) );
 110+ // Uses storyboard-unpublish or storyboard-publish.
 111+ $publishMsg = htmlspecialchars( wfMsg( "storyboard-$publishAction" ) );
108112
109 - $imageAction = $story->story_image_hidden ? 'unhideimage' : 'hideimage';
110 - // Uses storyboard-unhideimage or storyboard-hideimage
111 - $imageMsg = htmlspecialchars( wfMsg( "storyboard-$imageAction" ) );
112 -
113113 $editMsg = htmlspecialchars( wfMsg( 'edit' ) );
114 - $hideMsg = htmlspecialchars( wfMsg( 'hide' ) );
115 - $deleteImageMsg = htmlspecialchars( wfMsg( 'storyboard-deleteimage' ) );
 114+ $hideMsg = htmlspecialchars( wfMsg( 'hide' ) );
116115
117 - global $wgTitle;
118 - $editUrl = SpecialPage::getTitleFor( 'story', $story->story_title )->getFullURL('action=edit&returnto=' . $wgTitle->getPrefixedText() );
119 - $editUrl = Xml::escapeJsString( $editUrl );
 116+ $imageHtml = '';
 117+ $imageButtonsHtml = '';
120118
 119+ if ( $story->story_author_image ) {
 120+ $imageAction = $story->story_image_hidden ? 'unhideimage' : 'hideimage';
 121+ // Uses storyboard-unhideimage or storyboard-hideimage.
 122+ $imageMsg = htmlspecialchars( wfMsg( "storyboard-$imageAction" ) );
 123+
 124+ $deleteImageMsg = htmlspecialchars( wfMsg( 'storyboard-deleteimage' ) );
 125+
 126+ $imgAttribs = array(
 127+ 'src' => $story->story_author_image,
 128+ 'class' => 'story-image',
 129+ 'id' => "story_image_$story->story_id",
 130+ 'title' => $title,
 131+ 'alt' => $title
 132+ );
 133+
 134+ if ( $story->story_image_hidden ) {
 135+ $imgAttribs['style'] = 'display:none;';
 136+ }
 137+
 138+ $imageHtml = Html::element( 'img', $imgAttribs );
 139+
 140+ $imageButtonsHtml = <<<EOT
 141+ &nbsp;&nbsp;&nbsp;<button type="button"
 142+ onclick="stbDoStoryAction( this, $story->story_id, '$imageAction' )" id="image_button_$story->story_id">$imageMsg</button>
 143+ &nbsp;&nbsp;&nbsp;<button type="button" onclick="stbDeleteStoryImage( this, $story->story_id )">$deleteImageMsg</button>
 144+EOT;
 145+ }
 146+
121147 return <<<EOT
122148 <table width="100%" border="1" id="story_$story->story_id">
123149 <tr>
124150 <td>
125151 <div class="story">
126 - <img src="http://upload.wikimedia.org/wikipedia/mediawiki/9/99/SemanticMaps.png" class="story-image">
 152+ $imageHtml
127153 <div class="story-title">$title</div><br />
128154 $text
129155 </div>
@@ -132,9 +158,7 @@
133159 <td align="center" height="35">
134160 <button type="button" onclick="stbDoStoryAction( this, $story->story_id, '$publishAction' )">$publishMsg</button>&nbsp;&nbsp;&nbsp;
135161 <button type="button" onclick="window.location='$editUrl'">$editMsg</button>&nbsp;&nbsp;&nbsp;
136 - <button type="button" onclick="stbDoStoryAction( this, $story->story_id, 'hide' )">$hideMsg</button>&nbsp;&nbsp;&nbsp;
137 - <button type="button" onclick="stbDoStoryAction( this, $story->story_id, '$imageAction' )">$imageMsg</button>&nbsp;&nbsp;&nbsp;
138 - <button type="button" onclick="stbDeleteStoryImage( this, $story->story_id )">$deleteImageMsg</button>
 162+ <button type="button" onclick="stbDoStoryAction( this, $story->story_id, 'hide' )">$hideMsg</button>$imageButtonsHtml
139163 </td>
140164 </tr>
141165 </table>
Index: trunk/extensions/Storyboard/storyboard.js
@@ -98,12 +98,22 @@
9999 if ( data.storyreview ) {
100100 switch( data.storyreview.action ) {
101101 case 'publish' : case 'unpublish' : case 'hide' :
 102+ sender.innerHTML = 'Done'; // TODO: i18n
102103 jQuery( '#story_' + data.storyreview.id ).slideUp( 'slow', function () {
103104 jQuery( this ).remove();
104105 } );
105106 // TODO: would be neat to update the other list when doing an (un)publish here
106107 break;
107 - // TODO: add handling for the other actions
 108+ case 'hideimage' : case 'unhideimage' :
 109+ stbToggeShowImage( sender, data.storyreview.id, data.storyreview.action );
 110+ break;
 111+ case 'deleteimage' :
 112+ sender.innerHTML = 'Image deleted'; // TODO: i18n
 113+ jQuery( '#story_image_' + data.storyreview.id ).slideUp( 'slow', function () {
 114+ jQuery( this ).remove();
 115+ } );
 116+ document.getElementById( 'image_button_' + data.storyreview.id ).disabled = true;
 117+ break;
108118 }
109119 } else {
110120 alert( 'An error occured:\n' + data.error.info ); // TODO: i18n
@@ -113,6 +123,35 @@
114124 }
115125
116126 /**
 127+ * Updates the show/hide image button after a hideimage/unhideimage
 128+ * action has completed sucesfully. Also updates the image on the
 129+ * page itself accordingly, and hooks up the correct event to the button.
 130+ *
 131+ * @param sender The button that invoked the completed action.
 132+ * @param storyId The id of the story that has been affected.
 133+ * @param completedAction The name ofthe action that has been performed.
 134+ */
 135+function stbToggeShowImage( sender, storyId, completedAction ) {
 136+ if ( completedAction == 'hideimage' ) {
 137+ jQuery( '#story_image_' + storyId ).slideUp( 'slow', function () {
 138+ sender.innerHTML = 'Show image'; // TODO: i18n
 139+ sender.onclick = function() {
 140+ stbDoStoryAction( sender, storyId, 'unhideimage' );
 141+ };
 142+ sender.disabled = false;
 143+ } );
 144+ } else {
 145+ jQuery( '#story_image_' + storyId ).slideDown( 'slow', function () {
 146+ sender.innerHTML = 'Hide image'; // TODO: i18n
 147+ sender.onclick = function() {
 148+ stbDoStoryAction( sender, storyId, 'hideimage' );
 149+ };
 150+ sender.disabled = false;
 151+ } );
 152+ }
 153+}
 154+
 155+/**
117156 * Asks the user to confirm the deletion of an image, and if confirmed, calls stbDoStoryAction with action=delete.
118157 *
119158 * @param sender The UI element invocing the action, typically a button.
@@ -123,7 +162,7 @@
124163 function stbDeleteStoryImage( sender, storyid ) {
125164 var confirmed = confirm( 'Are you sure you want to permanently delete this stories image?' ); // TODO: i18n
126165 if ( confirmed ) {
127 - doStoryAction( sender, storyid, 'deleteimage' );
 166+ stbDoStoryAction( sender, storyid, 'deleteimage' );
128167 }
129168 return confirmed;
130169 }
\ No newline at end of file

Status & tagging log