From 0beb6f98322327791cba42c1ef6d1c3d5967888f Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Sat, 2 Feb 2013 17:09:16 -0800 Subject: [PATCH] [ExternalStore] Added ExternalStoreMwstore class that uses a file backend. Change-Id: I7785a621fe32f549b2e7c636f2b6e7b18be367f4 --- includes/AutoLoader.php | 1 + .../externalstore/ExternalStoreMwstore.php | 71 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 includes/externalstore/ExternalStoreMwstore.php diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index df17f2806b..75eadabe5b 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -95,6 +95,7 @@ $wgAutoloadLocalClasses = array( 'ExternalStoreDB' => 'includes/externalstore/ExternalStoreDB.php', 'ExternalStoreHttp' => 'includes/externalstore/ExternalStoreHttp.php', 'ExternalStoreMedium' => 'includes/externalstore/ExternalStoreMedium.php', + 'ExternalStoreMwstore' => 'includes/externalstore/ExternalStoreMwstore.php', 'ExternalUser' => 'includes/ExternalUser.php', 'FakeTitle' => 'includes/FakeTitle.php', 'Fallback' => 'includes/Fallback.php', diff --git a/includes/externalstore/ExternalStoreMwstore.php b/includes/externalstore/ExternalStoreMwstore.php new file mode 100644 index 0000000000..35b3494cfb --- /dev/null +++ b/includes/externalstore/ExternalStoreMwstore.php @@ -0,0 +1,71 @@ +backendFromPath( $url ); + if ( $be instanceof FileBackend ) { + // We don't need "latest" since objects are immutable and + // backends should at least have "read-after-create" consistency. + return $be->getFileContents( array( 'src' => $url ) ); + } + return false; + } + + /** + * @see ExternalStoreMedium::store() + */ + public function store( $backend, $data ) { + $be = FileBackendGroup::singleton()->get( $backend ); + if ( $be instanceof FileBackend ) { + // Get three random base 36 characters to act as shard directories + $rand = wfBaseConvert( mt_rand( 0, 46655 ), 10, 36, 3 ); + // Make sure ID is roughly lexicographically increasing for performance + $id = str_pad( UIDGenerator::getTimestampedID128( 32 ), 26, '0', STR_PAD_LEFT ); + // Segregate items by wiki ID for the sake of book keeping + $wiki = isset( $this->params['wiki'] ) ? $this->params['wiki'] : wfWikiID(); + + $url = $be->getContainerStoragePath( 'data' ) . '/' . + rawurlencode( $wiki ) . "/{$rand[0]}/{$rand[1]}/{$rand[2]}/{$id}"; + + $be->prepare( array( 'dir' => dirname( $url ) ) ); + if ( $be->create( array( 'dst' => $url, 'content' => $data ) )->isOK() ) { + return $url; + } + } + return false; + } +} -- 2.20.1