wiki.techinc.nl/includes/content/JSONContentHandler.php
Kunal Mehta d2a82fcb60 Add JSONContent and handler from EventLogging
As was discussed at the architecture summit, a basic JSON content
class which handles validation and basic display. Not intended to
be used directly, but for extensions to subclass.

Co-Authored-By: addshore <addshorewiki@gmail.com>
Change-Id: Ifcde9bcd0efcf15a3ab692dd2a0a3038559e0254
2014-08-08 23:31:26 +00:00

48 lines
1.1 KiB
PHP

<?php
/**
* JSON Schema Content Handler
*
* @file
*
* @author Ori Livneh <ori@wikimedia.org>
* @author Kunal Mehta <legoktm@gmail.com>
*/
class JSONContentHandler extends TextContentHandler {
public function __construct( $modelId = CONTENT_MODEL_JSON ) {
parent::__construct( $modelId, array( CONTENT_FORMAT_JSON ) );
}
/**
* Unserializes a JSONContent object.
*
* @param string $text Serialized form of the content
* @param null|string $format The format used for serialization
*
* @return JSONContent
*/
public function unserializeContent( $text, $format = null ) {
$this->checkFormat( $format );
return new JSONContent( $text );
}
/**
* Creates an empty JSONContent object.
*
* @return JSONContent
*/
public function makeEmptyContent() {
return new JSONContent( '' );
}
/** JSON is English **/
public function getPageLanguage( Title $title, Content $content = null ) {
return wfGetLangObj( 'en' );
}
/** JSON is English **/
public function getPageViewLanguage( Title $title, Content $content = null ) {
return wfGetLangObj( 'en' );
}
}