Page MenuHomePhabricator

[JsonConfig extension support question] Using JsonConfig extension, is it possible to create "*.json" pages using the native 'json' content model type?
Closed, InvalidPublic

Description

Similarly as I asked here https://mediawiki.org/wiki/Topic:Wv90hlknkozvezcb

initially having issues with getting anything to work, but now having identified a working solution that I am mostly satisfied with (almost), I still am curious to further understand if it is possible to configure JsonConfig in LocalSettings.php with a rule to use the native 'json' content type as referenced in includes/DefaultSettings.php:

	// simple implementation, for use by extensions, etc.
	CONTENT_MODEL_JSON => JsonContentHandler::class,

rather than creating a duplicated redundant class that does practically the exact same thing.

but also, that results in errors when attempting to edit pages that (in MySQL database:, pages table, page_content_model column, the value is 'json' even though my current JsonConfig configuration is using a duplicated custom named 'Json.JsonConfig'

Content format not supported
The content format application/json+pretty is not supported by the content model wikitext.

Is there a way to configure to use the existing 'json' content model type?

For reference, here is my current LocalSettings.php configuration:

$wgJsonConfigModels['Json.JsonConfig'] = null;
 $wgJsonConfigs['JSON.JsonConfig'] = [
     'cacheExp' => 86400,
     'cacheKey' => '',
     'flaggedRevs' => false,
     'isLocal' => true,
     'license' => 'CC0-1.0',
     'model' => 'Json.JsonConfig',
     'namespace' => 486,
     'nsName' => 'Data',
     'nsTalk' => 'Data_talk',
     'pattern' => '/.\.json$/',
     //'pattern' => '/^Json:./',
     'store' => true
  ];

Event Timeline

https://github.com/wikimedia/mediawiki-extensions-JsonConfig/blob/master/includes/JCSingleton.php#L134

Is there a reason that JsonConfig is not able to allow pages to be created so that the MySQL database pages table page_content_model column is set with the value 'json' using MediaWiki's native model type for this? Is it necessary that JsonConfig ignore/neglect that existing model type to reproduce/replicate/duplicate it redundantly? And if so, it is there any way that JsonConfig can ensure that editing pages with either of the identical content types are not showing any errors preventing editing user interface expereince?

I am still not sure if I fully grasp or understand if it is possible to configure JsonConfig extension to allow for pages to be created using the 'json' existing native content model type, but I have not figured out how to accomplish this yet and I am still investigating, analyzing the code to find a way to achieve this in an automated fashion (matching .\.json$ regex.

Oh, apparently https://github.com/wikimedia/mediawiki/blob/master/includes/DefaultSettings.php#L1711 appears the code was updated from:

	// simple implementation, for use by extensions, etc.
	CONTENT_MODEL_JSON => JsonContentHandler::class,

but with that comment (which is now gone), I am curious why JsonConfig extension does not utilize the existing content model type.

Also see

"The advice I got from Platform was to not use JsonContent ever, as it had a lot of old-style architectural decisions that they didn't want continue. We're in the middle of switching WikiLambda to its own direct implementation of AbstractContent."

Hmmm.... That seems a bit confusing, given that MediaWiki 1.37.2 shows comment:

	// simple implementation, for use by extensions, etc.
	CONTENT_MODEL_JSON => JsonContentHandler::class,

even though it was since changed: https://github.com/wikimedia/mediawiki/blob/master/includes/DefaultSettings.php#L1711

Also per further comparison of the HTML output rendering from the native 'json' content model type to the one provided by JsonConfig, I see the native 'json' shows:

  • empty arrays with text indicating the arrays are empty
  • string values show quotation marks surrounding the text
  • an additional table nesting of the JSON compared to the JsonConfig

I stumbled upon this strange issue with LocalSettings.php commenting out all of my JsonConfig configurations, and using only:

$wgJsonConfigModels['json'] = null;
$wgJsonConfigs['JSON.JsonConfig'] = [
    'cacheExp' => 86400,
    'cacheKey' => '',
    'flaggedRevs' => false,
    'isLocal' => true,
    'license' => 'CC0-1.0',
    //'model' => 'JSON.JsonConfig',
    'model' => 'json',
    'namespace' => 486,
    'nsName' => 'Data',
    'nsTalk' => 'Data_talk',
    'pattern' => '/.\.json2$/',
    //'pattern' => '/^Json:./',
    'store' => true
 ];

when trying to create a page in Data namespace (with and without ".json$" ending (matching the pattern or not) then shows:

Permission error

You do not have permission to create this page, for the following reason:

⧼jsonconfig-blocked-page-creation⧽

Note that the "⧼jsonconfig-blocked-page-creation⧽" appears to not have any i18n language to represent the message key.

./includes/JCSingleton.php:                     $result = 'jsonconfig-blocked-page-creation';

but if I remove the line:

$wgJsonConfigModels['json'] = null;

then the edit page works fine.

Also see https://codesearch.wmcloud.org/search/?q=jsonconfig-blocked-page-creation&i=nope&files=&excludeFiles=&repos=

Yuri replied to my email also:

"Hi Jason, it has been over 5 years since I last looked at that code, and there are many other people working on it, so I doubt I would be able to help there. Phabricator is usually the best place to coordinate this work with others, esp if you also mention people who recently worked on that extension in a comment if you think they might know about it. Good luck!"

Glancing at https://gerrit.wikimedia.org/g/mediawiki/extensions/JsonConfig/%2Blog/master others who recently contributed to the repo include: @xSavitar @thiemowmde @LucasWerkmeister @cscott @Zabe.

In the MediaWiki Discord server, while I was/am learning more about and tinkering with JsonConfig extension, asking questions and whatnot, TheDJ stated:

https://discord.com/channels/178359708581625856/178361698573484032/973590534289522738

"Think of content model not just as definition the format of content, but also the context that is associated with it. It can influence which editor you see, which extension handles the content, the security constraints etc.
so you cannot reuse them from an extension, because then you would get a conflict of responsibility.
JsonConfig in particular is a bit of a weird extension here, which tried to mix responsibilities which makes things confusing.
See also: https://mediawiki.org/wiki/Content_handlers
content model: id used by db to track what kind of content is in the revision. determines which handler will be used to process it.
content format: mimetype application/json
content handler: defines how to interact with the content, serialize validate, protect etc.
There can be multiple models that use format application/json, but for each handler there can only be one model. You can subclass a handler, but you still need your own model. The handler might also be able to run conversions. A JSONContentHandler might know that this is serializable to text and be able to convert it to a text model (this is basically what Special:ChangeContentModel allows you to do)
this is definetly one of the more complex parts of mediawiki if you are not used to working with it."

and I found some of that informative, and is related to this thread here, so I'm including the quotes also.

Also, I think I better understand the case that using the 'json' (CONTENT_MODEL_JSON constant in MediaWiki) content model type, which I initially thought was preferable to use and build on top of, that this is not the case, and that I should instead utilize the content model types created by JsonConfig extension. In this case, however, I am curious about the slight differences in html rendering markup that exists between the two views. For example:

and I am curious if there is a way to configure JsonConfig extension to use the output view that shows " quotation marks around strings as well as explicit empty array value indicator. I can't find any examples of empty array values shown on Wikimedia sites, but for example see:

Hi @Jasonkhanlar. This does not sound like something is wrong in the code base (a so-called "software bug"), but instead like a support request (how to change settings, questions how to do something, etc.).
As Wikimedia Phabricator is for bug reports and enhancement requests, please ask on the MediaWiki Support Desk or ask on a dedicated project/extension talk page if existing. When asking there, please always include version information for the MediaWiki software (and for any other projects/extensions that your problem is related to). Thanks for your understanding!

Repeating this bug mention https://phabricator.wikimedia.org/T307978#7916685 since it appears this task is closed, and the bug is perhaps still not yet resolved, and I believe that this is related to "something is wrong in the code base (a so-called "software bug")":

when trying to create a page in Data namespace (with and without ".json$" ending (matching the pattern or not) then shows:

Permission error

You do not have permission to create this page, for the following reason:

⧼jsonconfig-blocked-page-creation⧽

Note that the "⧼jsonconfig-blocked-page-creation⧽" appears to not have any i18n language to represent the message key.

./includes/JCSingleton.php:                     $result = 'jsonconfig-blocked-page-creation';

but if I remove the line:

$wgJsonConfigModels['json'] = null;

then the edit page works fine.

Also see https://codesearch.wmcloud.org/search/?q=jsonconfig-blocked-page-creation&i=nope&files=&excludeFiles=&repos=


Also the message closing this issue, appears identical copy paste as https://phabricator.wikimedia.org/T307978#7920061 and posted at the same minute as the previous message, which I am not sure if Aklapper skimmed through to notice whether or not the wording in the message is realistically accurately deterministically representative of whether or not the words suggestive of "sounding" are practical or otherwise interpretable, or other human characteristic-related observational phenomena.

Hi, if you think that you experience a software bug, then please use the bug report form (linked from the top of the task creation page) to create a bug report, and fill in the sections in the template. Thanks!

As far as I can tell the null in $wgJsonConfigModels['json'] = null; is not supported and can cause all kinds of unexpected, unwanted behavior. I don't know what you want it to do, so there is not much more I can say, I'm afraid.