Merge "Use batch inserts for watchlist"
[lhc/web/wiklou.git] / includes / content / JSONContentHandler.php
1 <?php
2 /**
3 * JSON Schema Content Handler
4 *
5 * @file
6 *
7 * @author Ori Livneh <ori@wikimedia.org>
8 * @author Kunal Mehta <legoktm@gmail.com>
9 */
10
11 /**
12 * @since 1.24
13 */
14 class JSONContentHandler extends TextContentHandler {
15
16 /**
17 * The class name of objects that should be created
18 *
19 * @var string
20 */
21 protected $contentClass = 'JSONContent';
22
23 public function __construct( $modelId = CONTENT_MODEL_JSON ) {
24 parent::__construct( $modelId, array( CONTENT_FORMAT_JSON ) );
25 }
26
27 /**
28 * Unserializes a JSONContent object.
29 *
30 * @param string $text Serialized form of the content
31 * @param null|string $format The format used for serialization
32 *
33 * @return JSONContent
34 */
35 public function unserializeContent( $text, $format = null ) {
36 $this->checkFormat( $format );
37 return new $this->contentClass( $text );
38 }
39
40 /**
41 * Creates an empty JSONContent object.
42 *
43 * @return JSONContent
44 */
45 public function makeEmptyContent() {
46 return new $this->contentClass( '' );
47 }
48
49 /**
50 * Returns the english language, because JSON is english, and should be handled as such.
51 *
52 * @param Title $title
53 * @param Content|null $content
54 *
55 * @return Language Return of wfGetLangObj( 'en' )
56 *
57 * @see ContentHandler::getPageLanguage()
58 */
59 public function getPageLanguage( Title $title, Content $content = null ) {
60 return wfGetLangObj( 'en' );
61 }
62
63 /**
64 * Returns the english language, because JSON is english, and should be handled as such.
65 *
66 * @param Title $title
67 * @param Content|null $content
68 *
69 * @return Language Return of wfGetLangObj( 'en' )
70 *
71 * @see ContentHandler::getPageLanguage()
72 */
73 public function getPageViewLanguage( Title $title, Content $content = null ) {
74 return wfGetLangObj( 'en' );
75 }
76 }