3use Wikimedia\TestingAccessWrapper;
62 if ( $this->
getCliArg(
'use-filebackend' ) ) {
63 if ( self::$backendToUse ) {
66 $name = $this->
getCliArg(
'use-filebackend' );
69 if ( $conf[
'name'] == $name ) {
74 $useConfig[
'name'] =
'localtesting';
75 $useConfig[
'shardViaHashLevels'] = [
76 'unittest-cont1' => [
'levels' => 1,
'base' => 16,
'repeat' => 1 ]
78 if ( isset( $useConfig[
'fileJournal'] ) ) {
82 $class = $useConfig[
'class'];
83 self::$backendToUse =
new $class( $useConfig );
88 'name' =>
'localtesting',
92 'unittest-cont1' =>
"{$tmpDir}/localtesting-cont1",
93 'unittest-cont2' =>
"{$tmpDir}/localtesting-cont2" ]
97 'name' =>
'localtesting',
99 'parallelize' =>
'implicit',
103 'name' =>
'localmultitesting1',
104 'class' => FSFileBackend::class,
105 'containerPaths' => [
106 'unittest-cont1' =>
"{$tmpDir}/localtestingmulti1-cont1",
107 'unittest-cont2' =>
"{$tmpDir}/localtestingmulti1-cont2" ],
108 'isMultiMaster' =>
false
111 'name' =>
'localmultitesting2',
112 'class' => FSFileBackend::class,
113 'containerPaths' => [
114 'unittest-cont1' =>
"{$tmpDir}/localtestingmulti2-cont1",
115 'unittest-cont2' =>
"{$tmpDir}/localtestingmulti2-cont2" ],
116 'isMultiMaster' =>
true
123 return 'mwstore://localtesting';
127 return get_class( $this->backend );
135 "FileBackend::isStoragePath on path '$path'" );
140 [
'mwstore://',
true ],
141 [
'mwstore://backend',
true ],
142 [
'mwstore://backend/container',
true ],
143 [
'mwstore://backend/container/',
true ],
144 [
'mwstore://backend/container/path',
true ],
145 [
'mwstore://backend//container/',
true ],
146 [
'mwstore://backend//container//',
true ],
147 [
'mwstore://backend//container//path',
true ],
148 [
'mwstore:///',
true ],
149 [
'mwstore:/',
false ],
150 [
'mwstore:',
false ],
159 "FileBackend::splitStoragePath on path '$path'" );
164 [
'mwstore://backend/container', [
'backend',
'container',
'' ] ],
165 [
'mwstore://backend/container/', [
'backend',
'container',
'' ] ],
166 [
'mwstore://backend/container/path', [
'backend',
'container',
'path' ] ],
167 [
'mwstore://backend/container//path', [
'backend',
'container',
'/path' ] ],
168 [
'mwstore://backend//container/path', [
null,
null, null ] ],
169 [
'mwstore://backend//container//path', [
null,
null, null ] ],
170 [
'mwstore://', [
null,
null, null ] ],
171 [
'mwstore://backend', [
null,
null, null ] ],
172 [
'mwstore:///', [
null,
null, null ] ],
173 [
'mwstore:/', [
null,
null, null ] ],
174 [
'mwstore:', [
null,
null, null ] ]
183 "FileBackend::normalizeStoragePath on path '$path'" );
188 [
'mwstore://backend/container',
'mwstore://backend/container' ],
189 [
'mwstore://backend/container/',
'mwstore://backend/container' ],
190 [
'mwstore://backend/container/path',
'mwstore://backend/container/path' ],
191 [
'mwstore://backend/container//path',
'mwstore://backend/container/path' ],
192 [
'mwstore://backend/container///path',
'mwstore://backend/container/path' ],
194 'mwstore://backend/container///path//to///obj',
195 'mwstore://backend/container/path/to/obj'
197 [
'mwstore://', null ],
198 [
'mwstore://backend', null ],
199 [
'mwstore://backend//container/path', null ],
200 [
'mwstore://backend//container//path', null ],
201 [
'mwstore:///', null ],
202 [
'mwstore:/', null ],
203 [
'mwstore:', null ],
212 "FileBackend::parentStoragePath on path '$path'" );
217 [
'mwstore://backend/container/path/to/obj',
'mwstore://backend/container/path/to' ],
218 [
'mwstore://backend/container/path/to',
'mwstore://backend/container/path' ],
219 [
'mwstore://backend/container/path',
'mwstore://backend/container' ],
220 [
'mwstore://backend/container', null ],
221 [
'mwstore://backend/container/path/to/obj/',
'mwstore://backend/container/path/to' ],
222 [
'mwstore://backend/container/path/to/',
'mwstore://backend/container/path' ],
223 [
'mwstore://backend/container/path/',
'mwstore://backend/container' ],
224 [
'mwstore://backend/container/', null ],
233 "FileBackend::extensionFromPath on path '$path'" );
238 [
'mwstore://backend/container/path.txt',
'txt' ],
239 [
'mwstore://backend/container/path.svg.png',
'png' ],
240 [
'mwstore://backend/container/path',
'' ],
241 [
'mwstore://backend/container/path.',
'' ],
267 $this->
prepare( [
'dir' => dirname( $dest ) ] );
269 file_put_contents(
$source,
"Unit test file" );
271 if ( isset( $op[
'overwrite'] ) || isset( $op[
'overwriteSame'] ) ) {
272 $this->backend->store( $op );
275 $status = $this->backend->doOperation( $op );
278 "Store from $source to $dest succeeded without warnings ($backendName)." );
279 $this->assertEquals(
true,
$status->isOK(),
280 "Store from $source to $dest succeeded ($backendName)." );
281 $this->assertEquals( [ 0 =>
true ],
$status->success,
282 "Store from $source to $dest has proper 'success' field in Status ($backendName)." );
283 $this->assertEquals(
true, file_exists(
$source ),
284 "Source file $source still exists ($backendName)." );
285 $this->assertEquals(
true, $this->backend->fileExists( [
'src' => $dest ] ),
286 "Destination file $dest exists ($backendName)." );
288 $this->assertEquals( filesize(
$source ),
289 $this->backend->getFileSize( [
'src' => $dest ] ),
290 "Destination file $dest has correct size ($backendName)." );
293 $props2 = $this->backend->getFileProps( [
'src' => $dest ] );
294 $this->assertEquals( $props1, $props2,
295 "Source and destination have the same props ($backendName)." );
305 $op = [
'op' =>
'store',
'src' => $tmpName,
'dst' => $toPath ];
309 $op2[
'overwrite'] =
true;
313 $op3[
'overwriteSame'] =
true;
340 $this->
prepare( [
'dir' => dirname( $dest ) ] );
342 if ( isset( $op[
'ignoreMissingSource'] ) ) {
343 $status = $this->backend->doOperation( $op );
345 "Move from $source to $dest succeeded without warnings ($backendName)." );
346 $this->assertEquals( [ 0 =>
true ],
$status->success,
347 "Move from $source to $dest has proper 'success' field in Status ($backendName)." );
348 $this->assertEquals(
false, $this->backend->fileExists( [
'src' =>
$source ] ),
349 "Source file $source does not exist ($backendName)." );
350 $this->assertEquals(
false, $this->backend->fileExists( [
'src' => $dest ] ),
351 "Destination file $dest does not exist ($backendName)." );
356 $status = $this->backend->doOperation(
357 [
'op' =>
'create',
'content' =>
'blahblah',
'dst' =>
$source ] );
359 "Creation of file at $source succeeded ($backendName)." );
361 if ( isset( $op[
'overwrite'] ) || isset( $op[
'overwriteSame'] ) ) {
362 $this->backend->copy( $op );
365 $status = $this->backend->doOperation( $op );
368 "Copy from $source to $dest succeeded without warnings ($backendName)." );
369 $this->assertEquals(
true,
$status->isOK(),
370 "Copy from $source to $dest succeeded ($backendName)." );
371 $this->assertEquals( [ 0 =>
true ],
$status->success,
372 "Copy from $source to $dest has proper 'success' field in Status ($backendName)." );
373 $this->assertEquals(
true, $this->backend->fileExists( [
'src' =>
$source ] ),
374 "Source file $source still exists ($backendName)." );
375 $this->assertEquals(
true, $this->backend->fileExists( [
'src' => $dest ] ),
376 "Destination file $dest exists after copy ($backendName)." );
379 $this->backend->getFileSize( [
'src' =>
$source ] ),
380 $this->backend->getFileSize( [
'src' => $dest ] ),
381 "Destination file $dest has correct size ($backendName)." );
383 $props1 = $this->backend->getFileProps( [
'src' =>
$source ] );
384 $props2 = $this->backend->getFileProps( [
'src' => $dest ] );
385 $this->assertEquals( $props1, $props2,
386 "Source and destination have the same props ($backendName)." );
397 $op = [
'op' =>
'copy',
'src' =>
$source,
'dst' => $dest ];
405 $op2[
'overwrite'] =
true;
413 $op2[
'overwriteSame'] =
true;
421 $op2[
'ignoreMissingSource'] =
true;
429 $op2[
'ignoreMissingSource'] =
true;
460 $this->
prepare( [
'dir' => dirname( $dest ) ] );
462 if ( isset( $op[
'ignoreMissingSource'] ) ) {
463 $status = $this->backend->doOperation( $op );
465 "Move from $source to $dest succeeded without warnings ($backendName)." );
466 $this->assertEquals( [ 0 =>
true ],
$status->success,
467 "Move from $source to $dest has proper 'success' field in Status ($backendName)." );
468 $this->assertEquals(
false, $this->backend->fileExists( [
'src' =>
$source ] ),
469 "Source file $source does not exist ($backendName)." );
470 $this->assertEquals(
false, $this->backend->fileExists( [
'src' => $dest ] ),
471 "Destination file $dest does not exist ($backendName)." );
476 $status = $this->backend->doOperation(
477 [
'op' =>
'create',
'content' =>
'blahblah',
'dst' =>
$source ] );
479 "Creation of file at $source succeeded ($backendName)." );
481 if ( isset( $op[
'overwrite'] ) || isset( $op[
'overwriteSame'] ) ) {
482 $this->backend->copy( $op );
485 $status = $this->backend->doOperation( $op );
487 "Move from $source to $dest succeeded without warnings ($backendName)." );
488 $this->assertEquals(
true,
$status->isOK(),
489 "Move from $source to $dest succeeded ($backendName)." );
490 $this->assertEquals( [ 0 =>
true ],
$status->success,
491 "Move from $source to $dest has proper 'success' field in Status ($backendName)." );
492 $this->assertEquals(
false, $this->backend->fileExists( [
'src' =>
$source ] ),
493 "Source file $source does not still exists ($backendName)." );
494 $this->assertEquals(
true, $this->backend->fileExists( [
'src' => $dest ] ),
495 "Destination file $dest exists after move ($backendName)." );
497 $this->assertNotEquals(
498 $this->backend->getFileSize( [
'src' =>
$source ] ),
499 $this->backend->getFileSize( [
'src' => $dest ] ),
500 "Destination file $dest has correct size ($backendName)." );
502 $props1 = $this->backend->getFileProps( [
'src' =>
$source ] );
503 $props2 = $this->backend->getFileProps( [
'src' => $dest ] );
504 $this->assertEquals(
false, $props1[
'fileExists'],
505 "Source file does not exist accourding to props ($backendName)." );
506 $this->assertEquals(
true, $props2[
'fileExists'],
507 "Destination file exists accourding to props ($backendName)." );
518 $op = [
'op' =>
'move',
'src' =>
$source,
'dst' => $dest ];
526 $op2[
'overwrite'] =
true;
534 $op2[
'overwriteSame'] =
true;
542 $op2[
'ignoreMissingSource'] =
true;
550 $op2[
'ignoreMissingSource'] =
true;
582 $status = $this->backend->doOperation(
583 [
'op' =>
'create',
'content' =>
'blahblah',
'dst' =>
$source ] );
585 "Creation of file at $source succeeded ($backendName)." );
588 $status = $this->backend->doOperation( $op );
591 "Deletion of file at $source succeeded without warnings ($backendName)." );
592 $this->assertEquals(
true,
$status->isOK(),
593 "Deletion of file at $source succeeded ($backendName)." );
594 $this->assertEquals( [ 0 =>
true ],
$status->success,
595 "Deletion of file at $source has proper 'success' field in Status ($backendName)." );
597 $this->assertEquals(
false,
$status->isOK(),
598 "Deletion of file at $source failed ($backendName)." );
601 $this->assertEquals(
false, $this->backend->fileExists( [
'src' =>
$source ] ),
602 "Source file $source does not exist after move ($backendName)." );
605 $this->backend->getFileSize( [
'src' =>
$source ] ),
606 "Source file $source has correct size (false) ($backendName)." );
608 $props1 = $this->backend->getFileProps( [
'src' =>
$source ] );
609 $this->assertFalse( $props1[
'fileExists'],
610 "Source file $source does not exist according to props ($backendName)." );
620 $op = [
'op' =>
'delete',
'src' =>
$source ];
633 $op[
'ignoreMissingSource'] =
true;
640 $op[
'ignoreMissingSource'] =
true;
673 $status = $this->backend->doOperation(
674 [
'op' =>
'create',
'content' =>
'blahblah',
'dst' =>
$source,
675 'headers' => [
'Content-Disposition' =>
'xxx' ] ] );
677 "Creation of file at $source succeeded ($backendName)." );
679 $attr = $this->backend->getFileXAttributes( [
'src' =>
$source ] );
684 'headers' => [
'Content-Disposition' =>
'' ] ] );
686 "Removal of header for $source succeeded ($backendName)." );
689 $attr = $this->backend->getFileXAttributes( [
'src' =>
$source ] );
690 $this->assertFalse( isset( $attr[
'headers'][
'content-disposition'] ),
691 "File 'Content-Disposition' header removed." );
695 $status = $this->backend->doOperation( $op );
698 "Describe of file at $source succeeded without warnings ($backendName)." );
699 $this->assertEquals(
true,
$status->isOK(),
700 "Describe of file at $source succeeded ($backendName)." );
701 $this->assertEquals( [ 0 =>
true ],
$status->success,
702 "Describe of file at $source has proper 'success' field in Status ($backendName)." );
704 $attr = $this->backend->getFileXAttributes( [
'src' =>
$source ] );
708 $this->assertEquals(
false,
$status->isOK(),
709 "Describe of file at $source failed ($backendName)." );
716 foreach ( $headers as $n => $v ) {
718 $this->assertTrue( isset( $attr[
'headers'][strtolower( $n )] ),
719 "File has '$n' header." );
720 $this->assertEquals( $v, $attr[
'headers'][strtolower( $n )],
721 "File has '$n' header value." );
723 $this->assertFalse( isset( $attr[
'headers'][strtolower( $n )] ),
724 "File does not have '$n' header." );
734 $op = [
'op' =>
'describe',
'src' =>
$source,
735 'headers' => [
'Content-Disposition' =>
'inline' ], ];
754 public function testCreate( $op, $alreadyExists, $okStatus, $newSize ) {
757 $this->
doTestCreate( $op, $alreadyExists, $okStatus, $newSize );
762 $this->
doTestCreate( $op, $alreadyExists, $okStatus, $newSize );
766 private function doTestCreate( $op, $alreadyExists, $okStatus, $newSize ) {
770 $this->
prepare( [
'dir' => dirname( $dest ) ] );
772 $oldText =
'blah...blah...waahwaah';
773 if ( $alreadyExists ) {
774 $status = $this->backend->doOperation(
775 [
'op' =>
'create',
'content' => $oldText,
'dst' => $dest ] );
777 "Creation of file at $dest succeeded ($backendName)." );
780 $status = $this->backend->doOperation( $op );
783 "Creation of file at $dest succeeded without warnings ($backendName)." );
784 $this->assertEquals(
true,
$status->isOK(),
785 "Creation of file at $dest succeeded ($backendName)." );
786 $this->assertEquals( [ 0 =>
true ],
$status->success,
787 "Creation of file at $dest has proper 'success' field in Status ($backendName)." );
789 $this->assertEquals(
false,
$status->isOK(),
790 "Creation of file at $dest failed ($backendName)." );
793 $this->assertEquals(
true, $this->backend->fileExists( [
'src' => $dest ] ),
794 "Destination file $dest exists after creation ($backendName)." );
796 $props1 = $this->backend->getFileProps( [
'src' => $dest ] );
797 $this->assertEquals(
true, $props1[
'fileExists'],
798 "Destination file $dest exists according to props ($backendName)." );
800 $this->assertEquals( $newSize, $props1[
'size'],
801 "Destination file $dest has expected size according to props ($backendName)." );
802 $this->assertEquals( $newSize,
803 $this->backend->getFileSize( [
'src' => $dest ] ),
804 "Destination file $dest has correct size ($backendName)." );
806 $this->assertEquals( strlen( $oldText ), $props1[
'size'],
807 "Destination file $dest has original size according to props ($backendName)." );
808 $this->assertEquals( strlen( $oldText ),
809 $this->backend->getFileSize( [
'src' => $dest ] ),
810 "Destination file $dest has original size according to props ($backendName)." );
824 $op = [
'op' =>
'create',
'content' =>
'test test testing',
'dst' => $dest ];
829 strlen( $op[
'content'] )
833 $op2[
'content'] =
"\n";
838 strlen( $op2[
'content'] )
842 $op2[
'content'] =
"fsf\n waf 3kt";
847 strlen( $op2[
'content'] )
851 $op2[
'content'] =
"egm'g gkpe gpqg eqwgwqg";
852 $op2[
'overwrite'] =
true;
857 strlen( $op2[
'content'] )
861 $op2[
'content'] =
"39qjmg3-qg";
862 $op2[
'overwriteSame'] =
true;
867 strlen( $op2[
'content'] )
888 "$base/unittest-cont1/e/fileA.a",
889 "$base/unittest-cont1/e/fileB.a",
890 "$base/unittest-cont1/e/fileC.a"
894 foreach ( $files as $path ) {
897 "Preparing $path succeeded without warnings ($backendName)." );
898 $createOps[] = [
'op' =>
'create',
'dst' =>
$path,
'content' => mt_rand( 0, 50000 ) ];
899 $copyOps[] = [
'op' =>
'copy',
'src' =>
$path,
'dst' =>
"$path-2" ];
900 $moveOps[] = [
'op' =>
'move',
'src' =>
"$path-2",
'dst' =>
"$path-3" ];
901 $purgeOps[] = [
'op' =>
'delete',
'src' =>
$path ];
902 $purgeOps[] = [
'op' =>
'delete',
'src' =>
"$path-3" ];
904 $purgeOps[] = [
'op' =>
'null' ];
907 $this->backend->doQuickOperations( $createOps ),
908 "Creation of source files succeeded ($backendName)." );
909 foreach ( $files as $file ) {
910 $this->assertTrue( $this->backend->fileExists( [
'src' => $file ] ),
911 "File $file exists." );
915 $this->backend->doQuickOperations( $copyOps ),
916 "Quick copy of source files succeeded ($backendName)." );
917 foreach ( $files as $file ) {
918 $this->assertTrue( $this->backend->fileExists( [
'src' =>
"$file-2" ] ),
919 "File $file-2 exists." );
923 $this->backend->doQuickOperations( $moveOps ),
924 "Quick move of source files succeeded ($backendName)." );
925 foreach ( $files as $file ) {
926 $this->assertTrue( $this->backend->fileExists( [
'src' =>
"$file-3" ] ),
927 "File $file-3 move in." );
928 $this->assertFalse( $this->backend->fileExists( [
'src' =>
"$file-2" ] ),
929 "File $file-2 moved away." );
933 $this->backend->quickCopy( [
'src' => $files[0],
'dst' => $files[0] ] ),
934 "Copy of file {$files[0]} over itself succeeded ($backendName)." );
935 $this->assertTrue( $this->backend->fileExists( [
'src' => $files[0] ] ),
936 "File {$files[0]} still exists." );
939 $this->backend->quickMove( [
'src' => $files[0],
'dst' => $files[0] ] ),
940 "Move of file {$files[0]} over itself succeeded ($backendName)." );
941 $this->assertTrue( $this->backend->fileExists( [
'src' => $files[0] ] ),
942 "File {$files[0]} still exists." );
945 $this->backend->doQuickOperations( $purgeOps ),
946 "Quick deletion of source files succeeded ($backendName)." );
947 foreach ( $files as $file ) {
948 $this->assertFalse( $this->backend->fileExists( [
'src' => $file ] ),
949 "File $file purged." );
950 $this->assertFalse( $this->backend->fileExists( [
'src' =>
"$file-3" ] ),
951 "File $file-3 purged." );
958 public function testConcatenate( $op, $srcs, $srcsContent, $alreadyExists, $okStatus ) {
976 foreach ( $srcs as $i =>
$source ) {
981 'content' => $srcsContent[$i]
983 $expContent .= $srcsContent[$i];
985 $status = $this->backend->doOperations( $ops );
988 "Creation of source files succeeded ($backendName)." );
991 if ( $alreadyExists ) {
992 $ok = file_put_contents( $dest,
'blah...blah...waahwaah' ) !==
false;
993 $this->assertEquals(
true, $ok,
994 "Creation of file at $dest succeeded ($backendName)." );
996 $ok = file_put_contents( $dest,
'' ) !==
false;
997 $this->assertEquals(
true, $ok,
998 "Creation of 0-byte file at $dest succeeded ($backendName)." );
1005 "Creation of concat file at $dest succeeded without warnings ($backendName)." );
1006 $this->assertEquals(
true,
$status->isOK(),
1007 "Creation of concat file at $dest succeeded ($backendName)." );
1009 $this->assertEquals(
false,
$status->isOK(),
1010 "Creation of concat file at $dest failed ($backendName)." );
1014 $this->assertEquals(
true, is_file( $dest ),
1015 "Dest concat file $dest exists after creation ($backendName)." );
1017 $this->assertEquals(
true, is_file( $dest ),
1018 "Dest concat file $dest exists after failed creation ($backendName)." );
1021 $contents = file_get_contents( $dest );
1022 $this->assertNotEquals(
false, $contents,
"File at $dest exists ($backendName)." );
1025 $this->assertEquals( $expContent, $contents,
1026 "Concat file at $dest has correct contents ($backendName)." );
1028 $this->assertNotEquals( $expContent, $contents,
1029 "Concat file at $dest has correct contents ($backendName)." );
1060 $params = [
'srcs' => $srcs ];
1099 if ( $alreadyExists ) {
1100 $this->
prepare( [
'dir' => dirname( $path ) ] );
1103 "Creation of file at $path succeeded ($backendName)." );
1105 $size = $this->backend->getFileSize( [
'src' => $path ] );
1106 $time = $this->backend->getFileTimestamp( [
'src' => $path ] );
1107 $stat = $this->backend->getFileStat( [
'src' => $path ] );
1109 $this->assertEquals( strlen(
$content ), $size,
1110 "Correct file size of '$path'" );
1112 "Correct file timestamp of '$path'" );
1114 $size = $stat[
'size'];
1115 $time = $stat[
'mtime'];
1116 $this->assertEquals( strlen(
$content ), $size,
1117 "Correct file size of '$path'" );
1119 "Correct file timestamp of '$path'" );
1121 $this->backend->clearCache( [ $path ] );
1123 $size = $this->backend->getFileSize( [
'src' => $path ] );
1125 $this->assertEquals( strlen(
$content ), $size,
1126 "Correct file size of '$path'" );
1128 $this->backend->preloadCache( [ $path ] );
1130 $size = $this->backend->getFileSize( [
'src' => $path ] );
1132 $this->assertEquals( strlen(
$content ), $size,
1133 "Correct file size of '$path'" );
1135 $size = $this->backend->getFileSize( [
'src' => $path ] );
1136 $time = $this->backend->getFileTimestamp( [
'src' => $path ] );
1137 $stat = $this->backend->getFileStat( [
'src' => $path ] );
1139 $this->assertFalse( $size,
"Correct file size of '$path'" );
1140 $this->assertFalse(
$time,
"Correct file timestamp of '$path'" );
1141 $this->assertFalse( $stat,
"Correct file stat of '$path'" );
1149 $cases[] = [
"$base/unittest-cont1/e/b/z/some_file.txt",
"some file contents",
true ];
1150 $cases[] = [
"$base/unittest-cont1/e/b/some-other_file.txt",
"",
true ];
1151 $cases[] = [
"$base/unittest-cont1/e/b/some-diff_file.txt",
null,
false ];
1175 $this->
prepare( [
'dir' => dirname( $path ) ] );
1178 "Creation of file at $path succeeded ($backendName)." );
1181 $this->backend->streamFile( [
'src' => $path,
'headless' => 1,
'allowOB' => 1 ] );
1182 $data = ob_get_contents();
1185 $this->assertEquals(
$content, $data,
"Correct content streamed from '$path'" );
1188 $this->backend->streamFile( [
'src' => $path,
'headless' => 1,
'allowOB' => 1 ] );
1189 $data = ob_get_contents();
1192 $this->assertRegExp(
'#<h1>File not found</h1>#', $data,
1193 "Correct content streamed from '$path' ($backendName)" );
1201 $cases[] = [
"$base/unittest-cont1/e/b/z/some_file.txt",
"some file contents" ];
1202 $cases[] = [
"$base/unittest-cont1/e/b/some-other_file.txt", null ];
1223 $path =
"$base/unittest-cont1/e/b/z/range_file.txt";
1226 $this->
prepare( [
'dir' => dirname( $path ) ] );
1229 "Creation of file at $path succeeded ($backendName)." );
1233 'bytes=0-3' =>
'0123',
1234 'bytes=4-8' =>
'45678',
1235 'bytes=15-15' =>
'F',
1236 'bytes=14-15' =>
'EF',
1237 'bytes=-5' =>
'BCDEF',
1239 'bytes=10-16' =>
'ABCDEF',
1240 'bytes=10-99' =>
'ABCDEF',
1243 foreach ( $ranges as $range => $chunk ) {
1245 $this->backend->streamFile( [
'src' => $path,
'headless' => 1,
'allowOB' => 1,
1246 'options' => [
'range' => $range ] ] );
1247 $data = ob_get_contents();
1250 $this->assertEquals( $chunk, $data,
"Correct chunk streamed from '$path' for '$range'" );
1274 foreach ( $srcs as $i => $src ) {
1275 $this->
prepare( [
'dir' => dirname( $src ) ] );
1276 $status = $this->backend->doOperation(
1277 [
'op' =>
'create',
'content' =>
$content[$i],
'dst' => $src ] );
1279 "Creation of file at $src succeeded ($backendName)." );
1283 $contents = $this->backend->getFileContentsMulti( [
'srcs' =>
$source ] );
1284 foreach ( $contents as $path => $data ) {
1285 $this->assertNotEquals(
false, $data,
"Contents of $path exists ($backendName)." );
1286 $this->assertEquals(
1289 "Contents of $path is correct ($backendName)."
1293 $this->assertEquals(
1295 array_keys( $contents ),
1296 "Contents in right order ($backendName)."
1298 $this->assertEquals(
1301 "Contents array size correct ($backendName)."
1304 $data = $this->backend->getFileContents( [
'src' =>
$source ] );
1305 $this->assertNotEquals(
false, $data,
"Contents of $source exists ($backendName)." );
1306 $this->assertEquals(
$content[0], $data,
"Contents of $source is correct ($backendName)." );
1314 $cases[] = [
"$base/unittest-cont1/e/b/z/some_file.txt",
"some file contents" ];
1315 $cases[] = [
"$base/unittest-cont1/e/b/some-other_file.txt",
"more file contents" ];
1317 [
"$base/unittest-cont1/e/a/x.txt",
"$base/unittest-cont1/e/a/y.txt",
1318 "$base/unittest-cont1/e/a/z.txt" ],
1319 [
"contents xx",
"contents xy",
"contents xz" ]
1345 foreach ( $srcs as $i => $src ) {
1346 $this->
prepare( [
'dir' => dirname( $src ) ] );
1347 $status = $this->backend->doOperation(
1348 [
'op' =>
'create',
'content' =>
$content[$i],
'dst' => $src ] );
1350 "Creation of file at $src succeeded ($backendName)." );
1355 foreach (
$tmpFiles as $path => $tmpFile ) {
1356 $this->assertNotNull( $tmpFile,
1357 "Creation of local copy of $path succeeded ($backendName)." );
1358 $contents = file_get_contents( $tmpFile->getPath() );
1359 $this->assertNotEquals(
false, $contents,
"Local copy of $path exists ($backendName)." );
1360 $this->assertEquals(
1363 "Local copy of $path is correct ($backendName)."
1367 $this->assertEquals(
1370 "Local copies in right order ($backendName)."
1372 $this->assertEquals(
1375 "Local copies array size correct ($backendName)."
1378 $tmpFile = $this->backend->getLocalCopy( [
'src' =>
$source ] );
1379 $this->assertNotNull( $tmpFile,
1380 "Creation of local copy of $source succeeded ($backendName)." );
1381 $contents = file_get_contents( $tmpFile->getPath() );
1382 $this->assertNotEquals(
false, $contents,
"Local copy of $source exists ($backendName)." );
1383 $this->assertEquals(
1386 "Local copy of $source is correct ($backendName)."
1390 $obj =
new stdClass();
1391 $tmpFile->bind( $obj );
1398 $cases[] = [
"$base/unittest-cont1/e/a/z/some_file.txt",
"some file contents" ];
1399 $cases[] = [
"$base/unittest-cont1/e/a/some-other_file.txt",
"more file contents" ];
1400 $cases[] = [
"$base/unittest-cont1/e/a/\$odd&.txt",
"test file contents" ];
1402 [
"$base/unittest-cont1/e/a/x.txt",
"$base/unittest-cont1/e/a/y.txt",
1403 "$base/unittest-cont1/e/a/z.txt" ],
1404 [
"contents xx $",
"contents xy 111",
"contents xz" ]
1430 foreach ( $srcs as $i => $src ) {
1431 $this->
prepare( [
'dir' => dirname( $src ) ] );
1432 $status = $this->backend->doOperation(
1433 [
'op' =>
'create',
'content' =>
$content[$i],
'dst' => $src ] );
1435 "Creation of file at $src succeeded ($backendName)." );
1439 $tmpFiles = $this->backend->getLocalReferenceMulti( [
'srcs' =>
$source ] );
1440 foreach (
$tmpFiles as $path => $tmpFile ) {
1441 $this->assertNotNull( $tmpFile,
1442 "Creation of local copy of $path succeeded ($backendName)." );
1443 $contents = file_get_contents( $tmpFile->getPath() );
1444 $this->assertNotEquals(
false, $contents,
"Local ref of $path exists ($backendName)." );
1445 $this->assertEquals(
1448 "Local ref of $path is correct ($backendName)."
1452 $this->assertEquals(
1455 "Local refs in right order ($backendName)."
1457 $this->assertEquals(
1460 "Local refs array size correct ($backendName)."
1463 $tmpFile = $this->backend->getLocalReference( [
'src' =>
$source ] );
1464 $this->assertNotNull( $tmpFile,
1465 "Creation of local copy of $source succeeded ($backendName)." );
1466 $contents = file_get_contents( $tmpFile->getPath() );
1467 $this->assertNotEquals(
false, $contents,
"Local ref of $source exists ($backendName)." );
1468 $this->assertEquals(
$content[0], $contents,
"Local ref of $source is correct ($backendName)." );
1476 $cases[] = [
"$base/unittest-cont1/e/a/z/some_file.txt",
"some file contents" ];
1477 $cases[] = [
"$base/unittest-cont1/e/a/some-other_file.txt",
"more file contents" ];
1478 $cases[] = [
"$base/unittest-cont1/e/a/\$odd&.txt",
"test file contents" ];
1480 [
"$base/unittest-cont1/e/a/x.txt",
"$base/unittest-cont1/e/a/y.txt",
1481 "$base/unittest-cont1/e/a/z.txt" ],
1482 [
"contents xx 1111",
"contents xy %",
"contents xz $" ]
1505 $tmpFile = $this->backend->getLocalCopy( [
1506 'src' =>
"$base/unittest-cont1/not-there" ] );
1507 $this->assertEquals(
null, $tmpFile,
"Local copy of not existing file is null ($backendName)." );
1509 $tmpFile = $this->backend->getLocalReference( [
1510 'src' =>
"$base/unittest-cont1/not-there" ] );
1511 $this->assertEquals(
null, $tmpFile,
"Local ref of not existing file is null ($backendName)." );
1533 $status = $this->backend->doOperation(
1536 "Creation of file at $source succeeded ($backendName)." );
1538 $url = $this->backend->getFileHttpUrl( [
'src' =>
$source ] );
1540 if ( $url !==
null ) {
1542 $this->assertEquals(
$content, $data,
1543 "HTTP GET of URL has right contents ($backendName)." );
1551 $cases[] = [
"$base/unittest-cont1/e/a/z/some_file.txt",
"some file contents" ];
1552 $cases[] = [
"$base/unittest-cont1/e/a/some-other_file.txt",
"more file contents" ];
1553 $cases[] = [
"$base/unittest-cont1/e/a/\$odd&.txt",
"test file contents" ];
1575 [
"$base/unittest-cont1/e/a/z/some_file1.txt",
true ],
1576 [
"$base/unittest-cont2/a/z/some_file2.txt",
true ],
1577 # Specific to FS backend with no basePath field set
1578 # [ "$base/unittest-cont3/a/z/some_file3.txt", false ],
1588 "Preparing dir $path succeeded without warnings ($backendName)." );
1589 $this->assertEquals(
true,
$status->isOK(),
1590 "Preparing dir $path succeeded ($backendName)." );
1592 $this->assertEquals(
false,
$status->isOK(),
1593 "Preparing dir $path failed ($backendName)." );
1596 $status = $this->backend->secure( [
'dir' => dirname( $path ) ] );
1599 "Securing dir $path succeeded without warnings ($backendName)." );
1600 $this->assertEquals(
true,
$status->isOK(),
1601 "Securing dir $path succeeded ($backendName)." );
1603 $this->assertEquals(
false,
$status->isOK(),
1604 "Securing dir $path failed ($backendName)." );
1607 $status = $this->backend->publish( [
'dir' => dirname( $path ) ] );
1610 "Publishing dir $path succeeded without warnings ($backendName)." );
1611 $this->assertEquals(
true,
$status->isOK(),
1612 "Publishing dir $path succeeded ($backendName)." );
1614 $this->assertEquals(
false,
$status->isOK(),
1615 "Publishing dir $path failed ($backendName)." );
1618 $status = $this->backend->clean( [
'dir' => dirname( $path ) ] );
1621 "Cleaning dir $path succeeded without warnings ($backendName)." );
1622 $this->assertEquals(
true,
$status->isOK(),
1623 "Cleaning dir $path succeeded ($backendName)." );
1625 $this->assertEquals(
false,
$status->isOK(),
1626 "Cleaning dir $path failed ($backendName)." );
1645 "$base/unittest-cont1",
1646 "$base/unittest-cont1/e",
1647 "$base/unittest-cont1/e/a",
1648 "$base/unittest-cont1/e/a/b",
1649 "$base/unittest-cont1/e/a/b/c",
1650 "$base/unittest-cont1/e/a/b/c/d0",
1651 "$base/unittest-cont1/e/a/b/c/d1",
1652 "$base/unittest-cont1/e/a/b/c/d2",
1653 "$base/unittest-cont1/e/a/b/c/d0/1",
1654 "$base/unittest-cont1/e/a/b/c/d0/2",
1655 "$base/unittest-cont1/e/a/b/c/d1/3",
1656 "$base/unittest-cont1/e/a/b/c/d1/4",
1657 "$base/unittest-cont1/e/a/b/c/d2/5",
1658 "$base/unittest-cont1/e/a/b/c/d2/6"
1660 foreach (
$dirs as $dir ) {
1663 "Preparing dir $dir succeeded without warnings ($backendName)." );
1667 foreach (
$dirs as $dir ) {
1668 $this->assertEquals(
true, $this->backend->directoryExists( [
'dir' => $dir ] ),
1669 "Dir $dir exists ($backendName)." );
1673 $status = $this->backend->clean(
1674 [
'dir' =>
"$base/unittest-cont1",
'recursive' => 1 ] );
1676 "Recursive cleaning of dir $dir succeeded without warnings ($backendName)." );
1678 foreach (
$dirs as $dir ) {
1679 $this->assertEquals(
false, $this->backend->directoryExists( [
'dir' => $dir ] ),
1680 "Dir $dir no longer exists ($backendName)." );
1699 $fileA =
"$base/unittest-cont1/e/a/b/fileA.txt";
1700 $fileAContents =
'3tqtmoeatmn4wg4qe-mg3qt3 tq';
1701 $fileB =
"$base/unittest-cont1/e/a/b/fileB.txt";
1702 $fileBContents =
'g-jmq3gpqgt3qtg q3GT ';
1703 $fileC =
"$base/unittest-cont1/e/a/b/fileC.txt";
1704 $fileCContents =
'eigna[ogmewt 3qt g3qg flew[ag';
1705 $fileD =
"$base/unittest-cont1/e/a/b/fileD.txt";
1707 $this->
prepare( [
'dir' => dirname( $fileA ) ] );
1708 $this->
create( [
'dst' => $fileA,
'content' => $fileAContents ] );
1709 $this->
prepare( [
'dir' => dirname( $fileB ) ] );
1710 $this->
create( [
'dst' => $fileB,
'content' => $fileBContents ] );
1711 $this->
prepare( [
'dir' => dirname( $fileC ) ] );
1712 $this->
create( [
'dst' => $fileC,
'content' => $fileCContents ] );
1713 $this->
prepare( [
'dir' => dirname( $fileD ) ] );
1715 $status = $this->backend->doOperations( [
1716 [
'op' =>
'describe',
'src' => $fileA,
1717 'headers' => [
'X-Content-Length' =>
'91.3' ],
'disposition' =>
'inline' ],
1718 [
'op' =>
'copy',
'src' => $fileA,
'dst' => $fileC,
'overwrite' => 1 ],
1720 [
'op' =>
'copy',
'src' => $fileC,
'dst' => $fileA,
'overwriteSame' => 1 ],
1722 [
'op' =>
'move',
'src' => $fileC,
'dst' => $fileD,
'overwrite' => 1 ],
1724 [
'op' =>
'move',
'src' => $fileB,
'dst' => $fileC ],
1726 [
'op' =>
'move',
'src' => $fileD,
'dst' => $fileA,
'overwriteSame' => 1 ],
1728 [
'op' =>
'move',
'src' => $fileC,
'dst' => $fileA,
'overwrite' => 1 ],
1730 [
'op' =>
'copy',
'src' => $fileA,
'dst' => $fileC ],
1732 [
'op' =>
'move',
'src' => $fileA,
'dst' => $fileC,
'overwriteSame' => 1 ],
1734 [
'op' =>
'copy',
'src' => $fileC,
'dst' => $fileC,
'overwrite' => 1 ],
1736 [
'op' =>
'copy',
'src' => $fileC,
'dst' => $fileC,
'overwriteSame' => 1 ],
1738 [
'op' =>
'move',
'src' => $fileC,
'dst' => $fileC,
'overwrite' => 1 ],
1740 [
'op' =>
'move',
'src' => $fileC,
'dst' => $fileC,
'overwriteSame' => 1 ],
1747 $this->assertEquals(
true,
$status->isOK(),
"Operation batch succeeded" );
1748 $this->assertEquals( 14, count(
$status->success ),
1749 "Operation batch has correct success array" );
1751 $this->assertEquals(
false, $this->backend->fileExists( [
'src' => $fileA ] ),
1752 "File does not exist at $fileA" );
1753 $this->assertEquals(
false, $this->backend->fileExists( [
'src' => $fileB ] ),
1754 "File does not exist at $fileB" );
1755 $this->assertEquals(
false, $this->backend->fileExists( [
'src' => $fileD ] ),
1756 "File does not exist at $fileD" );
1758 $this->assertEquals(
true, $this->backend->fileExists( [
'src' => $fileC ] ),
1759 "File exists at $fileC" );
1760 $this->assertEquals( $fileBContents,
1761 $this->backend->getFileContents( [
'src' => $fileC ] ),
1762 "Correct file contents of $fileC" );
1763 $this->assertEquals( strlen( $fileBContents ),
1764 $this->backend->getFileSize( [
'src' => $fileC ] ),
1765 "Correct file size of $fileC" );
1766 $this->assertEquals(
Wikimedia\base_convert( sha1( $fileBContents ), 16, 36, 31 ),
1767 $this->backend->getFileSha1Base36( [
'src' => $fileC ] ),
1768 "Correct file SHA-1 of $fileC" );
1787 $fileAContents =
'3tqtmoeatmn4wg4qe-mg3qt3 tq';
1788 $fileBContents =
'g-jmq3gpqgt3qtg q3GT ';
1789 $fileCContents =
'eigna[ogmewt 3qt g3qg flew[ag';
1794 $this->
addTmpFiles( [ $tmpNameA, $tmpNameB, $tmpNameC ] );
1795 file_put_contents( $tmpNameA, $fileAContents );
1796 file_put_contents( $tmpNameB, $fileBContents );
1797 file_put_contents( $tmpNameC, $fileCContents );
1799 $fileA =
"$base/unittest-cont1/e/a/b/fileA.txt";
1800 $fileB =
"$base/unittest-cont1/e/a/b/fileB.txt";
1801 $fileC =
"$base/unittest-cont1/e/a/b/fileC.txt";
1802 $fileD =
"$base/unittest-cont1/e/a/b/fileD.txt";
1804 $this->
prepare( [
'dir' => dirname( $fileA ) ] );
1805 $this->
create( [
'dst' => $fileA,
'content' => $fileAContents ] );
1806 $this->
prepare( [
'dir' => dirname( $fileB ) ] );
1807 $this->
prepare( [
'dir' => dirname( $fileC ) ] );
1808 $this->
prepare( [
'dir' => dirname( $fileD ) ] );
1810 $status = $this->backend->doOperations( [
1811 [
'op' =>
'store',
'src' => $tmpNameA,
'dst' => $fileA,
'overwriteSame' => 1 ],
1812 [
'op' =>
'store',
'src' => $tmpNameB,
'dst' => $fileB,
'overwrite' => 1 ],
1813 [
'op' =>
'store',
'src' => $tmpNameC,
'dst' => $fileC,
'overwrite' => 1 ],
1814 [
'op' =>
'copy',
'src' => $fileA,
'dst' => $fileC,
'overwrite' => 1 ],
1816 [
'op' =>
'copy',
'src' => $fileC,
'dst' => $fileA,
'overwriteSame' => 1 ],
1818 [
'op' =>
'move',
'src' => $fileC,
'dst' => $fileD,
'overwrite' => 1 ],
1820 [
'op' =>
'move',
'src' => $fileB,
'dst' => $fileC ],
1822 [
'op' =>
'move',
'src' => $fileD,
'dst' => $fileA,
'overwriteSame' => 1 ],
1824 [
'op' =>
'move',
'src' => $fileC,
'dst' => $fileA,
'overwrite' => 1 ],
1826 [
'op' =>
'copy',
'src' => $fileA,
'dst' => $fileC ],
1828 [
'op' =>
'move',
'src' => $fileA,
'dst' => $fileC,
'overwriteSame' => 1 ],
1830 [
'op' =>
'copy',
'src' => $fileC,
'dst' => $fileC,
'overwrite' => 1 ],
1832 [
'op' =>
'copy',
'src' => $fileC,
'dst' => $fileC,
'overwriteSame' => 1 ],
1834 [
'op' =>
'move',
'src' => $fileC,
'dst' => $fileC,
'overwrite' => 1 ],
1836 [
'op' =>
'move',
'src' => $fileC,
'dst' => $fileC,
'overwriteSame' => 1 ],
1843 $this->assertEquals(
true,
$status->isOK(),
"Operation batch succeeded" );
1844 $this->assertEquals( 16, count(
$status->success ),
1845 "Operation batch has correct success array" );
1847 $this->assertEquals(
false, $this->backend->fileExists( [
'src' => $fileA ] ),
1848 "File does not exist at $fileA" );
1849 $this->assertEquals(
false, $this->backend->fileExists( [
'src' => $fileB ] ),
1850 "File does not exist at $fileB" );
1851 $this->assertEquals(
false, $this->backend->fileExists( [
'src' => $fileD ] ),
1852 "File does not exist at $fileD" );
1854 $this->assertEquals(
true, $this->backend->fileExists( [
'src' => $fileC ] ),
1855 "File exists at $fileC" );
1856 $this->assertEquals( $fileBContents,
1857 $this->backend->getFileContents( [
'src' => $fileC ] ),
1858 "Correct file contents of $fileC" );
1859 $this->assertEquals( strlen( $fileBContents ),
1860 $this->backend->getFileSize( [
'src' => $fileC ] ),
1861 "Correct file size of $fileC" );
1862 $this->assertEquals(
Wikimedia\base_convert( sha1( $fileBContents ), 16, 36, 31 ),
1863 $this->backend->getFileSha1Base36( [
'src' => $fileC ] ),
1864 "Correct file SHA-1 of $fileC" );
1882 $fileA =
"$base/unittest-cont2/a/b/fileA.txt";
1883 $fileAContents =
'3tqtmoeatmn4wg4qe-mg3qt3 tq';
1884 $fileB =
"$base/unittest-cont2/a/b/fileB.txt";
1885 $fileBContents =
'g-jmq3gpqgt3qtg q3GT ';
1886 $fileC =
"$base/unittest-cont2/a/b/fileC.txt";
1887 $fileCContents =
'eigna[ogmewt 3qt g3qg flew[ag';
1888 $fileD =
"$base/unittest-cont2/a/b/fileD.txt";
1890 $this->
prepare( [
'dir' => dirname( $fileA ) ] );
1891 $this->
create( [
'dst' => $fileA,
'content' => $fileAContents ] );
1892 $this->
prepare( [
'dir' => dirname( $fileB ) ] );
1893 $this->
create( [
'dst' => $fileB,
'content' => $fileBContents ] );
1894 $this->
prepare( [
'dir' => dirname( $fileC ) ] );
1895 $this->
create( [
'dst' => $fileC,
'content' => $fileCContents ] );
1897 $status = $this->backend->doOperations( [
1898 [
'op' =>
'copy',
'src' => $fileA,
'dst' => $fileC,
'overwrite' => 1 ],
1900 [
'op' =>
'copy',
'src' => $fileC,
'dst' => $fileA,
'overwriteSame' => 1 ],
1902 [
'op' =>
'copy',
'src' => $fileB,
'dst' => $fileD,
'overwrite' => 1 ],
1904 [
'op' =>
'move',
'src' => $fileC,
'dst' => $fileD ],
1906 [
'op' =>
'move',
'src' => $fileB,
'dst' => $fileC,
'overwriteSame' => 1 ],
1908 [
'op' =>
'move',
'src' => $fileB,
'dst' => $fileA,
'overwrite' => 1 ],
1910 [
'op' =>
'delete',
'src' => $fileD ],
1914 ], [
'force' => 1 ] );
1916 $this->assertNotEquals( [],
$status->getErrors(),
"Operation had warnings" );
1917 $this->assertEquals(
true,
$status->isOK(),
"Operation batch succeeded" );
1918 $this->assertEquals( 8, count(
$status->success ),
1919 "Operation batch has correct success array" );
1921 $this->assertEquals(
false, $this->backend->fileExists( [
'src' => $fileB ] ),
1922 "File does not exist at $fileB" );
1923 $this->assertEquals(
false, $this->backend->fileExists( [
'src' => $fileD ] ),
1924 "File does not exist at $fileD" );
1926 $this->assertEquals(
true, $this->backend->fileExists( [
'src' => $fileA ] ),
1927 "File does not exist at $fileA" );
1928 $this->assertEquals(
true, $this->backend->fileExists( [
'src' => $fileC ] ),
1929 "File exists at $fileC" );
1930 $this->assertEquals( $fileBContents,
1931 $this->backend->getFileContents( [
'src' => $fileA ] ),
1932 "Correct file contents of $fileA" );
1933 $this->assertEquals( strlen( $fileBContents ),
1934 $this->backend->getFileSize( [
'src' => $fileA ] ),
1935 "Correct file size of $fileA" );
1936 $this->assertEquals(
Wikimedia\base_convert( sha1( $fileBContents ), 16, 36, 31 ),
1937 $this->backend->getFileSha1Base36( [
'src' => $fileA ] ),
1938 "Correct file SHA-1 of $fileA" );
1958 $iter = $this->backend->getFileList( [
'dir' =>
"$base/unittest-cont-notexists" ] );
1961 "$base/unittest-cont1/e/test1.txt",
1962 "$base/unittest-cont1/e/test2.txt",
1963 "$base/unittest-cont1/e/test3.txt",
1964 "$base/unittest-cont1/e/subdir1/test1.txt",
1965 "$base/unittest-cont1/e/subdir1/test2.txt",
1966 "$base/unittest-cont1/e/subdir2/test3.txt",
1967 "$base/unittest-cont1/e/subdir2/test4.txt",
1968 "$base/unittest-cont1/e/subdir2/subdir/test1.txt",
1969 "$base/unittest-cont1/e/subdir2/subdir/test2.txt",
1970 "$base/unittest-cont1/e/subdir2/subdir/test3.txt",
1971 "$base/unittest-cont1/e/subdir2/subdir/test4.txt",
1972 "$base/unittest-cont1/e/subdir2/subdir/test5.txt",
1973 "$base/unittest-cont1/e/subdir2/subdir/sub/test0.txt",
1974 "$base/unittest-cont1/e/subdir2/subdir/sub/120-px-file.txt",
1979 foreach ( $files as $file ) {
1980 $this->
prepare( [
'dir' => dirname( $file ) ] );
1981 $ops[] = [
'op' =>
'create',
'content' =>
'xxy',
'dst' => $file ];
1983 $status = $this->backend->doQuickOperations( $ops );
1985 "Creation of files succeeded ($backendName)." );
1986 $this->assertEquals(
true,
$status->isOK(),
1987 "Creation of files succeeded with OK status ($backendName)." );
1994 "e/subdir1/test1.txt",
1995 "e/subdir1/test2.txt",
1996 "e/subdir2/test3.txt",
1997 "e/subdir2/test4.txt",
1998 "e/subdir2/subdir/test1.txt",
1999 "e/subdir2/subdir/test2.txt",
2000 "e/subdir2/subdir/test3.txt",
2001 "e/subdir2/subdir/test4.txt",
2002 "e/subdir2/subdir/test5.txt",
2003 "e/subdir2/subdir/sub/test0.txt",
2004 "e/subdir2/subdir/sub/120-px-file.txt",
2009 $iter = $this->backend->getFileList( [
'dir' =>
"$base/unittest-cont1" ] );
2012 $this->assertEquals( $expected, $list,
"Correct file listing ($backendName)." );
2015 $iter = $this->backend->getFileList( [
2016 'dir' =>
"$base/unittest-cont1",
2021 $this->assertEquals( $expected, $list,
"Correct file listing ($backendName)." );
2025 $iter = $this->backend->getFileList( [
'dir' =>
"$base/unittest-cont1/" ] );
2026 foreach ( $iter as $file ) {
2030 $this->assertEquals( $expected, $list,
"Correct file listing ($backendName)." );
2040 "sub/120-px-file.txt",
2045 $iter = $this->backend->getFileList( [
'dir' =>
"$base/unittest-cont1/e/subdir2/subdir" ] );
2048 $this->assertEquals( $expected, $list,
"Correct file listing ($backendName)." );
2051 $iter = $this->backend->getFileList( [
2052 'dir' =>
"$base/unittest-cont1/e/subdir2/subdir",
2057 $this->assertEquals( $expected, $list,
"Correct file listing ($backendName)." );
2061 $iter = $this->backend->getFileList( [
'dir' =>
"$base/unittest-cont1/e/subdir2/subdir/" ] );
2062 foreach ( $iter as $file ) {
2066 $this->assertEquals( $expected, $list,
"Correct file listing ($backendName)." );
2071 $this->assertEquals( $expected, $list,
"Correct file listing ($backendName), second iteration." );
2074 $iter = $this->backend->getTopFileList( [
'dir' =>
"$base/unittest-cont1" ] );
2077 $this->assertEquals( [], $list,
"Correct top file listing ($backendName)." );
2090 $iter = $this->backend->getTopFileList(
2091 [
'dir' =>
"$base/unittest-cont1/e/subdir2/subdir" ]
2095 $this->assertEquals( $expected, $list,
"Correct top file listing ($backendName)." );
2098 $iter = $this->backend->getTopFileList( [
2099 'dir' =>
"$base/unittest-cont1/e/subdir2/subdir",
2104 $this->assertEquals( $expected, $list,
"Correct top file listing ($backendName)." );
2106 foreach ( $files as $file ) {
2107 $this->backend->doOperation( [
'op' =>
'delete',
'src' => $file ] );
2110 $iter = $this->backend->getFileList( [
'dir' =>
"$base/unittest-cont1/not/exists" ] );
2111 foreach ( $iter as $iter ) {
2133 "$base/unittest-cont1/e/test1.txt",
2134 "$base/unittest-cont1/e/test2.txt",
2135 "$base/unittest-cont1/e/test3.txt",
2136 "$base/unittest-cont1/e/subdir1/test1.txt",
2137 "$base/unittest-cont1/e/subdir1/test2.txt",
2138 "$base/unittest-cont1/e/subdir2/test3.txt",
2139 "$base/unittest-cont1/e/subdir2/test4.txt",
2140 "$base/unittest-cont1/e/subdir2/subdir/test1.txt",
2141 "$base/unittest-cont1/e/subdir3/subdir/test2.txt",
2142 "$base/unittest-cont1/e/subdir4/subdir/test3.txt",
2143 "$base/unittest-cont1/e/subdir4/subdir/test4.txt",
2144 "$base/unittest-cont1/e/subdir4/subdir/test5.txt",
2145 "$base/unittest-cont1/e/subdir4/subdir/sub/test0.txt",
2146 "$base/unittest-cont1/e/subdir4/subdir/sub/120-px-file.txt",
2151 foreach ( $files as $file ) {
2152 $this->
prepare( [
'dir' => dirname( $file ) ] );
2153 $ops[] = [
'op' =>
'create',
'content' =>
'xxy',
'dst' => $file ];
2155 $status = $this->backend->doQuickOperations( $ops );
2157 "Creation of files succeeded ($backendName)." );
2158 $this->assertEquals(
true,
$status->isOK(),
2159 "Creation of files succeeded with OK status ($backendName)." );
2161 $this->assertEquals(
true,
2162 $this->backend->directoryExists( [
'dir' =>
"$base/unittest-cont1/e/subdir1" ] ),
2163 "Directory exists in ($backendName)." );
2164 $this->assertEquals(
true,
2165 $this->backend->directoryExists( [
'dir' =>
"$base/unittest-cont1/e/subdir2/subdir" ] ),
2166 "Directory exists in ($backendName)." );
2167 $this->assertEquals(
false,
2168 $this->backend->directoryExists( [
'dir' =>
"$base/unittest-cont1/e/subdir2/test1.txt" ] ),
2169 "Directory does not exists in ($backendName)." );
2179 $iter = $this->backend->getTopDirectoryList( [
'dir' =>
"$base/unittest-cont1" ] );
2180 foreach ( $iter as $file ) {
2185 $this->assertEquals( $expected, $list,
"Correct top dir listing ($backendName)." );
2198 $iter = $this->backend->getTopDirectoryList( [
'dir' =>
"$base/unittest-cont1/e" ] );
2199 foreach ( $iter as $file ) {
2204 $this->assertEquals( $expected, $list,
"Correct top dir listing ($backendName)." );
2208 $iter = $this->backend->getTopDirectoryList( [
'dir' =>
"$base/unittest-cont1/e/" ] );
2209 foreach ( $iter as $file ) {
2214 $this->assertEquals( $expected, $list,
"Correct top dir listing ($backendName)." );
2224 $iter = $this->backend->getTopDirectoryList( [
'dir' =>
"$base/unittest-cont1/e/subdir2" ] );
2225 foreach ( $iter as $file ) {
2230 $this->assertEquals( $expected, $list,
"Correct top dir listing ($backendName)." );
2234 $iter = $this->backend->getTopDirectoryList(
2235 [
'dir' =>
"$base/unittest-cont1/e/subdir2/" ]
2238 foreach ( $iter as $file ) {
2243 $this->assertEquals( $expected, $list,
"Correct top dir listing ($backendName)." );
2247 foreach ( $iter as $file ) {
2252 $this->assertEquals(
2255 "Correct top dir listing ($backendName), second iteration."
2268 "e/subdir4/subdir/sub",
2274 $iter = $this->backend->getDirectoryList( [
'dir' =>
"$base/unittest-cont1/" ] );
2275 foreach ( $iter as $file ) {
2280 $this->assertEquals( $expected, $list,
"Correct dir listing ($backendName)." );
2291 $iter = $this->backend->getDirectoryList( [
'dir' =>
"$base/unittest-cont1/e/subdir4" ] );
2292 foreach ( $iter as $file ) {
2297 $this->assertEquals( $expected, $list,
"Correct dir listing ($backendName)." );
2301 foreach ( $iter as $file ) {
2306 $this->assertEquals( $expected, $list,
"Correct dir listing ($backendName)." );
2308 $iter = $this->backend->getDirectoryList( [
'dir' =>
"$base/unittest-cont1/e/subdir1" ] );
2310 $this->assertEquals( [], $items,
"Directory listing is empty." );
2312 foreach ( $files as $file ) {
2313 $this->backend->doOperation( [
'op' =>
'delete',
'src' => $file ] );
2316 $iter = $this->backend->getDirectoryList( [
'dir' =>
"$base/unittest-cont1/not/exists" ] );
2317 foreach ( $iter as $file ) {
2322 $this->assertEquals( [], $items,
"Directory listing is empty." );
2324 $iter = $this->backend->getDirectoryList( [
'dir' =>
"$base/unittest-cont1/e/not/exists" ] );
2326 $this->assertEquals( [], $items,
"Directory listing is empty." );
2336 $base = $this->backend->getContainerStoragePath(
'test' );
2344 "$base/subdir1/test1.txt",
2345 "$base/subdir1/test2.txt",
2348 "$base/subdir2/test3.txt",
2349 "$base/subdir2/test4.txt",
2350 "$base/subdir2/subdir",
2351 "$base/subdir2/subdir/test1.txt",
2352 "$base/subdir2/subdir/test2.txt",
2353 "$base/subdir2/subdir/test3.txt",
2354 "$base/subdir2/subdir/test4.txt",
2355 "$base/subdir2/subdir/test5.txt",
2356 "$base/subdir2/subdir/sub",
2357 "$base/subdir2/subdir/sub/test0.txt",
2358 "$base/subdir2/subdir/sub/120-px-file.txt",
2361 for ( $i = 0; $i < 25; $i++ ) {
2362 $status = $this->backend->lockFiles( $paths, LockManager::LOCK_EX );
2363 $this->assertEquals( print_r( [],
true ), print_r(
$status->getErrors(),
true ),
2364 "Locking of files succeeded ($backendName) ($i)." );
2365 $this->assertEquals(
true,
$status->isOK(),
2366 "Locking of files succeeded with OK status ($backendName) ($i)." );
2368 $status = $this->backend->lockFiles( $paths, LockManager::LOCK_SH );
2369 $this->assertEquals( print_r( [],
true ), print_r(
$status->getErrors(),
true ),
2370 "Locking of files succeeded ($backendName) ($i)." );
2371 $this->assertEquals(
true,
$status->isOK(),
2372 "Locking of files succeeded with OK status ($backendName) ($i)." );
2374 $status = $this->backend->unlockFiles( $paths, LockManager::LOCK_SH );
2375 $this->assertEquals( print_r( [],
true ), print_r(
$status->getErrors(),
true ),
2376 "Locking of files succeeded ($backendName) ($i)." );
2377 $this->assertEquals(
true,
$status->isOK(),
2378 "Locking of files succeeded with OK status ($backendName) ($i)." );
2380 $status = $this->backend->unlockFiles( $paths, LockManager::LOCK_EX );
2381 $this->assertEquals( print_r( [],
true ), print_r(
$status->getErrors(),
true ),
2382 "Locking of files succeeded ($backendName). ($i)" );
2383 $this->assertEquals(
true,
$status->isOK(),
2384 "Locking of files succeeded with OK status ($backendName) ($i)." );
2386 # # Flip the acquire/release ordering around ##
2388 $status = $this->backend->lockFiles( $paths, LockManager::LOCK_SH );
2389 $this->assertEquals( print_r( [],
true ), print_r(
$status->getErrors(),
true ),
2390 "Locking of files succeeded ($backendName) ($i)." );
2391 $this->assertEquals(
true,
$status->isOK(),
2392 "Locking of files succeeded with OK status ($backendName) ($i)." );
2394 $status = $this->backend->lockFiles( $paths, LockManager::LOCK_EX );
2395 $this->assertEquals( print_r( [],
true ), print_r(
$status->getErrors(),
true ),
2396 "Locking of files succeeded ($backendName) ($i)." );
2397 $this->assertEquals(
true,
$status->isOK(),
2398 "Locking of files succeeded with OK status ($backendName) ($i)." );
2400 $status = $this->backend->unlockFiles( $paths, LockManager::LOCK_EX );
2401 $this->assertEquals( print_r( [],
true ), print_r(
$status->getErrors(),
true ),
2402 "Locking of files succeeded ($backendName). ($i)" );
2403 $this->assertEquals(
true,
$status->isOK(),
2404 "Locking of files succeeded with OK status ($backendName) ($i)." );
2406 $status = $this->backend->unlockFiles( $paths, LockManager::LOCK_SH );
2407 $this->assertEquals( print_r( [],
true ), print_r(
$status->getErrors(),
true ),
2408 "Locking of files succeeded ($backendName) ($i)." );
2409 $this->assertEquals(
true,
$status->isOK(),
2410 "Locking of files succeeded with OK status ($backendName) ($i)." );
2414 $sl = $this->backend->getScopedFileLocks( $paths, LockManager::LOCK_EX,
$status );
2415 $this->assertInstanceOf( ScopedLock::class, $sl,
2416 "Scoped locking of files succeeded ($backendName)." );
2417 $this->assertEquals( [],
$status->getErrors(),
2418 "Scoped locking of files succeeded ($backendName)." );
2419 $this->assertEquals(
true,
$status->isOK(),
2420 "Scoped locking of files succeeded with OK status ($backendName)." );
2423 $this->assertEquals(
null, $sl,
2424 "Scoped unlocking of files succeeded ($backendName)." );
2425 $this->assertEquals( [],
$status->getErrors(),
2426 "Scoped unlocking of files succeeded ($backendName)." );
2427 $this->assertEquals(
true,
$status->isOK(),
2428 "Scoped unlocking of files succeeded with OK status ($backendName)." );
2439 'name' =>
'testing',
2440 'class' => MemoryFileBackend::class,
2442 'mimeCallback' => $mimeCallback
2446 $dst =
'mwstore://testing/container/path/to/file_no_ext';
2447 $src =
"$IP/tests/phpunit/data/media/srgb.jpg";
2448 $this->assertEquals(
'image/jpeg', $be->getContentType( $dst,
null, $src ) );
2449 $this->assertEquals(
2450 $mimeFromString ?
'image/jpeg' :
'unknown/unknown',
2451 $be->getContentType( $dst, file_get_contents( $src ),
null ) );
2453 $src =
"$IP/tests/phpunit/data/media/Png-native-test.png";
2454 $this->assertEquals(
'image/png', $be->getContentType( $dst,
null, $src ) );
2455 $this->assertEquals(
2456 $mimeFromString ?
'image/png' :
'unknown/unknown',
2457 $be->getContentType( $dst, file_get_contents( $src ),
null ) );
2468 $be = TestingAccessWrapper::newFromObject(
2470 'name' =>
'localtesting',
2471 'wikiId' =>
wfWikiID() . mt_rand(),
2474 'name' =>
'multitesting0',
2475 'class' => MemoryFileBackend::class,
2476 'isMultiMaster' =>
false,
2477 'readAffinity' =>
true
2480 'name' =>
'multitesting1',
2481 'class' => MemoryFileBackend::class,
2482 'isMultiMaster' =>
true
2488 $this->assertEquals(
2490 $be->getReadIndexFromParams( [
'latest' => 1 ] ),
2491 'Reads with "latest" flag use backend 1'
2493 $this->assertEquals(
2495 $be->getReadIndexFromParams( [
'latest' => 0 ] ),
2496 'Reads without "latest" flag use backend 0'
2499 $p =
'container/test-cont/file.txt';
2500 $be->backends[0]->quickCreate( [
2501 'dst' =>
"mwstore://multitesting0/$p",
'content' =>
'cattitude' ] );
2502 $be->backends[1]->quickCreate( [
2503 'dst' =>
"mwstore://multitesting1/$p",
'content' =>
'princess of power' ] );
2505 $this->assertEquals(
2507 $be->getFileContents( [
'src' =>
"mwstore://localtesting/$p" ] ),
2508 "Non-latest read came from backend 0"
2510 $this->assertEquals(
2511 'princess of power',
2512 $be->getFileContents( [
'src' =>
"mwstore://localtesting/$p",
'latest' => 1 ] ),
2513 "Latest read came from backend1"
2518 $be = TestingAccessWrapper::newFromObject(
2520 'name' =>
'localtesting',
2521 'wikiId' =>
wfWikiID() . mt_rand(),
2524 'name' =>
'multitesting0',
2525 'class' => MemoryFileBackend::class,
2526 'isMultiMaster' =>
false
2529 'name' =>
'multitesting1',
2530 'class' => MemoryFileBackend::class,
2531 'isMultiMaster' =>
true
2534 'replication' =>
'async'
2540 $p =
'container/test-cont/file.txt';
2542 'dst' =>
"mwstore://localtesting/$p",
'content' =>
'cattitude' ] );
2544 $this->assertEquals(
2546 $be->backends[0]->getFileContents( [
'src' =>
"mwstore://multitesting0/$p" ] ),
2547 "File not yet written to backend 0"
2549 $this->assertEquals(
2551 $be->backends[1]->getFileContents( [
'src' =>
"mwstore://multitesting1/$p" ] ),
2552 "File already written to backend 1"
2555 DeferredUpdates::doUpdates();
2557 $this->assertEquals(
2559 $be->backends[0]->getFileContents( [
'src' =>
"mwstore://multitesting0/$p" ] ),
2560 "File now written to backend 0"
2566 'name' =>
'localtesting',
2575 'Content-dUration' => 25.6,
2576 'X-LONG-VALUE' => str_pad(
'0', 300 ),
2577 'CONTENT-LENGTH' => 855055,
2583 'content-duration' => 25.6,
2584 'content-length' => 855055
2588 Wikimedia\suppressWarnings();
2589 $actual = $be->sanitizeOpHeaders(
$input );
2590 Wikimedia\restoreWarnings();
2592 $this->assertEquals( $expected, $actual,
"Header sanitized properly" );
2597 return is_array( $iter ) ? $iter : iterator_to_array( $iter );
2602 return $this->backend->prepare(
$params );
2609 return $this->backend->doQuickOperations( [
$params ] );
2613 $containers = [
'unittest-cont1',
'unittest-cont2',
'unittest-cont-bad' ];
2614 foreach ( $containers as $container ) {
2621 $iter = $this->backend->getFileList( [
'dir' =>
"$base/$container" ] );
2623 foreach ( $iter as $file ) {
2624 $this->backend->quickDelete( [
'src' =>
"$base/$container/$file" ] );
2629 $this->backend->clean( [
'dir' =>
"$base/$container",
'recursive' => 1 ] );
2634 $status = $this->backend->consistencyCheck( $paths );
2640 $this->assertEquals( print_r( [], 1 ), print_r(
$status->getErrors(), 1 ), $msg );
$wgFileBackends
File backend structure configuration.
wfTempDir()
Tries to get the system directory for temporary files.
wfRandomString( $length=32)
Get a random string containing a number of pseudo-random hex characters.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
Class for a file system (FS) based file backend.
static getPropsFromPath( $path, $ext=true)
Get an associative array containing information about a file in the local filesystem.
Proxy backend that mirrors writes to several internal backends.
FileRepo FileBackend medium.
static provider_testStreamFile()
static provider_testGetFileStat()
doTestGetFileHttpUrl( $source, $content)
testDoOperationsPipeline()
static provider_testSplitStoragePath()
testStreamFile( $path, $content, $alreadyExists)
provider_testGetFileStat
testMove( $op)
provider_testMove
testDelete( $op, $withSource, $okStatus)
provider_testDelete
doTestDoQuickOperations()
testGetLocalCopy( $source, $content)
provider_testGetLocalCopy
static provider_testIsStoragePath()
FSFileBackend $singleBackend
doTestPrepareAndClean( $path, $isOK)
doTestStreamFile( $path, $content)
testGetFileHttpUrl( $source, $content)
provider_testGetFileHttpUrl
testDoOperationsFailing()
FileBackendMultiWrite $multiBackend
doTestGetFileStat( $path, $content, $alreadyExists)
testGetLocalCopyAndReference404()
testGetLocalReference( $source, $content)
provider_testGetLocalReference
testGetContentType( $mimeCallback, $mimeFromString)
provider_testGetContentType
doTestGetLocalReference( $source, $content)
doTestDescribe( $op, $withSource, $okStatus)
testPrepareAndClean( $path, $isOK)
provider_testPrepareAndClean
assertBackendPathsConsistent(array $paths)
doTestConcatenate( $params, $srcs, $srcsContent, $alreadyExists, $okStatus)
testExtensionFromPath( $path, $res)
provider_testExtensionFromPath
static provider_testStore()
assertGoodStatus(StatusValue $status, $msg)
static provider_testGetFileHttpUrl()
testGetFileContents( $source, $content)
provider_testGetFileContents
doTestDoOperationsPipeline()
static provider_testGetContentType()
static provider_testParentStoragePath()
doTestGetFileContents( $source, $content)
doTestGetLocalCopyAndReference404()
static provider_testDescribe()
assertHasHeaders(array $headers, array $attr)
testStore( $op)
provider_testStore
testGetFileStat( $path, $content, $alreadyExists)
provider_testGetFileStat
doTestDoOperationsFailing()
doTestCreate( $op, $alreadyExists, $okStatus, $newSize)
static provider_testMove()
static provider_testConcatenate()
testNormalizeStoragePath( $path, $res)
provider_normalizeStoragePath
testConcatenate( $op, $srcs, $srcsContent, $alreadyExists, $okStatus)
provider_testConcatenate
testCreate( $op, $alreadyExists, $okStatus, $newSize)
provider_testCreate
testCopy( $op)
provider_testCopy
static provider_testGetLocalCopy()
testDescribe( $op, $withSource, $okStatus)
provider_testDescribe
static provider_testCopy()
doTestDelete( $op, $withSource, $okStatus)
static provider_testPrepareAndClean()
doTestGetLocalCopy( $source, $content)
static provider_normalizeStoragePath()
static provider_testCreate()
provider_testCreate
static provider_testGetFileContents()
testSplitStoragePath( $path, $res)
provider_testSplitStoragePath
static provider_testGetLocalReference()
static provider_testDelete()
testIsStoragePath( $path, $isStorePath)
provider_testIsStoragePath
static provider_testExtensionFromPath()
testParentStoragePath( $path, $res)
provider_testParentStoragePath
Base class for all file backend classes (including multi-write backends).
static parentStoragePath( $storagePath)
Get the parent storage directory of a storage path.
static isStoragePath( $path)
Check if a given path is a "mwstore://" path.
static splitStoragePath( $storagePath)
Split a storage path into a backend name, a container name, and a relative file path.
static extensionFromPath( $path, $case='lowercase')
Get the final extension from a storage or FS path.
static makeContentDisposition( $type, $filename='')
Build a Content-Disposition header value per RFC 6266.
static normalizeStoragePath( $storagePath)
Normalize a storage path by cleaning up directory separators.
const ATTR_HEADERS
Bitfield flags for supported features.
static factory(array $config, $backend)
Create an appropriate FileJournal object from config.
static request( $method, $url, $options=[], $caller=__METHOD__)
Perform an HTTP request.
static singleton( $domain=false)
Simulation of a backend storage in memory.
static release(ScopedLock &$lock=null)
Release a scoped lock and set any errors in the attatched StatusValue object.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
static factory( $prefix, $extension='', $tmpDirectory=null)
Make a new temporary file on the file system.
see documentation in includes Linker php for Linker::makeImageLink & $time
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Status::newGood()` to allow deletion, and then `return false` from the hook function. Ensure you consume the 'ChangeTagAfterDelete' hook to carry out custom deletion actions. $tag:name of the tag $user:user initiating the action & $status:Status object. See above. 'ChangeTagsListActive':Allows you to nominate which of the tags your extension uses are in active use. & $tags:list of all active tags. Append to this array. 'ChangeTagsAfterUpdateTags':Called after tags have been updated with the ChangeTags::updateTags function. Params:$addedTags:tags effectively added in the update $removedTags:tags effectively removed in the update $prevTags:tags that were present prior to the update $rc_id:recentchanges table id $rev_id:revision table id $log_id:logging table id $params:tag params $rc:RecentChange being tagged when the tagging accompanies the action, or null $user:User who performed the tagging when the tagging is subsequent to the action, or null 'ChangeTagsAllowedAdd':Called when checking if a user can add tags to a change. & $allowedTags:List of all the tags the user is allowed to add. Any tags the user wants to add( $addTags) that are not in this array will cause it to fail. You may add or remove tags to this array as required. $addTags:List of tags user intends to add. $user:User who is adding the tags. 'ChangeUserGroups':Called before user groups are changed. $performer:The User who will perform the change $user:The User whose groups will be changed & $add:The groups that will be added & $remove:The groups that will be removed 'Collation::factory':Called if $wgCategoryCollation is an unknown collation. $collationName:Name of the collation in question & $collationObject:Null. Replace with a subclass of the Collation class that implements the collation given in $collationName. 'ConfirmEmailComplete':Called after a user 's email has been confirmed successfully. $user:user(object) whose email is being confirmed 'ContentAlterParserOutput':Modify parser output for a given content object. Called by Content::getParserOutput after parsing has finished. Can be used for changes that depend on the result of the parsing but have to be done before LinksUpdate is called(such as adding tracking categories based on the rendered HTML). $content:The Content to render $title:Title of the page, as context $parserOutput:ParserOutput to manipulate 'ContentGetParserOutput':Customize parser output for a given content object, called by AbstractContent::getParserOutput. May be used to override the normal model-specific rendering of page content. $content:The Content to render $title:Title of the page, as context $revId:The revision ID, as context $options:ParserOptions for rendering. To avoid confusing the parser cache, the output can only depend on parameters provided to this hook function, not on global state. $generateHtml:boolean, indicating whether full HTML should be generated. If false, generation of HTML may be skipped, but other information should still be present in the ParserOutput object. & $output:ParserOutput, to manipulate or replace 'ContentHandlerDefaultModelFor':Called when the default content model is determined for a given title. May be used to assign a different model for that title. $title:the Title in question & $model:the model name. Use with CONTENT_MODEL_XXX constants. 'ContentHandlerForModelID':Called when a ContentHandler is requested for a given content model name, but no entry for that model exists in $wgContentHandlers. Note:if your extension implements additional models via this hook, please use GetContentModels hook to make them known to core. $modeName:the requested content model name & $handler:set this to a ContentHandler object, if desired. 'ContentModelCanBeUsedOn':Called to determine whether that content model can be used on a given page. This is especially useful to prevent some content models to be used in some special location. $contentModel:ID of the content model in question $title:the Title in question. & $ok:Output parameter, whether it is OK to use $contentModel on $title. Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok. 'ContribsPager::getQueryInfo':Before the contributions query is about to run & $pager:Pager object for contributions & $queryInfo:The query for the contribs Pager 'ContribsPager::reallyDoQuery':Called before really executing the query for My Contributions & $data:an array of results of all contribs queries $pager:The ContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'ContributionsLineEnding':Called before a contributions HTML line is finished $page:SpecialPage object for contributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'ContributionsToolLinks':Change tool links above Special:Contributions $id:User identifier $title:User page title & $tools:Array of tool links $specialPage:SpecialPage instance for context and services. Can be either SpecialContributions or DeletedContributionsPage. Extensions should type hint against a generic SpecialPage though. 'ConvertContent':Called by AbstractContent::convert when a conversion to another content model is requested. Handler functions that modify $result should generally return false to disable further attempts at conversion. $content:The Content object to be converted. $toModel:The ID of the content model to convert to. $lossy: boolean indicating whether lossy conversion is allowed. & $result:Output parameter, in case the handler function wants to provide a converted Content object. Note that $result->getContentModel() must return $toModel. 'ContentSecurityPolicyDefaultSource':Modify the allowed CSP load sources. This affects all directives except for the script directive. If you want to add a script source, see ContentSecurityPolicyScriptSource hook. & $defaultSrc:Array of Content-Security-Policy allowed sources $policyConfig:Current configuration for the Content-Security-Policy header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'ContentSecurityPolicyDirectives':Modify the content security policy directives. Use this only if ContentSecurityPolicyDefaultSource and ContentSecurityPolicyScriptSource do not meet your needs. & $directives:Array of CSP directives $policyConfig:Current configuration for the CSP header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'ContentSecurityPolicyScriptSource':Modify the allowed CSP script sources. Note that you also have to use ContentSecurityPolicyDefaultSource if you want non-script sources to be loaded from whatever you add. & $scriptSrc:Array of CSP directives $policyConfig:Current configuration for the CSP header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'CustomEditor':When invoking the page editor Return true to allow the normal editor to be used, or false if implementing a custom editor, e.g. for a special namespace, etc. $article:Article being edited $user:User performing the edit 'DatabaseOraclePostInit':Called after initialising an Oracle database $db:the DatabaseOracle object 'DeletedContribsPager::reallyDoQuery':Called before really executing the query for Special:DeletedContributions Similar to ContribsPager::reallyDoQuery & $data:an array of results of all contribs queries $pager:The DeletedContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'DeletedContributionsLineEnding':Called before a DeletedContributions HTML line is finished. Similar to ContributionsLineEnding $page:SpecialPage object for DeletedContributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'DeleteUnknownPreferences':Called by the cleanupPreferences.php maintenance script to build a WHERE clause with which to delete preferences that are not known about. This hook is used by extensions that have dynamically-named preferences that should not be deleted in the usual cleanup process. For example, the Gadgets extension creates preferences prefixed with 'gadget-', and so anything with that prefix is excluded from the deletion. &where:An array that will be passed as the $cond parameter to IDatabase::select() to determine what will be deleted from the user_properties table. $db:The IDatabase object, useful for accessing $db->buildLike() etc. 'DifferenceEngineAfterLoadNewText':called in DifferenceEngine::loadNewText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before returning true from this function. $differenceEngine:DifferenceEngine object 'DifferenceEngineLoadTextAfterNewContentIsLoaded':called in DifferenceEngine::loadText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before checking if the variable 's value is null. This hook can be used to inject content into said class member variable. $differenceEngine:DifferenceEngine object 'DifferenceEngineMarkPatrolledLink':Allows extensions to change the "mark as
patrolled" link which is shown both on the diff header as well as on the bottom of a page, usually wrapped in a span element which has class="patrollink". $differenceEngine:DifferenceEngine object & $markAsPatrolledLink:The "mark as patrolled" link HTML(string) $rcid:Recent change ID(rc_id) for this change(int) 'DifferenceEngineMarkPatrolledRCID':Allows extensions to possibly change the rcid parameter. For example the rcid might be set to zero due to the user being the same as the performer of the change but an extension might still want to show it under certain conditions. & $rcid:rc_id(int) of the change or 0 $differenceEngine:DifferenceEngine object $change:RecentChange object $user:User object representing the current user 'DifferenceEngineNewHeader':Allows extensions to change the $newHeader variable, which contains information about the new revision, such as the revision 's author, whether the revision was marked as a minor edit or not, etc. $differenceEngine:DifferenceEngine object & $newHeader:The string containing the various #mw-diff-otitle[1-5] divs, which include things like revision author info, revision comment, RevisionDelete link and more $formattedRevisionTools:Array containing revision tools, some of which may have been injected with the DiffRevisionTools hook $nextlink:String containing the link to the next revision(if any) $status
processing should stop and the error should be shown to the user * false
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
if(is_array($mode)) switch( $mode) $input