24use UtfNormal\Validator;
36 define(
'CONTENT_MODEL_SCRIBUNTO',
'Scribunto' );
47 $engine->setTitle( Title::makeTitle(
NS_SPECIAL,
'Version' ) );
48 $engine->getSoftwareInfo( $software );
59 $parser->
setFunctionHook(
'invoke',
'ScribuntoHooks::invokeHook', Parser::SFH_OBJECT_ARGS );
81 $parser->scribunto_engine =
null;
96 global $wgScribuntoGatherFunctionStats;
99 if ( count(
$args ) < 2 ) {
106 if ( !
$title || !
$title->hasContentModel( CONTENT_MODEL_SCRIBUNTO ) ) {
108 [
'args' => [ $moduleName ] ] );
110 $module = $engine->fetchModuleFromParser(
$title );
113 [
'args' => [ $moduleName ] ] );
115 $functionName = trim( $frame->
expand(
$args[1] ) );
117 $bits =
$args[1]->splitArg();
126 if ( $wgScribuntoGatherFunctionStats ) {
127 $u0 = $engine->getResourceUsage( $engine::CPU_SECONDS );
128 $result = $module->invoke( $functionName, $childFrame );
129 $u1 = $engine->getResourceUsage( $engine::CPU_SECONDS );
132 $timingMs = (int)( 1000 * ( $u1 - $u0 ) );
135 if ( $timingMs > 20 ) {
140 $result = $module->invoke( $functionName, $childFrame );
143 return Validator::cleanUp( strval( $result ) );
146 $html = Html::element(
'p', [], $e->getMessage() );
147 if ( $trace !==
false ) {
148 $html .= Html::element(
'p',
150 wfMessage(
'scribunto-common-backtrace' )->inContentLanguage()->text()
153 $html .= Html::element(
'p',
155 wfMessage(
'scribunto-common-no-details' )->inContentLanguage()->text()
159 $errors = $out->getExtensionData(
'ScribuntoErrors' );
160 if ( $errors ===
null ) {
164 $out->addModules(
'ext.scribunto.errors' );
167 $out->setExtensionData(
'ScribuntoErrors', $errors );
168 $out->addJsConfigVars(
'ScribuntoErrors', $errors );
169 $id =
'mw-scribunto-error-' . ( count( $errors ) - 1 );
170 $parserError = htmlspecialchars( $e->getMessage() );
173 return "<strong class=\"error\"><span class=\"scribunto-error\" id=\"$id\">" .
174 $parserError .
"</span></strong>";
185 public static function reportTiming( $moduleName, $functionName, $timing ) {
186 global $wgScribuntoGatherFunctionStats, $wgScribuntoSlowFunctionThreshold;
188 if ( !$wgScribuntoGatherFunctionStats ) {
192 $threshold = $wgScribuntoSlowFunctionThreshold;
193 if ( !( is_float( $threshold ) && $threshold > 0 && $threshold < 1 ) ) {
213 $key =
$cache->makeGlobalKey( __METHOD__, $cacheVersion, $threshold );
219 $ps =
$cache->get( $key ) ?:
new PSquare( $threshold );
220 $ps->addObservation( $timing );
221 $cache->set( $key, $ps, 60 );
223 if ( $ps->getCount() < 1000 || $timing < $ps->getValue() ) {
230 $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
233 $metricKey = sprintf(
'scribunto.traces.%s__%s__%s', wfWikiId(), $moduleName, $functionName );
234 $stats->timing( $metricKey, $timing );
243 global $wgScribuntoUseCodeEditor;
244 if ( $wgScribuntoUseCodeEditor &&
$title->hasContentModel( CONTENT_MODEL_SCRIBUNTO )
247 if ( $engine->getCodeEditorLanguage() ) {
248 $languageCode = $engine->getCodeEditorLanguage();
264 if ( $model ===
'sanitized-css' ) {
269 $model = CONTENT_MODEL_SCRIBUNTO;
285 $engine->reportLimitData( $output );
300 public static function formatLimitData( $key, &$value, &$report, $isHTML, $localize ) {
302 return $engine->formatLimitData( $key, $value, $report, $isHTML, $localize );
314 if ( $editor->
getTitle()->hasContentModel( CONTENT_MODEL_SCRIBUNTO ) ) {
316 $editor->editFormTextAfterTools .=
'<div id="mw-scribunto-console"></div>';
329 if ( $editor->
getTitle()->hasContentModel( CONTENT_MODEL_SCRIBUNTO ) ) {
331 $editor->editFormTextAfterContent .=
'<div id="mw-scribunto-console"></div>';
345 if ( $editor->
getTitle()->hasContentModel( CONTENT_MODEL_SCRIBUNTO ) ) {
346 unset( $buttons[
'preview'] );
367 if ( $validateStatus->isOK() ) {
371 $status->
merge( $validateStatus );
373 if ( isset( $validateStatus->scribunto_error->params[
'module'] ) ) {
374 $module = $validateStatus->scribunto_error->params[
'module'];
375 $line = $validateStatus->scribunto_error->params[
'line'];
376 if ( $module ===
$title->getPrefixedDBkey() && preg_match(
'/^\d+$/',
$line ) ) {
378 $out->addInlineScript(
'window.location.hash = ' . Xml::encodeJsVar(
"#mw-ce-l$line" ) );
395 wfMessage(
'scribunto-doc-page-header', $forModule->getPrefixedText() )->parseAsBlock()
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Class for viewing MediaWiki article and history.
getContext()
Gets the context this Article is executed in.
getTitle()
Get the title object of the article.
The edit page/HTML interface (split from Article) The actual database and text munging is still in Ar...
A BagOStuff object with no objects in it.
This is one of the Core classes and should be read at least once by any new developers.
addModules( $modules)
Load one or more ResourceLoader modules on this page.
PHP Parser - Processes wiki markup (which uses a more user-friendly syntax, such as "[[link]]" for ma...
addTrackingCategory( $msg)
setFunctionHook( $id, callable $callback, $flags=0)
Create a function, e.g.
getOutput()
Get the ParserOutput object.
Represents the content of a Scribunto script page.
An exception class which represents an error in the script.
getScriptTraceHtml( $options=[])
Get the backtrace as HTML, or false if there is none available.
Hooks for the Scribunto extension.
static showStandardInputsOptions(EditPage $editor, OutputPage $output, &$tab)
EditPage::showStandardInputs:options hook.
static contentHandlerDefaultModelFor(Title $title, &$model)
Set the Scribunto content handler for modules.
static beforeEditButtons(EditPage &$editor, array &$buttons, &$tabindex)
EditPageBeforeEditButtons hook.
static showReadOnlyFormInitial(EditPage $editor, OutputPage $output)
EditPage::showReadOnlyForm:initial hook.
static formatLimitData( $key, &$value, &$report, $isHTML, $localize)
Formats the limit report data.
static validateScript(IContextSource $context, Content $content, Status $status)
static getCodeLanguage(Title $title, &$languageCode)
static onRegistration()
Define content handler constant upon extension registration.
static parserCloned(Parser $parser)
Called when the parser is cloned.
static reportLimitData(Parser $parser, ParserOutput $output)
Adds report of number of evaluations by the single wikitext page.
static showDocPageHeader(Article &$article, &$outputDone, &$pcache)
static setupParserHook(Parser &$parser)
Register parser hooks.
static invokeHook(Parser &$parser, PPFrame $frame, array $args)
Hook function for {{#invoke:module|func}}.
static clearState(Parser &$parser)
Called when the interpreter is to be reset.
static getSoftwareInfo(array &$software)
Get software information for Special:Version.
static reportTiming( $moduleName, $functionName, $timing)
Record stats on slow function calls.
static newDefaultEngine( $extraOptions=[])
Create a new engine object with default parameters.
static isParserEnginePresent(Parser $parser)
Check if an engine instance is present in the given parser.
static isDocPage(Title $title, Title &$forModule=null)
Test whether the page should be considered a documentation page.
static getParserEngine(Parser $parser)
Get an engine instance for the given parser, and cache it in the parser so that subsequent calls to t...
static resetParserEngine(Parser $parser)
Remove the current engine instance from the parser.
merge( $other, $overwriteValue=false)
Merge another status object into this one.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Represents a title within MediaWiki.
Base interface for content objects.
Interface for objects which can provide a MediaWiki context on request.
expand( $root, $flags=0)
Expand a document tree node.
newChild( $args=false, $title=false, $indexOffset=0)
Create a child frame.