From 679b0e69b89f988a04252d27fe12fae51a4c42ee Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Mon, 9 Jan 2006 03:16:56 +0000 Subject: [PATCH] Option to write text directly to external storage. --- includes/DefaultSettings.php | 6 ++++++ includes/ExternalStore.php | 32 +++++++++++++++++++++++++++++--- includes/ExternalStoreDB.php | 6 +++++- includes/Revision.php | 25 +++++++++++++++++++++---- 4 files changed, 61 insertions(+), 8 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index e8d2c0b206..e1b1b220e7 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -1748,6 +1748,12 @@ $wgExternalStores = false; */ $wgExternalServers = array(); +/** + * The place to put new revisions, false to put them in the local text table. + * Part of a URL, e.g. DB://cluster1 + */ +$wgDefaultExternalStore = false; + /** * list of trusted media-types and mime types. * Use the MEDIATYPE_xxx constants to represent media types. diff --git a/includes/ExternalStore.php b/includes/ExternalStore.php index 2c1fe3bacb..71c4aaac22 100644 --- a/includes/ExternalStore.php +++ b/includes/ExternalStore.php @@ -23,6 +23,20 @@ class ExternalStore { /* Bad URL */ if ($path=="") return false; + + $store =& ExternalStore::getStoreObject( $proto ); + if ( $store === false ) + return false; + return $store->fetchFromURL($url); + } + + /** + * Get an external store object of the given type + */ + function &getStoreObject( $proto ) { + global $wgExternalStores; + if (!$wgExternalStores) + return false; /* Protocol not enabled */ if (!in_array( $proto, $wgExternalStores )) return false; @@ -34,11 +48,23 @@ class ExternalStore { return false; } $store=new $class(); - return $store->fetchFromURL($url); + return $store; } - /* XXX: may require other methods, for store, delete, - * whatever, for initial ext storage + /** + * Store a data item to an external store, identified by a partial URL + * The protocol part is used to identify the class, the rest is passed to the + * class itself as a parameter. + * Returns the URL of the stored data item, or false on error */ + function insert( $url, $data ) { + list( $proto, $params ) = explode( '://', $url, 2 ); + $store =& ExternalStore::getStoreObject( $proto ); + if ( $store === false ) { + return false; + } else { + return $store->store( $params, $data ); + } + } } ?> diff --git a/includes/ExternalStoreDB.php b/includes/ExternalStoreDB.php index acafebe455..92026db010 100644 --- a/includes/ExternalStoreDB.php +++ b/includes/ExternalStoreDB.php @@ -128,7 +128,11 @@ class ExternalStoreDB { $id = $dbw->nextSequenceValue( 'blob_blob_id_seq' ); $dbw->insert( $this->getTable( $dbw ), array( 'blob_id' => $id, 'blob_text' => $data ), $fname ); - return "DB://$cluster/" . $dbw->insertId(); + $id = $dbw->insertId(); + if ( $dbw->getFlag( DBO_TRX ) ) { + $dbw->immediateCommit(); + } + return "DB://$cluster/$id"; } } ?> diff --git a/includes/Revision.php b/includes/Revision.php index 1a367f0b57..437d1d85d6 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -517,19 +517,36 @@ class Revision { * @return int */ function insertOn( &$dbw ) { + global $wgDefaultExternalStore; + $fname = 'Revision::insertOn'; wfProfileIn( $fname ); - $mungedText = $this->mText; - $flags = Revision::compressRevisionText( $mungedText ); + $data = $this->mText; + $flags = Revision::compressRevisionText( $data ); - # Record the text to the text table + # Write to external storage if required + if ( $wgDefaultExternalStore ) { + require_once('ExternalStore.php'); + // Store and get the URL + $data = ExternalStore::insert( $wgDefaultExternalStore, $data ); + if ( !$data ) { + # This should only happen in the case of a configuration error, where the external store is not valid + wfDebugDieBacktrace( "Unable to store text to external storage $wgDefaultExternalStore" ); + } + if ( $flags ) { + $flags .= ','; + } + $flags .= 'external'; + } + + # Record the text (or external storage URL) to the text table if( !isset( $this->mTextId ) ) { $old_id = $dbw->nextSequenceValue( 'text_old_id_val' ); $dbw->insert( 'text', array( 'old_id' => $old_id, - 'old_text' => $mungedText, + 'old_text' => $data, 'old_flags' => $flags, ), $fname ); -- 2.20.1