From 176b2a7c86b4eda2b80556a0f4b93367dcf32910 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Wed, 14 Dec 2005 20:56:43 +0000 Subject: [PATCH] * Added plugin interface for dumpBackup, so additional filters and output sink types can be registered at runtime from an extension --- RELEASE-NOTES | 2 ++ maintenance/backup.inc | 61 +++++++++++++++++++++++++++++++++--------- 2 files changed, 50 insertions(+), 13 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 001a01e53e..0e76452d5f 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -320,6 +320,8 @@ fully support the editing toolbar, but was found to be too confusing. * (bug 4258) Use ugly urls for ISAPI by default patch by Rob Church * Fixed --server override on dumpTextPass.php +* Added plugin interface for dumpBackup, so additional filters and output + sink types can be registered at runtime from an extension === Caveats === diff --git a/maintenance/backup.inc b/maintenance/backup.inc index df9821839b..7b4af762ec 100644 --- a/maintenance/backup.inc +++ b/maintenance/backup.inc @@ -39,38 +39,73 @@ class BackupDumper { function BackupDumper( $args ) { $this->stderr = fopen( "php://stderr", "wt" ); + + // Built-in output and filter plugins + $this->registerOutput( 'file', 'DumpFileOutput' ); + $this->registerOutput( 'gzip', 'DumpGZipOutput' ); + $this->registerOutput( 'bzip2', 'DumpBZip2Output' ); + $this->registerOutput( '7zip', 'Dump7ZipOutput' ); + + $this->registerFilter( 'latest', 'DumpLatestFilter' ); + $this->registerFilter( 'notalk', 'DumpNotalkFilter' ); + $this->registerFilter( 'namespace', 'DumpNamespaceFilter' ); + $this->sink = $this->processArgs( $args ); } + /** + * @param string $name + * @param string $class name of output filter plugin class + */ + function registerOutput( $name, $class ) { + $this->outputTypes[$name] = $class; + } + + /** + * @param string $name + * @param string $class name of filter plugin class + */ + function registerFilter( $name, $class ) { + $this->filterTypes[$name] = $class; + } + + /** + * Load a plugin and register it + * @param string $class Name of plugin class; must have a static 'register' + * method that takes a BackupDumper as a parameter. + * @param string $file Full or relative path to the PHP file to load, or empty + */ + function loadPlugin( $class, $file ) { + if( $file != '' ) { + require_once( $file ); + } + $register = array( $class, 'register' ); + call_user_func_array( $register, array( &$this ) ); + } + /** * @param array $args * @return array * @static */ function processArgs( $args ) { - $outputTypes = array( - 'file' => 'DumpFileOutput', - 'gzip' => 'DumpGZipOutput', - 'bzip2' => 'DumpBZip2Output', - '7zip' => 'Dump7ZipOutput' ); - $filterTypes = array( - 'latest' => 'DumpLatestFilter', - 'notalk' => 'DumpNotalkFilter', - 'namespace' => 'DumpNamespaceFilter' ); $sink = null; $sinks = array(); foreach( $args as $arg ) { if( preg_match( '/^--(.+?)(?:=(.+?)(?::(.+?))?)?$/', $arg, $matches ) ) { @list( $full, $opt, $val, $param ) = $matches; switch( $opt ) { + case "plugin": + $this->loadPlugin( $val, $param ); + break; case "output": if( !is_null( $sink ) ) { $sinks[] = $sink; } - if( !isset( $outputTypes[$val] ) ) { + if( !isset( $this->outputTypes[$val] ) ) { die( "Unrecognized output sink type '$val'\n" ); } - $type = $outputTypes[$val]; + $type = $this->outputTypes[$val]; $sink = new $type( $param ); break; case "filter": @@ -78,10 +113,10 @@ class BackupDumper { $this->progress( "Warning: assuming stdout for filter output\n" ); $sink = new DumpOutput(); } - if( !isset( $filterTypes[$val] ) ) { + if( !isset( $this->filterTypes[$val] ) ) { die( "Unrecognized filter type '$val'\n" ); } - $type = $filterTypes[$val]; + $type = $this->filterTypes[$val]; $filter = new $type( $sink, $param ); // references are lame in php... -- 2.20.1