31 $user = self::$users[
'uploader'];
32 $userName =
$user->getUser()->getName();
33 $password =
$user->getPassword();
37 'lgname' => $userName,
38 'lgpassword' => $password
41 $this->assertArrayHasKey(
"login",
$result );
42 $this->assertArrayHasKey(
"result",
$result[
'login'] );
43 $this->assertEquals(
"NeedToken",
$result[
'login'][
'result'] );
44 $token =
$result[
'login'][
'token'];
49 'lgname' => $userName,
50 'lgpassword' => $password
53 $this->assertArrayHasKey(
"login",
$result );
54 $this->assertArrayHasKey(
"result",
$result[
'login'] );
55 $this->assertEquals(
"Success",
$result[
'login'][
'result'] );
57 $this->assertNotEmpty( $session,
'API Login must return a session' );
73 $this->assertContains(
'The "token" parameter must be set',
$e->getMessage() );
75 $this->assertTrue( $exception,
"Got exception" );
86 ], $session, self::$users[
'uploader']->getUser() );
90 'One of the parameters "filekey", "file" and "url" is required.',
94 $this->assertTrue( $exception,
"Got exception" );
102 $mimeType =
'image/png';
106 $filePaths = $randomImageGenerator->writeImages( 1, $extension, $this->
getNewTempDirectory() );
107 }
catch ( Exception
$e ) {
108 $this->markTestIncomplete(
$e->getMessage() );
112 $filePath = $filePaths[0];
113 $fileSize = filesize( $filePath );
114 $fileName = basename( $filePath );
119 if ( !$this->
fakeUploadFile(
'file', $fileName, $mimeType, $filePath ) ) {
120 $this->markTestIncomplete(
"Couldn't upload file!\n" );
124 'action' =>
'upload',
125 'filename' => $fileName,
126 'file' =>
'dummy content',
127 'comment' =>
'dummy comment',
128 'text' =>
"This is the page text for $fileName",
134 self::$users[
'uploader']->getUser() );
138 $this->assertTrue( isset(
$result[
'upload'] ) );
139 $this->assertEquals(
'Success',
$result[
'upload'][
'result'] );
140 $this->assertEquals( $fileSize, (
int)
$result[
'upload'][
'imageinfo'][
'size'] );
141 $this->assertEquals( $mimeType,
$result[
'upload'][
'imageinfo'][
'mime'] );
142 $this->assertFalse( $exception );
152 $mimeType =
'image/png';
155 $fileName =
"apiTestUploadZeroLength.png";
159 if ( !$this->
fakeUploadFile(
'file', $fileName, $mimeType, $filePath ) ) {
160 $this->markTestIncomplete(
"Couldn't upload file!\n" );
164 'action' =>
'upload',
165 'filename' => $fileName,
166 'file' =>
'dummy content',
167 'comment' =>
'dummy comment',
168 'text' =>
"This is the page text for $fileName",
175 $this->assertContains(
'The file you submitted was empty',
$e->getMessage() );
178 $this->assertTrue( $exception );
189 $mimeType =
'image/png';
193 $filePaths = $randomImageGenerator->writeImages( 2, $extension, $this->
getNewTempDirectory() );
194 }
catch ( Exception
$e ) {
195 $this->markTestIncomplete(
$e->getMessage() );
200 $fileName = basename( $filePaths[0] );
207 'action' =>
'upload',
208 'filename' => $fileName,
209 'file' =>
'dummy content',
210 'comment' =>
'dummy comment',
211 'text' =>
"This is the page text for $fileName",
216 if ( !$this->
fakeUploadFile(
'file', $fileName, $mimeType, $filePaths[0] ) ) {
217 $this->markTestIncomplete(
"Couldn't upload file!\n" );
223 self::$users[
'uploader']->getUser() );
227 $this->assertTrue( isset(
$result[
'upload'] ) );
228 $this->assertEquals(
'Success',
$result[
'upload'][
'result'] );
229 $this->assertFalse( $exception );
233 if ( !$this->
fakeUploadFile(
'file', $fileName, $mimeType, $filePaths[1] ) ) {
234 $this->markTestIncomplete(
"Couldn't upload file!\n" );
240 self::$users[
'uploader']->getUser() );
244 $this->assertTrue( isset(
$result[
'upload'] ) );
245 $this->assertEquals(
'Warning',
$result[
'upload'][
'result'] );
246 $this->assertTrue( isset(
$result[
'upload'][
'warnings'] ) );
247 $this->assertTrue( isset(
$result[
'upload'][
'warnings'][
'exists'] ) );
248 $this->assertFalse( $exception );
259 $mimeType =
'image/png';
263 $filePaths = $randomImageGenerator->writeImages( 1, $extension, $this->
getNewTempDirectory() );
264 }
catch ( Exception
$e ) {
265 $this->markTestIncomplete(
$e->getMessage() );
269 $fileNames[0] = basename( $filePaths[0] );
270 $fileNames[1] =
"SameContentAs" . $fileNames[0];
280 'action' =>
'upload',
281 'filename' => $fileNames[0],
282 'file' =>
'dummy content',
283 'comment' =>
'dummy comment',
284 'text' =>
"This is the page text for " . $fileNames[0],
287 if ( !$this->
fakeUploadFile(
'file', $fileNames[0], $mimeType, $filePaths[0] ) ) {
288 $this->markTestIncomplete(
"Couldn't upload file!\n" );
294 self::$users[
'uploader']->getUser() );
298 $this->assertTrue( isset(
$result[
'upload'] ) );
299 $this->assertEquals(
'Success',
$result[
'upload'][
'result'] );
300 $this->assertFalse( $exception );
304 if ( !$this->
fakeUploadFile(
'file', $fileNames[1], $mimeType, $filePaths[0] ) ) {
305 $this->markTestIncomplete(
"Couldn't upload file!\n" );
309 'action' =>
'upload',
310 'filename' => $fileNames[1],
311 'file' =>
'dummy content',
312 'comment' =>
'dummy comment',
313 'text' =>
"This is the page text for " . $fileNames[1],
319 self::$users[
'uploader']->getUser() );
323 $this->assertTrue( isset(
$result[
'upload'] ) );
324 $this->assertEquals(
'Warning',
$result[
'upload'][
'result'] );
325 $this->assertTrue( isset(
$result[
'upload'][
'warnings'] ) );
326 $this->assertTrue( isset(
$result[
'upload'][
'warnings'][
'duplicate'] ) );
327 $this->assertFalse( $exception );
339 'wgUser' => self::$users[
'uploader']->getUser(),
343 $mimeType =
'image/png';
347 $filePaths = $randomImageGenerator->writeImages( 1, $extension, $this->
getNewTempDirectory() );
348 }
catch ( Exception
$e ) {
349 $this->markTestIncomplete(
$e->getMessage() );
353 $filePath = $filePaths[0];
354 $fileSize = filesize( $filePath );
355 $fileName = basename( $filePath );
360 if ( !$this->
fakeUploadFile(
'file', $fileName, $mimeType, $filePath ) ) {
361 $this->markTestIncomplete(
"Couldn't upload file!\n" );
365 'action' =>
'upload',
367 'filename' => $fileName,
368 'file' =>
'dummy content',
369 'comment' =>
'dummy comment',
370 'text' =>
"This is the page text for $fileName",
376 self::$users[
'uploader']->getUser() );
380 $this->assertFalse( $exception );
381 $this->assertTrue( isset(
$result[
'upload'] ) );
382 $this->assertEquals(
'Success',
$result[
'upload'][
'result'] );
383 $this->assertEquals( $fileSize, (
int)
$result[
'upload'][
'imageinfo'][
'size'] );
384 $this->assertEquals( $mimeType,
$result[
'upload'][
'imageinfo'][
'mime'] );
385 $this->assertTrue( isset(
$result[
'upload'][
'filekey'] ) );
386 $this->assertEquals(
$result[
'upload'][
'sessionkey'],
$result[
'upload'][
'filekey'] );
387 $filekey =
$result[
'upload'][
'filekey'];
394 'action' =>
'upload',
395 'filekey' => $filekey,
396 'filename' => $fileName,
397 'comment' =>
'dummy comment',
398 'text' =>
"This is the page text for $fileName, altered",
405 self::$users[
'uploader']->getUser() );
409 $this->assertTrue( isset(
$result[
'upload'] ) );
410 $this->assertEquals(
'Success',
$result[
'upload'][
'result'] );
411 $this->assertFalse( $exception,
"No ApiUsageException exception." );
423 'wgUser' => self::$users[
'uploader']->getUser(),
426 $chunkSize = 1048576;
430 $mimeType =
'image/jpeg';
431 $url =
'http://upload.wikimedia.org/wikipedia/commons/'
432 .
'e/ed/Oberaargletscher_from_Oberaar%2C_2010_07.JPG';
435 copy( $url, $filePath );
436 }
catch ( Exception
$e ) {
437 $this->markTestIncomplete(
$e->getMessage() );
440 $fileSize = filesize( $filePath );
441 $fileName = basename( $filePath );
448 'action' =>
'upload',
450 'filename' => $fileName,
451 'filesize' => $fileSize,
456 $chunkSessionKey =
false;
459 Wikimedia\suppressWarnings();
460 $handle = fopen( $filePath,
"r" );
461 Wikimedia\restoreWarnings();
463 if ( $handle ===
false ) {
464 $this->markTestIncomplete(
"could not open file: $filePath" );
467 while ( !feof( $handle ) ) {
469 Wikimedia\suppressWarnings();
470 $chunkData = fread( $handle, $chunkSize );
471 Wikimedia\restoreWarnings();
477 if ( !$chunkSessionKey ) {
481 self::$users[
'uploader']->getUser() );
483 $this->markTestIncomplete(
$e->getMessage() );
486 $this->assertTrue( isset(
$result[
'upload'] ) );
487 $this->assertTrue( isset(
$result[
'upload'][
'filekey'] ) );
489 if ( !isset(
$result[
'upload'][
'filekey'] ) ) {
490 $this->markTestIncomplete(
"no filekey provided" );
492 $chunkSessionKey =
$result[
'upload'][
'filekey'];
493 $this->assertEquals(
'Continue',
$result[
'upload'][
'result'] );
495 $this->assertEquals( $chunkSize,
$result[
'upload'][
'offset'] );
496 $resultOffset =
$result[
'upload'][
'offset'];
500 $params[
'filekey'] = $chunkSessionKey;
503 $params[
'offset'] += $chunkSize;
505 $this->assertEquals( $resultOffset,
$params[
'offset'] );
509 self::$users[
'uploader']->getUser() );
511 $this->markTestIncomplete(
$e->getMessage() );
514 $this->assertTrue( isset(
$result[
'upload'] ) );
515 $this->assertTrue( isset(
$result[
'upload'][
'filekey'] ) );
518 if (
$params[
'offset'] + $chunkSize >= $fileSize ) {
519 $this->assertEquals(
'Success',
$result[
'upload'][
'result'] );
522 $this->assertEquals(
'Continue',
$result[
'upload'][
'result'] );
524 $resultOffset =
$result[
'upload'][
'offset'];
531 .
" hohoh filesize {$fileSize} info {$result['upload']['imageinfo']['size']}\n\n" );
532 $this->assertEquals( $fileSize,
$result[
'upload'][
'imageinfo'][
'size'] );
533 $this->assertEquals( $mimeType,
$result[
'upload'][
'imageinfo'][
'mime'] );
534 $this->assertTrue( isset(
$result[
'upload'][
'filekey'] ) );
535 $filekey =
$result[
'upload'][
'filekey'];
539 'action' =>
'upload',
540 'filekey' => $filekey,
541 'filename' => $fileName,
542 'comment' =>
'dummy comment',
543 'text' =>
"This is the page text for $fileName, altered",
549 self::$users[
'uploader']->getUser() );
553 $this->assertTrue( isset(
$result[
'upload'] ) );
554 $this->assertEquals(
'Success',
$result[
'upload'][
'result'] );
555 $this->assertFalse( $exception );
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
doApiRequestWithToken(array $params, array $session=null, User $user=null, $tokenType='auto')
Convenience function to access the token parameter of doApiRequest() more succinctly.
doApiRequest(array $params, array $session=null, $appendModule=false, User $user=null, $tokenType=null)
Does the API request and returns the result.
Abstract class to support upload tests.
clearFakeUploads()
Remove traces of previous fake uploads.
fakeUploadChunk( $fieldName, $fileName, $type, & $chunkData)
deleteFileByContent( $filePath)
Helper function – given a file on the filesystem, find matching content in the db (and associated art...
deleteFileByFileName( $fileName)
Helper function – remove files and associated articles with a particular filename.
fakeUploadFile( $fieldName, $fileName, $type, $filePath)
Fake an upload by dumping the file into temp space, and adding info to $_FILES.
testUploadZeroLength( $session)
@depends testLogin
testUploadStash( $session)
@depends testLogin
testLogin()
Testing login XXX this is a funny way of getting session context.
testUploadSameContent( $session)
@depends testLogin
testUploadRequiresToken( $session)
@depends testLogin
testUploadMissingParams( $session)
@depends testLogin
testUploadSameFileName( $session)
@depends testLogin
testUpload( $session)
@depends testLogin
testUploadChunks( $session)
@depends testLogin
Exception used to abort API execution with an error.
RandomImageGenerator: does what it says on the tin.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImgAuthModifyHeaders':Executed just before a file is streamed to a user via img_auth.php, allowing headers to be modified beforehand. $title:LinkTarget object & $headers:HTTP headers(name=> value, names are case insensitive). Two headers get special handling:If-Modified-Since(value must be a valid HTTP date) and Range(must be of the form "bytes=(\d*-\d*)") will be honored when streaming the file. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUnknownUser':When a user doesn 't exist locally, this hook is called to give extensions an opportunity to auto-create it. If the auto-creation is successful, return false. $name:User name 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED since 1.28! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
return true to allow those checks to and false if checking is done & $user
returning false will NOT prevent logging $e
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php