mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Scribunto
synced 2024-11-28 10:10:04 +00:00
b630ecdd3a
I94ae07bc arbitrarily removed this restriction, which seems liable to result in confusion where non-Module-namespace pages can be marked as modules but can't be #invoked. Change-Id: Ia80f49d14b1f5cded0d3f5bffb6b450fb26cd986
90 lines
2.1 KiB
PHP
90 lines
2.1 KiB
PHP
<?php
|
|
/**
|
|
* Scribunto Content Handler
|
|
*
|
|
* @file
|
|
* @ingroup Extensions
|
|
* @ingroup Scribunto
|
|
*
|
|
* @author Brad Jorsch <bjorsch@wikimedia.org>
|
|
*/
|
|
|
|
class ScribuntoContentHandler extends TextContentHandler {
|
|
|
|
/**
|
|
* @param string $modelId
|
|
* @param string[] $formats
|
|
*/
|
|
public function __construct( $modelId = CONTENT_MODEL_SCRIBUNTO, $formats = array( CONTENT_FORMAT_TEXT ) ) {
|
|
parent::__construct( $modelId, $formats );
|
|
}
|
|
|
|
/**
|
|
* @param string $format
|
|
* @return bool
|
|
*/
|
|
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 );
|
|
}
|
|
|
|
/**
|
|
* 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( '' );
|
|
}
|
|
|
|
/**
|
|
* Scripts themselves should be in English.
|
|
*
|
|
* @param Title $title
|
|
* @param Content $content
|
|
* @return Language wfGetLangObj( 'en' )
|
|
*/
|
|
public function getPageLanguage( Title $title, Content $content = null ) {
|
|
return wfGetLangObj( 'en' );
|
|
}
|
|
|
|
/**
|
|
* Scripts themselves should be in English.
|
|
*
|
|
* @param Title $title
|
|
* @param Content $content
|
|
* @return Language wfGetLangObj( 'en' )
|
|
*/
|
|
public function getPageViewLanguage( Title $title, Content $content = null ) {
|
|
return wfGetLangObj( 'en' );
|
|
}
|
|
|
|
/**
|
|
* 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 );
|
|
}
|
|
}
|