Breaking the 'math' table setup out to Math extension. Should be the last main step in extension-ification of the math options!

The 'math' table will no longer be created on a default install unless you've explicitly enabled the Math plugin at install time; the usual update.php procedure will add it in.

Postgres, Oracle, MSSQL, and DB2 variants are included -- broken out from the core files -- but have not been tested.

I know there has been some code duplication in parser test infrastructure but could only find one instance of the parser test temporary table setup to remove the 'math' table from (the extension adds it back via the hook). If the phpunit-based runner breaks, please track it down and fix it there too.
This commit is contained in:
Brion Vibber 2011-04-22 21:37:16 +00:00
parent b2a6d5413e
commit d61409f974
7 changed files with 98 additions and 0 deletions

View File

@ -97,4 +97,44 @@ class MathHooks {
return true;
}
/**
* LoadExtensionSchemaUpdates handler; set up math table on install/upgrade.
*
* @param $updater DatabaseUpdater
* @return bool
*/
static function onLoadExtensionSchemaUpdates( $updater ) {
$map = array(
'mysql' => 'math.sql',
'sqlite' => 'math.sql',
'postgres' => 'math.pg.sql',
'oracle' => 'math.oracle.sql',
'mssql' => 'math.mssql.sql',
'db2' => 'math.db2.sql',
);
$base = dirname( __FILE__ );
$type = $updater->getDB()->getType();
if ( array_key_exists( $type, $map ) ) {
$file = $map[$type];
$sql = "$base/db/$file";
$updater->addNewExtension( 'CodeReview', $sql );
$updater->addExtensionTable( 'math', $sql );
} else {
throw new MWException( "Math extension does not currently support $type database." );
}
return true;
}
/**
* Add 'math' table to the list of tables that need to be copied to
* temporary tables for parser tests to run.
*
* @param array $tables
* @return bool
*/
function onParserTestTables( &$tables ) {
$tables[] = 'math';
return true;
}
}

View File

@ -87,6 +87,8 @@ $wgMathDirectory = false;
$wgExtensionFunctions[] = 'MathHooks::setup';
$wgHooks['ParserFirstCallInit'][] = 'MathHooks::onParserFirstCallInit';
$wgHooks['GetPreferences'][] = 'MathHooks::onGetPreferences';
$wgHooks['LoadExtensionSchemaUpdates'][] = 'MathHooks::onLoadExtensionSchemaUpdates';
$wgHooks['ParserTestTables'][] = 'MathHooks::onParserTestTables';
$dir = dirname( __FILE__ ) . '/';
$wgAutoloadClasses['MathHooks'] = $dir . 'Math.hooks.php';

7
db/math.db2.sql Normal file
View File

@ -0,0 +1,7 @@
CREATE TABLE math (
math_inputhash VARCHAR(16) FOR BIT DATA NOT NULL UNIQUE,
math_outputhash VARCHAR(16) FOR BIT DATA NOT NULL,
math_html_conservativeness SMALLINT NOT NULL,
math_html CLOB(64K) INLINE LENGTH 4096,
math_mathml CLOB(64K) INLINE LENGTH 4096
);

11
db/math.mssql.sql Normal file
View File

@ -0,0 +1,11 @@
--
-- Used by the math module to keep track
-- of previously-rendered items.
--
CREATE TABLE /*$wgDBprefix*/math (
math_inputhash varbinary(16) NOT NULL PRIMARY KEY,
math_outputhash varbinary(16) NOT NULL,
math_html_conservativeness tinyint NOT NULL,
math_html NVARCHAR(MAX),
math_mathml NVARCHAR(MAX),
);

8
db/math.oracle.sql Normal file
View File

@ -0,0 +1,8 @@
CREATE TABLE &mw_prefix.math (
math_inputhash VARCHAR2(32) NOT NULL,
math_outputhash VARCHAR2(32) NOT NULL,
math_html_conservativeness NUMBER NOT NULL,
math_html CLOB,
math_mathml CLOB
);
CREATE UNIQUE INDEX &mw_prefix.math_u01 ON &mw_prefix.math (math_inputhash);

7
db/math.pg.sql Normal file
View File

@ -0,0 +1,7 @@
CREATE TABLE math (
math_inputhash BYTEA NOT NULL UNIQUE,
math_outputhash BYTEA NOT NULL,
math_html_conservativeness SMALLINT NOT NULL,
math_html TEXT,
math_mathml TEXT
);

23
db/math.sql Normal file
View File

@ -0,0 +1,23 @@
--
-- Used by the math module to keep track
-- of previously-rendered items.
--
CREATE TABLE /*_*/math (
-- Binary MD5 hash of the latex fragment, used as an identifier key.
math_inputhash varbinary(16) NOT NULL,
-- Not sure what this is, exactly...
math_outputhash varbinary(16) NOT NULL,
-- texvc reports how well it thinks the HTML conversion worked;
-- if it's a low level the PNG rendering may be preferred.
math_html_conservativeness tinyint NOT NULL,
-- HTML output from texvc, if any
math_html text,
-- MathML output from texvc, if any
math_mathml text
) /*$wgDBTableOptions*/;
CREATE UNIQUE INDEX /*i*/math_inputhash ON /*_*/math (math_inputhash);