*
* API for MediaWiki 1.8+
*
- * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright (C) 2006, 2010 Yuri Astrakhan <Firstname><Lastname>@gmail.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
} else
return false;
}
-
+
/**
* Callback for preg_replace_callback() call in makeHelpMsg().
* Replaces a source file name with a link to ViewVC
$file = $wgAutoloadLocalClasses[get_class( $this )];
else if ( isset( $wgAutoloadClasses[get_class( $this )] ) )
$file = $wgAutoloadClasses[get_class( $this )];
-
+
// Do some guesswork here
$path = strstr( $file, 'includes/api/' );
if ( $path === false )
$path = strstr( $file, 'extensions/' );
else
$path = 'phase3/' . $path;
-
+
// Get the filename from $matches[2] instead of $file
// If they're not the same file, they're assumed to be in the
// same directory
protected function getParamDescription() {
return false;
}
-
+
/**
* Get final list of parameters, after hooks have had a chance to
* tweak it as needed.
$paramSettings = $params[$paramName];
return $this->getParameterFromSettings( $paramName, $paramSettings, $parseLimit );
}
-
+
/**
* Die if none or more than one of a certain set of parameters is set
* @param $params array of parameter names
public function requireOnlyOneParameter( $params ) {
$required = func_get_args();
array_shift( $required );
-
+
$intersection = array_intersect( array_keys( array_filter( $params,
create_function( '$x', 'return !is_null($x);' )
) ), $required );
}
}
}
-
+
/**
* Truncate an array to a certain length.
* @param $arr array Array to truncate
// uploadMsgs
'invalid-session-key' => array( 'code' => 'invalid-session-key', 'info' => 'Not a valid session key' ),
'nouploadmodule' => array( 'code' => 'nouploadmodule', 'info' => 'No upload module set' ),
+ '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' ),
+ 'chunked-error' => array( 'code' => 'chunked-error', 'info' => 'There was a problem initializing the chunked upload.' ),
);
/**
$parsed = $this->parseMsg( $error );
$this->dieUsage( $parsed['info'], $parsed['code'] );
}
-
+
/**
* Return the error message related to a certain array
* @param $error array Element of a getUserPermissionsErrors()-style array
* Created on Aug 21, 2008
* API for MediaWiki 1.8+
*
- * Copyright (C) 2008 - 2009 Bryan Tong Minh <Bryan.TongMinh@Gmail.com>
+ * Copyright (C) 2008 - 2010 Bryan Tong Minh <Bryan.TongMinh@Gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
);
if ( !$this->mUpload->status->isOK() ) {
- return $this->dieUsageMsg( $this->mUpload->status->getWikiText(),
- 'chunked-error' );
+ return $this->dieUsageMsg( $this->mUpload->status->getErrorsArray() );
}
} elseif ( isset( $this->mParams['file'] ) ) {
$this->mUpload = new UploadFromFile();
} else if ( $this->sessionKey && $done ) {
$this->chunkMode = self::DONE;
}
-
if ( $this->chunkMode == self::CHUNK || $this->chunkMode == self::DONE ) {
$this->mTempPath = $path;
$this->fileSize += $fileSize;
protected function initFromSessionKey( $sessionKey, $sessionData ) {
// testing against null because we don't want to cause obscure
// bugs when $sessionKey is full of "0"
- if ( $sessionKey !== null ) {
- $this->status = Status::newFromFatal( 'import-token-mismatch' );
+ if ( $sessionKey === null ) {
return;
}
$this->sessionKey = $sessionKey;
$this->repoPath = $sessionData[$this->sessionKey]['repoPath'];
$this->mDesiredDestName = $sessionData[$this->sessionKey]['mDesiredDestName'];
} else {
- $this->status = Status::newFromFatal( 'Missing session data.' );
+ $this->status = Status::newFatal( 'invalid-session-key' );
}
}
global $wgScriptPath, $wgServerName;
$req = HttpRequest::factory( self::$apiUrl . "?action=login&format=xml",
- array( "method" => "POST",
- "postData" => array(
- "lgname" => self::$userName,
- "lgpassword" => self::$passWord ) ) );
+ array( "method" => "POST",
+ "postData" => array( "lgname" => self::$userName,
+ "lgpassword" => self::$passWord ) ) );
$req->execute();
$cj = $req->getCookieJar();
- $this->markTestIncomplete("Need to make sure cookie/domain handling is correct");
$this->assertRegexp( '/_session=[^;]*; .*UserID=[0-9]*; .*UserName=' . self::$userName . '; .*Token=/',
$cj->serializeToHttpRequest( $wgScriptPath, $wgServerName ) );
+
+
+ return $cj;
+ }
+
+ /**
+ * @depends testApiGotCookie
+ */
+ function testApiListPages(CookieJar $cj) {
+ $this->markTestIncomplete("Not done with this yet");
+
+ $req = HttpRequest::factory( self::$apiUrl . "?action=query&format=xml&prop=revisions&".
+ "titles=Main%20Page&rvprop=timestamp|user|comment|content" );
+ $req->setCookieJar($cj);
+ $req->execute();
+ libxml_use_internal_errors( true );
+ $sxe = simplexml_load_string( $req->getContent() );
+ $this->assertNotType( "bool", $sxe );
+ $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
+ $a = $sxe->query[0]->pages[0]->page[0]->attributes();
}
}
--- /dev/null
+<?php
+
+require_once("ApiSetup.php");
+
+class UploadFromChunksTest extends ApiSetup {
+
+ function setUp() {
+ global $wgEnableUploads;
+
+ $wgEnableUploads=true;
+ ini_set('file_loads', true);
+ }
+
+ function testGetEditToken() {
+ }
+
+ function testInitFromSessionKey() {
+
+ }
+
+ function testInitialize() {
+ }
+
+ function testSetupChunkSession() {
+ }
+
+
+ function makeChunk() {
+ $file = tempnam( wfTempDir(), "" );
+ $fh = fopen($file, "w");
+ if($fh == false) {
+ $this->markTestIncomplete("Couldn't open $file!\n");
+ return;
+ }
+ fwrite($fh, "123");
+ fclose($fh);
+
+ $_FILES['chunk']['tmp_name'] = $file;
+ $_FILES['chunk']['size'] = 3;
+ $_FILES['chunk']['error'] = null;
+ $_FILES['chunk']['name'] = "test.txt";
+ }
+
+ function cleanChunk() {
+ unlink($_FILES['chunk']['tmp_name']);
+ }
+
+ /**
+ * @expectedException UsageException
+ */
+ function testPerformUploadInitError() {
+ global $wgUser;
+
+ $wgUser = User::newFromId(1);
+ $token = $wgUser->editToken();
+ $this->makeChunk();
+
+ $req = new FauxRequest(
+ array('action' => 'upload',
+ 'enablechunks' => '1',
+ 'filename' => 'test.txt',
+ 'token' => $token,
+ ));
+ $module = new ApiMain($req, true);
+ $module->execute();
+ }
+
+ function testPerformUploadInitSuccess() {
+ global $wgUser;
+
+ $wgUser = User::newFromId(1);
+ $token = $wgUser->editToken();
+ $this->makeChunk();
+
+ $req = new FauxRequest(
+ array('action' => 'upload',
+ 'enablechunks' => '1',
+ 'filename' => 'test.txt',
+ 'token' => $token,
+ ));
+ $module = new ApiMain($req, true);
+ $module->execute();
+ }
+
+ function testAppendToUploadFile() {
+ }
+
+ function testAppendChunk() {
+ }
+
+ function testPeformUploadChunk() {
+ }
+
+ function testPeformUploadDone() {
+ }
+
+
+
+}