Index: trunk/extensions/MultiUpload/MultiUpload.body.php |
— | — | @@ -1,30 +1,28 @@ |
2 | 2 | <?php |
3 | 3 | /** |
| 4 | + * Form for handling multiple uploads and special page. |
| 5 | + * |
4 | 6 | * @file |
5 | 7 | * @ingroup SpecialPage |
6 | 8 | * @ingroup Upload |
7 | | - * |
8 | | - * Form for handling multiple uploads and special page. |
9 | | - * |
10 | 9 | */ |
11 | 10 | |
12 | 11 | class MultipleUpload extends SpecialUpload { |
13 | | - /** |
14 | | - * Constructor : initialise object |
15 | | - * Get data POSTed through the form and assign them to the object |
16 | | - * @param WebRequest $request Data posted. |
17 | | - */ |
18 | | - |
19 | 12 | public $mDesiredDestNames; |
20 | 13 | public $mUploads; |
21 | 14 | public $mUploadHasBeenShown; |
22 | | - public $mSessionKeys; |
| 15 | + public $mSessionKeys; |
23 | 16 | |
24 | 17 | // status messagse for multiple files |
25 | 18 | public $mWarnings; |
26 | 19 | public $mSuccesses; |
27 | | - public $mErrors; |
| 20 | + public $mErrors; |
28 | 21 | |
| 22 | + /** |
| 23 | + * Constructor : initialise object |
| 24 | + * Get data POSTed through the form and assign them to the object |
| 25 | + * @param WebRequest $request Data posted. |
| 26 | + */ |
29 | 27 | public function __construct( $request = null ) { |
30 | 28 | global $wgRequest; |
31 | 29 | |
— | — | @@ -53,50 +51,52 @@ |
54 | 52 | $this->mUploads = array(); |
55 | 53 | |
56 | 54 | // deal with session keys, if we have some pick the first one, for now |
57 | | - $vals = $request->getValues(); |
58 | | - $fromsession = false; |
59 | | - foreach ($vals as $k=>$v) { |
60 | | - if (preg_match("@^wpSessionKey@", $k)) { |
61 | | - $request->setVal('wpSessionKey', $v); |
| 55 | + $vals = $request->getValues(); |
| 56 | + $fromsession = false; |
| 57 | + foreach ( $vals as $k => $v ) { |
| 58 | + if ( preg_match( "@^wpSessionKey@", $k ) ) { |
| 59 | + $request->setVal( 'wpSessionKey', $v ); |
62 | 60 | $fromsession = true; |
63 | | - $filenum = preg_replace("@wpSessionKey@", "", $k); |
64 | | - $request->setVal('wpDestFile', $request->getVal('wpDestFile' . $filenum)); |
| 61 | + $filenum = preg_replace( "@wpSessionKey@", '', $k ); |
| 62 | + $request->setVal( 'wpDestFile', $request->getVal( 'wpDestFile' . $filenum ) ); |
65 | 63 | $up = UploadBase::createFromRequest( $request ); |
66 | 64 | $this->mUploads[] = $up; |
67 | | - $this->mDesiredDestNames[] = $request->getVal('wpDestFile' . $filenum); |
| 65 | + $this->mDesiredDestNames[] = $request->getVal( 'wpDestFile' . $filenum ); |
68 | 66 | } |
69 | 67 | } |
70 | | - |
71 | | - parent::loadRequest($request); |
72 | 68 | |
73 | | - $this->mUploadClicked = $request->wasPosted() |
74 | | - && ( $request->getCheck( 'wpUpload' ) |
| 69 | + parent::loadRequest( $request ); |
| 70 | + |
| 71 | + $this->mUploadClicked = $request->wasPosted() |
| 72 | + && ( $request->getCheck( 'wpUpload' ) |
75 | 73 | || $request->getCheck( 'wpUploadIgnoreWarning' ) ); |
76 | 74 | |
77 | | - if (!$fromsession) { |
78 | | - for ($i = 0; $i < $wgMaxUploadFiles; $i++) { |
79 | | - $this->mDesiredDestNames[$i] = $request->getText( 'wpDestFile'. $i); |
80 | | - if( !$this->mDesiredDestNames[$i] && $request->getFileName( 'wpUploadFile' . $i) !== null ) |
81 | | - $this->mDesiredDestNames[$i] = $request->getFileName( 'wpUploadFile' . $i); |
82 | | - $request->setVal('wpUploadFile', $_FILES['wpUploadFile' . $i]); |
83 | | - $request->setVal('wpDestFile', $request->getVal('wpDestFile' . $i)); |
84 | | - move_uploaded_file('wpUploadFile' . $i, 'wpUploadFile'); |
| 75 | + if ( !$fromsession ) { |
| 76 | + for ( $i = 0; $i < $wgMaxUploadFiles; $i++ ) { |
| 77 | + $this->mDesiredDestNames[$i] = $request->getText( 'wpDestFile'. $i ); |
| 78 | + if( !$this->mDesiredDestNames[$i] && $request->getFileName( 'wpUploadFile' . $i ) !== null ) { |
| 79 | + $this->mDesiredDestNames[$i] = $request->getFileName( 'wpUploadFile' . $i ); |
| 80 | + } |
| 81 | + $request->setVal( 'wpUploadFile', $_FILES['wpUploadFile' . $i] ); |
| 82 | + $request->setVal( 'wpDestFile', $request->getVal( 'wpDestFile' . $i ) ); |
| 83 | + move_uploaded_file( 'wpUploadFile' . $i, 'wpUploadFile' ); |
85 | 84 | $_FILES['wpUploadFile'] = $_FILES['wpUploadFile' . $i]; |
86 | 85 | $up = UploadBase::createFromRequest( $request ); |
87 | | - $this->mUploads[$i] = $up; |
| 86 | + $this->mUploads[$i] = $up; |
88 | 87 | } |
89 | 88 | } |
90 | | - // |
91 | 89 | $this->mDesiredDestName = $this->mDesiredDestNames[0]; |
92 | 90 | $this->mUpload= $this->mUploads[0]; |
93 | 91 | } |
94 | 92 | |
95 | | - function showUploadForm($form) { |
96 | | - if ($this->mUploadHasBeenShown) |
| 93 | + function showUploadForm( $form ) { |
| 94 | + if ( $this->mUploadHasBeenShown ) { |
97 | 95 | return; |
98 | | - parent::showUploadForm($form); |
| 96 | + } |
| 97 | + parent::showUploadForm( $form ); |
99 | 98 | $this->mUploadHasBeenShown = true; |
100 | 99 | } |
| 100 | + |
101 | 101 | /** |
102 | 102 | * Get an UploadForm instance with title and text properly set. |
103 | 103 | * |
— | — | @@ -106,21 +106,23 @@ |
107 | 107 | */ |
108 | 108 | protected function getUploadForm( $message = '', $sessionKeys = array(), $hideIgnoreWarning = false ) { |
109 | 109 | global $wgOut, $wgMaxUploadFiles; |
110 | | - |
| 110 | + |
111 | 111 | # Initialize form |
112 | 112 | $options = array( |
113 | | - 'watch' => $this->getWatchCheck(), |
114 | | - 'forreupload' => $this->mForReUpload, |
| 113 | + 'watch' => $this->getWatchCheck(), |
| 114 | + 'forreupload' => $this->mForReUpload, |
115 | 115 | 'hideignorewarning' => $hideIgnoreWarning, |
116 | 116 | 'destwarningack' => (bool)$this->mDestWarningAck, |
117 | 117 | 'texttop' => $this->uploadFormTextTop, |
118 | 118 | 'textaftersummary' => $this->uploadFormTextAfterSummary, |
119 | 119 | ); |
120 | | - foreach ($this->mSessionKeys as $f=>$key) |
| 120 | + foreach ( $this->mSessionKeys as $f => $key ) { |
121 | 121 | $options['sessionkey'. $f] = $key; |
122 | | - for ($i = 0; $i < $wgMaxUploadFiles; $i++) |
| 122 | + } |
| 123 | + for ( $i = 0; $i < $wgMaxUploadFiles; $i++ ) { |
123 | 124 | $options['destfile' . $i] = $this->mDesiredDestNames[$i]; |
124 | | - $form = new MultiUploadForm($options); |
| 125 | + } |
| 126 | + $form = new MultiUploadForm( $options ); |
125 | 127 | $form->setTitle( $this->getTitle() ); |
126 | 128 | |
127 | 129 | # Check the token, but only if necessary |
— | — | @@ -130,33 +132,33 @@ |
131 | 133 | } |
132 | 134 | |
133 | 135 | # Add text to form |
134 | | - $form->addPreText( '<div id="uploadtext">' . |
135 | | - wfMsgExt( 'uploadtext', 'parse', array( $this->mDesiredDestName ) ) . |
| 136 | + $form->addPreText( '<div id="uploadtext">' . |
| 137 | + wfMsgExt( 'uploadtext', 'parse', array( $this->mDesiredDestName ) ) . |
136 | 138 | '</div>' ); |
137 | 139 | # Add upload error message |
138 | 140 | $form->addPreText( $message ); |
139 | | - |
| 141 | + |
140 | 142 | # Add footer to form |
141 | 143 | $uploadFooter = wfMsgNoTrans( 'uploadfooter' ); |
142 | 144 | if ( $uploadFooter != '-' && !wfEmptyMsg( 'uploadfooter', $uploadFooter ) ) { |
143 | 145 | $form->addPostText( '<div id="mw-upload-footer-message">' |
144 | 146 | . $wgOut->parse( $uploadFooter ) . "</div>\n" ); |
145 | 147 | } |
146 | | - |
147 | | - return $form; |
148 | 148 | |
| 149 | + return $form; |
149 | 150 | } |
150 | 151 | |
151 | 152 | /** |
152 | | - * Shows the "view X deleted revivions link"" |
| 153 | + * Shows the "view X deleted revivions link" |
153 | 154 | */ |
154 | 155 | protected function showViewDeletedLinks() { |
155 | 156 | global $wgMaxUploadFiles; |
156 | | - for ($i = 0; $i < $wgMaxUploadFiles; $i++) |
157 | | - $this->showViewDeletedLinksInner($this->mDesiredDestNames[$i]); |
| 157 | + for ( $i = 0; $i < $wgMaxUploadFiles; $i++ ) { |
| 158 | + $this->showViewDeletedLinksInner( $this->mDesiredDestNames[$i] ); |
| 159 | + } |
158 | 160 | } |
159 | 161 | |
160 | | - protected function showViewDeletedLinksInner($name) { |
| 162 | + protected function showViewDeletedLinksInner( $name ) { |
161 | 163 | global $wgOut, $wgUser; |
162 | 164 | |
163 | 165 | $title = Title::makeTitleSafe( NS_FILE, $this->mDesiredDestName ); |
— | — | @@ -186,8 +188,8 @@ |
187 | 189 | * Stashes the upload, shows the main form, but adds an "continue anyway button". |
188 | 190 | * Also checks whether there are actually warnings to display. |
189 | 191 | * |
190 | | - * @param array $warnings |
191 | | - * @return boolean true if warnings were displayed, false if there are no |
| 192 | + * @param $warnings Array |
| 193 | + * @return Boolean: true if warnings were displayed, false if there are no |
192 | 194 | * warnings and the should continue processing like there was no warning |
193 | 195 | */ |
194 | 196 | protected function showUploadWarning( $warnings ) { |
— | — | @@ -197,14 +199,13 @@ |
198 | 200 | # mDestWarningAck is set when some javascript has shown the warning |
199 | 201 | # to the user. mForReUpload is set when the user clicks the "upload a |
200 | 202 | # new version" link. |
201 | | - if ( !$warnings || ( count( $warnings ) == 1 && |
202 | | - isset( $warnings['exists'] ) && |
| 203 | + if ( !$warnings || ( count( $warnings ) == 1 && |
| 204 | + isset( $warnings['exists'] ) && |
203 | 205 | ( $this->mDestWarningAck || $this->mForReUpload ) ) ) |
204 | 206 | { |
205 | 207 | return false; |
206 | 208 | } |
207 | 209 | |
208 | | - |
209 | 210 | $sessionKey = $this->mUpload->stashSession(); |
210 | 211 | |
211 | 212 | $sk = $wgUser->getSkin(); |
— | — | @@ -222,10 +223,11 @@ |
223 | 224 | array( Title::makeTitle( NS_FILE, $args )->getPrefixedText() ) ) |
224 | 225 | . "</li>\n"; |
225 | 226 | } else { |
226 | | - if ( $args === true ) |
| 227 | + if ( $args === true ) { |
227 | 228 | $args = array(); |
228 | | - elseif ( !is_array( $args ) ) |
| 229 | + } elseif ( !is_array( $args ) ) { |
229 | 230 | $args = array( $args ); |
| 231 | + } |
230 | 232 | $msg = "\t<li>" . wfMsgExt( $warning, 'parseinline', $args ) . "</li>\n"; |
231 | 233 | } |
232 | 234 | $warningHtml .= $msg; |
— | — | @@ -234,59 +236,62 @@ |
235 | 237 | $warningHtml .= wfMsgExt( 'uploadwarning-text', 'parse' ); |
236 | 238 | |
237 | 239 | // store it in an array to show later |
238 | | - $this->mWarnings[] = $warningHtml; |
| 240 | + $this->mWarnings[] = $warningHtml; |
239 | 241 | $this->mSessionKeys[$this->mUpload->getLocalFile()->getName()] = $sessionKey; |
240 | 242 | |
241 | 243 | # Indicate that we showed a form |
242 | 244 | return true; |
243 | 245 | } |
244 | 246 | |
245 | | - /** |
246 | | - * Show the upload form with error message, but do not stash the file. |
247 | | - * |
248 | | - * @param string $message |
249 | | - */ |
250 | | - protected function showUploadError( $message ) { |
251 | | - $this->mErrors[] = '<ul><li>' . $this->mLocalFile->getTitle()->getFullText() . ':' . $message . "</li></ul>\n"; |
252 | | - } |
| 247 | + /** |
| 248 | + * Show the upload form with error message, but do not stash the file. |
| 249 | + * |
| 250 | + * @param $message String |
| 251 | + */ |
| 252 | + protected function showUploadError( $message ) { |
| 253 | + $this->mErrors[] = '<ul><li>' . |
| 254 | + $this->mLocalFile->getTitle()->getFullText() . ':' . |
| 255 | + $message . "</li></ul>\n"; |
| 256 | + } |
253 | 257 | |
254 | | - |
255 | 258 | /** |
256 | 259 | * Do the upload. |
257 | 260 | * Checks are made in SpecialUpload::execute() |
258 | 261 | */ |
259 | 262 | protected function processUpload() { |
260 | | - global $wgMaxUploadFiles, $wgOut; |
| 263 | + global $wgMaxUploadFiles, $wgOut; |
261 | 264 | |
262 | | - for ($i = 0; $i < $wgMaxUploadFiles; $i++) { |
263 | | - if (isset($this->mUploads[$i])) { |
| 265 | + for ( $i = 0; $i < $wgMaxUploadFiles; $i++ ) { |
| 266 | + if ( isset( $this->mUploads[$i] ) ) { |
264 | 267 | $this->mUpload = $this->mUploads[$i]; |
265 | 268 | $this->mUploadSuccessful = false; // reset |
266 | 269 | parent::processUpload(); |
267 | | - if ( $this->mUploadSuccessful) { |
268 | | - $this->mSuccesses[] = "<ul><li><a href='" . $this->mLocalFile->getTitle()->getFullURL() . "' target='new'>{$this->mLocalFile->getTitle()->getFullText()}: " . wfMsg('multiupload-fileuploaded') . "</a></li></ul>"; |
| 270 | + if ( $this->mUploadSuccessful ) { |
| 271 | + $this->mSuccesses[] = "<ul><li><a href='" . $this->mLocalFile->getTitle()->getFullURL() . |
| 272 | + "' target='new'>{$this->mLocalFile->getTitle()->getFullText()}: " . |
| 273 | + wfMsg( 'multiupload-fileuploaded' ) . '</a></li></ul>'; |
269 | 274 | } |
270 | 275 | } |
271 | 276 | } |
272 | 277 | // clear out the redirects |
273 | | - $wgOut->redirect(''); |
| 278 | + $wgOut->redirect( '' ); |
274 | 279 | |
275 | 280 | // tell the good news first |
276 | | - if (sizeof($this->mSuccesses) > 0) { |
277 | | - $wgOut->addHTML('<h2>' . wfMsgHtml( 'successfulupload' ) . "</h2>\n"); |
278 | | - $wgOut->addHTML(implode($this->mSuccesses)); |
| 281 | + if ( sizeof( $this->mSuccesses ) > 0 ) { |
| 282 | + $wgOut->addHTML( '<h2>' . wfMsgHtml( 'successfulupload' ) . "</h2>\n" ); |
| 283 | + $wgOut->addHTML( implode( $this->mSuccesses ) ); |
279 | 284 | } |
280 | 285 | |
281 | 286 | // the bad news |
282 | | - if (sizeof($this->mErrors) > 0) { |
283 | | - $wgOut->addHTML('<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n"); |
284 | | - $wgOut->addHTML(implode($this->mErrors)); |
| 287 | + if ( sizeof( $this->mErrors ) > 0 ) { |
| 288 | + $wgOut->addHTML( '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" ); |
| 289 | + $wgOut->addHTML( implode( $this->mErrors ) ); |
285 | 290 | } |
286 | 291 | |
287 | 292 | // the hopefully recoverable news |
288 | | - if (sizeof($this->mWarnings) > 0 || sizeof($this->mErrors) > 0 ) { |
289 | | - $wgOut->addHTML("<br/><br/><hr/>"); // visually separate the form from the errors/successes |
290 | | - $form = $this->getUploadForm( implode($this->mWarnings), $this->mSessionKeys, /* $hideIgnoreWarning */ true ); |
| 293 | + if ( sizeof( $this->mWarnings ) > 0 || sizeof( $this->mErrors ) > 0 ) { |
| 294 | + $wgOut->addHTML( '<br /><br /><hr />' ); // visually separate the form from the errors/successes |
| 295 | + $form = $this->getUploadForm( implode( $this->mWarnings ), $this->mSessionKeys, /* $hideIgnoreWarning */ true ); |
291 | 296 | $form->setSubmitText( wfMsg( 'upload-tryagain' ) ); |
292 | 297 | $form->addButton( 'wpUploadIgnoreWarning', wfMsg( 'ignorewarning' ) ); |
293 | 298 | $form->addButton( 'wpCancelUpload', wfMsg( 'reuploaddesc' ) ); |
— | — | @@ -297,30 +302,30 @@ |
298 | 303 | |
299 | 304 | /** |
300 | 305 | * Remove a temporarily kept file stashed by saveTempUploadedFile(). |
301 | | - * @access private |
302 | | - * @return success |
| 306 | + * |
| 307 | + * @return Boolean: success |
303 | 308 | */ |
304 | 309 | protected function unsaveUploadedFile() { |
305 | 310 | global $wgMaxUploadFiles; |
306 | 311 | $ret = true; |
307 | | - for ($i = 0; $i < $wgMaxUploadFiles; $i++) { |
308 | | - if (isset($this->mUploads[$i])) { |
| 312 | + for ( $i = 0; $i < $wgMaxUploadFiles; $i++ ) { |
| 313 | + if ( isset( $this->mUploads[$i] ) ) { |
309 | 314 | $this->mUpload = $this->mUploads[$i]; |
310 | 315 | // return false if even one of them failed |
311 | 316 | $ret = $ret && parent::unsaveUploadedFile(); |
312 | 317 | } |
313 | | - } |
| 318 | + } |
314 | 319 | return $ret; |
315 | 320 | } |
316 | 321 | |
317 | | - /** |
318 | | - * Construct a warning and a gallery from an array of duplicate files. |
| 322 | + /** |
| 323 | + * Construct a warning and a gallery from an array of duplicate files. |
319 | 324 | * Override because the original doesn't say which file is a dupe |
320 | | - */ |
321 | | - public static function getDupeWarning( $dupes, $dupetitle = null ) { |
322 | | - $result = parent::getDupeWarning($dupes); |
323 | | - return preg_replace("@<li>@", "<li>{$dupetitle->getText()}", $result); |
324 | | - } |
| 325 | + */ |
| 326 | + public static function getDupeWarning( $dupes, $dupetitle = null ) { |
| 327 | + $result = parent::getDupeWarning( $dupes ); |
| 328 | + return preg_replace( "@<li>@", "<li>{$dupetitle->getText()}", $result ); |
| 329 | + } |
325 | 330 | |
326 | 331 | } |
327 | 332 | |
— | — | @@ -329,42 +334,42 @@ |
330 | 335 | */ |
331 | 336 | class MultiUploadForm extends UploadForm { |
332 | 337 | |
333 | | - protected $mDestFiles; |
| 338 | + protected $mDestFiles; |
334 | 339 | protected $mSessionKeys; |
335 | 340 | |
336 | 341 | public function __construct( $options = array() ) { |
337 | | - |
338 | | -// basically we want to map filenames to session keys here somehow |
| 342 | + // basically we want to map filenames to session keys here somehow |
339 | 343 | global $wgMaxUploadFiles; |
340 | 344 | $this->mDestFiles = array(); |
341 | | - for($i = 0; $i < $wgMaxUploadFiles; $i++) { |
| 345 | + for( $i = 0; $i < $wgMaxUploadFiles; $i++ ) { |
342 | 346 | $this->mDestFiles[$i] = $options['destfile'. $i]; |
343 | | - } |
| 347 | + } |
344 | 348 | $this->mSessionKeys = array(); |
345 | | - foreach ($options as $k=>$v) { |
346 | | - if (preg_match("@^sessionkey@", $k)) |
347 | | - $this->mSessionKeys[$k] = $v; |
| 349 | + foreach ( $options as $k => $v ) { |
| 350 | + if ( preg_match( "@^sessionkey@", $k ) ) { |
| 351 | + $this->mSessionKeys[$k] = $v; |
| 352 | + } |
348 | 353 | } |
349 | | - parent::__construct( $options) ; |
| 354 | + parent::__construct( $options ); |
350 | 355 | } |
351 | 356 | |
352 | | - |
353 | 357 | protected function getDescriptionSection() { |
354 | 358 | // get the usual one and clear out the DestFile |
355 | | - $descriptor = parent::getDescriptionSection(); |
356 | | - unset($descriptor['DestFile']); |
| 359 | + $descriptor = parent::getDescriptionSection(); |
| 360 | + unset( $descriptor['DestFile'] ); |
357 | 361 | return $descriptor; |
358 | 362 | } |
| 363 | + |
359 | 364 | /** |
360 | | - * Get the descriptor of the fieldset that contains the file source |
| 365 | + * Get the descriptor of the fieldset that contains the file source |
361 | 366 | * selection. The section is 'source' |
362 | | - * |
| 367 | + * |
363 | 368 | * @return array Descriptor array |
364 | 369 | */ |
365 | 370 | protected function getSourceSection() { |
366 | 371 | global $wgLang, $wgUser, $wgRequest, $wgMaxUploadFiles; |
367 | 372 | |
368 | | - if ( sizeof($this->mSessionKeys) > 0) { |
| 373 | + if ( sizeof( $this->mSessionKeys ) > 0) { |
369 | 374 | $data = array( |
370 | 375 | 'wpSourceType' => array( |
371 | 376 | 'type' => 'hidden', |
— | — | @@ -372,17 +377,19 @@ |
373 | 378 | ), |
374 | 379 | ); |
375 | 380 | $index = 0; |
376 | | - foreach ($this->mDestFiles as $k=>$v) { |
377 | | - if ($v == "") continue; |
| 381 | + foreach ( $this->mDestFiles as $k => $v ) { |
| 382 | + if ( $v == '' ) { |
| 383 | + continue; |
| 384 | + } |
378 | 385 | $data['wpDestFile' . $index] = array( |
379 | 386 | 'type' => 'hidden', |
380 | 387 | 'default' => $v, |
381 | 388 | ); |
382 | 389 | $data['wpSessionKey' . $index] = array( |
383 | 390 | 'type' => 'hidden', |
384 | | - 'default' => $this->mSessionKeys['sessionkey' . $v], |
| 391 | + 'default' => $this->mSessionKeys['sessionkey' . $v], |
385 | 392 | ); |
386 | | - $index++; |
| 393 | + $index++; |
387 | 394 | } |
388 | 395 | return $data; |
389 | 396 | } |
— | — | @@ -400,29 +407,29 @@ |
401 | 408 | 'raw' => true, |
402 | 409 | ); |
403 | 410 | } |
404 | | - |
405 | | - for ($i = 0; $i < $wgMaxUploadFiles; $i++) { |
| 411 | + |
| 412 | + for ( $i = 0; $i < $wgMaxUploadFiles; $i++ ) { |
406 | 413 | $descriptor['UploadFile' . $i] = array( |
407 | | - 'class' => 'UploadSourceField', |
408 | | - 'section' => 'source', |
409 | | - 'type' => 'file', |
410 | | - 'id' => 'wpUploadFile' . $i, |
411 | | - 'label-message' => 'sourcefilename', |
412 | | - 'upload-type' => 'File', |
413 | | - 'radio' => &$radio, |
414 | | - 'checked' => $selectedSourceType == 'file', |
| 414 | + 'class' => 'UploadSourceField', |
| 415 | + 'section' => 'source', |
| 416 | + 'type' => 'file', |
| 417 | + 'id' => 'wpUploadFile' . $i, |
| 418 | + 'label-message' => 'sourcefilename', |
| 419 | + 'upload-type' => 'File', |
| 420 | + 'radio' => &$radio, |
| 421 | + 'checked' => $selectedSourceType == 'file', |
415 | 422 | ); |
416 | 423 | $descriptor['DestFile' . $i] = array( |
417 | | - 'type' => 'text', |
418 | | - 'section' => 'source', |
419 | | - 'id' => 'wpDestFile' . $i, |
420 | | - 'label-message' => 'destfilename', |
421 | | - 'size' => 60, |
422 | | - 'default' => $this->mDestFiles[$i], |
423 | | - # FIXME: hack to work around poor handling of the 'default' option in HTMLForm |
424 | | - 'nodata' => strval( $this->mDestFile ) !== '', |
425 | | - ); |
426 | | - |
| 424 | + 'type' => 'text', |
| 425 | + 'section' => 'source', |
| 426 | + 'id' => 'wpDestFile' . $i, |
| 427 | + 'label-message' => 'destfilename', |
| 428 | + 'size' => 60, |
| 429 | + 'default' => $this->mDestFiles[$i], |
| 430 | + # FIXME: hack to work around poor handling of the 'default' option in HTMLForm |
| 431 | + 'nodata' => strval( $this->mDestFile ) !== '', |
| 432 | + ); |
| 433 | + |
427 | 434 | if ( $canUploadByUrl ) { |
428 | 435 | global $wgMaxUploadSize; |
429 | 436 | $descriptor['UploadFileURL'] = array( |
— | — | @@ -457,14 +464,10 @@ |
458 | 465 | return $descriptor; |
459 | 466 | } |
460 | 467 | |
461 | | - |
462 | 468 | /** |
463 | | - * Add upload JS to $wgOut |
464 | | - * |
465 | | - * @param bool $autofill Whether or not to autofill the destination |
466 | | - * filename text box |
| 469 | + * Add upload JavaScript to $wgOut |
467 | 470 | */ |
468 | | - protected function addUploadJS( ) { |
| 471 | + protected function addUploadJS() { |
469 | 472 | global $wgScriptPath, $wgMaxUploadFiles, $wgFileExtensions; |
470 | 473 | |
471 | 474 | global $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview, $wgEnableAPI; |
— | — | @@ -484,13 +487,16 @@ |
485 | 488 | ); |
486 | 489 | |
487 | 490 | $wgOut->addScript( Skin::makeVariablesScript( $scriptVars ) ); |
488 | | - |
| 491 | + |
489 | 492 | // For <charinsert> support |
490 | 493 | $wgOut->addScriptFile( 'edit.js' ); |
491 | 494 | |
492 | 495 | // changed |
493 | 496 | $wgOut->addScriptFile( "$wgScriptPath/extensions/MultiUpload/multiupload.js" ); |
494 | | - $newscriptVars = array('wgMaxUploadFiles' => $wgMaxUploadFiles, 'wgFileExtensions' => $wgFileExtensions); |
| 497 | + $newscriptVars = array( |
| 498 | + 'wgMaxUploadFiles' => $wgMaxUploadFiles, |
| 499 | + 'wgFileExtensions' => $wgFileExtensions |
| 500 | + ); |
495 | 501 | $wgOut->addScript( Skin::makeVariablesScript( $newscriptVars ) ); |
496 | 502 | } |
497 | 503 | |
Index: trunk/extensions/MultiUpload/MultiUpload.php |
— | — | @@ -1,7 +1,4 @@ |
2 | 2 | <?php |
3 | | -if ( ! defined( 'MEDIAWIKI' ) ) |
4 | | - die(); |
5 | | - |
6 | 3 | /** |
7 | 4 | * An extension that allows users to upload multiple files at once. |
8 | 5 | * |
— | — | @@ -12,6 +9,10 @@ |
13 | 10 | * @link http://www.mediawiki.org/wiki/Extension:MultiUpload Documentation |
14 | 11 | */ |
15 | 12 | |
| 13 | +if ( !defined( 'MEDIAWIKI' ) ) { |
| 14 | + die(); |
| 15 | +} |
| 16 | + |
16 | 17 | // change this parameter to limit the # of files one can upload |
17 | 18 | $wgMaxUploadFiles = isset( $wgMaxUploadFiles ) ? intval( $wgMaxUploadFiles ) : 5; |
18 | 19 | |
— | — | @@ -20,13 +21,13 @@ |
21 | 22 | 'path' => __FILE__, |
22 | 23 | 'name' => 'MultipleUpload', |
23 | 24 | 'author' => 'Travis Derouin', |
24 | | - 'version' => '1.01', |
| 25 | + 'version' => '2.0', |
25 | 26 | 'descriptionmsg' => 'multipleupload-desc', |
26 | 27 | 'url' => 'http://www.mediawiki.org/wiki/Extension:MultiUpload', |
27 | 28 | ); |
28 | 29 | |
29 | 30 | // Set up the new special page |
30 | | -$dir = dirname(__FILE__) . '/'; |
| 31 | +$dir = dirname( __FILE__ ) . '/'; |
31 | 32 | $wgAutoloadClasses['MultipleUpload'] = $dir . 'MultiUpload.body.php'; |
32 | 33 | $wgAutoloadClasses['MultipleUploadForm'] = $dir . 'MultiUpload.body.php'; |
33 | 34 | $wgExtensionMessagesFiles['MultiUpload'] = $dir . 'MultiUpload.i18n.php'; |
Index: trunk/extensions/MultiUpload/multiupload.js |
— | — | @@ -1,11 +1,10 @@ |
| 2 | +var current; |
2 | 3 | |
3 | | -var current; |
4 | | - |
5 | 4 | function licenseSelectorCheck() { |
6 | | - var selector = document.getElementById( "wpLicense" ); |
| 5 | + var selector = document.getElementById( 'wpLicense' ); |
7 | 6 | var selection = selector.options[selector.selectedIndex].value; |
8 | 7 | if( selector.selectedIndex > 0 ) { |
9 | | - if( selection == "" ) { |
| 8 | + if( selection == '' ) { |
10 | 9 | // Option disabled, but browser is broken and doesn't respect this |
11 | 10 | selector.selectedIndex = 0; |
12 | 11 | } |
— | — | @@ -20,81 +19,82 @@ |
21 | 20 | if( e ) { |
22 | 21 | if( !e.checked ) { |
23 | 22 | var ein = document.getElementById( 'wpUploadFileURL' ); |
24 | | - if(ein) |
| 23 | + if( ein ) { |
25 | 24 | ein.setAttribute( 'disabled', 'disabled' ); |
| 25 | + } |
26 | 26 | } |
27 | 27 | } |
28 | 28 | |
29 | 29 | // For MSIE/Mac: non-breaking spaces cause the <option> not to render. |
30 | 30 | // But for some reason, setting the text to itself works |
31 | | - var selector = document.getElementById("wpLicense"); |
32 | | - if (selector) { |
| 31 | + var selector = document.getElementById( 'wpLicense' ); |
| 32 | + if ( selector ) { |
33 | 33 | var ua = navigator.userAgent; |
34 | | - var isMacIe = (ua.indexOf("MSIE") != -1) && (ua.indexOf("Mac") != -1); |
35 | | - if (isMacIe) { |
36 | | - for (var i = 0; i < selector.options.length; i++) { |
| 34 | + var isMacIe = ( ua.indexOf( 'MSIE' ) != -1 ) && ( ua.indexOf( 'Mac' ) != -1 ); |
| 35 | + if ( isMacIe ) { |
| 36 | + for ( var i = 0; i < selector.options.length; i++ ) { |
37 | 37 | selector.options[i].text = selector.options[i].text; |
38 | 38 | } |
39 | 39 | } |
40 | 40 | } |
41 | | - |
| 41 | + |
42 | 42 | // Toggle source type |
43 | 43 | var sourceTypeCheckboxes = document.getElementsByName( 'wpSourceType' ); |
44 | 44 | for ( var i = 0; i < sourceTypeCheckboxes.length; i++ ) { |
45 | 45 | sourceTypeCheckboxes[i].onchange = toggleUploadInputs; |
46 | 46 | } |
47 | | - |
| 47 | + |
48 | 48 | // AJAX wpDestFile warnings |
49 | 49 | if ( wgAjaxUploadDestCheck ) { |
50 | 50 | // Insert an event handler that fetches upload warnings when wpDestFile |
51 | 51 | // has been changed |
52 | | - for (i = 0; i < wgMaxUploadFiles; i++) { |
53 | | - document.getElementById( 'wpDestFile' + i ).onchange = function ( e ) { |
54 | | - wgUploadWarningObj.checkNow(this.value); |
| 52 | + for ( i = 0; i < wgMaxUploadFiles; i++ ) { |
| 53 | + document.getElementById( 'wpDestFile' + i ).onchange = function( e ) { |
| 54 | + wgUploadWarningObj.checkNow( this.value ); |
55 | 55 | }; |
56 | 56 | } |
57 | | - // Insert a row where the warnings will be displayed just below the |
| 57 | + // Insert a row where the warnings will be displayed just below the |
58 | 58 | // wpDestFile row |
59 | 59 | var optionsTable = document.getElementById( 'mw-htmlform-description' ).tBodies[0]; |
60 | 60 | var row = optionsTable.insertRow( 1 ); |
61 | 61 | var td = document.createElement( 'td' ); |
62 | 62 | td.id = 'wpDestFile-warning'; |
63 | 63 | td.colSpan = 2; |
64 | | - |
| 64 | + |
65 | 65 | row.appendChild( td ); |
66 | 66 | } |
67 | | - |
| 67 | + |
68 | 68 | if ( wgAjaxLicensePreview ) { |
69 | 69 | // License selector check |
70 | 70 | document.getElementById( 'wpLicense' ).onchange = licenseSelectorCheck; |
71 | | - |
| 71 | + |
72 | 72 | // License selector table row |
73 | 73 | var wpLicense = document.getElementById( 'wpLicense' ); |
74 | 74 | var wpLicenseRow = wpLicense.parentNode.parentNode; |
75 | 75 | var wpLicenseTbody = wpLicenseRow.parentNode; |
76 | | - |
| 76 | + |
77 | 77 | var row = document.createElement( 'tr' ); |
78 | 78 | var td = document.createElement( 'td' ); |
79 | 79 | row.appendChild( td ); |
80 | 80 | td = document.createElement( 'td' ); |
81 | 81 | td.id = 'mw-license-preview'; |
82 | 82 | row.appendChild( td ); |
83 | | - |
| 83 | + |
84 | 84 | wpLicenseTbody.insertBefore( row, wpLicenseRow.nextSibling ); |
85 | 85 | } |
86 | | - |
87 | | - |
| 86 | + |
88 | 87 | // fillDestFile setup |
89 | | - for ( var i = 0; i < wgUploadSourceIds.length; i++ ) |
90 | | - document.getElementById( wgUploadSourceIds[i] ).onchange = function (e) { |
| 88 | + for ( var i = 0; i < wgUploadSourceIds.length; i++ ) { |
| 89 | + document.getElementById( wgUploadSourceIds[i] ).onchange = function( e ) { |
91 | 90 | fillDestFilename( this.id ); |
92 | 91 | }; |
| 92 | + } |
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
96 | 96 | * Iterate over all upload source fields and disable all except the selected one. |
97 | | - * |
98 | | - * @param enabledId The id of the selected radio button |
| 97 | + * |
| 98 | + * @param enabledId The id of the selected radio button |
99 | 99 | * @return emptiness |
100 | 100 | */ |
101 | 101 | function toggleUploadInputs() { |
— | — | @@ -105,28 +105,31 @@ |
106 | 106 | } else { |
107 | 107 | // Older browsers don't support getElementsByClassName |
108 | 108 | rows = new Array(); |
109 | | - |
| 109 | + |
110 | 110 | var allRows = document.getElementsByTagName( 'tr' ); |
111 | 111 | for ( var i = 0; i < allRows.length; i++ ) { |
112 | | - if ( allRows[i].className == 'mw-htmlform-field-UploadSourceField' ) |
| 112 | + if ( allRows[i].className == 'mw-htmlform-field-UploadSourceField' ) { |
113 | 113 | rows.push( allRows[i] ); |
| 114 | + } |
114 | 115 | } |
115 | 116 | } |
116 | | - |
| 117 | + |
117 | 118 | for ( var i = 0; i < rows.length; i++ ) { |
118 | 119 | var inputs = rows[i].getElementsByTagName( 'input' ); |
119 | | - |
| 120 | + |
120 | 121 | // Check if this row is selected |
121 | 122 | var isChecked = true; // Default true in case wpSourceType is not found |
122 | 123 | for ( var j = 0; j < inputs.length; j++ ) { |
123 | | - if ( inputs[j].name == 'wpSourceType' ) |
| 124 | + if ( inputs[j].name == 'wpSourceType' ) { |
124 | 125 | isChecked = inputs[j].checked; |
| 126 | + } |
125 | 127 | } |
126 | | - |
| 128 | + |
127 | 129 | // Disable all unselected rows |
128 | 130 | for ( var j = 0; j < inputs.length; j++ ) { |
129 | | - if ( inputs[j].type != 'radio') |
| 131 | + if ( inputs[j].type != 'radio' ) { |
130 | 132 | inputs[j].disabled = !isChecked; |
| 133 | + } |
131 | 134 | } |
132 | 135 | } |
133 | 136 | } |
— | — | @@ -138,24 +141,28 @@ |
139 | 142 | 'delay': 500, // ms |
140 | 143 | 'timeoutID': false, |
141 | 144 | |
142 | | - 'keypress': function () { |
143 | | - if ( !wgAjaxUploadDestCheck || !sajax_init_object() ) return; |
| 145 | + 'keypress': function() { |
| 146 | + if ( !wgAjaxUploadDestCheck || !sajax_init_object() ) { |
| 147 | + return; |
| 148 | + } |
144 | 149 | |
145 | 150 | // Find file to upload |
146 | | - var destFile = document.getElementById('wpDestFile' + current); |
| 151 | + var destFile = document.getElementById( 'wpDestFile' + current ); |
147 | 152 | var warningElt = document.getElementById( 'wpDestFile-warning' ); |
148 | | - if ( !destFile || !warningElt ) return ; |
| 153 | + if ( !destFile || !warningElt ) { |
| 154 | + return; |
| 155 | + } |
149 | 156 | |
150 | | - this.nameToCheck = destFile.value ; |
| 157 | + this.nameToCheck = destFile.value; |
151 | 158 | |
152 | 159 | // Clear timer |
153 | 160 | if ( this.timeoutID ) { |
154 | 161 | window.clearTimeout( this.timeoutID ); |
155 | 162 | } |
156 | 163 | // Check response cache |
157 | | - for (cached in this.responseCache) { |
158 | | - if (this.nameToCheck == cached) { |
159 | | - this.setWarning(this.responseCache[this.nameToCheck]); |
| 164 | + for ( cached in this.responseCache ) { |
| 165 | + if ( this.nameToCheck == cached ) { |
| 166 | + this.setWarning( this.responseCache[this.nameToCheck] ); |
160 | 167 | return; |
161 | 168 | } |
162 | 169 | } |
— | — | @@ -163,8 +170,10 @@ |
164 | 171 | this.timeoutID = window.setTimeout( 'wgUploadWarningObj.timeout()', this.delay ); |
165 | 172 | }, |
166 | 173 | |
167 | | - 'checkNow': function (fname) { |
168 | | - if ( !wgAjaxUploadDestCheck || !sajax_init_object() ) return; |
| 174 | + 'checkNow': function( fname ) { |
| 175 | + if ( !wgAjaxUploadDestCheck || !sajax_init_object() ) { |
| 176 | + return; |
| 177 | + } |
169 | 178 | if ( this.timeoutID ) { |
170 | 179 | window.clearTimeout( this.timeoutID ); |
171 | 180 | } |
— | — | @@ -173,33 +182,35 @@ |
174 | 183 | }, |
175 | 184 | |
176 | 185 | 'timeout' : function() { |
177 | | - if ( !wgAjaxUploadDestCheck || !sajax_init_object() ) return; |
| 186 | + if ( !wgAjaxUploadDestCheck || !sajax_init_object() ) { |
| 187 | + return; |
| 188 | + } |
178 | 189 | injectSpinner( document.getElementById( 'wpDestFile' + current ), 'destcheck' ); |
179 | 190 | |
180 | 191 | // Get variables into local scope so that they will be preserved for the |
181 | 192 | // anonymous callback. fileName is copied so that multiple overlapping |
182 | | - // ajax requests can be supported. |
| 193 | + // AJAX requests can be supported. |
183 | 194 | var obj = this; |
184 | 195 | var fileName = this.nameToCheck; |
185 | 196 | sajax_do_call( 'SpecialUpload::ajaxGetExistsWarning', [this.nameToCheck], |
186 | | - function (result) { |
187 | | - obj.processResult(result, fileName) |
| 197 | + function( result ) { |
| 198 | + obj.processResult( result, fileName ); |
188 | 199 | } |
189 | 200 | ); |
190 | 201 | }, |
191 | 202 | |
192 | | - 'processResult' : function (result, fileName) { |
| 203 | + 'processResult' : function( result, fileName ) { |
193 | 204 | removeSpinner( 'destcheck' ); |
194 | 205 | this.setWarning(result.responseText); |
195 | 206 | this.responseCache[fileName] = result.responseText; |
196 | 207 | }, |
197 | 208 | |
198 | | - 'setWarning' : function (warning) { |
| 209 | + 'setWarning' : function( warning ) { |
199 | 210 | var warningElt = document.getElementById( 'wpDestFile-warning' ); |
200 | 211 | var ackElt = document.getElementsByName( 'wpDestFileWarningAck' ); |
201 | 212 | |
202 | | - this.setInnerHTML(warningElt, warning); |
203 | | - |
| 213 | + this.setInnerHTML( warningElt, warning ); |
| 214 | + |
204 | 215 | // Set a value in the form indicating that the warning is acknowledged and |
205 | 216 | // doesn't need to be redisplayed post-upload |
206 | 217 | if ( warning == '' || warning == ' ' ) { |
— | — | @@ -209,46 +220,49 @@ |
210 | 221 | } |
211 | 222 | |
212 | 223 | }, |
213 | | - 'setInnerHTML' : function (element, text) { |
| 224 | + 'setInnerHTML' : function( element, text ) { |
214 | 225 | // Check for no change to avoid flicker in IE 7 |
215 | | - if (element.innerHTML != text) { |
| 226 | + if ( element.innerHTML != text ) { |
216 | 227 | element.innerHTML = text; |
217 | 228 | } |
218 | 229 | } |
219 | 230 | } |
220 | 231 | |
221 | | -function fillDestFilename(id) { |
222 | | - if (!wgUploadAutoFill) { |
| 232 | +function fillDestFilename( id ) { |
| 233 | + if ( !wgUploadAutoFill ) { |
223 | 234 | return; |
224 | 235 | } |
225 | | - if (!document.getElementById) { |
| 236 | + if ( !document.getElementById ) { |
226 | 237 | return; |
227 | 238 | } |
228 | 239 | // Remove any previously flagged errors |
229 | 240 | var e = document.getElementById( 'mw-upload-permitted' ); |
230 | | - if( e ) e.className = ''; |
| 241 | + if( e ) { |
| 242 | + e.className = ''; |
| 243 | + } |
231 | 244 | |
232 | 245 | var e = document.getElementById( 'mw-upload-prohibited' ); |
233 | | - if( e ) e.className = ''; |
| 246 | + if( e ) { |
| 247 | + e.className = ''; |
| 248 | + } |
234 | 249 | |
235 | | - |
236 | | - var path = document.getElementById(id).value; |
| 250 | + var path = document.getElementById( id ).value; |
237 | 251 | // Find trailing part |
238 | | - var slash = path.lastIndexOf('/'); |
239 | | - var backslash = path.lastIndexOf('\\'); |
| 252 | + var slash = path.lastIndexOf( '/' ); |
| 253 | + var backslash = path.lastIndexOf( '\\' ); |
240 | 254 | var fname; |
241 | | - if (slash == -1 && backslash == -1) { |
| 255 | + if ( slash == -1 && backslash == -1 ) { |
242 | 256 | fname = path; |
243 | | - } else if (slash > backslash) { |
244 | | - fname = path.substring(slash+1, 10000); |
| 257 | + } else if ( slash > backslash ) { |
| 258 | + fname = path.substring( slash + 1, 10000 ); |
245 | 259 | } else { |
246 | | - fname = path.substring(backslash+1, 10000); |
| 260 | + fname = path.substring( backslash + 1, 10000 ); |
247 | 261 | } |
248 | 262 | |
249 | 263 | // Clear the filename if it does not have a valid extension. |
250 | | - // URLs are less likely to have a useful extension, so don't include them in the |
| 264 | + // URLs are less likely to have a useful extension, so don't include them in the |
251 | 265 | // extension check. |
252 | | - current= id.replace(/[^0-9]/g, ""); |
| 266 | + current = id.replace( /[^0-9]/g, '' ); |
253 | 267 | if( wgFileExtensions && id != 'wpUploadFileURL' ) { |
254 | 268 | var found = false; |
255 | 269 | if( fname.lastIndexOf( '.' ) != -1 ) { |
— | — | @@ -263,16 +277,22 @@ |
264 | 278 | if( !found ) { |
265 | 279 | // Not a valid extension |
266 | 280 | // Clear the upload and set mw-upload-permitted to error |
267 | | - document.getElementById(id).value = ''; |
| 281 | + document.getElementById( id ).value = ''; |
268 | 282 | var e = document.getElementById( 'mw-upload-permitted' ); |
269 | | - if( e ) e.className = 'error'; |
| 283 | + if( e ) { |
| 284 | + e.className = 'error'; |
| 285 | + } |
270 | 286 | |
271 | 287 | var e = document.getElementById( 'mw-upload-prohibited' ); |
272 | | - if( e ) e.className = 'error'; |
| 288 | + if( e ) { |
| 289 | + e.className = 'error'; |
| 290 | + } |
273 | 291 | |
274 | 292 | // Clear wpDestFile as well |
275 | | - var e = document.getElementById( 'wpDestFile' + current) |
276 | | - if( e ) e.value = ''; |
| 293 | + var e = document.getElementById( 'wpDestFile' + current ); |
| 294 | + if( e ) { |
| 295 | + e.value = ''; |
| 296 | + } |
277 | 297 | |
278 | 298 | return false; |
279 | 299 | } |
— | — | @@ -280,21 +300,23 @@ |
281 | 301 | |
282 | 302 | // Capitalise first letter and replace spaces by underscores |
283 | 303 | // FIXME: $wgCapitalizedNamespaces |
284 | | - fname = fname.charAt(0).toUpperCase().concat(fname.substring(1,10000)).replace(/ /g, '_'); |
| 304 | + fname = fname.charAt( 0 ).toUpperCase().concat( fname.substring( 1, 10000 ) ).replace( / /g, '_' ); |
285 | 305 | |
286 | 306 | // Output result |
287 | | - var destFile = document.getElementById('wpDestFile' + current); |
288 | | - if (destFile) { |
| 307 | + var destFile = document.getElementById( 'wpDestFile' + current ); |
| 308 | + if ( destFile ) { |
289 | 309 | destFile.value = fname; |
290 | | - wgUploadWarningObj.checkNow(fname) ; |
| 310 | + wgUploadWarningObj.checkNow( fname ); |
291 | 311 | } |
292 | 312 | } |
293 | 313 | |
294 | 314 | function toggleFilenameFiller() { |
295 | | - if(!document.getElementById) return; |
296 | | - var upfield = document.getElementById('wpUploadFile'); |
297 | | - var destName = document.getElementById('wpDestFile').value; |
298 | | - if (destName=='' || destName==' ') { |
| 315 | + if( !document.getElementById ) { |
| 316 | + return; |
| 317 | + } |
| 318 | + var upfield = document.getElementById( 'wpUploadFile' ); |
| 319 | + var destName = document.getElementById( 'wpDestFile' ).value; |
| 320 | + if ( destName == '' || destName == ' ' ) { |
299 | 321 | wgUploadAutoFill = true; |
300 | 322 | } else { |
301 | 323 | wgUploadAutoFill = false; |
— | — | @@ -306,27 +328,32 @@ |
307 | 329 | 'responseCache' : { '' : '' }, |
308 | 330 | |
309 | 331 | 'fetchPreview': function( license ) { |
310 | | - if( !wgAjaxLicensePreview ) return; |
311 | | - for (cached in this.responseCache) { |
312 | | - if (cached == license) { |
| 332 | + if( !wgAjaxLicensePreview ) { |
| 333 | + return; |
| 334 | + } |
| 335 | + for ( cached in this.responseCache ) { |
| 336 | + if ( cached == license ) { |
313 | 337 | this.showPreview( this.responseCache[license] ); |
314 | 338 | return; |
315 | 339 | } |
316 | 340 | } |
317 | 341 | injectSpinner( document.getElementById( 'wpLicense' ), 'license' ); |
318 | | - |
319 | | - var title = document.getElementById('wpDestFile' + current).value; |
320 | | - if ( !title ) title = 'File:Sample.jpg'; |
321 | | - |
| 342 | + |
| 343 | + var title = document.getElementById( 'wpDestFile' + current ).value; |
| 344 | + if ( !title ) { |
| 345 | + title = 'File:Sample.jpg'; |
| 346 | + } |
| 347 | + |
322 | 348 | var url = wgScriptPath + '/api' + wgScriptExtension |
323 | 349 | + '?action=parse&text={{' + encodeURIComponent( license ) + '}}' |
324 | | - + '&title=' + encodeURIComponent( title ) |
| 350 | + + '&title=' + encodeURIComponent( title ) |
325 | 351 | + '&prop=text&pst&format=json'; |
326 | | - |
| 352 | + |
327 | 353 | var req = sajax_init_object(); |
328 | 354 | req.onreadystatechange = function() { |
329 | | - if ( req.readyState == 4 && req.status == 200 ) |
| 355 | + if ( req.readyState == 4 && req.status == 200 ) { |
330 | 356 | wgUploadLicenseObj.processResult( eval( '(' + req.responseText + ')' ), license ); |
| 357 | + } |
331 | 358 | }; |
332 | 359 | req.open( 'GET', url, true ); |
333 | 360 | req.send( '' ); |
— | — | @@ -336,15 +363,15 @@ |
337 | 364 | removeSpinner( 'license' ); |
338 | 365 | this.responseCache[license] = result['parse']['text']['*']; |
339 | 366 | this.showPreview( this.responseCache[license] ); |
340 | | - |
341 | 367 | }, |
342 | 368 | |
343 | 369 | 'showPreview' : function( preview ) { |
344 | 370 | var previewPanel = document.getElementById( 'mw-license-preview' ); |
345 | | - if( previewPanel.innerHTML != preview ) |
| 371 | + if( previewPanel.innerHTML != preview ) { |
346 | 372 | previewPanel.innerHTML = preview; |
| 373 | + } |
347 | 374 | } |
348 | 375 | |
349 | 376 | } |
350 | 377 | |
351 | | -addOnloadHook( wgUploadSetup ); |
| 378 | +addOnloadHook( wgUploadSetup ); |
\ No newline at end of file |