MediaWiki
REL1_24
|
00001 <?php 00033 class ExternalStoreMwstore extends ExternalStoreMedium { 00039 public function fetchFromURL( $url ) { 00040 $be = FileBackendGroup::singleton()->backendFromPath( $url ); 00041 if ( $be instanceof FileBackend ) { 00042 // We don't need "latest" since objects are immutable and 00043 // backends should at least have "read-after-create" consistency. 00044 return $be->getFileContents( array( 'src' => $url ) ); 00045 } 00046 00047 return false; 00048 } 00049 00057 public function batchFetchFromURLs( array $urls ) { 00058 $pathsByBackend = array(); 00059 foreach ( $urls as $url ) { 00060 $be = FileBackendGroup::singleton()->backendFromPath( $url ); 00061 if ( $be instanceof FileBackend ) { 00062 $pathsByBackend[$be->getName()][] = $url; 00063 } 00064 } 00065 $blobs = array(); 00066 foreach ( $pathsByBackend as $backendName => $paths ) { 00067 $be = FileBackendGroup::singleton()->get( $backendName ); 00068 $blobs = $blobs + $be->getFileContentsMulti( array( 'srcs' => $paths ) ); 00069 } 00070 00071 return $blobs; 00072 } 00073 00077 public function store( $backend, $data ) { 00078 $be = FileBackendGroup::singleton()->get( $backend ); 00079 if ( $be instanceof FileBackend ) { 00080 // Get three random base 36 characters to act as shard directories 00081 $rand = wfBaseConvert( mt_rand( 0, 46655 ), 10, 36, 3 ); 00082 // Make sure ID is roughly lexicographically increasing for performance 00083 $id = str_pad( UIDGenerator::newTimestampedUID128( 32 ), 26, '0', STR_PAD_LEFT ); 00084 // Segregate items by wiki ID for the sake of bookkeeping 00085 $wiki = isset( $this->params['wiki'] ) ? $this->params['wiki'] : wfWikiID(); 00086 00087 $url = $be->getContainerStoragePath( 'data' ) . '/' . rawurlencode( $wiki ); 00088 $url .= ( $be instanceof FSFileBackend ) 00089 ? "/{$rand[0]}/{$rand[1]}/{$rand[2]}/{$id}" // keep directories small 00090 : "/{$rand[0]}/{$rand[1]}/{$id}"; // container sharding is only 2-levels 00091 00092 $be->prepare( array( 'dir' => dirname( $url ), 'noAccess' => 1, 'noListing' => 1 ) ); 00093 if ( $be->create( array( 'dst' => $url, 'content' => $data ) )->isOK() ) { 00094 return $url; 00095 } 00096 } 00097 00098 return false; 00099 } 00100 }