MediaWiki master
Preprocessor.php
Go to the documentation of this file.
1<?php
24namespace MediaWiki\Parser;
25
27
31abstract class Preprocessor {
33 public const DOM_FOR_INCLUSION = 1;
37 public const DOM_UNCACHED = 4;
38 // Does preprocessing start in Start-Of-Line(SOL) state? Only relevant for Parsoid
39 // content, since Parsoid models templates as independent documents in SOL start.
40 // This flag is never set by the legacy parser (but see T2529 which has a similar
41 // effect).
42 public const START_IN_SOL_STATE = 8;
43
45 public $parser;
46
48 protected $wanCache;
49
52
54 protected $rules = [
55 '{' => [
56 'end' => '}',
57 'names' => [
58 2 => 'template',
59 3 => 'tplarg',
60 ],
61 'min' => 2,
62 'max' => 3,
63 ],
64 '[' => [
65 'end' => ']',
66 'names' => [ 2 => null ],
67 'min' => 2,
68 'max' => 2,
69 ],
70 '-{' => [
71 'end' => '}-',
72 'names' => [ 2 => null ],
73 'min' => 2,
74 'max' => 2,
75 ],
76 ];
77
84 public function __construct(
87 array $options = []
88 ) {
89 $this->parser = $parser;
90 $this->wanCache = $wanCache ?: WANObjectCache::newEmpty();
91 $this->disableLangConversion = !empty( $options['disableLangConversion'] );
92 }
93
104 public function resetParser( ?Parser $parser ) {
105 // @phan-suppress-next-line PhanPossiblyNullTypeMismatchProperty For internal use only
106 $this->parser = $parser;
107 }
108
114 abstract public function newFrame();
115
124 abstract public function newCustomFrame( $args );
125
133 abstract public function newPartNodeArray( $values );
134
154 abstract public function preprocessToObj( $text, $flags = 0 );
155}
156
158class_alias( Preprocessor::class, 'Preprocessor' );
PHP Parser - Processes wiki markup (which uses a more user-friendly syntax, such as "[[link]]" for ma...
Definition Parser.php:147
resetParser(?Parser $parser)
Allows resetting the internal Parser reference after Preprocessor is cloned.
__construct(Parser $parser, ?WANObjectCache $wanCache=null, array $options=[])
newPartNodeArray( $values)
Create a new custom node for programmatic use of parameter replacement.
newFrame()
Create a new top-level frame for expansion of a page.
const DOM_UNCACHED
Preprocessor cache bypass flag for Preprocessor::preprocessToObj.
const DOM_LANG_CONVERSION_DISABLED
Language conversion construct omission flag for Preprocessor::preprocessToObj()
preprocessToObj( $text, $flags=0)
Get the document object model for the given wikitext.
const DOM_FOR_INCLUSION
Transclusion mode flag for Preprocessor::preprocessToObj()
newCustomFrame( $args)
Create a new custom frame for programmatic use of parameter replacement.
array $rules
Brace matching rules.
bool $disableLangConversion
Whether language variant conversion is disabled.
Multi-datacenter aware caching interface.