2011-04-09 00:39:40 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* MediaWiki math extension
|
|
|
|
*
|
2018-04-13 14:18:16 +00:00
|
|
|
* @copyright 2002-2015 various MediaWiki contributors
|
|
|
|
* @license GPL-2.0-or-later
|
2011-04-09 00:39:40 +00:00
|
|
|
*/
|
|
|
|
|
2021-04-07 22:22:05 +00:00
|
|
|
namespace MediaWiki\Extension\Math;
|
|
|
|
|
|
|
|
use DatabaseUpdater;
|
|
|
|
use Exception;
|
2021-06-21 11:32:26 +00:00
|
|
|
use ExtensionRegistry;
|
2021-04-07 22:22:05 +00:00
|
|
|
use Maintenance;
|
2021-04-02 18:30:13 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2021-04-07 22:22:05 +00:00
|
|
|
use RequestContext;
|
2015-04-14 19:42:48 +00:00
|
|
|
|
2021-04-07 22:22:05 +00:00
|
|
|
class Hooks {
|
2017-07-10 09:40:12 +00:00
|
|
|
|
2011-04-09 19:57:35 +00:00
|
|
|
/**
|
|
|
|
* MaintenanceRefreshLinksInit handler; optimize settings for refreshLinks batch job.
|
|
|
|
*
|
|
|
|
* @param Maintenance $maint
|
|
|
|
*/
|
2018-11-02 17:52:06 +00:00
|
|
|
public static function onMaintenanceRefreshLinksInit( $maint ) {
|
2020-09-27 01:02:10 +00:00
|
|
|
$user = RequestContext::getMain()->getUser();
|
2011-04-09 19:57:35 +00:00
|
|
|
|
2020-09-28 12:50:50 +00:00
|
|
|
// Don't parse LaTeX to improve performance
|
2021-04-02 18:30:13 +00:00
|
|
|
MediaWikiServices::getInstance()->getUserOptionsManager()
|
2021-08-11 18:15:35 +00:00
|
|
|
->setOption( $user, 'math', MathConfig::MODE_SOURCE );
|
2011-04-09 19:57:35 +00:00
|
|
|
}
|
2011-04-22 21:37:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* LoadExtensionSchemaUpdates handler; set up math table on install/upgrade.
|
|
|
|
*
|
2019-11-25 05:31:29 +00:00
|
|
|
* @param DatabaseUpdater $updater
|
2015-01-10 01:55:54 +00:00
|
|
|
* @throws Exception
|
2011-04-22 21:37:16 +00:00
|
|
|
*/
|
2019-11-25 05:31:29 +00:00
|
|
|
public static function onLoadExtensionSchemaUpdates( DatabaseUpdater $updater ) {
|
2021-08-11 18:15:35 +00:00
|
|
|
$type = $updater->getDB()->getType();
|
2022-06-01 08:39:29 +00:00
|
|
|
if ( !in_array( $type, [ 'mysql', 'sqlite', 'postgres' ] ) ) {
|
|
|
|
throw new Exception( "Math extension does not currently support $type database." );
|
2015-01-22 18:56:13 +00:00
|
|
|
}
|
2022-06-01 08:39:29 +00:00
|
|
|
|
|
|
|
foreach ( [ 'mathoid', 'mathlatexml' ] as $mode ) {
|
|
|
|
$updater->addExtensionTable(
|
|
|
|
$mode,
|
2022-06-10 20:11:28 +00:00
|
|
|
__DIR__ . "/../sql/$type/$mode.sql"
|
2022-06-01 08:39:29 +00:00
|
|
|
);
|
2011-04-22 21:37:16 +00:00
|
|
|
}
|
2015-01-22 18:56:13 +00:00
|
|
|
|
2022-06-01 08:39:29 +00:00
|
|
|
if ( $type === 'mysql' ) {
|
|
|
|
$updater->addExtensionField(
|
|
|
|
'mathoid',
|
|
|
|
'math_png',
|
2022-06-10 20:11:28 +00:00
|
|
|
__DIR__ . '/../sql/' . $type . '/patch-mathoid.add_png.sql'
|
2022-06-01 08:39:29 +00:00
|
|
|
);
|
|
|
|
}
|
2011-04-22 21:37:16 +00:00
|
|
|
}
|
|
|
|
|
2019-12-28 08:54:09 +00:00
|
|
|
/**
|
|
|
|
* Remove Special:MathWikibase if the Wikibase client extension isn't loaded
|
|
|
|
*
|
|
|
|
* @param array &$list
|
|
|
|
*/
|
2021-06-21 11:32:26 +00:00
|
|
|
public static function onSpecialPageInitList( &$list ) {
|
|
|
|
if ( !ExtensionRegistry::getInstance()->isLoaded( 'WikibaseClient' ) ) {
|
2019-12-28 08:54:09 +00:00
|
|
|
unset( $list['MathWikibase'] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-09 00:39:40 +00:00
|
|
|
}
|