Go to the documentation of this file.
24 use UtfNormal\Validator;
25 use Wikimedia\PSquare;
36 define(
'CONTENT_MODEL_SCRIBUNTO',
'Scribunto' );
48 $engine->getSoftwareInfo( $software );
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 ) );
147 if ( $trace !==
false ) {
150 wfMessage(
'scribunto-common-backtrace' )->inContentLanguage()->text()
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()
static validateScript(IContextSource $context, Content $content, Status $status)
Hooks for the Scribunto extension.
A BagOStuff object with no objects in it.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
static isParserEnginePresent(Parser $parser)
Check if an engine instance is present in the given parser.
static encodeJsVar( $value, $pretty=false)
Encode a variable of arbitrary type to JavaScript.
newChild( $args=false, $title=false, $indexOffset=0)
Create a child frame.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
static reportTiming( $moduleName, $functionName, $timing)
Record stats on slow function calls.
static getCodeLanguage(Title $title, &$languageCode)
static newDefaultEngine( $extraOptions=[])
Create a new engine object with default parameters.
static getParserEngine(Parser $parser)
Get an engine instance for the given parser, and cache it in the parser so that subsequent calls to t...
Represents the content of a Scribunto script page.
getTitle()
Get the title object of the article.
static onRegistration()
Define content handler constant upon extension registration.
static showStandardInputsOptions(EditPage $editor, OutputPage $output, &$tab)
EditPage::showStandardInputs:options hook.
merge( $other, $overwriteValue=false)
Merge another status object into this one.
getContext()
Gets the context this Article is executed in.
addModules( $modules)
Load one or more ResourceLoader modules on this page.
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
getScriptTraceHtml( $options=[])
Get the backtrace as HTML, or false if there is none available.
static clearState(Parser &$parser)
Called when the interpreter is to be reset.
static getSoftwareInfo(array &$software)
Get software information for Special:Version.
This is one of the Core classes and should be read at least once by any new developers.
static parserCloned(Parser $parser)
Called when the parser is cloned.
addTrackingCategory( $msg)
static resetParserEngine(Parser $parser)
Remove the current engine instance from the parser.
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
expand( $root, $flags=0)
Expand a document tree node.
setFunctionHook( $id, callable $callback, $flags=0)
Create a function, e.g.
static invokeHook(Parser &$parser, PPFrame $frame, array $args)
Hook function for {{#invoke:module|func}}.
PHP Parser - Processes wiki markup (which uses a more user-friendly syntax, such as "[[link]]" for ma...
An exception class which represents an error in the script.
The edit page/HTML interface (split from Article) The actual database and text munging is still in Ar...
Interface for objects which can provide a MediaWiki context on request.
Base interface for content objects.
static setupParserHook(Parser &$parser)
Register parser hooks.
Represents a title within MediaWiki.
getOutput()
Get the ParserOutput object.
static showDocPageHeader(Article &$article, &$outputDone, &$pcache)
static beforeEditButtons(EditPage &$editor, array &$buttons, &$tabindex)
EditPageBeforeEditButtons hook.
static reportLimitData(Parser $parser, ParserOutput $output)
Adds report of number of evaluations by the single wikitext page.
static contentHandlerDefaultModelFor(Title $title, &$model)
Set the Scribunto content handler for modules.
Class for viewing MediaWiki article and history.
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
static isDocPage(Title $title, Title &$forModule=null)
Test whether the page should be considered a documentation page.
static formatLimitData( $key, &$value, &$report, $isHTML, $localize)
Formats the limit report data.
static getLocalServerInstance( $fallback=CACHE_NONE)
Factory function for CACHE_ACCEL (referenced from DefaultSettings.php)
static showReadOnlyFormInitial(EditPage $editor, OutputPage $output)
EditPage::showReadOnlyForm:initial hook.