diff --git a/VisualEditor.hooks.php b/VisualEditor.hooks.php index a2dc1d1ffb..c427d28bc9 100644 --- a/VisualEditor.hooks.php +++ b/VisualEditor.hooks.php @@ -35,6 +35,28 @@ class VisualEditorHooks { return true; } + /** + * Convert the content model of messages that are actually JSON to JSON. + * This only affects validation and UI when saving and editing, not + * loading the content. + * + * @param Title $title + * @param string $model + * @return bool + */ + public static function onContentHandlerDefaultModelFor( Title $title, &$model ) { + $messages = array( + 'Visualeditor-cite-tool-definition.json', + 'Visualeditor-specialcharinspector-characterlist-insert' + ); + + if ( $title->inNamespace( NS_MEDIAWIKI ) && in_array( $title->getText(), $messages ) ) { + $model = CONTENT_MODEL_JSON; + } + + return true; + } + /** * Changes the Edit tab and adds the VisualEditor tab. * diff --git a/VisualEditor.php b/VisualEditor.php index 4c3bf11ad5..9fd3bd464c 100644 --- a/VisualEditor.php +++ b/VisualEditor.php @@ -74,6 +74,7 @@ $wgConfigRegistry['visualeditor'] = 'GlobalVarConfig::newInstance'; // Register Hooks $wgHooks['BeforePageDisplay'][] = 'VisualEditorHooks::onBeforePageDisplay'; +$wgHooks['ContentHandlerDefaultModelFor'][] = 'VisualEditorHooks::onContentHandlerDefaultModelFor'; $wgHooks['DoEditSectionLink'][] = 'VisualEditorHooks::onDoEditSectionLink'; $wgHooks['GetBetaFeaturePreferences'][] = 'VisualEditorHooks::onGetBetaPreferences'; $wgHooks['GetPreferences'][] = 'VisualEditorHooks::onGetPreferences';