Option to write text directly to external storage.
authorTim Starling <tstarling@users.mediawiki.org>
Mon, 9 Jan 2006 03:16:56 +0000 (03:16 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Mon, 9 Jan 2006 03:16:56 +0000 (03:16 +0000)
includes/DefaultSettings.php
includes/ExternalStore.php
includes/ExternalStoreDB.php
includes/Revision.php

index e8d2c0b..e1b1b22 100644 (file)
@@ -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.
index 2c1fe3b..71c4aaa 100644 (file)
@@ -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 );
+               }
+       }
 }
 ?>
index acafebe..92026db 100644 (file)
@@ -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";
        }
 }
 ?>
index 1a367f0..437d1d8 100644 (file)
@@ -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
                        );