Index: trunk/extensions/UploadWizard/includes/UploadWizardTutorial.php |
— | — | @@ -7,26 +7,17 @@ |
8 | 8 | */ |
9 | 9 | class UploadWizardTutorial { |
10 | 10 | |
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. |
21 | 12 | const IMAGEMAP_ID = 'tutorialMap'; |
22 | 13 | |
23 | 14 | /** |
24 | 15 | * Fetches appropriate HTML for the tutorial portion of the wizard. |
25 | 16 | * Looks up an image on the current wiki. This will work as is on Commons, and will also work |
26 | 17 | * 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. |
29 | 20 | */ |
30 | | - public static function getHtml() { |
| 21 | + public static function getHtml( $campaign = null ) { |
31 | 22 | global $wgLang; |
32 | 23 | |
33 | 24 | $error = null; |
— | — | @@ -37,10 +28,10 @@ |
38 | 29 | |
39 | 30 | $tutorialFile = false; |
40 | 31 | // getFile returns false if it can't find the right file |
41 | | - if ( ! $tutorialFile = self::getFile( $langCode ) ) { |
| 32 | + if ( ! $tutorialFile = self::getFile( $langCode, $campaign ) ) { |
42 | 33 | $error = 'localized-file-missing'; |
43 | 34 | if ( $langCode !== 'en' ) { |
44 | | - $tutorialFile = self::getFile( 'en' ); |
| 35 | + $tutorialFile = self::getFile( 'en', $campaign ); |
45 | 36 | } |
46 | 37 | } |
47 | 38 | |
— | — | @@ -57,7 +48,8 @@ |
58 | 49 | // put it into a div of appropriate dimensions. |
59 | 50 | |
60 | 51 | // 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 | + |
62 | 54 | if ( $thumbnailImage ) { |
63 | 55 | $tutorialHtml = self::getImageHtml( $thumbnailImage ); |
64 | 56 | } else { |
— | — | @@ -77,51 +69,73 @@ |
78 | 70 | |
79 | 71 | /** |
80 | 72 | * 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 |
83 | 78 | */ |
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 ) ); |
88 | 82 | } |
89 | 83 | |
90 | 84 | /** |
91 | 85 | * 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 |
94 | 91 | */ |
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' ); |
98 | 94 | |
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 ) != ''; |
106 | 105 | |
| 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 | + |
107 | 116 | // here we use the not-yet-forgotten HTML imagemap to add a clickable area to the tutorial image. |
108 | 117 | // we could do more special effects with hovers and images and such, not to mention SVG scripting, |
109 | 118 | // 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; |
126 | 140 | } |
127 | 141 | |
128 | 142 | } |
Index: trunk/extensions/UploadWizard/includes/specials/SpecialUploadWizard.php |
— | — | @@ -214,7 +214,7 @@ |
215 | 215 | // only load the tutorial HTML if we aren't skipping the first step |
216 | 216 | // TODO should use user preference not a cookie ( so the user does not have to skip it for every browser ) |
217 | 217 | if ( !isset( $_COOKIE['skiptutorial'] ) && !$globalConf['skipTutorial'] ) { |
218 | | - $tutorialHtml = UploadWizardTutorial::getHtml(); |
| 218 | + $tutorialHtml = UploadWizardTutorial::getHtml( $this->campaign ); |
219 | 219 | } |
220 | 220 | |
221 | 221 | // TODO move this into UploadWizard.js or some other javascript resource so the upload wizard |