mediawiki-extensions-Math/src/Hooks.php
Umherirrender 44f7c7821a schema: Move all sql files to sql folder
It is good practice to have a folder in the root for all sql files.
Also use the engine folder to store the patches

Change-Id: Ic26c042f0a5a8ca6e0568b38c4b4b2b4f0686efb
2022-06-22 18:11:51 +00:00

73 lines
1.7 KiB
PHP

<?php
/**
* MediaWiki math extension
*
* @copyright 2002-2015 various MediaWiki contributors
* @license GPL-2.0-or-later
*/
namespace MediaWiki\Extension\Math;
use DatabaseUpdater;
use Exception;
use ExtensionRegistry;
use Maintenance;
use MediaWiki\MediaWikiServices;
use RequestContext;
class Hooks {
/**
* MaintenanceRefreshLinksInit handler; optimize settings for refreshLinks batch job.
*
* @param Maintenance $maint
*/
public static function onMaintenanceRefreshLinksInit( $maint ) {
$user = RequestContext::getMain()->getUser();
// Don't parse LaTeX to improve performance
MediaWikiServices::getInstance()->getUserOptionsManager()
->setOption( $user, 'math', MathConfig::MODE_SOURCE );
}
/**
* LoadExtensionSchemaUpdates handler; set up math table on install/upgrade.
*
* @param DatabaseUpdater $updater
* @throws Exception
*/
public static function onLoadExtensionSchemaUpdates( DatabaseUpdater $updater ) {
$type = $updater->getDB()->getType();
if ( !in_array( $type, [ 'mysql', 'sqlite', 'postgres' ] ) ) {
throw new Exception( "Math extension does not currently support $type database." );
}
foreach ( [ 'mathoid', 'mathlatexml' ] as $mode ) {
$updater->addExtensionTable(
$mode,
__DIR__ . "/../sql/$type/$mode.sql"
);
}
if ( $type === 'mysql' ) {
$updater->addExtensionField(
'mathoid',
'math_png',
__DIR__ . '/../sql/' . $type . '/patch-mathoid.add_png.sql'
);
}
}
/**
* Remove Special:MathWikibase if the Wikibase client extension isn't loaded
*
* @param array &$list
*/
public static function onSpecialPageInitList( &$list ) {
if ( !ExtensionRegistry::getInstance()->isLoaded( 'WikibaseClient' ) ) {
unset( $list['MathWikibase'] );
}
}
}