Skip to content

Commit

Permalink
feat: add wgMwJsonAllowSubmitInvalide config var
Browse files Browse the repository at this point in the history
  • Loading branch information
simontaurus committed Apr 13, 2024
1 parent 12ba08c commit 4d46aa7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
11 changes: 9 additions & 2 deletions extension.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version":2,
"name":"MwJson",
"version":"0.36.0",
"version":"0.37.0",
"author":[
"[https://github.com/simontaurus Simon Stier]"
],
Expand Down Expand Up @@ -228,9 +228,16 @@
"SpecialSlotResolver": "special/SlotResolver.php"
},
"Hooks":{
"BeforePageDisplay":"MwJson::onBeforePageDisplay"
"BeforePageDisplay":"MwJson::onBeforePageDisplay",
"ResourceLoaderGetConfigVars": "MwJson::onResourceLoaderGetConfigVars"
},
"SpecialPages": {
"SlotResolver": "SpecialSlotResolver"
},
"config": {
"MwJsonAllowSubmitInvalide": {
"value": "always",
"description": "Forbid ('never'), conditional if set in schema option ('option') or always ('always') allow the user to save data failing schema validation."
}
}
}
5 changes: 5 additions & 0 deletions includes/MwJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@ public static function onBeforePageDisplay( $out ) {

}

// see https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderGetConfigVars
public static function onResourceLoaderGetConfigVars( array &$vars, $skin, Config $config ): void {
$vars['wgMwJsonAllowSubmitInvalide'] = $config->get( 'MwJsonAllowSubmitInvalide' );
}

}
11 changes: 7 additions & 4 deletions modules/ext.MwJson.editor/MwJson_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mwjson.editor = class {
mode: "default", // options: default, query
copy: false, // editor is used to create a copy of an exiting entry => copy_ignore schema option is applied
submit_enabled: true, //if true, add save button
allow_submit_with_errors: true,
allow_submit_with_errors: undefined, //allow submitting forms even if schema validation fails (see option wgMwJsonAllowSubmitInvalide)
lang: mw.config.get('wgUserLanguage'),
format: {}, // e.g. datetime format
user_id: mw.config.get('wgUserName'),
Expand Down Expand Up @@ -70,9 +70,12 @@ mwjson.editor = class {
}

createEditor() {
//return function(err, config) {

//console.log(this);
// set allow_submit_with_errors if still undefined
if (this.config.allow_submit_with_errors !== true && this.config.allow_submit_with_errors != false) {
if (mw.config.get('wgMwJsonAllowSubmitInvalide') === "always") this.config.allow_submit_with_errors = true;
if (mw.config.get('wgMwJsonAllowSubmitInvalide') === "option") this.config.allow_submit_with_errors = this.schema?.options?.allow_submit_with_errors || false;
if (mw.config.get('wgMwJsonAllowSubmitInvalide') === "never") this.config.allow_submit_with_errors = false;
}

//JSONEditor.defaults.language = "de";
this.config.JSONEditorConfig = this.config.JSONEditorConfig || {};
Expand Down

0 comments on commit 4d46aa7

Please sign in to comment.