wiki.techinc.nl/includes/content/JSONContentHandler.php
Kunal Mehta ccee80b8a6 Make it easier to subclass Content and ContentHandler subclasses
Currently the names of associated Content classes are hardcoded,
meaning that any extension that wishes to subclass these implementations
must also re-implement that function, usually copying it exactly
with just the class name changed. Using "static" avoids that issue.

For ContentHandlers, I added a TextContentHandler::getContentClass,
which should be used when creating new Content objects.

Change-Id: I70f1a3291aec3460120ec20121a23f4cb68e04d1
2014-08-16 23:04:08 -07:00

66 lines
1.4 KiB
PHP

<?php
/**
* JSON Schema Content Handler
*
* @file
*
* @author Ori Livneh <ori@wikimedia.org>
* @author Kunal Mehta <legoktm@gmail.com>
*/
/**
* @since 1.24
*/
class JSONContentHandler extends TextContentHandler {
/**
* The class name of objects that should be created
*
* @deprecated override getContentClass instead
*
* @var string
*/
protected $contentClass = 'JSONContent';
public function __construct( $modelId = CONTENT_MODEL_JSON ) {
parent::__construct( $modelId, array( CONTENT_FORMAT_JSON ) );
}
/**
* Temporary back-compat until extensions
* are updated to override this
*
* @return string
*/
protected function getContentClass() {
return $this->contentClass;
}
/**
* Returns the english language, because JSON is english, and should be handled as such.
*
* @param Title $title
* @param Content|null $content
*
* @return Language Return of wfGetLangObj( 'en' )
*
* @see ContentHandler::getPageLanguage()
*/
public function getPageLanguage( Title $title, Content $content = null ) {
return wfGetLangObj( 'en' );
}
/**
* Returns the english language, because JSON is english, and should be handled as such.
*
* @param Title $title
* @param Content|null $content
*
* @return Language Return of wfGetLangObj( 'en' )
*
* @see ContentHandler::getPageLanguage()
*/
public function getPageViewLanguage( Title $title, Content $content = null ) {
return wfGetLangObj( 'en' );
}
}