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;
|
|
|
|
|
2023-08-15 14:43:04 +00:00
|
|
|
// phpcs:disable MediaWiki.NamingConventions.LowerCamelFunctionsName.FunctionName
|
|
|
|
|
2023-05-22 20:17:58 +00:00
|
|
|
use ConfigException;
|
2021-06-21 11:32:26 +00:00
|
|
|
use ExtensionRegistry;
|
2021-04-07 22:22:05 +00:00
|
|
|
use Maintenance;
|
2023-08-15 14:43:04 +00:00
|
|
|
use MediaWiki\Hook\MaintenanceRefreshLinksInitHook;
|
2021-04-02 18:30:13 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2023-05-22 20:17:58 +00:00
|
|
|
use MediaWiki\Settings\SettingsBuilder;
|
2023-08-15 14:43:04 +00:00
|
|
|
use MediaWiki\SpecialPage\Hook\SpecialPage_initListHook;
|
2021-04-07 22:22:05 +00:00
|
|
|
use RequestContext;
|
2015-04-14 19:42:48 +00:00
|
|
|
|
2023-08-15 14:43:04 +00:00
|
|
|
class Hooks implements
|
|
|
|
SpecialPage_initListHook,
|
|
|
|
MaintenanceRefreshLinksInitHook
|
|
|
|
{
|
2017-07-10 09:40:12 +00:00
|
|
|
|
2023-05-22 20:17:58 +00:00
|
|
|
/**
|
|
|
|
* Extension registration callback, used to apply dynamic defaults for configuration variables.
|
|
|
|
*/
|
|
|
|
public static function onConfig( array $extInfo, SettingsBuilder $settings ) {
|
|
|
|
$config = $settings->getConfig();
|
|
|
|
|
|
|
|
$fullRestbaseUrl = $config->get( 'MathFullRestbaseURL' );
|
|
|
|
$internalRestbaseURL = $config->get( 'MathInternalRestbaseURL' );
|
|
|
|
$useInternalRestbasePath = $config->get( 'MathUseInternalRestbasePath' );
|
|
|
|
$virtualRestConfig = $config->get( 'VirtualRestConfig' );
|
|
|
|
|
|
|
|
if ( !$fullRestbaseUrl ) {
|
|
|
|
if ( $config->has( 'VisualEditorFullRestbaseURL' ) ) {
|
|
|
|
$settings->warning( "MathFullRestbaseURL is falling back to using VisualEditorFullRestbaseURL. " .
|
|
|
|
"Please configure the Mathoid API URL explicitly." );
|
|
|
|
|
|
|
|
$fullRestbaseUrl = $config->get( 'VisualEditorFullRestbaseURL' );
|
|
|
|
$settings->overrideConfigValue( 'MathFullRestbaseURL', $fullRestbaseUrl );
|
|
|
|
} else {
|
|
|
|
throw new ConfigException(
|
|
|
|
'Math extension can not find Restbase URL. Please specify $wgMathFullRestbaseURL.'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !$useInternalRestbasePath ) {
|
|
|
|
if ( $internalRestbaseURL ) {
|
|
|
|
$settings->warning( "The MathInternalRestbaseURL setting will be ignored " .
|
|
|
|
"because MathUseInternalRestbasePath is set to false." );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Force the use of the external URL for internal calls as well.
|
|
|
|
$settings->overrideConfigValue( 'MathInternalRestbaseURL', $fullRestbaseUrl );
|
|
|
|
} elseif ( !$internalRestbaseURL ) {
|
|
|
|
if ( isset( $virtualRestConfig['modules']['restbase'] ) ) {
|
|
|
|
$settings->warning( "The MathInternalRestbaseURL is falling back to " .
|
|
|
|
"VirtualRestConfig. Please set MathInternalRestbaseURL explicitly." );
|
|
|
|
|
|
|
|
$restBaseUrl = $virtualRestConfig['modules']['restbase']['url'];
|
|
|
|
$restBaseUrl = rtrim( $restBaseUrl, '/' );
|
|
|
|
|
|
|
|
$restBaseDomain = $virtualRestConfig['modules']['restbase']['domain'] ?? 'localhost';
|
|
|
|
|
|
|
|
// Ensure the correct domain format: strip protocol, port,
|
|
|
|
// and trailing slash if present. This lets us use
|
|
|
|
// $wgCanonicalServer as a default value, which is very convenient.
|
|
|
|
// XXX: This was copied from RestbaseVirtualRESTService. Use UrlUtils::parse instead?
|
|
|
|
$restBaseDomain = preg_replace(
|
|
|
|
'/^((https?:)?\/\/)?([^\/:]+?)(:\d+)?\/?$/',
|
|
|
|
'$3',
|
|
|
|
$restBaseDomain
|
|
|
|
);
|
|
|
|
|
2023-06-08 01:05:08 +00:00
|
|
|
$internalRestbaseURL = "$restBaseUrl/$restBaseDomain/";
|
2023-05-22 20:17:58 +00:00
|
|
|
} else {
|
|
|
|
// Default to using the external URL for internal calls as well.
|
|
|
|
$internalRestbaseURL = $fullRestbaseUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
$settings->overrideConfigValue( 'MathInternalRestbaseURL', $internalRestbaseURL );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-09 19:57:35 +00:00
|
|
|
/**
|
|
|
|
* MaintenanceRefreshLinksInit handler; optimize settings for refreshLinks batch job.
|
|
|
|
*
|
|
|
|
* @param Maintenance $maint
|
|
|
|
*/
|
2023-08-15 14:43:04 +00:00
|
|
|
public 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
|
|
|
|
2019-12-28 08:54:09 +00:00
|
|
|
/**
|
|
|
|
* Remove Special:MathWikibase if the Wikibase client extension isn't loaded
|
|
|
|
*
|
|
|
|
* @param array &$list
|
|
|
|
*/
|
2023-08-15 14:43:04 +00:00
|
|
|
public function onSpecialPage_initList( &$list ) {
|
2021-06-21 11:32:26 +00:00
|
|
|
if ( !ExtensionRegistry::getInstance()->isLoaded( 'WikibaseClient' ) ) {
|
2019-12-28 08:54:09 +00:00
|
|
|
unset( $list['MathWikibase'] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-09 00:39:40 +00:00
|
|
|
}
|