39 parent::__construct( $text, $modelId );
51 $this->jsonParse ??= FormatJson::parse( $this->
getText() );
59 return $this->
getData()->isGood();
70 return FormatJson::encode( $this->
getData()->getValue(),
"\t", FormatJson::UTF8_OK );
82 if ( is_object( $val ) ) {
85 } elseif ( is_array( $val ) ) {
91 $table = Html::rawElement(
'table', [
'class' =>
'mw-json mw-json-single-value' ],
92 Html::rawElement(
'tbody', [],
93 Html::rawElement(
'tr', [],
100 return Html::rawElement(
'div', [
'class' =>
'noresize' ], $table );
113 foreach ( $mapping as $key => $val ) {
114 $rows[] = $this->
objectRow( $key, $val );
118 $rows[] = Html::rawElement(
'tr', [],
120 wfMessage(
'content-json-empty-object' )->text()
124 return Html::rawElement(
'table', [
'class' =>
'mw-json' ],
125 Html::rawElement(
'tbody', [], implode(
'', $rows ) )
138 $th = Html::rawElement(
'th', [], $thContent );
140 return Html::rawElement(
'tr', [], $th . $td );
153 foreach ( $mapping as $val ) {
158 $rows[] = Html::rawElement(
'tr', [],
160 wfMessage(
'content-json-empty-array' )->text()
164 return Html::rawElement(
'table', [
'class' =>
'mw-json' ],
165 Html::rawElement(
'tbody', [], implode(
"\n", $rows ) )
177 return Html::rawElement(
'tr', [], $td );
187 if ( is_object( $val ) ) {
188 return Html::rawElement(
'td', [], $this->
objectTable( $val ) );
191 if ( is_array( $val ) ) {
192 return Html::rawElement(
'td', [], $this->
arrayTable( $val ) );
205 if ( is_string( $val ) ) {
208 return '"' . $val .
'"';
210 return FormatJson::encode( $val );
214class_alias( JsonContent::class,
'JsonContent' );
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
JSON text content that can be viewed and edit directly by users.
primitiveValue( $val)
Construct text representing a JSON primitive value.
beautifyJSON()
Pretty-print JSON.
rootValueTable( $val)
Construct HTML table representation of any JSON value.
arrayTable( $mapping)
Create HTML table representing a JSON array.
getData()
Decodes the JSON string.
__construct( $text, $modelId=CONTENT_MODEL_JSON)
objectTable( $mapping)
Create HTML table representing a JSON object.
arrayRow( $val)
Create HTML table row representing the value in an array.
valueCell( $val)
Construct HTML table cell representing any JSON value.
objectRow( $key, $val)
Create HTML table row representing one object property.
Content object implementation for representing flat text.
getText()
Returns the text represented by this Content object, as a string.