MediaWiki  REL1_21
ExternalStoreMwstore.php
Go to the documentation of this file.
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 
00052         public function store( $backend, $data ) {
00053                 $be = FileBackendGroup::singleton()->get( $backend );
00054                 if ( $be instanceof FileBackend ) {
00055                         // Get three random base 36 characters to act as shard directories
00056                         $rand = wfBaseConvert( mt_rand( 0, 46655 ), 10, 36, 3 );
00057                         // Make sure ID is roughly lexicographically increasing for performance
00058                         $id = str_pad( UIDGenerator::newTimestampedUID128( 32 ), 26, '0', STR_PAD_LEFT );
00059                         // Segregate items by wiki ID for the sake of bookkeeping
00060                         $wiki = isset( $this->params['wiki'] ) ? $this->params['wiki'] : wfWikiID();
00061 
00062                         $url = $be->getContainerStoragePath( 'data' ) . '/' .
00063                                 rawurlencode( $wiki ) . "/{$rand[0]}/{$rand[1]}/{$rand[2]}/{$id}";
00064 
00065                         $be->prepare( array( 'dir' => dirname( $url ), 'noAccess' => 1, 'noListing' => 1 ) );
00066                         if ( $be->create( array( 'dst' => $url, 'content' => $data ) )->isOK() ) {
00067                                 return $url;
00068                         }
00069                 }
00070                 return false;
00071         }
00072 }