MediaWiki REL1_37
JsonContentHandler.php
Go to the documentation of this file.
1<?php
22
33
34 public function __construct( $modelId = CONTENT_MODEL_JSON ) {
35 parent::__construct( $modelId, [ CONTENT_FORMAT_JSON ] );
36 }
37
41 protected function getContentClass() {
42 return JsonContent::class;
43 }
44
45 public function makeEmptyContent() {
46 $class = $this->getContentClass();
47 return new $class( '{}' );
48 }
49
50 public function preSaveTransform(
52 PreSaveTransformParams $pstParams
53 ): Content {
54 $shouldCallDeprecatedMethod = $this->shouldCallDeprecatedContentTransformMethod(
56 $pstParams
57 );
58
59 if ( $shouldCallDeprecatedMethod ) {
60 return $this->callDeprecatedContentPST(
61 $content,
62 $pstParams
63 );
64 }
65
66 '@phan-var JsonContent $content';
67
68 // FIXME: WikiPage::doEditContent invokes PST before validation. As such, native data
69 // may be invalid (though PST result is discarded later in that case).
70 if ( !$content->isValid() ) {
71 return $content;
72 }
73
74 $contentClass = $this->getContentClass();
75 return new $contentClass( JsonContent::normalizeLineEndings( $content->beautifyJSON() ) );
76 }
77}
const CONTENT_FORMAT_JSON
For future use with the API, and for use by extensions.
Definition Defines.php:236
const CONTENT_MODEL_JSON
Definition Defines.php:212
Content handler for code content such as CSS, JavaScript, JSON, etc.
shouldCallDeprecatedContentTransformMethod(Content $content, $params)
Check if we need to provide content overrides deprecated Content method.
callDeprecatedContentPST(Content $content, PreSaveTransformParams $params)
Provided content overrides deprecated Content::preSaveTransform, call it and return.
Content handler for JSON.
preSaveTransform(Content $content, PreSaveTransformParams $pstParams)
Returns a $content object with pre-save transformations applied (or the same object if no transformat...
__construct( $modelId=CONTENT_MODEL_JSON)
makeEmptyContent()
Creates an empty TextContent object.
static normalizeLineEndings( $text)
Do a "\\r\\n" -> "\\n" and "\\r" -> "\\n" transformation as well as trim trailing whitespace.
Base interface for content objects.
Definition Content.php:35
$content
Definition router.php:76