MediaWiki REL1_31
JsonContent Class Reference

Represents the content of a JSON content. More...

Inheritance diagram for JsonContent:
Collaboration diagram for JsonContent:

Public Member Functions

 __construct ( $text, $modelId=CONTENT_MODEL_JSON)
 
 beautifyJSON ()
 Pretty-print JSON.
 
 getData ()
 Decodes the JSON string.
 
 getJsonData ()
 Decodes the JSON into a PHP associative array.
 
 isValid ()
 
 preSaveTransform (Title $title, User $user, ParserOptions $popts)
 Beautifies JSON prior to save.
 
- Public Member Functions inherited from TextContent
 convert ( $toModel, $lossy='')
 This implementation provides lossless conversion between content models based on TextContent.
 
 copy ()
 
 diff (Content $that, Language $lang=null)
 Diff this content object with another content object.
 
 getNativeData ()
 Returns the text represented by this Content object, as a string.
 
 getSize ()
 Returns the text's size in bytes.
 
 getTextForSearchIndex ()
 Returns the text represented by this Content object, as a string.
 
 getTextForSummary ( $maxlength=250)
 Returns a textual representation of the content suitable for use in edit summaries and log messages.
 
 getWikitextForTransclusion ()
 Returns attempts to convert this content object to wikitext, and then returns the text string.
 
 isCountable ( $hasLinks=null)
 Returns true if this content is not a redirect, and $wgArticleCountMethod is "any".
 
- Public Member Functions inherited from AbstractContent
 __construct ( $modelId=null)
 
 addSectionHeader ( $header)
 
 equals (Content $that=null)
 
 getContentHandler ()
 
 getDefaultFormat ()
 
 getDeletionUpdates (WikiPage $page, ParserOutput $parserOutput=null)
 
 getModel ()
 
 getParserOutput (Title $title, $revId=null, ParserOptions $options=null, $generateHtml=true)
 Returns a ParserOutput object containing information derived from this content.
 
 getRedirectChain ()
 
 getRedirectTarget ()
 Subclasses that implement redirects should override this.
 
 getSecondaryDataUpdates (Title $title, Content $old=null, $recursive=true, ParserOutput $parserOutput=null)
 Returns a list of DataUpdate objects for recording information about this Content in some secondary data store.
 
 getSection ( $sectionId)
 
 getSupportedFormats ()
 
 getUltimateRedirectTarget ()
 
 isEmpty ()
 
 isRedirect ()
 
 isSupportedFormat ( $format)
 
 matchMagicWord (MagicWord $word)
 This default implementation always returns false.
 
 preloadTransform (Title $title, ParserOptions $popts, $params=[])
 
 prepareSave (WikiPage $page, $flags, $parentRevId, User $user)
 
 replaceSection ( $sectionId, Content $with, $sectionTitle='')
 
 serialize ( $format=null)
 
 updateRedirect (Title $target)
 This default implementation always returns $this.
 

Protected Member Functions

 arrayRow ( $val)
 Create HTML table row representing the value in an array.
 
 arrayTable ( $mapping)
 Create HTML table representing a JSON array.
 
 fillParserOutput (Title $title, $revId, ParserOptions $options, $generateHtml, ParserOutput &$output)
 Set the HTML and add the appropriate styles.
 
 objectRow ( $key, $val)
 Create HTML table row representing one object property.
 
 objectTable ( $mapping)
 Create HTML table representing a JSON object.
 
 primitiveValue ( $val)
 Construct text representing a JSON primitive value.
 
 rootValueTable ( $val)
 Construct HTML table representation of any JSON value.
 
 valueCell ( $val)
 Construct HTML table cell representing any JSON value.
 
- Protected Member Functions inherited from TextContent
 getHighlightHtml ()
 Generates an HTML version of the content, for display.
 
 getHtml ()
 Generates an HTML version of the content, for display.
 
- Protected Member Functions inherited from AbstractContent
 checkFormat ( $format)
 
 checkModelID ( $modelId)
 

Protected Attributes

Status $jsonParse
 
- Protected Attributes inherited from TextContent
string $mText
 
- Protected Attributes inherited from AbstractContent
 $model_id
 Name of the content model this Content object represents.
 

Additional Inherited Members

- Static Public Member Functions inherited from TextContent
static normalizeLineEndings ( $text)
 Do a "\\r\\n" -> "\\n" and "\\r" -> "\\n" transformation as well as trim trailing whitespace.
 

Detailed Description

Represents the content of a JSON content.

Since
1.24

Definition at line 15 of file JsonContent.php.

Constructor & Destructor Documentation

◆ __construct()

JsonContent::__construct ( $text,
$modelId = CONTENT_MODEL_JSON )
Parameters
string$textJSON
string$modelId

Reimplemented from TextContent.

Definition at line 27 of file JsonContent.php.

Member Function Documentation

◆ arrayRow()

JsonContent::arrayRow ( $val)
protected

Create HTML table row representing the value in an array.

Parameters
mixed$val
Returns
string HTML.

Definition at line 214 of file JsonContent.php.

References valueCell().

Referenced by arrayTable().

◆ arrayTable()

JsonContent::arrayTable ( $mapping)
protected

Create HTML table representing a JSON array.

Parameters
array$mapping
Returns
string HTML

Definition at line 188 of file JsonContent.php.

References $rows, arrayRow(), text, and wfMessage().

Referenced by rootValueTable(), and valueCell().

◆ beautifyJSON()

JsonContent::beautifyJSON ( )

Pretty-print JSON.

If called before validation, it may return JSON "null".

Returns
string

Reimplemented in GadgetDefinitionContent.

Definition at line 71 of file JsonContent.php.

References getData().

Referenced by preSaveTransform().

◆ fillParserOutput()

JsonContent::fillParserOutput ( Title $title,
$revId,
ParserOptions $options,
$generateHtml,
ParserOutput & $output )
protected

Set the HTML and add the appropriate styles.

Parameters
Title$title
int$revId
ParserOptions$options
bool$generateHtml
ParserOutput&$output

Reimplemented from TextContent.

Reimplemented in GadgetDefinitionContent.

Definition at line 102 of file JsonContent.php.

References $output, getData(), isValid(), rootValueTable(), and ParserOutput\setText().

◆ getData()

JsonContent::getData ( )

Decodes the JSON string.

Note that this parses it without casting objects to associative arrays. Objects and arrays are kept as distinguishable types in the PHP values.

Returns
Status

Definition at line 50 of file JsonContent.php.

References $jsonParse, and TextContent\getNativeData().

Referenced by beautifyJSON(), fillParserOutput(), GadgetDefinitionContent\getAssocArray(), isValid(), and GadgetDefinitionContent\validate().

◆ getJsonData()

JsonContent::getJsonData ( )

Decodes the JSON into a PHP associative array.

Deprecated
since 1.25 Use getData instead.
Returns
array|null

Definition at line 37 of file JsonContent.php.

References TextContent\getNativeData(), and wfDeprecated().

◆ isValid()

JsonContent::isValid ( )
Returns
bool Whether content is valid.

Reimplemented from AbstractContent.

Reimplemented in GadgetDefinitionContent.

Definition at line 60 of file JsonContent.php.

References getData().

Referenced by fillParserOutput(), and preSaveTransform().

◆ objectRow()

JsonContent::objectRow ( $key,
$val )
protected

Create HTML table row representing one object property.

Parameters
string$key
mixed$val
Returns
string HTML.

Definition at line 176 of file JsonContent.php.

References valueCell().

Referenced by objectTable().

◆ objectTable()

JsonContent::objectTable ( $mapping)
protected

Create HTML table representing a JSON object.

Parameters
stdClass$mapping
Returns
string HTML

Definition at line 149 of file JsonContent.php.

References $rows, objectRow(), text, and wfMessage().

Referenced by rootValueTable(), and valueCell().

◆ preSaveTransform()

JsonContent::preSaveTransform ( Title $title,
User $user,
ParserOptions $popts )

Beautifies JSON prior to save.

Parameters
Title$title
User$user
ParserOptions$popts
Returns
JsonContent

Reimplemented from TextContent.

Definition at line 83 of file JsonContent.php.

References beautifyJSON(), isValid(), and TextContent\normalizeLineEndings().

◆ primitiveValue()

JsonContent::primitiveValue ( $val)
protected

Construct text representing a JSON primitive value.

Parameters
mixed$val
Returns
string Text.

Definition at line 243 of file JsonContent.php.

Referenced by rootValueTable(), and valueCell().

◆ rootValueTable()

JsonContent::rootValueTable ( $val)
protected

Construct HTML table representation of any JSON value.

See also valueCell, which is similar.

Parameters
mixed$val
Returns
string HTML.

Definition at line 123 of file JsonContent.php.

References arrayTable(), objectTable(), and primitiveValue().

Referenced by fillParserOutput().

◆ valueCell()

JsonContent::valueCell ( $val)
protected

Construct HTML table cell representing any JSON value.

Parameters
mixed$val
Returns
string HTML.

Definition at line 225 of file JsonContent.php.

References arrayTable(), objectTable(), and primitiveValue().

Referenced by arrayRow(), and objectRow().

Member Data Documentation

◆ $jsonParse

Status JsonContent::$jsonParse
protected
Since
1.25

Definition at line 21 of file JsonContent.php.

Referenced by getData().


The documentation for this class was generated from the following file: