2013-02-20 22:00:42 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Scribunto Content Handler
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @ingroup Extensions
|
|
|
|
* @ingroup Scribunto
|
|
|
|
*
|
|
|
|
* @author Brad Jorsch <bjorsch@wikimedia.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
class ScribuntoContentHandler extends TextContentHandler {
|
|
|
|
|
2014-10-10 09:02:03 +00:00
|
|
|
/**
|
|
|
|
* @param string $modelId
|
|
|
|
* @param string[] $formats
|
|
|
|
*/
|
2014-09-16 03:25:53 +00:00
|
|
|
public function __construct( $modelId = CONTENT_MODEL_SCRIBUNTO, $formats = array( CONTENT_FORMAT_TEXT ) ) {
|
2013-02-20 22:00:42 +00:00
|
|
|
parent::__construct( $modelId, $formats );
|
|
|
|
}
|
|
|
|
|
2014-10-10 09:02:03 +00:00
|
|
|
/**
|
|
|
|
* @param string $format
|
|
|
|
* @return bool
|
|
|
|
*/
|
2013-04-29 20:51:39 +00:00
|
|
|
public function isSupportedFormat( $format ) {
|
|
|
|
// An error in an earlier version of Scribunto means we might see this.
|
|
|
|
if ( $format === 'CONTENT_FORMAT_TEXT' ) {
|
|
|
|
$format = CONTENT_FORMAT_TEXT;
|
|
|
|
}
|
|
|
|
return parent::isSupportedFormat( $format );
|
|
|
|
}
|
|
|
|
|
2013-02-20 22:00:42 +00:00
|
|
|
/**
|
|
|
|
* Unserializes a ScribuntoContent object.
|
|
|
|
*
|
|
|
|
* @param $text string Serialized form of the content
|
|
|
|
* @param $format null|string The format used for serialization
|
|
|
|
* @return Content the ScribuntoContent object wrapping $text
|
|
|
|
*/
|
|
|
|
public function unserializeContent( $text, $format = null ) {
|
|
|
|
$this->checkFormat( $format );
|
|
|
|
return new ScribuntoContent( $text );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an empty ScribuntoContent object.
|
|
|
|
*
|
|
|
|
* @return Content
|
|
|
|
*/
|
|
|
|
public function makeEmptyContent() {
|
|
|
|
return new ScribuntoContent( '' );
|
|
|
|
}
|
2013-05-29 15:08:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Scripts themselves should be in English.
|
|
|
|
*
|
2014-10-10 09:02:03 +00:00
|
|
|
* @param Title $title
|
|
|
|
* @param Content $content
|
2013-05-29 15:08:31 +00:00
|
|
|
* @return Language wfGetLangObj( 'en' )
|
|
|
|
*/
|
|
|
|
public function getPageLanguage( Title $title, Content $content = null ) {
|
|
|
|
return wfGetLangObj( 'en' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scripts themselves should be in English.
|
|
|
|
*
|
2014-10-10 09:02:03 +00:00
|
|
|
* @param Title $title
|
|
|
|
* @param Content $content
|
2013-05-29 15:08:31 +00:00
|
|
|
* @return Language wfGetLangObj( 'en' )
|
|
|
|
*/
|
|
|
|
public function getPageViewLanguage( Title $title, Content $content = null ) {
|
|
|
|
return wfGetLangObj( 'en' );
|
|
|
|
}
|
2015-07-24 14:17:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Only allow this content handler to be used in the Module namespace
|
|
|
|
* @param Title $title
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function canBeUsedOn( Title $title ) {
|
|
|
|
if ( $title->getNamespace() !== NS_MODULE ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::canBeUsedOn( $title );
|
|
|
|
}
|
2013-02-20 22:00:42 +00:00
|
|
|
}
|