107 parent::__construct( $config );
109 $this->swiftAuthUrl = $config[
'swiftAuthUrl'];
110 $this->swiftUser = $config[
'swiftUser'];
111 $this->swiftKey = $config[
'swiftKey'];
113 $this->authTTL = isset( $config[
'swiftAuthTTL'] )
114 ? $config[
'swiftAuthTTL']
116 $this->swiftTempUrlKey = isset( $config[
'swiftTempUrlKey'] )
117 ? $config[
'swiftTempUrlKey']
119 $this->shardViaHashLevels = isset( $config[
'shardViaHashLevels'] )
120 ? $config[
'shardViaHashLevels']
122 $this->rgwS3AccessKey = isset( $config[
'rgwS3AccessKey'] )
123 ? $config[
'rgwS3AccessKey']
125 $this->rgwS3SecretKey = isset( $config[
'rgwS3SecretKey'] )
126 ? $config[
'rgwS3SecretKey']
131 if ( isset( $config[
'wanCache'] ) && $config[
'wanCache'] instanceof
WANObjectCache ) {
132 $this->memCache = $config[
'wanCache'];
137 if ( !empty( $config[
'cacheAuthInfo'] ) && isset( $config[
'srvCache'] ) ) {
138 $this->srvCache = $config[
'srvCache'];
150 if ( !mb_check_encoding( $relStoragePath,
'UTF-8' ) ) {
152 } elseif ( strlen( urlencode( $relStoragePath ) ) > 1024 ) {
156 return $relStoragePath;
161 if ( $rel === null ) {
176 return isset( $params[
'headers'] )
192 if ( preg_match(
'/^content-(type|length)$/',
$name ) ) {
194 } elseif ( preg_match(
'/^(x-)?content-/',
$name ) ) {
196 } elseif ( preg_match(
'/^content-(disposition)/',
$name ) ) {
201 if ( isset( $headers[
'content-disposition'] ) ) {
204 foreach ( explode(
';', $headers[
'content-disposition'] )
as $part ) {
205 $part = trim( $part );
206 $new = ( $disposition ===
'' ) ? $part :
"{$disposition};{$part}";
207 if ( strlen( $new ) <= 255 ) {
213 $headers[
'content-disposition'] = $disposition;
227 if ( strpos(
$name,
'x-object-meta-' ) === 0 ) {
242 $metadata[substr(
$name, strlen(
'x-object-meta-' ) )] =
$value;
252 if ( $dstRel === null ) {
253 $status->fatal(
'backend-fail-invalidpath', $params[
'dst'] );
258 $sha1Hash = Wikimedia\base_convert( sha1( $params[
'content'] ), 16, 36, 31 );
259 $contentType = isset( $params[
'headers'][
'content-type'] )
260 ? $params[
'headers'][
'content-type']
261 : $this->
getContentType( $params[
'dst'], $params[
'content'], null );
265 'url' => [ $dstCont, $dstRel ],
267 'content-length' => strlen( $params[
'content'] ),
268 'etag' => md5( $params[
'content'] ),
269 'content-type' => $contentType,
270 'x-object-meta-sha1base36' => $sha1Hash
272 'body' => $params[
'content']
275 $method = __METHOD__;
277 list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $request[
'response'];
278 if ( $rcode === 201 ) {
280 } elseif ( $rcode === 412 ) {
281 $status->fatal(
'backend-fail-contenttype', $params[
'dst'] );
283 $this->
onError(
$status, $method, $params, $rerr, $rcode, $rdesc );
288 if ( !empty( $params[
'async'] ) ) {
301 if ( $dstRel === null ) {
302 $status->fatal(
'backend-fail-invalidpath', $params[
'dst'] );
307 MediaWiki\suppressWarnings();
308 $sha1Hash = sha1_file( $params[
'src'] );
309 MediaWiki\restoreWarnings();
310 if ( $sha1Hash ===
false ) {
311 $status->fatal(
'backend-fail-store', $params[
'src'], $params[
'dst'] );
315 $sha1Hash = Wikimedia\base_convert( $sha1Hash, 16, 36, 31 );
316 $contentType = isset( $params[
'headers'][
'content-type'] )
317 ? $params[
'headers'][
'content-type']
320 $handle = fopen( $params[
'src'],
'rb' );
321 if ( $handle ===
false ) {
322 $status->fatal(
'backend-fail-store', $params[
'src'], $params[
'dst'] );
329 'url' => [ $dstCont, $dstRel ],
331 'content-length' => filesize( $params[
'src'] ),
332 'etag' => md5_file( $params[
'src'] ),
333 'content-type' => $contentType,
334 'x-object-meta-sha1base36' => $sha1Hash
339 $method = __METHOD__;
341 list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $request[
'response'];
342 if ( $rcode === 201 ) {
344 } elseif ( $rcode === 412 ) {
345 $status->fatal(
'backend-fail-contenttype', $params[
'dst'] );
347 $this->
onError(
$status, $method, $params, $rerr, $rcode, $rdesc );
352 if ( !empty( $params[
'async'] ) ) {
365 if ( $srcRel === null ) {
366 $status->fatal(
'backend-fail-invalidpath', $params[
'src'] );
372 if ( $dstRel === null ) {
373 $status->fatal(
'backend-fail-invalidpath', $params[
'dst'] );
380 'url' => [ $dstCont, $dstRel ],
382 'x-copy-from' =>
'/' . rawurlencode( $srcCont ) .
383 '/' . str_replace(
"%2F",
"/", rawurlencode( $srcRel ) )
387 $method = __METHOD__;
389 list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $request[
'response'];
390 if ( $rcode === 201 ) {
392 } elseif ( $rcode === 404 ) {
393 $status->fatal(
'backend-fail-copy', $params[
'src'], $params[
'dst'] );
395 $this->
onError(
$status, $method, $params, $rerr, $rcode, $rdesc );
400 if ( !empty( $params[
'async'] ) ) {
413 if ( $srcRel === null ) {
414 $status->fatal(
'backend-fail-invalidpath', $params[
'src'] );
420 if ( $dstRel === null ) {
421 $status->fatal(
'backend-fail-invalidpath', $params[
'dst'] );
429 'url' => [ $dstCont, $dstRel ],
431 'x-copy-from' =>
'/' . rawurlencode( $srcCont ) .
432 '/' . str_replace(
"%2F",
"/", rawurlencode( $srcRel ) )
436 if (
"{$srcCont}/{$srcRel}" !==
"{$dstCont}/{$dstRel}" ) {
438 'method' =>
'DELETE',
439 'url' => [ $srcCont, $srcRel ],
444 $method = __METHOD__;
446 list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $request[
'response'];
447 if ( $request[
'method'] ===
'PUT' && $rcode === 201 ) {
449 } elseif ( $request[
'method'] ===
'DELETE' && $rcode === 204 ) {
451 } elseif ( $rcode === 404 ) {
452 $status->fatal(
'backend-fail-move', $params[
'src'], $params[
'dst'] );
454 $this->
onError(
$status, $method, $params, $rerr, $rcode, $rdesc );
459 if ( !empty( $params[
'async'] ) ) {
472 if ( $srcRel === null ) {
473 $status->fatal(
'backend-fail-invalidpath', $params[
'src'] );
479 'method' =>
'DELETE',
480 'url' => [ $srcCont, $srcRel ],
484 $method = __METHOD__;
486 list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $request[
'response'];
487 if ( $rcode === 204 ) {
489 } elseif ( $rcode === 404 ) {
490 if ( empty( $params[
'ignoreMissingSource'] ) ) {
491 $status->fatal(
'backend-fail-delete', $params[
'src'] );
494 $this->
onError(
$status, $method, $params, $rerr, $rcode, $rdesc );
499 if ( !empty( $params[
'async'] ) ) {
512 if ( $srcRel === null ) {
513 $status->fatal(
'backend-fail-invalidpath', $params[
'src'] );
519 $stat = $this->
getFileStat( [
'src' => $params[
'src'],
'latest' => 1 ] );
520 if ( $stat && !isset( $stat[
'xattr'] ) ) {
521 $stat = $this->
doGetFileStat( [
'src' => $params[
'src'],
'latest' => 1 ] );
524 $status->fatal(
'backend-fail-describe', $params[
'src'] );
532 $metaHdrs[
"x-object-meta-$name"] =
$value;
534 $customHdrs = $this->
sanitizeHdrs( $params ) + $stat[
'xattr'][
'headers'];
538 'url' => [ $srcCont, $srcRel ],
539 'headers' => $metaHdrs + $customHdrs
542 $method = __METHOD__;
544 list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $request[
'response'];
545 if ( $rcode === 202 ) {
547 } elseif ( $rcode === 404 ) {
548 $status->fatal(
'backend-fail-describe', $params[
'src'] );
550 $this->
onError(
$status, $method, $params, $rerr, $rcode, $rdesc );
555 if ( !empty( $params[
'async'] ) ) {
569 if ( is_array( $stat ) ) {
571 } elseif ( $stat === null ) {
572 $status->fatal(
'backend-fail-internal', $this->
name );
573 $this->logger->error( __METHOD__ .
': cannot get container stat' );
579 if ( $stat ===
false ) {
580 $params[
'op'] =
'prepare';
589 if ( empty( $params[
'noAccess'] ) ) {
594 if ( is_array( $stat ) ) {
598 [ $this->swiftUser ],
601 } elseif ( $stat ===
false ) {
602 $status->fatal(
'backend-fail-usable', $params[
'dir'] );
604 $status->fatal(
'backend-fail-internal', $this->
name );
605 $this->logger->error( __METHOD__ .
': cannot get container stat' );
615 if ( is_array( $stat ) ) {
619 [ $this->swiftUser,
'.r:*' ],
622 } elseif ( $stat ===
false ) {
623 $status->fatal(
'backend-fail-usable', $params[
'dir'] );
625 $status->fatal(
'backend-fail-internal', $this->
name );
626 $this->logger->error( __METHOD__ .
': cannot get container stat' );
642 if ( $stat ===
false ) {
644 } elseif ( !is_array( $stat ) ) {
645 $status->fatal(
'backend-fail-internal', $this->
name );
646 $this->logger->error( __METHOD__ .
': cannot get container stat' );
652 if ( $stat[
'count'] == 0 ) {
653 $params[
'op'] =
'clean';
661 $params = [
'srcs' => [ $params[
'src'] ],
'concurrency' => 1 ] +
$params;
662 unset( $params[
'src'] );
665 return reset( $stats );
696 if ( isset( $objHdrs[
'x-object-meta-sha1base36'] ) ) {
702 $this->logger->error( __METHOD__ .
": $path was not stored with SHA-1 metadata." );
704 $objHdrs[
'x-object-meta-sha1base36'] =
false;
722 $hash = $tmpFile->getSha1Base36();
723 if ( $hash !==
false ) {
724 $objHdrs[
'x-object-meta-sha1base36'] = $hash;
726 $postHeaders[
'x-object-meta-sha1base36'] = $hash;
728 list( $rcode ) = $this->
http->run( [
730 'url' => $this->
storageUrl( $auth, $srcCont, $srcRel ),
733 if ( $rcode >= 200 && $rcode <= 299 ) {
742 $this->logger->error( __METHOD__ .
": unable to set SHA-1 metadata for $path" );
752 $ep = array_diff_key( $params, [
'srcs' => 1 ] );
757 foreach ( $params[
'srcs']
as $path ) {
759 if ( $srcRel === null || !$auth ) {
760 $contents[
$path] =
false;
764 $handle = fopen(
'php://temp',
'wb' );
768 'url' => $this->
storageUrl( $auth, $srcCont, $srcRel ),
774 $contents[
$path] =
false;
777 $opts = [
'maxConnsPerHost' => $params[
'concurrency'] ];
778 $reqs = $this->
http->runMulti( $reqs, $opts );
779 foreach ( $reqs
as $path => $op ) {
780 list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $op[
'response'];
781 if ( $rcode >= 200 && $rcode <= 299 ) {
782 rewind( $op[
'stream'] );
783 $contents[
$path] = stream_get_contents( $op[
'stream'] );
784 } elseif ( $rcode === 404 ) {
785 $contents[
$path] =
false;
787 $this->
onError( null, __METHOD__,
788 [
'src' => $path ] + $ep, $rerr, $rcode, $rdesc );
790 fclose( $op[
'stream'] );
797 $prefix = (
$dir ==
'' ) ? null :
"{$dir}/";
800 return ( count(
$status->value ) ) > 0;
841 if ( $after === INF ) {
847 $prefix = (
$dir ==
'' ) ? null :
"{$dir}/";
849 if ( !empty( $params[
'topOnly'] ) ) {
855 foreach ( $objects
as $object ) {
856 if ( substr( $object, -1 ) ===
'/' ) {
862 $getParentDir =
function (
$path ) {
867 $lastDir = $getParentDir( $after );
876 foreach ( $objects
as $object ) {
877 $objectDir = $getParentDir( $object );
879 if ( $objectDir !==
false && $objectDir !==
$dir ) {
884 if ( strcmp( $objectDir, $lastDir ) > 0 ) {
887 $dirs[] =
"{$pDir}/";
888 $pDir = $getParentDir( $pDir );
889 }
while ( $pDir !==
false
890 && strcmp( $pDir, $lastDir ) > 0
891 && strlen( $pDir ) > strlen(
$dir )
894 $lastDir = $objectDir;
899 if ( count( $objects ) <
$limit ) {
902 $after = end( $objects );
921 if ( $after === INF ) {
927 $prefix = (
$dir ==
'' ) ? null :
"{$dir}/";
930 if ( !empty( $params[
'topOnly'] ) ) {
931 if ( !empty( $params[
'adviseStat'] ) ) {
938 if ( !empty( $params[
'adviseStat'] ) ) {
954 if ( count( $objects ) <
$limit ) {
957 $after = end( $objects );
958 $after = is_object( $after ) ? $after->name : $after;
975 foreach ( $objects
as $object ) {
976 if ( is_object( $object ) ) {
977 if ( isset( $object->subdir ) || !isset( $object->name ) ) {
983 'size' => (int)$object->bytes,
986 'md5' => ctype_xdigit( $object->hash ) ? $object->hash : null,
989 $names[] = [ $object->name, $stat ];
990 } elseif ( substr( $object, -1 ) !==
'/' ) {
992 $names[] = [ $object, null ];
1006 $this->cheapCache->set(
$path,
'stat', $val );
1012 if ( !isset( $stat[
'xattr'] ) ) {
1018 return $stat[
'xattr'];
1027 if ( !isset( $stat[
'sha1'] ) ) {
1033 return $stat[
'sha1'];
1045 if ( $srcRel === null ) {
1047 $status->fatal(
'backend-fail-invalidpath', $params[
'src'] );
1055 $status->fatal(
'backend-fail-stream', $params[
'src'] );
1062 if ( $params[
'headers'] && !$this->
fileExists( $params ) ) {
1064 $status->fatal(
'backend-fail-stream', $params[
'src'] );
1070 foreach ( $params[
'headers']
as $header ) {
1074 if ( empty( $params[
'allowOB'] ) ) {
1076 call_user_func( $this->obResetFunc );
1079 $handle = fopen(
'php://output',
'wb' );
1080 list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $this->
http->run( [
1082 'url' => $this->
storageUrl( $auth, $srcCont, $srcRel ),
1085 'stream' => $handle,
1086 'flags' => [
'relayResponseHeaders' => empty( $params[
'headless'] ) ]
1089 if ( $rcode >= 200 && $rcode <= 299 ) {
1091 } elseif ( $rcode === 404 ) {
1092 $status->fatal(
'backend-fail-stream', $params[
'src'] );
1099 $this->
onError(
$status, __METHOD__, $params, $rerr, $rcode, $rdesc );
1111 $ep = array_diff_key( $params, [
'srcs' => 1 ] );
1116 foreach ( $params[
'srcs']
as $path ) {
1118 if ( $srcRel === null || !$auth ) {
1119 $tmpFiles[
$path] = null;
1127 $handle = fopen( $tmpFile->getPath(),
'wb' );
1131 'url' => $this->
storageUrl( $auth, $srcCont, $srcRel ),
1134 'stream' => $handle,
1140 $tmpFiles[
$path] = $tmpFile;
1143 $isLatest = ( $this->isRGW || !empty( $params[
'latest'] ) );
1144 $opts = [
'maxConnsPerHost' => $params[
'concurrency'] ];
1145 $reqs = $this->
http->runMulti( $reqs, $opts );
1146 foreach ( $reqs
as $path => $op ) {
1147 list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $op[
'response'];
1148 fclose( $op[
'stream'] );
1149 if ( $rcode >= 200 && $rcode <= 299 ) {
1150 $size = $tmpFiles[
$path] ? $tmpFiles[
$path]->getSize() : 0;
1152 if ( $size != $rhdrs[
'content-length'] ) {
1153 $tmpFiles[
$path] = null;
1154 $rerr =
"Got {$size}/{$rhdrs['content-length']} bytes";
1155 $this->
onError( null, __METHOD__,
1156 [
'src' => $path ] + $ep, $rerr, $rcode, $rdesc );
1160 $stat[
'latest'] = $isLatest;
1161 $this->cheapCache->set( $path,
'stat', $stat );
1162 } elseif ( $rcode === 404 ) {
1163 $tmpFiles[
$path] =
false;
1165 $tmpFiles[
$path] = null;
1166 $this->
onError( null, __METHOD__,
1167 [
'src' => $path ] + $ep, $rerr, $rcode, $rdesc );
1175 if ( $this->swiftTempUrlKey !=
'' ||
1176 ( $this->rgwS3AccessKey !=
'' && $this->rgwS3SecretKey !=
'' )
1179 if ( $srcRel === null ) {
1188 $ttl = isset( $params[
'ttl'] ) ? $params[
'ttl'] : 86400;
1189 $expires = time() + $ttl;
1191 if ( $this->swiftTempUrlKey !=
'' ) {
1192 $url = $this->
storageUrl( $auth, $srcCont, $srcRel );
1194 $contPath = parse_url( $this->
storageUrl( $auth, $srcCont ), PHP_URL_PATH );
1195 $signature = hash_hmac(
'sha1',
1196 "GET\n{$expires}\n{$contPath}/{$srcRel}",
1197 $this->swiftTempUrlKey
1200 return "{$url}?temp_url_sig={$signature}&temp_url_expires={$expires}";
1203 $spath =
'/' . rawurlencode( $srcCont ) .
'/' .
1204 str_replace(
'%2F',
'/', rawurlencode( $srcRel ) );
1206 $signature = base64_encode( hash_hmac(
1208 "GET\n\n\n{$expires}\n{$spath}",
1209 $this->rgwS3SecretKey,
1215 return str_replace(
'/swift/v1',
'', $this->
storageUrl( $auth ) . $spath ) .
1218 'Signature' => $signature,
1219 'Expires' => $expires,
1220 'AWSAccessKeyId' => $this->rgwS3AccessKey
1242 if ( !empty( $params[
'latest'] ) ) {
1243 $hdrs[
'x-newest'] =
'true';
1260 foreach ( $fileOpHandles
as $index => $fileOpHandle ) {
1261 $statuses[$index] = $this->
newStatus(
'backend-fail-connect', $this->
name );
1268 $httpReqsByStage = [];
1269 foreach ( $fileOpHandles
as $index => $fileOpHandle ) {
1271 $reqs = $fileOpHandle->httpOp;
1273 foreach ( $reqs
as $stage => &
$req ) {
1274 list( $container, $relPath ) =
$req[
'url'];
1276 $req[
'headers'] = isset(
$req[
'headers'] ) ?
$req[
'headers'] : [];
1278 $httpReqsByStage[$stage][$index] =
$req;
1284 $reqCount = count( $httpReqsByStage );
1285 for ( $stage = 0; $stage < $reqCount; ++$stage ) {
1286 $httpReqs = $this->
http->runMulti( $httpReqsByStage[$stage] );
1287 foreach ( $httpReqs
as $index => $httpReq ) {
1289 $callback = $fileOpHandles[$index]->callback;
1290 call_user_func_array( $callback, [ $httpReq, $statuses[$index] ] );
1293 if ( !$statuses[$index]->isOK() ) {
1294 $stages = count( $fileOpHandles[$index]->httpOp );
1295 for (
$s = ( $stage + 1 );
$s < $stages; ++
$s ) {
1296 unset( $httpReqsByStage[
$s][$index] );
1332 $status->fatal(
'backend-fail-connect', $this->
name );
1337 list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $this->
http->run( [
1339 'url' => $this->
storageUrl( $auth, $container ),
1341 'x-container-read' => implode(
',', $readGrps ),
1342 'x-container-write' => implode(
',', $writeGrps )
1346 if ( $rcode != 204 && $rcode !== 202 ) {
1347 $status->fatal(
'backend-fail-internal', $this->
name );
1348 $this->logger->error( __METHOD__ .
': unexpected rcode value (' . $rcode .
')' );
1365 if ( $bypassCache ) {
1366 $this->containerStatCache->clear( $container );
1367 } elseif ( !$this->containerStatCache->has( $container,
'stat' ) ) {
1370 if ( !$this->containerStatCache->has( $container,
'stat' ) ) {
1376 list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $this->
http->run( [
1378 'url' => $this->
storageUrl( $auth, $container ),
1382 if ( $rcode === 204 ) {
1384 'count' => $rhdrs[
'x-container-object-count'],
1385 'bytes' => $rhdrs[
'x-container-bytes-used']
1387 if ( $bypassCache ) {
1390 $this->containerStatCache->set( $container,
'stat', $stat );
1393 } elseif ( $rcode === 404 ) {
1396 $this->
onError( null, __METHOD__,
1397 [
'cont' => $container ], $rerr, $rcode, $rdesc );
1403 return $this->containerStatCache->get( $container,
'stat' );
1418 $status->fatal(
'backend-fail-connect', $this->
name );
1424 if ( empty( $params[
'noAccess'] ) ) {
1431 list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $this->
http->run( [
1433 'url' => $this->
storageUrl( $auth, $container ),
1435 'x-container-read' => implode(
',', $readGrps ),
1436 'x-container-write' => implode(
',', $writeGrps )
1440 if ( $rcode === 201 ) {
1442 } elseif ( $rcode === 202 ) {
1445 $this->
onError(
$status, __METHOD__, $params, $rerr, $rcode, $rdesc );
1463 $status->fatal(
'backend-fail-connect', $this->
name );
1468 list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $this->
http->run( [
1469 'method' =>
'DELETE',
1470 'url' => $this->
storageUrl( $auth, $container ),
1474 if ( $rcode >= 200 && $rcode <= 299 ) {
1475 $this->containerStatCache->clear( $container );
1476 } elseif ( $rcode === 404 ) {
1478 } elseif ( $rcode === 409 ) {
1479 $this->
onError(
$status, __METHOD__, $params, $rerr, $rcode, $rdesc );
1481 $this->
onError(
$status, __METHOD__, $params, $rerr, $rcode, $rdesc );
1500 $fullCont,
$type,
$limit, $after = null, $prefix = null, $delim = null
1506 $status->fatal(
'backend-fail-connect', $this->
name );
1512 if (
$type ===
'info' ) {
1513 $query[
'format'] =
'json';
1515 if ( $after !== null ) {
1516 $query[
'marker'] = $after;
1518 if ( $prefix !== null ) {
1519 $query[
'prefix'] = $prefix;
1521 if ( $delim !== null ) {
1522 $query[
'delimiter'] = $delim;
1525 list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $this->
http->run( [
1527 'url' => $this->
storageUrl( $auth, $fullCont ),
1532 $params = [
'cont' => $fullCont,
'prefix' => $prefix,
'delim' => $delim ];
1533 if ( $rcode === 200 ) {
1534 if (
$type ===
'info' ) {
1537 $status->value = explode(
"\n", trim( $rbody ) );
1539 } elseif ( $rcode === 204 ) {
1541 } elseif ( $rcode === 404 ) {
1551 foreach ( $containerInfo
as $container => $info ) {
1552 $this->containerStatCache->set( $container,
'stat', $info );
1562 foreach ( $params[
'srcs']
as $path ) {
1564 if ( $srcRel === null ) {
1565 $stats[
$path] =
false;
1567 } elseif ( !$auth ) {
1568 $stats[
$path] = null;
1574 if ( $cstat ===
false ) {
1575 $stats[
$path] =
false;
1577 } elseif ( !is_array( $cstat ) ) {
1578 $stats[
$path] = null;
1584 'url' => $this->
storageUrl( $auth, $srcCont, $srcRel ),
1589 $opts = [
'maxConnsPerHost' => $params[
'concurrency'] ];
1590 $reqs = $this->
http->runMulti( $reqs, $opts );
1592 foreach ( $params[
'srcs']
as $path ) {
1593 if ( array_key_exists( $path, $stats ) ) {
1597 list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $reqs[
$path][
'response'];
1598 if ( $rcode === 200 || $rcode === 204 ) {
1603 if ( $this->isRGW ) {
1604 $stat[
'latest'] =
true;
1606 } elseif ( $rcode === 404 ) {
1610 $this->
onError( null, __METHOD__, $params, $rerr, $rcode, $rdesc );
1612 $stats[
$path] = $stat;
1626 $headers = $this->
sanitizeHdrs( [
'headers' => $rhdrs ] );
1632 'size' => isset( $rhdrs[
'content-length'] ) ? (int)$rhdrs[
'content-length'] : 0,
1633 'sha1' => isset( $metadata[
'sha1base36'] ) ? $metadata[
'sha1base36'] : null,
1635 'md5' => ctype_xdigit( $rhdrs[
'etag'] ) ? $rhdrs[
'etag'] : null,
1636 'xattr' => [
'metadata' => $metadata,
'headers' => $headers ]
1644 if ( $this->authErrorTimestamp !== null ) {
1645 if ( ( time() - $this->authErrorTimestamp ) < 60 ) {
1648 $this->authErrorTimestamp = null;
1654 if ( !$this->authCreds || $reAuth ) {
1655 $this->authSessionTimestamp = 0;
1657 $creds = $this->srvCache->get( $cacheKey );
1659 if ( isset( $creds[
'auth_token'] ) && isset( $creds[
'storage_url'] ) ) {
1660 $this->authCreds = $creds;
1662 $this->authSessionTimestamp = time() - ceil( $this->authTTL / 2 );
1664 list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $this->
http->run( [
1666 'url' =>
"{$this->swiftAuthUrl}/v1.0",
1668 'x-auth-user' => $this->swiftUser,
1669 'x-auth-key' => $this->swiftKey
1673 if ( $rcode >= 200 && $rcode <= 299 ) {
1674 $this->authCreds = [
1675 'auth_token' => $rhdrs[
'x-auth-token'],
1676 'storage_url' => $rhdrs[
'x-storage-url']
1678 $this->srvCache->set( $cacheKey, $this->authCreds, ceil( $this->authTTL / 2 ) );
1679 $this->authSessionTimestamp = time();
1680 } elseif ( $rcode === 401 ) {
1681 $this->
onError( null, __METHOD__, [],
"Authentication failed.", $rcode );
1682 $this->authErrorTimestamp = time();
1686 $this->
onError( null, __METHOD__, [],
"HTTP return code: $rcode", $rcode );
1687 $this->authErrorTimestamp = time();
1693 if ( substr( $this->authCreds[
'storage_url'], -3 ) ===
'/v1' ) {
1694 $this->isRGW =
true;
1708 $parts = [ $creds[
'storage_url'] ];
1709 if ( strlen( $container ) ) {
1710 $parts[] = rawurlencode( $container );
1712 if ( strlen( $object ) ) {
1713 $parts[] = str_replace(
"%2F",
"/", rawurlencode( $object ) );
1716 return implode(
'/', $parts );
1724 return [
'x-auth-token' => $creds[
'auth_token'] ];
1734 return 'swiftcredentials:' . md5(
$username .
':' . $this->swiftAuthUrl );
1750 $status->fatal(
'backend-fail-internal', $this->
name );
1752 if (
$code == 401 ) {
1755 $this->logger->error(
1757 ( $err ?
": $err" :
"" )
1825 $this->container = $fullCont;
1827 if ( substr( $this->dir, -1 ) ===
'/' ) {
1828 $this->dir = substr( $this->dir, 0, -1 );
1830 if ( $this->dir ==
'' ) {
1831 $this->suffixStart = 0;
1833 $this->suffixStart = strlen( $this->dir ) + 1;
1851 next( $this->bufferIter );
1855 if ( !$this->
valid() && count( $this->bufferIter ) ) {
1857 $this->container, $this->dir, $this->bufferAfter, self::PAGE_SIZE, $this->params
1867 $this->bufferAfter = null;
1869 $this->container, $this->dir, $this->bufferAfter, self::PAGE_SIZE, $this->params
1878 if ( $this->bufferIter === null ) {
1881 return ( current( $this->bufferIter ) !==
false );
1907 return substr(
current( $this->bufferIter ), $this->suffixStart, -1 );
1925 $relPath = substr(
$path, $this->suffixStart );
1926 if ( is_array( $stat ) ) {
1927 $storageDir = rtrim( $this->params[
'dir'],
'/' );
1928 $this->backend->loadListingStatInternal(
"$storageDir/$relPath", $stat );
doStoreInternal(array $params)
doPrepareInternal($fullCont, $dir, array $params)
doGetFileStatMulti(array $params)
newStatus()
Yields the result of the status wrapper callback on either:
getFileListPageInternal($fullCont, $dir, &$after, $limit, array $params)
Do not call this function outside of SwiftFileBackendFileList.
primeContainerCache(array $items)
Do a batch lookup from cache for container stats for all containers used in a list of container names...
buildFileObjectListing(array $params, $dir, array $objects)
Build a list of file objects, filtering out any directories and extracting any stat info if provided ...
doCleanInternal($fullCont, $dir, array $params)
getFileListInternal($fullCont, $dir, array $params)
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 array() calling protocol came about after MediaWiki 1.4rc1.
resolveContainerPath($container, $relStoragePath)
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
getCustomHeaders(array $rawHeaders)
Iterator for listing directories.
processing should stop and the error should be shown to the user * false
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException'returning false will NOT prevent logging $e
string $swiftUser
Swift user (account:user) to authenticate as.
int $authErrorTimestamp
UNIX timestamp.
scopedProfileSection($section)
deleteContainer($container, array $params)
Delete a Swift container.
getFileStat(array $params)
const ATTR_HEADERS
Bitfield flags for supported features.
doDirectoryExists($fullCont, $dir, array $params)
doPublishInternal($fullCont, $dir, array $params)
string $bufferAfter
List items after this path.
getScopedFileLocks(array $paths, $type, StatusValue $status, $timeout=0)
Lock the files at the given storage paths in the backend.
it s the revision text itself In either if gzip is the revision text is gzipped $flags
SwiftFileBackend helper class to page through listings.
doDeleteInternal(array $params)
static send404Message($fname, $flags=0)
Send out a standard 404 message for a file.
doMoveInternal(array $params)
getStatFromHeaders(array $rhdrs)
static extensionFromPath($path, $case= 'lowercase')
Get the final extension from a storage or FS path.
setContainerAccess($container, array $readGrps, array $writeGrps)
Set read/write permissions for a Swift container.
doGetFileXAttributes(array $params)
static factory($prefix, $extension= '', $tmpDirectory=null)
Make a new temporary file on the file system.
loadListingStatInternal($path, array $val)
Do not call this function outside of SwiftFileBackendFileList.
Apache License January http
doGetFileContentsMulti(array $params)
addMissingMetadata(array $objHdrs, $path)
Fill in any missing object metadata and save it to Swift.
doGetLocalCopyMulti(array $params)
doGetFileSha1base36(array $params)
getContainerStat($container, $bypassCache=false)
Get a Swift container stat array, possibly from process cache.
doDescribeInternal(array $params)
getMetadata(array $rawHeaders)
getFileHttpUrl(array $params)
File backend exception for checked exceptions (e.g.
fileExists(array $params)
authTokenHeaders(array $creds)
headersFromParams(array $params)
Get headers to send to Swift when reading a file based on a FileBackend params array, e.g.
array $bufferIter
List of path or (path,stat array) entries.
storageUrl(array $creds, $container=null, $object=null)
isPathUsableInternal($storagePath)
__construct(SwiftFileBackend $backend, $fullCont, $dir, array $params)
string $swiftAuthUrl
Authentication base URL (without version)
string $dir
Storage directory.
const TS_MW
MediaWiki concatenated string timestamp (YYYYMMDDHHMMSS)
getCredsCacheKey($username)
Get the cache key for a container.
FileBackendStore $backend
clearCache(array $paths=null)
A BagOStuff object with no objects in it.
resolveStoragePathReal($storagePath)
Like resolveStoragePath() except null values are returned if the container is sharded and the shard c...
objectListing($fullCont, $type, $limit, $after=null, $prefix=null, $delim=null)
Get a list of objects under a container.
string $container
Container name.
int $authTTL
TTL in seconds.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable & $code
getContentType($storagePath, $content, $fsPath)
Get the content type to use in HEAD/GET requests for a file.
onError($status, $func, array $params, $err= '', $code=0, $desc= '')
Log an unexpected exception for this backend.
string $name
Unique backend name.
Base class for all backends using particular storage medium.
getLocalCopy(array $params)
Get a local copy on disk of the file at a storage path in the backend.
doStreamFile(array $params)
pageFromList($container, $dir, &$after, $limit, array $params)
pageFromList($container, $dir, &$after, $limit, array $params)
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
this hook is for auditing only $req
this hook is for auditing only or null if authentication failed before getting that far $username
Iterator for listing regular files.
setContainerCache($container, array $val)
Set the cached info for a container.
getDirectoryListInternal($fullCont, $dir, array $params)
__construct(array $config)
error also a ContextSource you ll probably need to make sure the header is varied on $request
SwiftFileBackend $backend
sanitizeHdrs(array $params)
Sanitize and filter the custom headers from a $params array.
doCopyInternal(array $params)
convertSwiftDate($ts, $format=TS_MW)
Convert dates like "Tue, 03 Jan 2012 22:01:04 GMT"/"2013-05-11T07:37:27.678360Z". ...
string $rgwS3AccessKey
S3 access key (RADOS Gateway)
doCreateInternal(array $params)
array $httpOp
List of Requests for MultiHttpClient.
doPrimeContainerCache(array $containerInfo)
Class for an OpenStack Swift (or Ceph RGW) based file backend.
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at name
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context the output can only depend on parameters provided to this hook not on global state indicating whether full HTML should be generated If generation of HTML may be but other information should still be present in the ParserOutput object to manipulate or replace but no entry for that model exists in $wgContentHandlers if desired 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 inclusive $limit
pageFromList($container, $dir, &$after, $limit, array $params)
Get the given list portion (page)
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
getMetadataHeaders(array $rawHeaders)
int $authSessionTimestamp
UNIX timestamp.
deleteFileCache($path)
Delete the cached stat info for a file path.
ProcessCacheLRU $containerStatCache
Container stat cache.
getDirListPageInternal($fullCont, $dir, &$after, $limit, array $params)
Do not call this function outside of SwiftFileBackendFileList.
doExecuteOpHandlesInternal(array $fileOpHandles)
doSecureInternal($fullCont, $dir, array $params)
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check set to true or false to override the $wgMaxImageArea check result gives extension the possibility to transform it themselves $handler
Class to handle concurrent HTTP requests.
doGetFileStat(array $params)
createContainer($container, array $params)
Create a Swift container.
FileBackendStore helper class for performing asynchronous file operations.
string $rgwS3SecretKey
S3 authentication key (RADOS Gateway)
Handles per process caching of items.
Library for creating and parsing MW-style timestamps.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached one of or reset my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type
__construct(SwiftFileBackend $backend, Closure $callback, array $httpOp)
string $swiftKey
Secret key for user.
bool $isRGW
Whether the server is an Ceph RGW.
string $swiftTempUrlKey
Shared secret value for making temp URLs.