r93392 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93391‎ | r93392 | r93393 >
Date:15:34, 28 July 2011
Author:jeroendedauw
Status:ok (Comments)
Tags:
Comment:
made tutorial template, tutorial with and tutorial image map configurable per campaign
Modified paths:
  • /trunk/extensions/UploadWizard/includes/UploadWizardTutorial.php (modified) (history)
  • /trunk/extensions/UploadWizard/includes/specials/SpecialUploadWizard.php (modified) (history)

Diff [purge]

Index: trunk/extensions/UploadWizard/includes/UploadWizardTutorial.php
@@ -7,26 +7,17 @@
88 */
99 class UploadWizardTutorial {
1010
11 - // name of the tutorial on Wikimedia Commons. The $1 is replaced with the language desired
12 - const NAME_TEMPLATE = 'Licensing_tutorial_$1.svg';
13 -
14 - // the width we want to scale the tutorial to, for our interface
15 - const WIDTH_PX = 720;
16 -
17 - // imagemap coordinates of the "helpdesk" button at the bottom, which is supposed to be clickable.
18 - const HELPDESK_BUTTON_COORDS = "27, 1319, 691, 1384";
19 -
20 - // id of imagemap used in tutorial
 11+ // Id of imagemap used in tutorial.
2112 const IMAGEMAP_ID = 'tutorialMap';
2213
2314 /**
2415 * Fetches appropriate HTML for the tutorial portion of the wizard.
2516 * Looks up an image on the current wiki. This will work as is on Commons, and will also work
2617 * on test wikis that enable instantCommons.
27 - * @param {String} $langCode language code as used by MediaWiki, similar but not identical to ISO 639-1.
28 - * @return {String} html that will display the tutorial.
 18+ * @param String|null $campaign Upload Wizard campaign for which the tutorial should be displayed.
 19+ * @return String html that will display the tutorial.
2920 */
30 - public static function getHtml() {
 21+ public static function getHtml( $campaign = null ) {
3122 global $wgLang;
3223
3324 $error = null;
@@ -37,10 +28,10 @@
3829
3930 $tutorialFile = false;
4031 // getFile returns false if it can't find the right file
41 - if ( ! $tutorialFile = self::getFile( $langCode ) ) {
 32+ if ( ! $tutorialFile = self::getFile( $langCode, $campaign ) ) {
4233 $error = 'localized-file-missing';
4334 if ( $langCode !== 'en' ) {
44 - $tutorialFile = self::getFile( 'en' );
 35+ $tutorialFile = self::getFile( 'en', $campaign );
4536 }
4637 }
4738
@@ -57,7 +48,8 @@
5849 // put it into a div of appropriate dimensions.
5950
6051 // n.b. File::transform() returns false if failed, MediaTransformOutput otherwise
61 - $thumbnailImage = $tutorialFile->transform( array( 'width' => self::WIDTH_PX ) );
 52+ $thumbnailImage = $tutorialFile->transform( array( 'width' => UploadWizardConfig::getSetting( 'tutorialWidth', $campaign ) ) );
 53+
6254 if ( $thumbnailImage ) {
6355 $tutorialHtml = self::getImageHtml( $thumbnailImage );
6456 } else {
@@ -77,51 +69,73 @@
7870
7971 /**
8072 * Get tutorial file for a particular language, or false if not available.
81 - * @param {String} $langCode: language Code
82 - * @return {File|false}
 73+ *
 74+ * @param String $langCode: language Code
 75+ * @param String|null $campaign Upload Wizard campaign for which the tutorial should be displayed.
 76+ *
 77+ * @return File|false
8378 */
84 - public static function getFile( $langCode ) {
85 - $tutorialName = str_replace( '$1', $langCode, self::NAME_TEMPLATE );
86 - $tutorialTitle = Title::newFromText( $tutorialName, NS_FILE );
87 - return wfFindFile( $tutorialTitle );
 79+ public static function getFile( $langCode, $campaign = null ) {
 80+ $tutorialName = str_replace( '$1', $langCode, UploadWizardConfig::getSetting( 'tutorialTemplate', $campaign ) );
 81+ return wfFindFile( Title::newFromText( $tutorialName, NS_FILE ) );
8882 }
8983
9084 /**
9185 * Constructs HTML for the tutorial (laboriously), including an imagemap for the clickable "Help desk" button.
92 - * @param {ThumbnailImage} $thumb
93 - * @return {String} HTML representing the image, with clickable helpdesk button
 86+ *
 87+ * @param MediaTransformOutput $thumb
 88+ * @param String|null $campaign Upload Wizard campaign for which the tutorial should be displayed.
 89+ *
 90+ * @return String HTML representing the image, with clickable helpdesk button
9491 */
95 - public static function getImageHtml( $thumb ) {
96 -
97 - $helpDeskUrl = wfMsg( 'mwe-upwiz-help-desk-url' );
 92+ public static function getImageHtml( MediaTransformOutput $thumb, $campaign = null ) {
 93+ $helpDeskUrl = wfMsg( 'mwe-upwiz-help-desk-url' );
9894
99 - // Per convention, we may be either using an absolute URL or a wiki page title in this UI message
100 - if( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $helpDeskUrl )) {
101 - $helpDeskHref = $helpDeskUrl;
102 - } else {
103 - $helpDeskTitle = Title::newFromText( $helpDeskUrl );
104 - $helpDeskHref = $helpDeskTitle ? $helpDeskTitle->getLocalURL() : '#';
105 - }
 95+ // Per convention, we may be either using an absolute URL or a wiki page title in this UI message
 96+ if( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $helpDeskUrl )) {
 97+ $helpDeskHref = $helpDeskUrl;
 98+ } else {
 99+ $helpDeskTitle = Title::newFromText( $helpDeskUrl );
 100+ $helpDeskHref = $helpDeskTitle ? $helpDeskTitle->getLocalURL() : '#';
 101+ }
 102+
 103+ $buttonCoords = UploadWizardConfig::getSetting( 'tutorialHelpdeskCoords', $campaign );
 104+ $useMap = $buttonCoords !== false && trim( $buttonCoords ) != '';
106105
 106+ $imgAttributes = array(
 107+ 'src' => $thumb->getUrl(),
 108+ 'width' => $thumb->getWidth(),
 109+ 'height' => $thumb->getHeight(),
 110+ );
 111+
 112+ if ( $useMap ) {
 113+ $imgAttributes['usemap'] = '#' . self::IMAGEMAP_ID;
 114+ }
 115+
107116 // here we use the not-yet-forgotten HTML imagemap to add a clickable area to the tutorial image.
108117 // we could do more special effects with hovers and images and such, not to mention SVG scripting,
109118 // but we aren't sure what we want yet...
110 - $img = Html::element( 'img', array(
111 - 'src' => $thumb->getUrl(),
112 - 'width' => $thumb->getWidth(),
113 - 'height' => $thumb->getHeight(),
114 - 'usemap' => '#' . self::IMAGEMAP_ID
115 - ) );
116 - $areaAltText = wfMsg( 'mwe-upwiz-help-desk' );
117 - $area = Html::element( 'area', array(
118 - 'shape' => 'rect',
119 - 'coords' => self::HELPDESK_BUTTON_COORDS,
120 - 'href' => $helpDeskHref,
121 - 'alt' => $areaAltText,
122 - 'title' => $areaAltText
123 - ) );
124 - $map = Html::rawElement( 'map', array( 'id' => self::IMAGEMAP_ID, 'name' => self::IMAGEMAP_ID ), $area );
125 - return $map . $img;
 119+ $imgHtml = Html::element( 'img', $imgAttributes );
 120+
 121+ if ( $useMap ) {
 122+ $areaAltText = wfMsg( 'mwe-upwiz-help-desk' );
 123+
 124+ $area = Html::element( 'area', array(
 125+ 'shape' => 'rect',
 126+ 'coords' => $buttonCoords,
 127+ 'href' => $helpDeskHref,
 128+ 'alt' => $areaAltText,
 129+ 'title' => $areaAltText
 130+ ) );
 131+
 132+ $imgHtml = Html::rawElement(
 133+ 'map',
 134+ array( 'id' => self::IMAGEMAP_ID, 'name' => self::IMAGEMAP_ID ),
 135+ $area
 136+ ) . $imgHtml;
 137+ }
 138+
 139+ return $imgHtml;
126140 }
127141
128142 }
Index: trunk/extensions/UploadWizard/includes/specials/SpecialUploadWizard.php
@@ -214,7 +214,7 @@
215215 // only load the tutorial HTML if we aren't skipping the first step
216216 // TODO should use user preference not a cookie ( so the user does not have to skip it for every browser )
217217 if ( !isset( $_COOKIE['skiptutorial'] ) && !$globalConf['skipTutorial'] ) {
218 - $tutorialHtml = UploadWizardTutorial::getHtml();
 218+ $tutorialHtml = UploadWizardTutorial::getHtml( $this->campaign );
219219 }
220220
221221 // TODO move this into UploadWizard.js or some other javascript resource so the upload wizard

Follow-up revisions

RevisionCommit summaryAuthorDate
r93395fu r93392; made new config appear in campaign admin uijeroendedauw15:44, 28 July 2011

Comments

#Comment by NeilK (talk | contribs)   13:17, 22 August 2011

Doing the help text button was not part of the spec at all, but okay. We would have been happy with a splash screen to replace the tutorial.

The help text button was a badly implemented idea in the first place.

Status & tagging log