Index: trunk/phase3/maintenance/tests/phpunit/includes/api/ApiUploadTest.php |
— | — | @@ -261,6 +261,7 @@ |
262 | 262 | |
263 | 263 | $filePaths = $randomImageGenerator->writeImages( 1, $extension, dirname( wfTempDir() ) ); |
264 | 264 | $filePath = $filePaths[0]; |
| 265 | + $fileSize = filesize( $filePath ); |
265 | 266 | $fileName = basename( $filePath ); |
266 | 267 | |
267 | 268 | $this->deleteFileByFileName( $fileName ); |
— | — | @@ -286,6 +287,8 @@ |
287 | 288 | } |
288 | 289 | $this->assertTrue( isset( $result['upload'] ) ); |
289 | 290 | $this->assertEquals( 'Success', $result['upload']['result'] ); |
| 291 | + $this->assertEquals( $fileSize, ( int )$result['upload']['imageinfo']['size'] ); |
| 292 | + $this->assertEquals( $mimeType, $result['upload']['imageinfo']['mime'] ); |
290 | 293 | $this->assertFalse( $exception ); |
291 | 294 | |
292 | 295 | // clean up |
— | — | @@ -511,6 +514,7 @@ |
512 | 515 | |
513 | 516 | $filePaths = $randomImageGenerator->writeImages( 1, $extension, dirname( wfTempDir() ) ); |
514 | 517 | $filePath = $filePaths[0]; |
| 518 | + $fileSize = filesize( $filePath ); |
515 | 519 | $fileName = basename( $filePath ); |
516 | 520 | |
517 | 521 | $this->deleteFileByFileName( $fileName ); |
— | — | @@ -538,6 +542,8 @@ |
539 | 543 | $this->assertFalse( $exception ); |
540 | 544 | $this->assertTrue( isset( $result['upload'] ) ); |
541 | 545 | $this->assertEquals( 'Success', $result['upload']['result'] ); |
| 546 | + $this->assertEquals( $fileSize, ( int )$result['upload']['imageinfo']['size'] ); |
| 547 | + $this->assertEquals( $mimeType, $result['upload']['imageinfo']['mime'] ); |
542 | 548 | $this->assertTrue( isset( $result['upload']['sessionkey'] ) ); |
543 | 549 | $sessionkey = $result['upload']['sessionkey']; |
544 | 550 | |
Index: trunk/phase3/includes/upload/UploadBase.php |
— | — | @@ -505,10 +505,15 @@ |
506 | 506 | * @return mixed Status indicating the whether the upload succeeded. |
507 | 507 | */ |
508 | 508 | public function performUpload( $comment, $pageText, $watch, $user ) { |
509 | | - wfDebug( "\n\n\performUpload: sum: " . $comment . ' c: ' . $pageText . |
510 | | - ' w: ' . $watch ); |
511 | | - $status = $this->getLocalFile()->upload( $this->mTempPath, $comment, $pageText, |
512 | | - File::DELETE_SOURCE, $this->mFileProps, false, $user ); |
| 509 | + $status = $this->getLocalFile()->upload( |
| 510 | + $this->mTempPath, |
| 511 | + $comment, |
| 512 | + $pageText, |
| 513 | + File::DELETE_SOURCE, i |
| 514 | + $this->mFileProps, |
| 515 | + false, |
| 516 | + $user |
| 517 | + ); |
513 | 518 | |
514 | 519 | if( $status->isGood() ) { |
515 | 520 | if ( $watch ) { |
— | — | @@ -636,8 +641,7 @@ |
637 | 642 | 'mFileProps' => $this->mFileProps |
638 | 643 | ); |
639 | 644 | $file = $stash->stashFile( $this->mTempPath, $data, $key ); |
640 | | - // TODO should we change the "local file" here? |
641 | | - // $this->mLocalFile = $file; |
| 645 | + $this->mLocalFile = $file; |
642 | 646 | return $file; |
643 | 647 | } |
644 | 648 | |
— | — | @@ -1207,8 +1211,16 @@ |
1208 | 1212 | */ |
1209 | 1213 | public function getImageInfo( $result ) { |
1210 | 1214 | $file = $this->getLocalFile(); |
1211 | | - $imParam = ApiQueryImageInfo::getPropertyNames(); |
1212 | | - return ApiQueryImageInfo::getInfo( $file, array_flip( $imParam ), $result ); |
| 1215 | + // TODO This cries out for refactoring. We really want to say $file->getAllInfo(); here. |
| 1216 | + // Perhaps "info" methods should be moved into files, and the API should just wrap them in queries. |
| 1217 | + if ( is_a( $file, 'UploadStashFile' ) ) { |
| 1218 | + $imParam = ApiQueryStashImageInfo::getPropertyNames(); |
| 1219 | + $info = ApiQueryStashImageInfo::getInfo( $file, array_flip( $imParam ), $result ); |
| 1220 | + } else { |
| 1221 | + $imParam = ApiQueryImageInfo::getPropertyNames(); |
| 1222 | + $info = ApiQueryImageInfo::getInfo( $file, array_flip( $imParam ), $result ); |
| 1223 | + } |
| 1224 | + return $info; |
1213 | 1225 | } |
1214 | 1226 | |
1215 | 1227 | |
Index: trunk/phase3/includes/api/ApiQuery.php |
— | — | @@ -54,6 +54,7 @@ |
55 | 55 | 'langlinks' => 'ApiQueryLangLinks', |
56 | 56 | 'images' => 'ApiQueryImages', |
57 | 57 | 'imageinfo' => 'ApiQueryImageInfo', |
| 58 | + 'stashimageinfo' => 'ApiQueryStashImageInfo', |
58 | 59 | 'templates' => 'ApiQueryLinks', |
59 | 60 | 'categories' => 'ApiQueryCategories', |
60 | 61 | 'extlinks' => 'ApiQueryExternalLinks', |
Index: trunk/phase3/includes/api/ApiQueryStashImageInfo.php |
— | — | @@ -0,0 +1,152 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * API for MediaWiki 1.16+ |
| 5 | + * |
| 6 | + * This program is free software; you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU General Public License as published by |
| 8 | + * the Free Software Foundation; either version 2 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License along |
| 17 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 19 | + * http://www.gnu.org/copyleft/gpl.html |
| 20 | + * |
| 21 | + * @file |
| 22 | + */ |
| 23 | + |
| 24 | +/** |
| 25 | + * A query action to get image information from temporarily stashed files. |
| 26 | + * |
| 27 | + * @ingroup API |
| 28 | + */ |
| 29 | +class ApiQueryStashImageInfo extends ApiQueryImageInfo { |
| 30 | + |
| 31 | + public function __construct( $query, $moduleName ) { |
| 32 | + parent::__construct( $query, $moduleName, 'sii' ); |
| 33 | + } |
| 34 | + |
| 35 | + public function execute() { |
| 36 | + $params = $this->extractRequestParams(); |
| 37 | + $modulePrefix = $this->getModulePrefix(); |
| 38 | + |
| 39 | + $prop = array_flip( $params['prop'] ); |
| 40 | + |
| 41 | + $scale = $this->getScale( $params ); |
| 42 | + |
| 43 | + $result = $this->getResult(); |
| 44 | + |
| 45 | + try { |
| 46 | + $stash = new UploadStash(); |
| 47 | + |
| 48 | + foreach ( $params['sessionkey'] as $sessionkey ) { |
| 49 | + $file = $stash->getFile( $sessionkey ); |
| 50 | + $imageInfo = self::getInfo( $file, $prop, $result, $scale ); |
| 51 | + $result->addValue( array( 'query', $this->getModuleName() ), null, $imageInfo ); |
| 52 | + $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), $modulePrefix ); |
| 53 | + } |
| 54 | + |
| 55 | + } catch ( UploadStashNotAvailableException $e ) { |
| 56 | + $this->dieUsage( "Session not available: " . $e->getMessage(), "nosession" ); |
| 57 | + } catch ( UploadStashFileNotFoundException $e ) { |
| 58 | + $this->dieUsage( "File not found: " . $e->getMessage(), "invalidsessiondata" ); |
| 59 | + } catch ( UploadStashBadPathException $e ) { |
| 60 | + $this->dieUsage( "Bad path: " . $e->getMessage(), "invalidsessiondata" ); |
| 61 | + } |
| 62 | + |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * Returns all valid parameters to siiprop |
| 67 | + */ |
| 68 | + public static function getPropertyNames() { |
| 69 | + return array( |
| 70 | + 'timestamp', |
| 71 | + 'url', |
| 72 | + 'size', |
| 73 | + 'dimensions', // For backwards compatibility with Allimages |
| 74 | + 'sha1', |
| 75 | + 'mime', |
| 76 | + 'thumbmime', |
| 77 | + 'metadata', |
| 78 | + 'bitdepth', |
| 79 | + ); |
| 80 | + } |
| 81 | + |
| 82 | + |
| 83 | + public function getAllowedParams() { |
| 84 | + return array( |
| 85 | + 'sessionkey' => array( |
| 86 | + ApiBase::PARAM_ISMULTI => true, |
| 87 | + ApiBase::PARAM_REQUIRED => true, |
| 88 | + ApiBase::PARAM_DFLT => null |
| 89 | + ), |
| 90 | + 'prop' => array( |
| 91 | + ApiBase::PARAM_ISMULTI => true, |
| 92 | + ApiBase::PARAM_DFLT => 'timestamp|url', |
| 93 | + ApiBase::PARAM_TYPE => self::getPropertyNames() |
| 94 | + ), |
| 95 | + 'urlwidth' => array( |
| 96 | + ApiBase::PARAM_TYPE => 'integer', |
| 97 | + ApiBase::PARAM_DFLT => -1 |
| 98 | + ), |
| 99 | + 'urlheight' => array( |
| 100 | + ApiBase::PARAM_TYPE => 'integer', |
| 101 | + ApiBase::PARAM_DFLT => -1 |
| 102 | + ) |
| 103 | + ); |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * Return the API documentation for the parameters. |
| 108 | + * @return {Array} parameter documentation. |
| 109 | + */ |
| 110 | + public function getParamDescription() { |
| 111 | + $p = $this->getModulePrefix(); |
| 112 | + return array( |
| 113 | + 'prop' => array( |
| 114 | + 'What image information to get:', |
| 115 | + ' timestamp - Adds timestamp for the uploaded version', |
| 116 | + ' url - Gives URL to the image and the description page', |
| 117 | + ' size - Adds the size of the image in bytes and the height and width', |
| 118 | + ' dimensions - Alias for size', |
| 119 | + ' sha1 - Adds sha1 hash for the image', |
| 120 | + ' mime - Adds MIME of the image', |
| 121 | + ' thumbmime - Adss MIME of the image thumbnail (requires url)', |
| 122 | + ' metadata - Lists EXIF metadata for the version of the image', |
| 123 | + ' bitdepth - Adds the bit depth of the version', |
| 124 | + ), |
| 125 | + 'sessionkey' => 'Session key that identifies a previous upload that was stashed temporarily.', |
| 126 | + 'urlwidth' => "If {$p}prop=url is set, a URL to an image scaled to this width will be returned.", |
| 127 | + 'urlheight' => "Similar to {$p}urlwidth. Cannot be used without {$p}urlwidth" |
| 128 | + ); |
| 129 | + } |
| 130 | + |
| 131 | + public function getDescription() { |
| 132 | + return 'Returns image information for stashed images'; |
| 133 | + } |
| 134 | + |
| 135 | + public function getPossibleErrors() { |
| 136 | + return array_merge( parent::getPossibleErrors(), array( |
| 137 | + array( 'code' => 'siiurlwidth', 'info' => 'siiurlheight cannot be used without iiurlwidth' ), |
| 138 | + ) ); |
| 139 | + } |
| 140 | + |
| 141 | + protected function getExamples() { |
| 142 | + return array( |
| 143 | + 'api.php?action=query&prop=stashimageinfo&siisessionkey=124sd34rsdf567', |
| 144 | + 'api.php?action=query&prop=stashimageinfo&siisessionkey=b34edoe3|bceffd4&siiurlwidth=120&siiprop=url', |
| 145 | + ); |
| 146 | + } |
| 147 | + |
| 148 | + public function getVersion() { |
| 149 | + return __CLASS__ . ': $Id$'; |
| 150 | + } |
| 151 | + |
| 152 | +} |
| 153 | + |
Property changes on: trunk/phase3/includes/api/ApiQueryStashImageInfo.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 154 | + native |
Added: svn:keywords |
2 | 155 | + Id |
Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -336,6 +336,7 @@ |
337 | 337 | 'ApiQueryRevisions' => 'includes/api/ApiQueryRevisions.php', |
338 | 338 | 'ApiQuerySearch' => 'includes/api/ApiQuerySearch.php', |
339 | 339 | 'ApiQuerySiteinfo' => 'includes/api/ApiQuerySiteinfo.php', |
| 340 | + 'ApiQueryStashImageInfo' => 'includes/api/ApiQueryStashImageInfo.php', |
340 | 341 | 'ApiQueryTags' => 'includes/api/ApiQueryTags.php', |
341 | 342 | 'ApiQueryUserInfo' => 'includes/api/ApiQueryUserInfo.php', |
342 | 343 | 'ApiQueryUsers' => 'includes/api/ApiQueryUsers.php', |
Index: trunk/extensions/UploadWizard/ApiQueryStashImageInfo.php |
— | — | @@ -1,152 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * API for MediaWiki 1.16+ |
5 | | - * |
6 | | - * This program is free software; you can redistribute it and/or modify |
7 | | - * it under the terms of the GNU General Public License as published by |
8 | | - * the Free Software Foundation; either version 2 of the License, or |
9 | | - * (at your option) any later version. |
10 | | - * |
11 | | - * This program is distributed in the hope that it will be useful, |
12 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | - * GNU General Public License for more details. |
15 | | - * |
16 | | - * You should have received a copy of the GNU General Public License along |
17 | | - * with this program; if not, write to the Free Software Foundation, Inc., |
18 | | - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
19 | | - * http://www.gnu.org/copyleft/gpl.html |
20 | | - * |
21 | | - * @file |
22 | | - */ |
23 | | - |
24 | | -/** |
25 | | - * A query action to get image information from temporarily stashed files. |
26 | | - * |
27 | | - * @ingroup API |
28 | | - */ |
29 | | -class ApiQueryStashImageInfo extends ApiQueryImageInfo { |
30 | | - |
31 | | - public function __construct( $query, $moduleName ) { |
32 | | - parent::__construct( $query, $moduleName, 'sii' ); |
33 | | - } |
34 | | - |
35 | | - public function execute() { |
36 | | - $params = $this->extractRequestParams(); |
37 | | - $modulePrefix = $this->getModulePrefix(); |
38 | | - |
39 | | - $prop = array_flip( $params['prop'] ); |
40 | | - |
41 | | - $scale = $this->getScale( $params ); |
42 | | - |
43 | | - $result = $this->getResult(); |
44 | | - |
45 | | - try { |
46 | | - $stash = new UploadStash(); |
47 | | - |
48 | | - foreach ( $params['sessionkey'] as $sessionkey ) { |
49 | | - $file = $stash->getFile( $sessionkey ); |
50 | | - $imageInfo = self::getInfo( $file, $prop, $result, $scale ); |
51 | | - $result->addValue( array( 'query', $this->getModuleName() ), null, $imageInfo ); |
52 | | - $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), $modulePrefix ); |
53 | | - } |
54 | | - |
55 | | - } catch ( UploadStashNotAvailableException $e ) { |
56 | | - $this->dieUsage( "Session not available: " . $e->getMessage(), "nosession" ); |
57 | | - } catch ( UploadStashFileNotFoundException $e ) { |
58 | | - $this->dieUsage( "File not found: " . $e->getMessage(), "invalidsessiondata" ); |
59 | | - } catch ( UploadStashBadPathException $e ) { |
60 | | - $this->dieUsage( "Bad path: " . $e->getMessage(), "invalidsessiondata" ); |
61 | | - } |
62 | | - |
63 | | - } |
64 | | - |
65 | | - /** |
66 | | - * Returns all valid parameters to siiprop |
67 | | - */ |
68 | | - public static function getPropertyNames() { |
69 | | - return array( |
70 | | - 'timestamp', |
71 | | - 'url', |
72 | | - 'size', |
73 | | - 'dimensions', // For backwards compatibility with Allimages |
74 | | - 'sha1', |
75 | | - 'mime', |
76 | | - 'thumbmime', |
77 | | - 'metadata', |
78 | | - 'bitdepth', |
79 | | - ); |
80 | | - } |
81 | | - |
82 | | - |
83 | | - public function getAllowedParams() { |
84 | | - return array( |
85 | | - 'sessionkey' => array( |
86 | | - ApiBase::PARAM_ISMULTI => true, |
87 | | - ApiBase::PARAM_REQUIRED => true, |
88 | | - ApiBase::PARAM_DFLT => null |
89 | | - ), |
90 | | - 'prop' => array( |
91 | | - ApiBase::PARAM_ISMULTI => true, |
92 | | - ApiBase::PARAM_DFLT => 'timestamp|url', |
93 | | - ApiBase::PARAM_TYPE => self::getPropertyNames() |
94 | | - ), |
95 | | - 'urlwidth' => array( |
96 | | - ApiBase::PARAM_TYPE => 'integer', |
97 | | - ApiBase::PARAM_DFLT => -1 |
98 | | - ), |
99 | | - 'urlheight' => array( |
100 | | - ApiBase::PARAM_TYPE => 'integer', |
101 | | - ApiBase::PARAM_DFLT => -1 |
102 | | - ) |
103 | | - ); |
104 | | - } |
105 | | - |
106 | | - /** |
107 | | - * Return the API documentation for the parameters. |
108 | | - * @return {Array} parameter documentation. |
109 | | - */ |
110 | | - public function getParamDescription() { |
111 | | - $p = $this->getModulePrefix(); |
112 | | - return array( |
113 | | - 'prop' => array( |
114 | | - 'What image information to get:', |
115 | | - ' timestamp - Adds timestamp for the uploaded version', |
116 | | - ' url - Gives URL to the image and the description page', |
117 | | - ' size - Adds the size of the image in bytes and the height and width', |
118 | | - ' dimensions - Alias for size', |
119 | | - ' sha1 - Adds sha1 hash for the image', |
120 | | - ' mime - Adds MIME of the image', |
121 | | - ' thumbmime - Adss MIME of the image thumbnail (requires url)', |
122 | | - ' metadata - Lists EXIF metadata for the version of the image', |
123 | | - ' bitdepth - Adds the bit depth of the version', |
124 | | - ), |
125 | | - 'sessionkey' => 'Session key that identifies a previous upload that was stashed temporarily.', |
126 | | - 'urlwidth' => "If {$p}prop=url is set, a URL to an image scaled to this width will be returned.", |
127 | | - 'urlheight' => "Similar to {$p}urlwidth. Cannot be used without {$p}urlwidth" |
128 | | - ); |
129 | | - } |
130 | | - |
131 | | - public function getDescription() { |
132 | | - return 'Returns image information for stashed images'; |
133 | | - } |
134 | | - |
135 | | - public function getPossibleErrors() { |
136 | | - return array_merge( parent::getPossibleErrors(), array( |
137 | | - array( 'code' => 'siiurlwidth', 'info' => 'siiurlheight cannot be used without iiurlwidth' ), |
138 | | - ) ); |
139 | | - } |
140 | | - |
141 | | - protected function getExamples() { |
142 | | - return array( |
143 | | - 'api.php?action=query&prop=stashimageinfo&siisessionkey=124sd34rsdf567', |
144 | | - 'api.php?action=query&prop=stashimageinfo&siisessionkey=b34edoe3|bceffd4&siiurlwidth=120&siiprop=url', |
145 | | - ); |
146 | | - } |
147 | | - |
148 | | - public function getVersion() { |
149 | | - return __CLASS__ . ': $Id$'; |
150 | | - } |
151 | | - |
152 | | -} |
153 | | - |
Index: trunk/extensions/UploadWizard/UploadWizard.php |
— | — | @@ -38,13 +38,12 @@ |
39 | 39 | # Require modules, includeing the special page |
40 | 40 | foreach ( array( 'SpecialUploadWizard', |
41 | 41 | 'UploadWizardMessages', |
42 | | - 'ApiQueryStashImageInfo', |
43 | 42 | 'UploadWizardHooks', |
44 | 43 | 'UploadWizardTutorial', |
45 | 44 | 'UploadWizardDependencyLoader' ) as $module ) { |
46 | 45 | $wgAutoloadLocalClasses[$module] = $dir . "/" . $module . ".php"; |
47 | 46 | } |
48 | | -$wgAPIPropModules['stashimageinfo'] = 'ApiQueryStashImageInfo'; |
| 47 | + |
49 | 48 | |
50 | 49 | # Let the special page be a special center of unique specialness |
51 | 50 | $wgSpecialPages['UploadWizard'] = 'SpecialUploadWizard'; |