Use HookHandlers for CodeEditor hook

This requires 1.41 for the interface (added in 4d6a470a)

Bug: T271014
Change-Id: Ic486f44bd9215ac7dad5bc70d7dca1e9aad470de
This commit is contained in:
Umherirrender 2023-08-15 15:36:56 +02:00 committed by Jforrester
parent 636c4482b3
commit 7f95440c4d
4 changed files with 52 additions and 19 deletions

View file

@ -5,4 +5,18 @@ $cfg = require __DIR__ . '/../vendor/mediawiki/mediawiki-phan-config/src/config.
// Namespace constants
$cfg['file_list'][] = 'Gadgets.namespaces.php';
$cfg['directory_list'] = array_merge(
$cfg['directory_list'],
[
'../../extensions/CodeEditor',
]
);
$cfg['exclude_analysis_directory_list'] = array_merge(
$cfg['exclude_analysis_directory_list'],
[
'../../extensions/CodeEditor',
]
);
return $cfg;

View file

@ -8,7 +8,7 @@
"descriptionmsg": "gadgets-desc",
"license-name": "GPL-2.0-or-later",
"requires": {
"MediaWiki": ">= 1.39.0"
"MediaWiki": ">= 1.41.0"
},
"type": "other",
"namespaces": [
@ -75,13 +75,16 @@
"HookHandlers": {
"GadgetHooks": {
"class": "MediaWiki\\Extension\\Gadgets\\Hooks"
},
"GadgetCodeEditorHooks": {
"class": "MediaWiki\\Extension\\Gadgets\\CodeEditorHooks"
}
},
"Hooks": {
"PageDeleteComplete": "GadgetHooks",
"PageSaveComplete": "GadgetHooks",
"BeforePageDisplay": "GadgetHooks",
"CodeEditorGetPageLanguage": "MediaWiki\\Extension\\Gadgets\\Hooks::onCodeEditorGetPageLanguage",
"CodeEditorGetPageLanguage": "GadgetCodeEditorHooks",
"ContentHandlerDefaultModelFor": "GadgetHooks",
"EditFilterMergedContent": "GadgetHooks",
"UserGetDefaultOptions": "GadgetHooks",

View file

@ -0,0 +1,33 @@
<?php
namespace MediaWiki\Extension\Gadgets;
use MediaWiki\Extension\CodeEditor\Hooks\CodeEditorGetPageLanguageHook;
use MediaWiki\Title\Title;
/**
* Hooks from CodeEditor extension,
* which is optional to use with this extension.
*/
class CodeEditorHooks implements CodeEditorGetPageLanguageHook {
/**
* Set the CodeEditor language for Gadget definition pages. It already
* knows the language for Gadget: namespace pages.
*
* @param Title $title
* @param string|null &$lang
* @param string $model
* @param string $format
* @return bool
*/
public function onCodeEditorGetPageLanguage( Title $title, ?string &$lang, string $model, string $format ) {
if ( $title->hasContentModel( 'GadgetDefinition' ) ) {
$lang = 'json';
return false;
}
return true;
}
}

View file

@ -400,23 +400,6 @@ class Hooks implements
return true;
}
/**
* Set the CodeEditor language for Gadget definition pages. It already
* knows the language for Gadget: namespace pages.
*
* @param Title $title
* @param string &$lang
* @return bool
*/
public static function onCodeEditorGetPageLanguage( Title $title, &$lang ) {
if ( $title->hasContentModel( 'GadgetDefinition' ) ) {
$lang = 'json';
return false;
}
return true;
}
/**
* Add the GadgetUsage special page to the list of QueryPages.
* @param array &$queryPages