MediaWiki  1.33.0
Preprocessor.php
Go to the documentation of this file.
1 <?php
25 
29 abstract 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  'end' => '}-',
54  'names' => [ 2 => null ],
55  'min' => 2,
56  'max' => 2,
57  ],
58  ];
59 
67  protected function cacheSetTree( $text, $flags, $tree ) {
68  $config = RequestContext::getMain()->getConfig();
69 
70  $length = strlen( $text );
71  $threshold = $config->get( 'PreprocessorCacheThreshold' );
72  if ( $threshold === false || $length < $threshold || $length > 1e6 ) {
73  return;
74  }
75 
77  $key = $cache->makeKey(
78  defined( 'static::CACHE_PREFIX' ) ? static::CACHE_PREFIX : static::class,
79  md5( $text ), $flags );
80  $value = sprintf( "%08d", static::CACHE_VERSION ) . $tree;
81 
82  $cache->set( $key, $value, 86400 );
83 
84  LoggerFactory::getInstance( 'Preprocessor' )
85  ->info( "Cached preprocessor output (key: $key)" );
86  }
87 
96  protected function cacheGetTree( $text, $flags ) {
97  $config = RequestContext::getMain()->getConfig();
98 
99  $length = strlen( $text );
100  $threshold = $config->get( 'PreprocessorCacheThreshold' );
101  if ( $threshold === false || $length < $threshold || $length > 1e6 ) {
102  return false;
103  }
104 
106 
107  $key = $cache->makeKey(
108  defined( 'static::CACHE_PREFIX' ) ? static::CACHE_PREFIX : static::class,
109  md5( $text ), $flags );
110 
111  $value = $cache->get( $key );
112  if ( !$value ) {
113  return false;
114  }
115 
116  $version = intval( substr( $value, 0, 8 ) );
117  if ( $version !== static::CACHE_VERSION ) {
118  return false;
119  }
120 
121  LoggerFactory::getInstance( 'Preprocessor' )
122  ->info( "Loaded preprocessor output from cache (key: $key)" );
123 
124  return substr( $value, 8 );
125  }
126 
132  abstract public function newFrame();
133 
142  abstract public function newCustomFrame( $args );
143 
150  abstract public function newPartNodeArray( $values );
151 
160  abstract public function preprocessToObj( $text, $flags = 0 );
161 }
162 
166 interface PPFrame {
167  const NO_ARGS = 1;
168  const NO_TEMPLATES = 2;
169  const STRIP_COMMENTS = 4;
170  const NO_IGNORE = 8;
171  const RECOVER_COMMENTS = 16;
172  const NO_TAGS = 32;
173 
174  const RECOVER_ORIG = self::NO_ARGS | self::NO_TEMPLATES | self::NO_IGNORE |
175  self::RECOVER_COMMENTS | self::NO_TAGS;
176 
179 
189  public function newChild( $args = false, $title = false, $indexOffset = 0 );
190 
198  public function cachedExpand( $key, $root, $flags = 0 );
199 
206  public function expand( $root, $flags = 0 );
207 
215  public function implodeWithFlags( $sep, $flags /*, ... */ );
216 
223  public function implode( $sep /*, ... */ );
224 
232  public function virtualImplode( $sep /*, ... */ );
233 
242  public function virtualBracketedImplode( $start, $sep, $end /*, ... */ );
243 
249  public function isEmpty();
250 
255  public function getArguments();
256 
261  public function getNumberedArguments();
262 
267  public function getNamedArguments();
268 
274  public function getArgument( $name );
275 
282  public function loopCheck( $title );
283 
288  public function isTemplate();
289 
301  public function setVolatile( $flag = true );
302 
312  public function isVolatile();
313 
326  public function getTTL();
327 
337  public function setTTL( $ttl );
338 
344  public function getTitle();
345 }
346 
360 interface PPNode {
366  public function getChildren();
367 
373  public function getFirstChild();
374 
379  public function getNextSibling();
380 
387  public function getChildrenOfType( $type );
388 
392  public function getLength();
393 
399  public function item( $i );
400 
414  public function getName();
415 
423  public function splitArg();
424 
430  public function splitExt();
431 
436  public function splitHeading();
437 }
PPFrame\isEmpty
isEmpty()
Returns true if there are no arguments in this frame.
PPFrame\getArguments
getArguments()
Returns all arguments of this frame.
Preprocessor\newCustomFrame
newCustomFrame( $args)
Create a new custom frame for programmatic use of parameter replacement as used in some extensions.
PPFrame\loopCheck
loopCheck( $title)
Returns true if the infinite loop check is OK, false if a loop is detected.
PPFrame\setTTL
setTTL( $ttl)
Set the TTL of the output of this frame and all of its ancestors.
PPFrame\getNamedArguments
getNamedArguments()
Returns all named arguments of this frame.
PPNode\item
item( $i)
Returns an item of an array-type node.
PPFrame\STRIP_COMMENTS
const STRIP_COMMENTS
Definition: Preprocessor.php:169
ObjectCache\getLocalClusterInstance
static getLocalClusterInstance()
Get the main cluster-local cache object.
Definition: ObjectCache.php:356
PPFrame\NO_ARGS
const NO_ARGS
Definition: Preprocessor.php:167
PPNode\splitArg
splitArg()
Split a "<part>" node into an associative array containing: name PPNode name index String index value...
Preprocessor\newPartNodeArray
newPartNodeArray( $values)
Create a new custom node for programmatic use of parameter replacement as used in some extensions.
PPFrame\NO_IGNORE
const NO_IGNORE
Definition: Preprocessor.php:170
PPNode\splitExt
splitExt()
Split an "<ext>" node into an associative array containing name, attr, inner and close All values in ...
PPNode\getFirstChild
getFirstChild()
Get the first child of a tree node.
Preprocessor\$rules
array $rules
Brace matching rules.
Definition: Preprocessor.php:36
PPFrame\getNumberedArguments
getNumberedArguments()
Returns all numbered arguments of this frame.
PPFrame\implode
implode( $sep)
Implode with no flags specified.
PPFrame\RECOVER_COMMENTS
const RECOVER_COMMENTS
Definition: Preprocessor.php:171
php
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:35
PPFrame\NO_TEMPLATES
const NO_TEMPLATES
Definition: Preprocessor.php:168
Preprocessor
Definition: Preprocessor.php:29
PPFrame\newChild
newChild( $args=false, $title=false, $indexOffset=0)
Create a child frame.
Preprocessor\newFrame
newFrame()
Create a new top-level frame for expansion of a page.
PPNode\getChildren
getChildren()
Get an array-type node containing the children of this node.
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
PPNode\getLength
getLength()
Returns the length of the array, or false if this is not an array-type node.
PPFrame\setVolatile
setVolatile( $flag=true)
Set the "volatile" flag.
PPFrame\getTitle
getTitle()
Get a title of frame.
PPNode
There are three types of nodes:
Definition: Preprocessor.php:360
PPFrame\RECOVER_ORIG
const RECOVER_ORIG
Definition: Preprocessor.php:174
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
PPNode\getChildrenOfType
getChildrenOfType( $type)
Get all children of this tree node which have a given name.
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
null
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:780
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271
PPFrame\implodeWithFlags
implodeWithFlags( $sep, $flags)
Implode with flags for expand()
PPNode\getName
getName()
Get the name of this node.
PPFrame\expand
expand( $root, $flags=0)
Expand a document tree node.
$value
$value
Definition: styleTest.css.php:49
PPFrame\NO_TAGS
const NO_TAGS
Definition: Preprocessor.php:172
PPFrame
Definition: Preprocessor.php:166
RequestContext\getMain
static getMain()
Get the RequestContext object associated with the main request.
Definition: RequestContext.php:430
PPFrame\isVolatile
isVolatile()
Get the "volatile" flag.
Preprocessor\CACHE_VERSION
const CACHE_VERSION
Definition: Preprocessor.php:31
$args
if( $line===false) $args
Definition: cdb.php:64
Preprocessor\cacheSetTree
cacheSetTree( $text, $flags, $tree)
Store a document tree in the cache.
Definition: Preprocessor.php:67
$cache
$cache
Definition: mcc.php:33
Preprocessor\preprocessToObj
preprocessToObj( $text, $flags=0)
Preprocess text to a PPNode.
PPFrame\cachedExpand
cachedExpand( $key, $root, $flags=0)
Expand a document tree node, caching the result on its parent with the given key.
LoggerFactory
MediaWiki Logger LoggerFactory implements a PSR[0] compatible message logging system Named Psr Log LoggerInterface instances can be obtained from the MediaWiki Logger LoggerFactory::getInstance() static method. MediaWiki\Logger\LoggerFactory expects a class implementing the MediaWiki\Logger\Spi interface to act as a factory for new Psr\Log\LoggerInterface instances. The "Spi" in MediaWiki\Logger\Spi stands for "service provider interface". An SPI is an API intended to be implemented or extended by a third party. This software design pattern is intended to enable framework extension and replaceable components. It is specifically used in the MediaWiki\Logger\LoggerFactory service to allow alternate PSR-3 logging implementations to be easily integrated with MediaWiki. The service provider interface allows the backend logging library to be implemented in multiple ways. The $wgMWLoggerDefaultSpi global provides the classname of the default MediaWiki\Logger\Spi implementation to be loaded at runtime. This can either be the name of a class implementing the MediaWiki\Logger\Spi with a zero argument const ructor or a callable that will return an MediaWiki\Logger\Spi instance. Alternately the MediaWiki\Logger\LoggerFactory MediaWiki Logger LoggerFactory
Definition: logger.txt:5
PPFrame\getArgument
getArgument( $name)
Get an argument to this frame by name.
PPFrame\virtualBracketedImplode
virtualBracketedImplode( $start, $sep, $end)
Virtual implode with brackets.
PPFrame\SUPPORTS_INDEX_OFFSET
const SUPPORTS_INDEX_OFFSET
This constant exists when $indexOffset is supported in newChild()
Definition: Preprocessor.php:178
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
PPFrame\isTemplate
isTemplate()
Return true if the frame is a template frame.
PPNode\getNextSibling
getNextSibling()
Get the next sibling of any node.
Preprocessor\cacheGetTree
cacheGetTree( $text, $flags)
Attempt to load a precomputed document tree for some given wikitext from the cache.
Definition: Preprocessor.php:96
PPFrame\virtualImplode
virtualImplode( $sep)
Makes an object that, when expand()ed, will be the same as one obtained with implode()
PPNode\splitHeading
splitHeading()
Split an "<h>" node.
PPFrame\getTTL
getTTL()
Get the TTL of the frame's output.
$type
$type
Definition: testCompression.php:48