mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Scribunto
synced 2024-11-11 17:01:00 +00:00
Check content model instead of title
Make Scribunto compatible with storing content model in the database, by checking for it directly instead of guessing it based on the title. Change-Id: I94ae07bc47273fbf65d64b2909e5895c1c3fd7e9
This commit is contained in:
parent
a68021a702
commit
bd5e46b941
|
@ -31,6 +31,8 @@ $wgExtensionCredits['parserhook']['Scribunto'] = array(
|
|||
'url' => 'https://www.mediawiki.org/wiki/Extension:Scribunto',
|
||||
);
|
||||
|
||||
define( 'CONTENT_MODEL_SCRIBUNTO', 'Scribunto' );
|
||||
|
||||
$dir = __DIR__ . '/';
|
||||
$wgMessagesDirs['Scribunto'] = __DIR__ . '/i18n';
|
||||
$wgExtensionMessagesFiles['Scribunto'] = $dir . 'Scribunto.i18n.php';
|
||||
|
@ -73,7 +75,7 @@ $wgHooks['ContentHandlerDefaultModelFor'][] = 'ScribuntoHooks::contentHandlerDef
|
|||
$wgHooks['UnitTestsList'][] = 'ScribuntoHooks::unitTestsList';
|
||||
$wgParserTestFiles[] = $dir . 'tests/engines/LuaCommon/luaParserTests.txt';
|
||||
|
||||
$wgContentHandlers['Scribunto'] = 'ScribuntoContentHandler';
|
||||
$wgContentHandlers[CONTENT_MODEL_SCRIBUNTO] = 'ScribuntoContentHandler';
|
||||
|
||||
$sbtpl = array(
|
||||
'localBasePath' => dirname( __FILE__ ) . '/modules',
|
||||
|
|
|
@ -92,8 +92,9 @@ class ScribuntoHooks {
|
|||
}
|
||||
$moduleName = trim( $frame->expand( $args[0] ) );
|
||||
$engine = Scribunto::getParserEngine( $parser );
|
||||
|
||||
$title = Title::makeTitleSafe( NS_MODULE, $moduleName );
|
||||
if ( !$title || Scribunto::isDocPage( $title ) ) {
|
||||
if ( !$title || !$title->hasContentModel( CONTENT_MODEL_SCRIBUNTO ) ) {
|
||||
throw new ScribuntoException( 'scribunto-common-nosuchmodule',
|
||||
array( 'args' => array( $moduleName ) ) );
|
||||
}
|
||||
|
@ -155,8 +156,7 @@ class ScribuntoHooks {
|
|||
*/
|
||||
public static function getCodeLanguage( Title $title, &$languageCode ) {
|
||||
global $wgScribuntoUseCodeEditor;
|
||||
if ( $wgScribuntoUseCodeEditor && $title->getNamespace() == NS_MODULE &&
|
||||
!Scribunto::isDocPage( $title )
|
||||
if ( $wgScribuntoUseCodeEditor && $title->hasContentModel( CONTENT_MODEL_SCRIBUNTO )
|
||||
) {
|
||||
$engine = Scribunto::newDefaultEngine();
|
||||
if ( $engine->getCodeEditorLanguage() ) {
|
||||
|
@ -177,7 +177,7 @@ class ScribuntoHooks {
|
|||
*/
|
||||
public static function contentHandlerDefaultModelFor( Title $title, &$model ) {
|
||||
if ( $title->getNamespace() == NS_MODULE && !Scribunto::isDocPage( $title ) ) {
|
||||
$model = 'Scribunto';
|
||||
$model = CONTENT_MODEL_SCRIBUNTO;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -254,17 +254,11 @@ class ScribuntoHooks {
|
|||
* @return bool
|
||||
*/
|
||||
public static function beforeEditChecks( EditPage &$editor, &$checkboxes, &$tabindex ) {
|
||||
if ( $editor->getTitle()->getNamespace() !== NS_MODULE ) {
|
||||
return true;
|
||||
if ( $editor->getTitle()->hasContentModel( CONTENT_MODEL_SCRIBUNTO ) ) {
|
||||
global $wgOut;
|
||||
$wgOut->addModules( 'ext.scribunto.edit' );
|
||||
$editor->editFormTextAfterTools = '<div id="mw-scribunto-console"></div>';
|
||||
}
|
||||
|
||||
if ( Scribunto::isDocPage( $editor->getTitle() ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
global $wgOut;
|
||||
$wgOut->addModules( 'ext.scribunto.edit' );
|
||||
$editor->editFormTextAfterTools = '<div id="mw-scribunto-console"></div>';
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -275,15 +269,9 @@ class ScribuntoHooks {
|
|||
* @param OutputPage $output
|
||||
*/
|
||||
public static function showReadOnlyFormInitial( EditPage $editor, OutputPage $output ) {
|
||||
if ( $editor->getTitle()->getNamespace() !== NS_MODULE ) {
|
||||
return true;
|
||||
if ( $editor->getTitle()->hasContentModel( CONTENT_MODEL_SCRIBUNTO ) ) {
|
||||
$output->addModules( 'ext.scribunto.edit' );
|
||||
}
|
||||
|
||||
if ( Scribunto::isDocPage( $editor->getTitle() ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$output->addModules( 'ext.scribunto.edit' );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -296,15 +284,9 @@ class ScribuntoHooks {
|
|||
* @return bool
|
||||
*/
|
||||
public static function beforeEditButtons( EditPage &$editor, array &$buttons, &$tabindex ) {
|
||||
if ( $editor->getTitle()->getNamespace() !== NS_MODULE ) {
|
||||
return true;
|
||||
if ( $editor->getTitle()->hasContentModel( CONTENT_MODEL_SCRIBUNTO ) ) {
|
||||
unset( $buttons['preview'] );
|
||||
}
|
||||
|
||||
if ( Scribunto::isDocPage( $editor->getTitle() ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
unset( $buttons['preview'] );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -319,11 +301,7 @@ class ScribuntoHooks {
|
|||
global $wgOut;
|
||||
$title = $editor->getTitle();
|
||||
|
||||
if ( $title->getNamespace() != NS_MODULE ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( Scribunto::isDocPage( $title ) ) {
|
||||
if ( !$title->hasContentModel( CONTENT_MODEL_SCRIBUNTO ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
class ScribuntoContent extends TextContent {
|
||||
|
||||
function __construct( $text ) {
|
||||
parent::__construct( $text, 'Scribunto' );
|
||||
parent::__construct( $text, CONTENT_MODEL_SCRIBUNTO );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -15,7 +15,7 @@ class ScribuntoContentHandler extends TextContentHandler {
|
|||
* @param string $modelId
|
||||
* @param string[] $formats
|
||||
*/
|
||||
public function __construct( $modelId = 'Scribunto', array $formats = array( CONTENT_FORMAT_TEXT ) ) {
|
||||
public function __construct( $modelId = CONTENT_MODEL_SCRIBUNTO, $formats = array( CONTENT_FORMAT_TEXT ) ) {
|
||||
parent::__construct( $modelId, $formats );
|
||||
}
|
||||
|
||||
|
|
|
@ -357,7 +357,7 @@ abstract class Scribunto_LuaEngine extends ScribuntoEngineBase {
|
|||
}
|
||||
$code .= "end\n";
|
||||
|
||||
if ( $params['title']->hasContentModel( 'Scribunto' ) ) {
|
||||
if ( $params['title']->hasContentModel( CONTENT_MODEL_SCRIBUNTO ) ) {
|
||||
$contentModule = $this->newModule(
|
||||
$params['content'], $params['title']->getPrefixedDBkey() );
|
||||
$contentInit = $contentModule->getInitChunk();
|
||||
|
@ -502,7 +502,7 @@ abstract class Scribunto_LuaEngine extends ScribuntoEngineBase {
|
|||
}
|
||||
|
||||
$title = Title::newFromText( $name );
|
||||
if ( !$title || $title->getNamespace() != NS_MODULE ) {
|
||||
if ( !$title || !$title->hasContentModel( CONTENT_MODEL_SCRIBUNTO ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
|
@ -927,7 +927,7 @@ class Scribunto_LuaError extends ScribuntoException {
|
|||
$src .= ':' . htmlspecialchars( $currentline );
|
||||
|
||||
$title = Title::newFromText( $short_src );
|
||||
if ( $title && $title->getNamespace() === NS_MODULE ) {
|
||||
if ( $title && $title->hasContentModel( CONTENT_MODEL_SCRIBUNTO ) ) {
|
||||
$title->setFragment( '#mw-ce-l' . $currentline );
|
||||
$src = Html::rawElement( 'a',
|
||||
array( 'href' => $title->getFullURL( 'action=edit' ) ),
|
||||
|
|
|
@ -162,7 +162,7 @@ class Scribunto_LuaSandboxEngine extends Scribunto_LuaEngine {
|
|||
if ( preg_match( '/^(.*?) *<([^<>]+):(\d+)>$/', $name, $m ) ) {
|
||||
$name = $m[1];
|
||||
$title = Title::newFromText( $m[2] );
|
||||
if ( $title && $title->getNamespace() === NS_MODULE ) {
|
||||
if ( $title && $title->hasContentModel( CONTENT_MODEL_SCRIBUNTO ) ) {
|
||||
$location = '<' . Linker::link( $title ) . ":{$m[3]}>";
|
||||
} else {
|
||||
$location = htmlspecialchars( "<{$m[2]}:{$m[3]}>" );
|
||||
|
|
Loading…
Reference in a new issue