MediaWiki
REL1_22
|
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 return false; 00047 } 00048 00056 public function batchFetchFromURLs( array $urls ) { 00057 $pathsByBackend = array(); 00058 foreach ( $urls as $url ) { 00059 $be = FileBackendGroup::singleton()->backendFromPath( $url ); 00060 if ( $be instanceof FileBackend ) { 00061 $pathsByBackend[$be->getName()][] = $url; 00062 } 00063 } 00064 $blobs = array(); 00065 foreach ( $pathsByBackend as $backendName => $paths ) { 00066 $be = FileBackendGroup::get( $backendName ); 00067 $blobs = $blobs + $be->getFileContentsMulti( array( 'srcs' => $paths ) ); 00068 } 00069 return $blobs; 00070 } 00071 00075 public function store( $backend, $data ) { 00076 $be = FileBackendGroup::singleton()->get( $backend ); 00077 if ( $be instanceof FileBackend ) { 00078 // Get three random base 36 characters to act as shard directories 00079 $rand = wfBaseConvert( mt_rand( 0, 46655 ), 10, 36, 3 ); 00080 // Make sure ID is roughly lexicographically increasing for performance 00081 $id = str_pad( UIDGenerator::newTimestampedUID128( 32 ), 26, '0', STR_PAD_LEFT ); 00082 // Segregate items by wiki ID for the sake of bookkeeping 00083 $wiki = isset( $this->params['wiki'] ) ? $this->params['wiki'] : wfWikiID(); 00084 00085 $url = $be->getContainerStoragePath( 'data' ) . '/' . 00086 rawurlencode( $wiki ) . "/{$rand[0]}/{$rand[1]}/{$rand[2]}/{$id}"; 00087 00088 $be->prepare( array( 'dir' => dirname( $url ), 'noAccess' => 1, 'noListing' => 1 ) ); 00089 if ( $be->create( array( 'dst' => $url, 'content' => $data ) )->isOK() ) { 00090 return $url; 00091 } 00092 } 00093 return false; 00094 } 00095 }