MediaWiki REL1_34
Base.php
Go to the documentation of this file.
1<?php
2
29abstract class ScribuntoEngineBase {
30
31 // Flags for ScribuntoEngineBase::getResourceUsage()
32 const CPU_SECONDS = 1;
33 const MEM_PEAK_BYTES = 2;
34
38 protected $title;
39
43 protected $options;
44
48 protected $modules = [];
49
53 protected $parser;
54
62 abstract protected function newModule( $text, $chunkName );
63
77 abstract public function runConsole( array $params );
78
83 abstract public function getSoftwareInfo( array &$software );
84
89 public function __construct( array $options ) {
90 $this->options = $options;
91 if ( isset( $options['parser'] ) ) {
92 $this->parser = $options['parser'];
93 }
94 if ( isset( $options['title'] ) ) {
95 $this->title = $options['title'];
96 }
97 }
98
99 public function __destruct() {
100 $this->destroy();
101 }
102
103 public function destroy() {
104 // Break reference cycles
105 $this->parser = null;
106 $this->title = null;
107 $this->modules = null;
108 }
109
113 public function setTitle( $title ) {
114 $this->title = $title;
115 }
116
120 public function getTitle() {
121 return $this->title;
122 }
123
130 public function getOption( $optionName ) {
131 return $this->options[$optionName] ?? null;
132 }
133
139 public function newException( $message, array $params = [] ) {
140 return new ScribuntoException( $message, $this->getDefaultExceptionParams() + $params );
141 }
142
146 public function getDefaultExceptionParams() {
147 $params = [];
148 if ( $this->title ) {
149 $params['title'] = $this->title;
150 }
151 return $params;
152 }
153
164 public function fetchModuleFromParser( Title $title ) {
165 $key = $title->getPrefixedDBkey();
166 if ( !array_key_exists( $key, $this->modules ) ) {
167 list( $text, $finalTitle ) = $this->parser->fetchTemplateAndTitle( $title );
168 if ( $text === false ) {
169 $this->modules[$key] = null;
170 return null;
171 }
172
173 $finalKey = $finalTitle->getPrefixedDBkey();
174 if ( !isset( $this->modules[$finalKey] ) ) {
175 $this->modules[$finalKey] = $this->newModule( $text, $finalKey );
176 }
177 // Almost certainly $key === $finalKey, but just in case...
178 $this->modules[$key] = $this->modules[$finalKey];
179 }
180 return $this->modules[$key];
181 }
182
191 public function validate( $text, $chunkName = false ) {
192 $module = $this->newModule( $text, $chunkName );
193 return $module->validate();
194 }
195
208 public function getResourceUsage( $resource ) {
209 return false;
210 }
211
216 public function getGeSHiLanguage() {
217 return false;
218 }
219
224 public function getCodeEditorLanguage() {
225 return false;
226 }
227
231 public function getParser() {
232 return $this->parser;
233 }
234
249 protected function getLibraries( $engine, array $coreLibraries = [] ) {
250 $extraLibraries = [];
251 Hooks::run( 'ScribuntoExternalLibraries', [ $engine, &$extraLibraries ] );
252 return $coreLibraries + $extraLibraries;
253 }
254
262 protected function getLibraryPaths( $engine, array $coreLibraryPaths = [] ) {
263 $extraLibraryPaths = [];
264 Hooks::run( 'ScribuntoExternalLibraryPaths', [ $engine, &$extraLibraryPaths ] );
265 return array_merge( $coreLibraryPaths, $extraLibraryPaths );
266 }
267
274 public function reportLimitData( ParserOutput $output ) {
275 }
276
287 public function formatLimitData( $key, &$value, &$report, $isHTML, $localize ) {
288 return true;
289 }
290}
291
296abstract class ScribuntoModuleBase {
300 protected $engine;
301
305 protected $code;
306
310 protected $chunkName;
311
318 $this->engine = $engine;
319 $this->code = $code;
320 $this->chunkName = $chunkName;
321 }
322
326 public function getEngine() {
327 return $this->engine;
328 }
329
333 public function getCode() {
334 return $this->code;
335 }
336
340 public function getChunkName() {
341 return $this->chunkName;
342 }
343
350 abstract public function validate();
351
359 abstract public function invoke( $name, $frame );
360}
PHP Parser - Processes wiki markup (which uses a more user-friendly syntax, such as "[[link]]" for ma...
Definition Parser.php:74
Wikitext scripting infrastructure for MediaWiki: base classes.
Definition Base.php:29
getLibraryPaths( $engine, array $coreLibraryPaths=[])
Load a list of all paths libraries can be in for this engine.
Definition Base.php:262
reportLimitData(ParserOutput $output)
Add limit report data to a ParserOutput object.
Definition Base.php:274
const CPU_SECONDS
Definition Base.php:32
getDefaultExceptionParams()
Definition Base.php:146
runConsole(array $params)
Run an interactive console request.
getOption( $optionName)
Get an element from the configuration array.
Definition Base.php:130
newException( $message, array $params=[])
Definition Base.php:139
getGeSHiLanguage()
Get the language for GeSHi syntax highlighter.
Definition Base.php:216
ScribuntoModuleBase[] $modules
Definition Base.php:48
getLibraries( $engine, array $coreLibraries=[])
Load a list of all libraries supported by this engine.
Definition Base.php:249
fetchModuleFromParser(Title $title)
Load a module from some parser-defined template loading mechanism and register a parser output depend...
Definition Base.php:164
getSoftwareInfo(array &$software)
Get software information for Special:Version.
newModule( $text, $chunkName)
Creates a new module object within this engine.
getResourceUsage( $resource)
Get CPU and memory usage information, if the script engine provides it.
Definition Base.php:208
validate( $text, $chunkName=false)
Validates the script and returns a Status object containing the syntax errors for the given code.
Definition Base.php:191
setTitle( $title)
Definition Base.php:113
__construct(array $options)
Definition Base.php:89
const MEM_PEAK_BYTES
Definition Base.php:33
getCodeEditorLanguage()
Get the language for Ace code editor.
Definition Base.php:224
formatLimitData( $key, &$value, &$report, $isHTML, $localize)
Format limit report data.
Definition Base.php:287
An exception class which represents an error in the script.
Definition Common.php:136
Class that represents a module.
Definition Base.php:296
validate()
Validates the script and returns a Status object containing the syntax errors for the given code.
invoke( $name, $frame)
Invoke the function with the specified name.
string bool $chunkName
Definition Base.php:310
__construct(ScribuntoEngineBase $engine, $code, $chunkName)
Definition Base.php:317
ScribuntoEngineBase $engine
Definition Base.php:300
Represents a title within MediaWiki.
Definition Title.php:42
getPrefixedDBkey()
Get the prefixed database key form.
Definition Title.php:1806