MediaWiki REL1_28
Preprocessor.php
Go to the documentation of this file.
1<?php
25
29abstract class Preprocessor {
30
31 const CACHE_VERSION = 1;
32
36 protected $rules = [
37 '{' => [
38 'end' => '}',
39 'names' => [
40 2 => 'template',
41 3 => 'tplarg',
42 ],
43 'min' => 2,
44 'max' => 3,
45 ],
46 '[' => [
47 'end' => ']',
48 'names' => [ 2 => null ],
49 'min' => 2,
50 'max' => 2,
51 ]
52 ];
53
60 protected function cacheSetTree( $text, $flags, $tree ) {
61 $config = RequestContext::getMain()->getConfig();
62
63 $length = strlen( $text );
64 $threshold = $config->get( 'PreprocessorCacheThreshold' );
65 if ( $threshold === false || $length < $threshold || $length > 1e6 ) {
66 return false;
67 }
68
69 $key = wfMemcKey(
70 defined( 'static::CACHE_PREFIX' ) ? static::CACHE_PREFIX : static::class,
71 md5( $text ), $flags );
72 $value = sprintf( "%08d", static::CACHE_VERSION ) . $tree;
73
74 $cache = ObjectCache::getInstance( $config->get( 'MainCacheType' ) );
75 $cache->set( $key, $value, 86400 );
76
77 LoggerFactory::getInstance( 'Preprocessor' )
78 ->info( "Cached preprocessor output (key: $key)" );
79 }
80
89 protected function cacheGetTree( $text, $flags ) {
90 $config = RequestContext::getMain()->getConfig();
91
92 $length = strlen( $text );
93 $threshold = $config->get( 'PreprocessorCacheThreshold' );
94 if ( $threshold === false || $length < $threshold || $length > 1e6 ) {
95 return false;
96 }
97
98 $cache = ObjectCache::getInstance( $config->get( 'MainCacheType' ) );
99
100 $key = wfMemcKey(
101 defined( 'static::CACHE_PREFIX' ) ? static::CACHE_PREFIX : static::class,
102 md5( $text ), $flags );
103
104 $value = $cache->get( $key );
105 if ( !$value ) {
106 return false;
107 }
108
109 $version = intval( substr( $value, 0, 8 ) );
110 if ( $version !== static::CACHE_VERSION ) {
111 return false;
112 }
113
114 LoggerFactory::getInstance( 'Preprocessor' )
115 ->info( "Loaded preprocessor output from cache (key: $key)" );
116
117 return substr( $value, 8 );
118 }
119
125 abstract public function newFrame();
126
135 abstract public function newCustomFrame( $args );
136
143 abstract public function newPartNodeArray( $values );
144
153 abstract public function preprocessToObj( $text, $flags = 0 );
154}
155
159interface PPFrame {
160 const NO_ARGS = 1;
161 const NO_TEMPLATES = 2;
162 const STRIP_COMMENTS = 4;
163 const NO_IGNORE = 8;
165 const NO_TAGS = 32;
166
167 const RECOVER_ORIG = 59; // = 1|2|8|16|32 no constant expression support in PHP yet
168
171
181 public function newChild( $args = false, $title = false, $indexOffset = 0 );
182
190 public function cachedExpand( $key, $root, $flags = 0 );
191
198 public function expand( $root, $flags = 0 );
199
207 public function implodeWithFlags( $sep, $flags /*, ... */ );
208
215 public function implode( $sep /*, ... */ );
216
224 public function virtualImplode( $sep /*, ... */ );
225
234 public function virtualBracketedImplode( $start, $sep, $end /*, ... */ );
235
241 public function isEmpty();
242
247 public function getArguments();
248
253 public function getNumberedArguments();
254
259 public function getNamedArguments();
260
266 public function getArgument( $name );
267
274 public function loopCheck( $title );
275
280 public function isTemplate();
281
293 public function setVolatile( $flag = true );
294
304 public function isVolatile();
305
318 public function getTTL();
319
329 public function setTTL( $ttl );
330
336 public function getTitle();
337}
338
352interface PPNode {
358 public function getChildren();
359
365 public function getFirstChild();
366
371 public function getNextSibling();
372
379 public function getChildrenOfType( $type );
380
384 public function getLength();
385
391 public function item( $i );
392
406 public function getName();
407
415 public function splitArg();
416
422 public function splitExt();
423
428 public function splitHeading();
429}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
wfMemcKey()
Make a cache key for the local wiki.
if( $line===false) $args
Definition cdb.php:64
PSR-3 logger instance factory.
preprocessToObj( $text, $flags=0)
Preprocess text to a PPNode.
cacheGetTree( $text, $flags)
Attempt to load a precomputed document tree for some given wikitext from the cache.
array $rules
Brace matching rules.
newPartNodeArray( $values)
Create a new custom node for programmatic use of parameter replacement as used in some extensions.
cacheSetTree( $text, $flags, $tree)
Store a document tree in the cache.
const CACHE_VERSION
newFrame()
Create a new top-level frame for expansion of a page.
newCustomFrame( $args)
Create a new custom frame for programmatic use of parameter replacement as used in some extensions.
static getMain()
Static methods.
the array() calling protocol came about after MediaWiki 1.4rc1.
namespace are movable Hooks may change this value to override the return value of MWNamespace::isMovable(). 'NewDifferenceEngine' do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached one of or reset my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type
Definition hooks.txt:2568
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition hooks.txt:2710
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
isEmpty()
Returns true if there are no arguments in this frame.
getArguments()
Returns all arguments of this frame.
const NO_TEMPLATES
const SUPPORTS_INDEX_OFFSET
This constant exists when $indexOffset is supported in newChild()
getTTL()
Get the TTL of the frame's output.
getArgument( $name)
Get an argument to this frame by name.
cachedExpand( $key, $root, $flags=0)
Expand a document tree node, caching the result on its parent with the given key.
const NO_TAGS
getNumberedArguments()
Returns all numbered arguments of this frame.
isVolatile()
Get the "volatile" flag.
virtualBracketedImplode( $start, $sep, $end)
Virtual implode with brackets.
const RECOVER_ORIG
implodeWithFlags( $sep, $flags)
Implode with flags for expand()
const RECOVER_COMMENTS
implode( $sep)
Implode with no flags specified.
const NO_ARGS
const NO_IGNORE
setTTL( $ttl)
Set the TTL of the output of this frame and all of its ancestors.
loopCheck( $title)
Returns true if the infinite loop check is OK, false if a loop is detected.
virtualImplode( $sep)
Makes an object that, when expand()ed, will be the same as one obtained with implode()
expand( $root, $flags=0)
Expand a document tree node.
isTemplate()
Return true if the frame is a template frame.
const STRIP_COMMENTS
getTitle()
Get a title of frame.
getNamedArguments()
Returns all named arguments of this frame.
newChild( $args=false, $title=false, $indexOffset=0)
Create a child frame.
setVolatile( $flag=true)
Set the "volatile" flag.
There are three types of nodes:
item( $i)
Returns an item of an array-type node.
getLength()
Returns the length of the array, or false if this is not an array-type node.
splitArg()
Split a "<part>" node into an associative array containing: name PPNode name index String index value...
splitExt()
Split an "<ext>" node into an associative array containing name, attr, inner and close All values in ...
getFirstChild()
Get the first child of a tree node.
getName()
Get the name of this node.
getChildren()
Get an array-type node containing the children of this node.
getChildrenOfType( $type)
Get all children of this tree node which have a given name.
splitHeading()
Split an "<h>" node.
getNextSibling()
Get the next sibling of any node.
$cache
Definition mcc.php:33