Index: trunk/phase3/maintenance/tests/UploadFromUrlTest.php |
— | — | @@ -112,7 +112,7 @@ |
113 | 113 | $this->doApiRequest( array( |
114 | 114 | 'action' => 'upload', |
115 | 115 | 'url' => 'http://www.example.com/test.png', |
116 | | - 'filename' => 'Test.png', |
| 116 | + 'filename' => 'UploadFromUrlTest.png', |
117 | 117 | 'token' => $token, |
118 | 118 | ), $data ); |
119 | 119 | } catch ( UsageException $e ) { |
— | — | @@ -128,18 +128,14 @@ |
129 | 129 | 'action' => 'upload', |
130 | 130 | 'url' => 'http://bits.wikimedia.org/skins-1.5/common/images/poweredby_mediawiki_88x31.png', |
131 | 131 | 'asyncdownload' => 1, |
132 | | - 'filename' => 'Test.png', |
| 132 | + 'filename' => 'UploadFromUrlTest.png', |
133 | 133 | 'token' => $token, |
134 | 134 | ), $data ); |
135 | 135 | |
136 | | - $this->assertTrue( $data[0]['upload']['queued'], 'Job added' ); |
137 | | - |
| 136 | + $this->assertEquals( $data[0]['upload']['result'], 'Queued', 'Queued upload' ); |
| 137 | + |
138 | 138 | $job = Job::pop(); |
139 | | - $this->assertThat( $job, $this->isInstanceOf( 'UploadFromUrlJob' ), |
140 | | - "Got Job Object" ); |
141 | | - |
142 | | - $job = Job::pop_type( 'upload' ); |
143 | | - $this->assertFalse( $job ); |
| 139 | + $this->assertThat( $job, $this->isInstanceOf( 'UploadFromUrlJob' ), 'Queued upload inserted' ); |
144 | 140 | } |
145 | 141 | |
146 | 142 | /** |
— | — | @@ -153,7 +149,7 @@ |
154 | 150 | $wgUser->addGroup( 'users' ); |
155 | 151 | $data = $this->doApiRequest( array( |
156 | 152 | 'action' => 'upload', |
157 | | - 'filename' => 'Test.png', |
| 153 | + 'filename' => 'UploadFromUrlTest.png', |
158 | 154 | 'url' => 'http://bits.wikimedia.org/skins-1.5/common/images/poweredby_mediawiki_88x31.png', |
159 | 155 | 'asyncdownload' => 1, |
160 | 156 | 'token' => $token, |
— | — | @@ -164,7 +160,7 @@ |
165 | 161 | |
166 | 162 | $status = $job->run(); |
167 | 163 | |
168 | | - $this->assertTrue( $status->isOk() ); |
| 164 | + $this->assertTrue( $status ); |
169 | 165 | |
170 | 166 | return $data; |
171 | 167 | } |
— | — | @@ -178,14 +174,14 @@ |
179 | 175 | $token = md5( $data[2]['wsToken'] ) . EDIT_TOKEN_SUFFIX; |
180 | 176 | |
181 | 177 | $job = Job::pop(); |
182 | | - $this->assertFalse( $job ); |
| 178 | + $this->assertFalse( $job, 'Starting with an empty jobqueue' ); |
183 | 179 | |
184 | | - $this->deleteFile( 'Test.png' ); |
| 180 | + //$this->deleteFile( 'UploadFromUrlTest.png' ); |
185 | 181 | |
186 | 182 | $wgUser->addGroup( 'users' ); |
187 | 183 | $data = $this->doApiRequest( array( |
188 | 184 | 'action' => 'upload', |
189 | | - 'filename' => 'Test.png', |
| 185 | + 'filename' => 'UploadFromUrlTest.png', |
190 | 186 | 'url' => 'http://bits.wikimedia.org/skins-1.5/common/images/poweredby_mediawiki_88x31.png', |
191 | 187 | 'ignorewarnings' => true, |
192 | 188 | 'token' => $token, |
— | — | @@ -203,18 +199,17 @@ |
204 | 200 | * @depends testDoDownload |
205 | 201 | */ |
206 | 202 | function testVerifyDownload( $data ) { |
207 | | - $t = Title::newFromText( "Test.png", NS_FILE ); |
| 203 | + $t = Title::newFromText( "UploadFromUrlTest.png", NS_FILE ); |
208 | 204 | |
209 | 205 | $this->assertTrue( $t->exists() ); |
210 | 206 | |
211 | | - $this->deleteFile( 'Test.png' ); |
| 207 | + $this->deleteFile( 'UploadFromUrlTest.png' ); |
212 | 208 | } |
213 | 209 | |
214 | 210 | /** |
215 | 211 | * |
216 | 212 | */ |
217 | 213 | function deleteFile( $name ) { |
218 | | - |
219 | 214 | $t = Title::newFromText( $name, NS_FILE ); |
220 | 215 | $this->assertTrue($t->exists(), "File '$name' exists"); |
221 | 216 | |
Index: trunk/phase3/includes/job/UploadFromUrlJob.php |
— | — | @@ -18,6 +18,14 @@ |
19 | 19 | } |
20 | 20 | |
21 | 21 | public function run() { |
| 22 | + # Until we find a way to store data in sessions, set leaveMessage to |
| 23 | + # true unconditionally |
| 24 | + $this->params['leaveMessage'] = true; |
| 25 | + # Similar for ignorewarnings. This is not really a good fallback, but |
| 26 | + # there is no easy way to get a wikitext formatted warning message to |
| 27 | + # show to the user |
| 28 | + $this->params['ignoreWarnings'] = true; |
| 29 | + |
22 | 30 | # Initialize this object and the upload object |
23 | 31 | $this->upload = new UploadFromUrl(); |
24 | 32 | $this->upload->initialize( |
— | — | @@ -31,7 +39,7 @@ |
32 | 40 | $status = $this->upload->fetchFile(); |
33 | 41 | if ( !$status->isOk() ) { |
34 | 42 | $this->leaveMessage( $status ); |
35 | | - return; |
| 43 | + return true; |
36 | 44 | } |
37 | 45 | |
38 | 46 | # Verify upload |
— | — | @@ -39,13 +47,13 @@ |
40 | 48 | if ( $result['status'] != UploadBase::OK ) { |
41 | 49 | $status = $this->upload->convertVerifyErrorToStatus( $result ); |
42 | 50 | $this->leaveMessage( $status ); |
43 | | - return; |
| 51 | + return true; |
44 | 52 | } |
45 | 53 | |
46 | 54 | # Check warnings |
47 | 55 | if ( !$this->params['ignoreWarnings'] ) { |
48 | 56 | $warnings = $this->upload->checkWarnings(); |
49 | | - if ( $warnings ) { |
| 57 | + if ( $warnings ) { |
50 | 58 | if ( $this->params['leaveMessage'] ) { |
51 | 59 | $this->user->leaveUserMessage( |
52 | 60 | wfMsg( 'upload-warning-subj' ), |
— | — | @@ -59,7 +67,7 @@ |
60 | 68 | } |
61 | 69 | |
62 | 70 | // FIXME: stash in session |
63 | | - return; |
| 71 | + return true; |
64 | 72 | } |
65 | 73 | } |
66 | 74 | |
— | — | @@ -71,6 +79,8 @@ |
72 | 80 | $this->user |
73 | 81 | ); |
74 | 82 | $this->leaveMessage( $status ); |
| 83 | + return true; |
| 84 | + |
75 | 85 | } |
76 | 86 | |
77 | 87 | /** |