Index: trunk/extensions/UploadWizard/UploadWizard.i18n.php |
— | — | @@ -32,7 +32,9 @@ |
33 | 33 | 'mwe-upwiz-step-details' => 'Describe', |
34 | 34 | 'mwe-upwiz-step-thanks' => 'Use', |
35 | 35 | 'mwe-upwiz-api-error-code' => 'API error code: $1', |
36 | | - 'mwe-upwiz-tutorial-error' => 'A tutorial about what images you can upload to this wiki should appear here. Please contact the system administrator.', |
| 36 | + 'mwe-upwiz-tutorial-error-localized-file-missing' => 'Sorry, we could not find a tutorial in your language. The English one is shown instead.', |
| 37 | + 'mwe-upwiz-tutorial-error-file-missing' => 'Sorry, we could not find any files for the tutorial that is supposed to go here. Please contact the system administrators.', |
| 38 | + 'mwe-upwiz-tutorial-error-cannot-transform' => 'Sorry, we could not get a scaled image of the tutorial to fit this screen. This may be a temporary problem with Wikimedia Commons; try again later.', |
37 | 39 | 'mwe-upwiz-help-desk' => 'Help Desk', |
38 | 40 | 'mwe-upwiz-intro' => "Welcome to Wikimedia Commons, a repository of images, sounds and movies that anyone can freely download and use. |
39 | 41 | Add to humanity's knowledge by uploading files that could be used for an educational purpose.", |
Index: trunk/extensions/UploadWizard/SpecialUploadWizard.php |
— | — | @@ -53,7 +53,7 @@ |
54 | 54 | * @param subpage, e.g. the "foo" in Special:UploadWizard/foo. |
55 | 55 | */ |
56 | 56 | public function execute( $subPage ) { |
57 | | - global $wgLang, $wgUser, $wgOut, $wgLanguageCode, $wgExtensionAssetsPath, |
| 57 | + global $wgLang, $wgUser, $wgOut, $wgExtensionAssetsPath, |
58 | 58 | $wgUploadWizardDebug, $wgUploadWizardDisableResourceLoader; |
59 | 59 | |
60 | 60 | // side effects: if we can't upload, will print error page to wgOut |
— | — | @@ -81,7 +81,7 @@ |
82 | 82 | $wgOut->addModules( 'ext.uploadWizard' ); |
83 | 83 | } else { |
84 | 84 | $basepath = "$wgExtensionAssetsPath/UploadWizard"; |
85 | | - $dependencyLoader = new UploadWizardDependencyLoader( $wgLanguageCode ); |
| 85 | + $dependencyLoader = new UploadWizardDependencyLoader( $wgLang->getCode() ); |
86 | 86 | if ( $wgUploadWizardDebug ) { |
87 | 87 | // each file as an individual script or style |
88 | 88 | $dependencyLoader->outputHtmlDebug( $wgOut, $basepath ); |
— | — | @@ -191,22 +191,35 @@ |
192 | 192 | * @return {String} html that will display the tutorial. |
193 | 193 | */ |
194 | 194 | function getTutorialHtml() { |
195 | | - global $wgLanguageCode; |
| 195 | + global $wgLang; |
196 | 196 | |
197 | | - // assume failure (this will be replaced if we're successful) |
198 | | - $tutorialHtml = '<p class="errorbox">' . wfMsg( 'mwe-upwiz-tutorial-error' ) . '</p>'; |
| 197 | + $error = null; |
| 198 | + $errorHtml = ''; |
| 199 | + $tutorialHtml = ''; |
199 | 200 | |
200 | 201 | // get a valid language code, even if the global is wrong |
201 | | - $langCode = $wgLanguageCode; |
| 202 | + if ( $wgLang ) { |
| 203 | + $langCode = $wgLang->getCode(); |
| 204 | + } |
202 | 205 | if ( !isset( $langCode) or $langCode === '' ) { |
203 | 206 | $langCode = 'en'; |
204 | 207 | } |
205 | 208 | |
206 | | - $tutorialName = str_replace( '$1', $langCode, self::TUTORIAL_NAME_TEMPLATE ); |
207 | | - $tutorialTitle = Title::newFromText( $tutorialName, NS_FILE ); |
| 209 | + $tutorialFile = false; |
| 210 | + // getTutorialFile returns false if it can't find the right file |
| 211 | + if ( ! $tutorialFile = self::getTutorialFile( $langCode ) ) { |
| 212 | + $error = 'localized-file-missing'; |
| 213 | + if ( $langCode !== 'en' ) { |
| 214 | + $tutorialFile = self::getTutorialFile( 'en' ); |
| 215 | + } |
| 216 | + } |
208 | 217 | |
209 | | - // wfFindFile() returns a File object, or false |
210 | | - if ( $tutorialFile = wfFindFile( $tutorialTitle ) ) { |
| 218 | + // at this point, we have one of the following situations: |
| 219 | + // $errors is empty, and tutorialFile is the right one for this language |
| 220 | + // $errors notes we couldn't find the tutorialFile for your language, and $tutorialFile is the english one |
| 221 | + // $errors notes we couldn't find the tutorialFile for your language, and $tutorialFile is still false |
| 222 | + |
| 223 | + if ( $tutorialFile ) { |
211 | 224 | // XXX TODO if the client can handle SVG, we could also just send it the unscaled thumb, client-scaled into a DIV or something. |
212 | 225 | // if ( client can handle SVG ) { |
213 | 226 | // $tutorialThumbnailImage->getUnscaledThumb(); |
— | — | @@ -214,34 +227,62 @@ |
215 | 228 | // put it into a div of appropriate dimensions. |
216 | 229 | |
217 | 230 | // n.b. File::transform() returns false if failed, MediaTransformOutput otherwise |
218 | | - if ( $tutorialThumbnailImage = $tutorialFile->transform( array( 'width' => self::TUTORIAL_WIDTH_PX ) ) ) { |
219 | | - // here we use the not-yet-forgotten HTML imagemap to add a clickable area to the tutorial image. |
220 | | - // we could do more special effects with hovers and images and such, not to mention SVG scripting, |
221 | | - // but we aren't sure what we want yet... |
222 | | - $img = Html::element( 'img', array( |
223 | | - 'src' => $tutorialThumbnailImage->getUrl(), |
224 | | - 'width' => $tutorialThumbnailImage->getWidth(), |
225 | | - 'height' => $tutorialThumbnailImage->getHeight(), |
226 | | - 'usemap' => '#' . self::TUTORIAL_IMAGEMAP_ID |
227 | | - ) ); |
228 | | - $areaAltText = wfMsg( 'mwe-upwiz-help-desk' ); |
229 | | - $area = Html::element( 'area', array( |
230 | | - 'shape' => 'rect', |
231 | | - 'coords' => self::TUTORIAL_HELPDESK_BUTTON_COORDS, |
232 | | - 'href' => self::TUTORIAL_HELPDESK_URL, |
233 | | - 'alt' => $areaAltText, |
234 | | - 'title' => $areaAltText |
235 | | - ) ); |
236 | | - $map = Html::rawElement( 'map', array( 'id' => self::TUTORIAL_IMAGEMAP_ID, 'name' => self::TUTORIAL_IMAGEMAP_ID ), $area ); |
237 | | - $tutorialHtml = $map . $img; |
| 231 | + if ( $thumbnailImage = $tutorialFile->transform( array( 'width' => self::TUTORIAL_WIDTH_PX ) ) ) { |
| 232 | + $tutorialHtml = self::getTutorialImageHtml( $thumbnailImage ); |
| 233 | + } else { |
| 234 | + $errors = 'cannot-transform'; |
238 | 235 | } |
| 236 | + } else { |
| 237 | + $error = 'file-missing'; |
239 | 238 | } |
| 239 | + |
| 240 | + if ( isset( $error ) ) { |
| 241 | + $errorHtml = Html::element( 'p', array( 'class' => 'errorbox', 'style' => 'float: none;' ), wfMsg( 'mwe-upwiz-tutorial-error-' . $error ) ); |
| 242 | + } |
| 243 | + |
| 244 | + return $errorHtml . $tutorialHtml; |
240 | 245 | |
241 | | - return $tutorialHtml; |
242 | | - |
243 | 246 | } |
244 | 247 | |
245 | 248 | /** |
| 249 | + * Get tutorial file for a particular language, or false if not available. |
| 250 | + * @param {String} $langCode: language Code |
| 251 | + * @return {File|false} |
| 252 | + */ |
| 253 | + function getTutorialFile( $langCode ) { |
| 254 | + $tutorialName = str_replace( '$1', $langCode, self::TUTORIAL_NAME_TEMPLATE ); |
| 255 | + $tutorialTitle = Title::newFromText( $tutorialName, NS_FILE ); |
| 256 | + return wfFindFile( $tutorialTitle ); |
| 257 | + } |
| 258 | + |
| 259 | + /** |
| 260 | + * Constructs HTML for the tutorial (laboriously), including an imagemap for the clickable "Help desk" button. |
| 261 | + * @param {ThumbnailImage} $thumb |
| 262 | + * @return {String} HTML representing the image, with clickable helpdesk button |
| 263 | + */ |
| 264 | + function getTutorialImageHtml( $thumb ) { |
| 265 | + // here we use the not-yet-forgotten HTML imagemap to add a clickable area to the tutorial image. |
| 266 | + // we could do more special effects with hovers and images and such, not to mention SVG scripting, |
| 267 | + // but we aren't sure what we want yet... |
| 268 | + $img = Html::element( 'img', array( |
| 269 | + 'src' => $thumb->getUrl(), |
| 270 | + 'width' => $thumb->getWidth(), |
| 271 | + 'height' => $thumb->getHeight(), |
| 272 | + 'usemap' => '#' . self::TUTORIAL_IMAGEMAP_ID |
| 273 | + ) ); |
| 274 | + $areaAltText = wfMsg( 'mwe-upwiz-help-desk' ); |
| 275 | + $area = Html::element( 'area', array( |
| 276 | + 'shape' => 'rect', |
| 277 | + 'coords' => self::TUTORIAL_HELPDESK_BUTTON_COORDS, |
| 278 | + 'href' => self::TUTORIAL_HELPDESK_URL, |
| 279 | + 'alt' => $areaAltText, |
| 280 | + 'title' => $areaAltText |
| 281 | + ) ); |
| 282 | + $map = Html::rawElement( 'map', array( 'id' => self::TUTORIAL_IMAGEMAP_ID, 'name' => self::TUTORIAL_IMAGEMAP_ID ), $area ); |
| 283 | + return $map . $img; |
| 284 | + } |
| 285 | + |
| 286 | + /** |
246 | 287 | * Return the basic HTML structure for the entire page |
247 | 288 | * Will be enhanced by the javascript to actually do stuff |
248 | 289 | * @return {String} html |