Index: trunk/phase3/maintenance/tests/ApiTest.php |
— | — | @@ -61,14 +61,32 @@ |
62 | 62 | global $wgScriptPath, $wgServerName; |
63 | 63 | |
64 | 64 | $req = HttpRequest::factory( self::$apiUrl . "?action=login&format=xml", |
65 | | - array( "method" => "POST", |
66 | | - "postData" => array( |
67 | | - "lgname" => self::$userName, |
68 | | - "lgpassword" => self::$passWord ) ) ); |
| 65 | + array( "method" => "POST", |
| 66 | + "postData" => array( "lgname" => self::$userName, |
| 67 | + "lgpassword" => self::$passWord ) ) ); |
69 | 68 | $req->execute(); |
70 | 69 | $cj = $req->getCookieJar(); |
71 | | - $this->markTestIncomplete("Need to make sure cookie/domain handling is correct"); |
72 | 70 | $this->assertRegexp( '/_session=[^;]*; .*UserID=[0-9]*; .*UserName=' . self::$userName . '; .*Token=/', |
73 | 71 | $cj->serializeToHttpRequest( $wgScriptPath, $wgServerName ) ); |
| 72 | + |
| 73 | + |
| 74 | + return $cj; |
74 | 75 | } |
| 76 | + |
| 77 | + /** |
| 78 | + * @depends testApiGotCookie |
| 79 | + */ |
| 80 | + function testApiListPages(CookieJar $cj) { |
| 81 | + $this->markTestIncomplete("Not done with this yet"); |
| 82 | + |
| 83 | + $req = HttpRequest::factory( self::$apiUrl . "?action=query&format=xml&prop=revisions&". |
| 84 | + "titles=Main%20Page&rvprop=timestamp|user|comment|content" ); |
| 85 | + $req->setCookieJar($cj); |
| 86 | + $req->execute(); |
| 87 | + libxml_use_internal_errors( true ); |
| 88 | + $sxe = simplexml_load_string( $req->getContent() ); |
| 89 | + $this->assertNotType( "bool", $sxe ); |
| 90 | + $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) ); |
| 91 | + $a = $sxe->query[0]->pages[0]->page[0]->attributes(); |
| 92 | + } |
75 | 93 | } |
Index: trunk/phase3/maintenance/tests/UploadFromChunksTest.php |
— | — | @@ -0,0 +1,99 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +require_once("ApiSetup.php"); |
| 5 | + |
| 6 | +class UploadFromChunksTest extends ApiSetup { |
| 7 | + |
| 8 | + function setUp() { |
| 9 | + global $wgEnableUploads; |
| 10 | + |
| 11 | + $wgEnableUploads=true; |
| 12 | + ini_set('file_loads', true); |
| 13 | + } |
| 14 | + |
| 15 | + function testGetEditToken() { |
| 16 | + } |
| 17 | + |
| 18 | + function testInitFromSessionKey() { |
| 19 | + |
| 20 | + } |
| 21 | + |
| 22 | + function testInitialize() { |
| 23 | + } |
| 24 | + |
| 25 | + function testSetupChunkSession() { |
| 26 | + } |
| 27 | + |
| 28 | + |
| 29 | + function makeChunk() { |
| 30 | + $file = tempnam( wfTempDir(), "" ); |
| 31 | + $fh = fopen($file, "w"); |
| 32 | + if($fh == false) { |
| 33 | + $this->markTestIncomplete("Couldn't open $file!\n"); |
| 34 | + return; |
| 35 | + } |
| 36 | + fwrite($fh, "123"); |
| 37 | + fclose($fh); |
| 38 | + |
| 39 | + $_FILES['chunk']['tmp_name'] = $file; |
| 40 | + $_FILES['chunk']['size'] = 3; |
| 41 | + $_FILES['chunk']['error'] = null; |
| 42 | + $_FILES['chunk']['name'] = "test.txt"; |
| 43 | + } |
| 44 | + |
| 45 | + function cleanChunk() { |
| 46 | + unlink($_FILES['chunk']['tmp_name']); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * @expectedException UsageException |
| 51 | + */ |
| 52 | + function testPerformUploadInitError() { |
| 53 | + global $wgUser; |
| 54 | + |
| 55 | + $wgUser = User::newFromId(1); |
| 56 | + $token = $wgUser->editToken(); |
| 57 | + $this->makeChunk(); |
| 58 | + |
| 59 | + $req = new FauxRequest( |
| 60 | + array('action' => 'upload', |
| 61 | + 'enablechunks' => '1', |
| 62 | + 'filename' => 'test.txt', |
| 63 | + 'token' => $token, |
| 64 | + )); |
| 65 | + $module = new ApiMain($req, true); |
| 66 | + $module->execute(); |
| 67 | + } |
| 68 | + |
| 69 | + function testPerformUploadInitSuccess() { |
| 70 | + global $wgUser; |
| 71 | + |
| 72 | + $wgUser = User::newFromId(1); |
| 73 | + $token = $wgUser->editToken(); |
| 74 | + $this->makeChunk(); |
| 75 | + |
| 76 | + $req = new FauxRequest( |
| 77 | + array('action' => 'upload', |
| 78 | + 'enablechunks' => '1', |
| 79 | + 'filename' => 'test.txt', |
| 80 | + 'token' => $token, |
| 81 | + )); |
| 82 | + $module = new ApiMain($req, true); |
| 83 | + $module->execute(); |
| 84 | + } |
| 85 | + |
| 86 | + function testAppendToUploadFile() { |
| 87 | + } |
| 88 | + |
| 89 | + function testAppendChunk() { |
| 90 | + } |
| 91 | + |
| 92 | + function testPeformUploadChunk() { |
| 93 | + } |
| 94 | + |
| 95 | + function testPeformUploadDone() { |
| 96 | + } |
| 97 | + |
| 98 | + |
| 99 | + |
| 100 | +} |
Property changes on: trunk/phase3/maintenance/tests/UploadFromChunksTest.php |
___________________________________________________________________ |
Name: svn:eol-syle |
1 | 101 | + native |
Index: trunk/phase3/includes/upload/UploadFromChunks.php |
— | — | @@ -51,7 +51,6 @@ |
52 | 52 | } else if ( $this->sessionKey && $done ) { |
53 | 53 | $this->chunkMode = self::DONE; |
54 | 54 | } |
55 | | - |
56 | 55 | if ( $this->chunkMode == self::CHUNK || $this->chunkMode == self::DONE ) { |
57 | 56 | $this->mTempPath = $path; |
58 | 57 | $this->fileSize += $fileSize; |
— | — | @@ -90,8 +89,7 @@ |
91 | 90 | protected function initFromSessionKey( $sessionKey, $sessionData ) { |
92 | 91 | // testing against null because we don't want to cause obscure |
93 | 92 | // bugs when $sessionKey is full of "0" |
94 | | - if ( $sessionKey !== null ) { |
95 | | - $this->status = Status::newFromFatal( 'import-token-mismatch' ); |
| 93 | + if ( $sessionKey === null ) { |
96 | 94 | return; |
97 | 95 | } |
98 | 96 | $this->sessionKey = $sessionKey; |
— | — | @@ -106,7 +104,7 @@ |
107 | 105 | $this->repoPath = $sessionData[$this->sessionKey]['repoPath']; |
108 | 106 | $this->mDesiredDestName = $sessionData[$this->sessionKey]['mDesiredDestName']; |
109 | 107 | } else { |
110 | | - $this->status = Status::newFromFatal( 'Missing session data.' ); |
| 108 | + $this->status = Status::newFatal( 'invalid-session-key' ); |
111 | 109 | } |
112 | 110 | } |
113 | 111 | |
Index: trunk/phase3/includes/api/ApiBase.php |
— | — | @@ -5,7 +5,7 @@ |
6 | 6 | * |
7 | 7 | * API for MediaWiki 1.8+ |
8 | 8 | * |
9 | | - * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com |
| 9 | + * Copyright (C) 2006, 2010 Yuri Astrakhan <Firstname><Lastname>@gmail.com |
10 | 10 | * |
11 | 11 | * This program is free software; you can redistribute it and/or modify |
12 | 12 | * it under the terms of the GNU General Public License as published by |
— | — | @@ -342,7 +342,7 @@ |
343 | 343 | } else |
344 | 344 | return false; |
345 | 345 | } |
346 | | - |
| 346 | + |
347 | 347 | /** |
348 | 348 | * Callback for preg_replace_callback() call in makeHelpMsg(). |
349 | 349 | * Replaces a source file name with a link to ViewVC |
— | — | @@ -353,14 +353,14 @@ |
354 | 354 | $file = $wgAutoloadLocalClasses[get_class( $this )]; |
355 | 355 | else if ( isset( $wgAutoloadClasses[get_class( $this )] ) ) |
356 | 356 | $file = $wgAutoloadClasses[get_class( $this )]; |
357 | | - |
| 357 | + |
358 | 358 | // Do some guesswork here |
359 | 359 | $path = strstr( $file, 'includes/api/' ); |
360 | 360 | if ( $path === false ) |
361 | 361 | $path = strstr( $file, 'extensions/' ); |
362 | 362 | else |
363 | 363 | $path = 'phase3/' . $path; |
364 | | - |
| 364 | + |
365 | 365 | // Get the filename from $matches[2] instead of $file |
366 | 366 | // If they're not the same file, they're assumed to be in the |
367 | 367 | // same directory |
— | — | @@ -409,7 +409,7 @@ |
410 | 410 | protected function getParamDescription() { |
411 | 411 | return false; |
412 | 412 | } |
413 | | - |
| 413 | + |
414 | 414 | /** |
415 | 415 | * Get final list of parameters, after hooks have had a chance to |
416 | 416 | * tweak it as needed. |
— | — | @@ -472,7 +472,7 @@ |
473 | 473 | $paramSettings = $params[$paramName]; |
474 | 474 | return $this->getParameterFromSettings( $paramName, $paramSettings, $parseLimit ); |
475 | 475 | } |
476 | | - |
| 476 | + |
477 | 477 | /** |
478 | 478 | * Die if none or more than one of a certain set of parameters is set |
479 | 479 | * @param $params array of parameter names |
— | — | @@ -480,7 +480,7 @@ |
481 | 481 | public function requireOnlyOneParameter( $params ) { |
482 | 482 | $required = func_get_args(); |
483 | 483 | array_shift( $required ); |
484 | | - |
| 484 | + |
485 | 485 | $intersection = array_intersect( array_keys( array_filter( $params, |
486 | 486 | create_function( '$x', 'return !is_null($x);' ) |
487 | 487 | ) ), $required ); |
— | — | @@ -721,7 +721,7 @@ |
722 | 722 | } |
723 | 723 | } |
724 | 724 | } |
725 | | - |
| 725 | + |
726 | 726 | /** |
727 | 727 | * Truncate an array to a certain length. |
728 | 728 | * @param $arr array Array to truncate |
— | — | @@ -885,6 +885,8 @@ |
886 | 886 | // uploadMsgs |
887 | 887 | 'invalid-session-key' => array( 'code' => 'invalid-session-key', 'info' => 'Not a valid session key' ), |
888 | 888 | 'nouploadmodule' => array( 'code' => 'nouploadmodule', 'info' => 'No upload module set' ), |
| 889 | + 'uploaddisabled' => array( 'code' => 'uploaddisabled', 'info' => 'Uploads are not enabled. Make sure $wgEnableUploads is set to true in LocalSettings.php and the PHP ini setting file_uploads is true' ), |
| 890 | + 'chunked-error' => array( 'code' => 'chunked-error', 'info' => 'There was a problem initializing the chunked upload.' ), |
889 | 891 | ); |
890 | 892 | |
891 | 893 | /** |
— | — | @@ -904,7 +906,7 @@ |
905 | 907 | $parsed = $this->parseMsg( $error ); |
906 | 908 | $this->dieUsage( $parsed['info'], $parsed['code'] ); |
907 | 909 | } |
908 | | - |
| 910 | + |
909 | 911 | /** |
910 | 912 | * Return the error message related to a certain array |
911 | 913 | * @param $error array Element of a getUserPermissionsErrors()-style array |
Index: trunk/phase3/includes/api/ApiUpload.php |
— | — | @@ -3,7 +3,7 @@ |
4 | 4 | * Created on Aug 21, 2008 |
5 | 5 | * API for MediaWiki 1.8+ |
6 | 6 | * |
7 | | - * Copyright (C) 2008 - 2009 Bryan Tong Minh <Bryan.TongMinh@Gmail.com> |
| 7 | + * Copyright (C) 2008 - 2010 Bryan Tong Minh <Bryan.TongMinh@Gmail.com> |
8 | 8 | * |
9 | 9 | * This program is free software; you can redistribute it and/or modify |
10 | 10 | * it under the terms of the GNU General Public License as published by |
— | — | @@ -93,8 +93,7 @@ |
94 | 94 | ); |
95 | 95 | |
96 | 96 | if ( !$this->mUpload->status->isOK() ) { |
97 | | - return $this->dieUsageMsg( $this->mUpload->status->getWikiText(), |
98 | | - 'chunked-error' ); |
| 97 | + return $this->dieUsageMsg( $this->mUpload->status->getErrorsArray() ); |
99 | 98 | } |
100 | 99 | } elseif ( isset( $this->mParams['file'] ) ) { |
101 | 100 | $this->mUpload = new UploadFromFile(); |