MediaWiki  1.27.2
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. More...
 
 getData ()
 Decodes the JSON string. More...
 
 getJsonData ()
 Decodes the JSON into a PHP associative array. More...
 
 isValid ()
 
 preSaveTransform (Title $title, User $user, ParserOptions $popts)
 Beautifies JSON prior to save. More...
 
- Public Member Functions inherited from TextContent
 __construct ($text, $model_id=CONTENT_MODEL_TEXT)
 
 convert ($toModel, $lossy= '')
 This implementation provides lossless conversion between content models based on TextContent. More...
 
 copy ()
 
 diff (Content $that, Language $lang=null)
 Diff this content object with another content object. More...
 
 getNativeData ()
 Returns the text represented by this Content object, as a string. More...
 
 getSize ()
 Returns the text's size in bytes. More...
 
 getTextForSearchIndex ()
 Returns the text represented by this Content object, as a string. More...
 
 getTextForSummary ($maxlength=250)
 Returns a textual representation of the content suitable for use in edit summaries and log messages. More...
 
 getWikitextForTransclusion ()
 Returns attempts to convert this content object to wikitext, and then returns the text string. More...
 
 isCountable ($hasLinks=null)
 Returns true if this content is not a redirect, and $wgArticleCountMethod is "any". More...
 
 preSaveTransform (Title $title, User $user, ParserOptions $popts)
 Returns a Content object with pre-save transformations applied. More...
 
- Public Member Functions inherited from AbstractContent
 __construct ($modelId=null)
 
 addSectionHeader ($header)
 
 convert ($toModel, $lossy= '')
 This base implementation calls the hook ConvertContent to enable custom conversions. More...
 
 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. More...
 
 getRedirectChain ()
 
 getRedirectTarget ()
 Subclasses that implement redirects should override this. More...
 
 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. More...
 
 getSection ($sectionId)
 
 getSupportedFormats ()
 
 getUltimateRedirectTarget ()
 
 isEmpty ()
 
 isRedirect ()
 
 isSupportedFormat ($format)
 
 isValid ()
 Subclasses may override this to implement (light weight) validation. More...
 
 matchMagicWord (MagicWord $word)
 This default implementation always returns false. More...
 
 preloadTransform (Title $title, ParserOptions $popts, $params=[])
 
 prepareSave (WikiPage $page, $flags, $parentRevId, User $user)
 
 preSaveTransform (Title $title, User $user, ParserOptions $popts)
 
 replaceSection ($sectionId, Content $with, $sectionTitle= '')
 
 serialize ($format=null)
 
 updateRedirect (Title $target)
 This default implementation always returns $this. More...
 

Protected Member Functions

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

Protected Attributes

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

Detailed Description

Represents the content of a JSON content.

Since
1.24

Definition at line 15 of file JsonContent.php.

Constructor & Destructor Documentation

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

Definition at line 26 of file JsonContent.php.

Member Function Documentation

JsonContent::arrayRow (   $val)
protected

Create HTML table row representing the value in an array.

Parameters
mixed$val
Returns
string HTML.

Definition at line 213 of file JsonContent.php.

References Html\rawElement(), and valueCell().

Referenced by arrayTable().

JsonContent::arrayTable (   $mapping)
protected

Create HTML table representing a JSON array.

Parameters
array$mapping
Returns
string HTML

Definition at line 187 of file JsonContent.php.

References arrayRow(), as, Html\element(), Html\rawElement(), text, and wfMessage().

Referenced by rootValueTable(), and valueCell().

JsonContent::beautifyJSON ( )

Pretty-print JSON.

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

Returns
string

Definition at line 70 of file JsonContent.php.

References FormatJson\encode(), getData(), and FormatJson\UTF8_OK.

Referenced by preSaveTransform().

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

Definition at line 101 of file JsonContent.php.

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

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 49 of file JsonContent.php.

References $jsonParse, TextContent\getNativeData(), and FormatJson\parse().

Referenced by beautifyJSON(), fillParserOutput(), and isValid().

JsonContent::getJsonData ( )

Decodes the JSON into a PHP associative array.

Deprecated:
since 1.25 Use getData instead.
Returns
array|null

Definition at line 36 of file JsonContent.php.

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

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

Implements Content.

Definition at line 59 of file JsonContent.php.

References getData().

Referenced by fillParserOutput(), and preSaveTransform().

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

Create HTML table row representing one object property.

Parameters
string$key
mixed$val
Returns
string HTML.

Definition at line 175 of file JsonContent.php.

References $key, Html\element(), Html\rawElement(), and valueCell().

Referenced by objectTable().

JsonContent::objectTable (   $mapping)
protected

Create HTML table representing a JSON object.

Parameters
stdClass$mapping
Returns
string HTML

Definition at line 148 of file JsonContent.php.

References $key, as, Html\element(), objectRow(), Html\rawElement(), text, and wfMessage().

Referenced by rootValueTable(), and valueCell().

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

Beautifies JSON prior to save.

Parameters
Title$titleTitle
User$userUser
ParserOptions$popts
Returns
JsonContent

Implements Content.

Definition at line 82 of file JsonContent.php.

References beautifyJSON(), and isValid().

JsonContent::primitiveValue (   $val)
protected

Construct text representing a JSON primitive value.

Parameters
mixed$val
Returns
string Text.

Definition at line 242 of file JsonContent.php.

References FormatJson\encode().

Referenced by rootValueTable(), and valueCell().

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 122 of file JsonContent.php.

References arrayTable(), Html\element(), objectTable(), primitiveValue(), and Html\rawElement().

Referenced by fillParserOutput().

JsonContent::valueCell (   $val)
protected

Construct HTML table cell representing any JSON value.

Parameters
mixed$val
Returns
string HTML.

Definition at line 224 of file JsonContent.php.

References arrayTable(), Html\element(), objectTable(), primitiveValue(), and Html\rawElement().

Referenced by arrayRow(), and objectRow().

Member Data Documentation

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: