MediaWiki  master
Preprocessor.php
Go to the documentation of this file.
1 <?php
26 
30 abstract class Preprocessor {
31 
32  const CACHE_VERSION = 1;
33 
37  protected $rules = [
38  '{' => [
39  'end' => '}',
40  'names' => [
41  2 => 'template',
42  3 => 'tplarg',
43  ],
44  'min' => 2,
45  'max' => 3,
46  ],
47  '[' => [
48  'end' => ']',
49  'names' => [ 2 => null ],
50  'min' => 2,
51  'max' => 2,
52  ],
53  '-{' => [
54  'end' => '}-',
55  'names' => [ 2 => null ],
56  'min' => 2,
57  'max' => 2,
58  ],
59  ];
60 
68  protected function cacheSetTree( $text, $flags, $tree ) {
69  $config = RequestContext::getMain()->getConfig();
70 
71  $length = strlen( $text );
72  $threshold = $config->get( 'PreprocessorCacheThreshold' );
73  if ( $threshold === false || $length < $threshold || $length > 1e6 ) {
74  return;
75  }
76 
77  $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
78  $key = $cache->makeKey(
79  defined( 'static::CACHE_PREFIX' ) ? static::CACHE_PREFIX : static::class,
80  md5( $text ),
81  $flags
82  );
83  $value = sprintf( "%08d", static::CACHE_VERSION ) . $tree;
84 
85  $cache->set( $key, $value, 86400 );
86 
87  LoggerFactory::getInstance( 'Preprocessor' )
88  ->info( "Cached preprocessor output (key: $key)" );
89  }
90 
99  protected function cacheGetTree( $text, $flags ) {
100  $config = RequestContext::getMain()->getConfig();
101 
102  $length = strlen( $text );
103  $threshold = $config->get( 'PreprocessorCacheThreshold' );
104  if ( $threshold === false || $length < $threshold || $length > 1e6 ) {
105  return false;
106  }
107 
108  $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
109 
110  $key = $cache->makeKey(
111  defined( 'static::CACHE_PREFIX' ) ? static::CACHE_PREFIX : static::class,
112  md5( $text ),
113  $flags
114  );
115 
116  $value = $cache->get( $key );
117  if ( !$value ) {
118  return false;
119  }
120 
121  $version = intval( substr( $value, 0, 8 ) );
122  if ( $version !== static::CACHE_VERSION ) {
123  return false;
124  }
125 
126  LoggerFactory::getInstance( 'Preprocessor' )
127  ->info( "Loaded preprocessor output from cache (key: $key)" );
128 
129  return substr( $value, 8 );
130  }
131 
137  abstract public function newFrame();
138 
147  abstract public function newCustomFrame( $args );
148 
155  abstract public function newPartNodeArray( $values );
156 
165  abstract public function preprocessToObj( $text, $flags = 0 );
166 }
array $rules
Brace matching rules.
cacheGetTree( $text, $flags)
Attempt to load a precomputed document tree for some given wikitext from the cache.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
$value
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 MediaWikiServices
Definition: injection.txt:23
if( $line===false) $args
Definition: cdb.php:64
static getMain()
Get the RequestContext object associated with the main request.
newCustomFrame( $args)
Create a new custom frame for programmatic use of parameter replacement as used in some extensions...
$cache
Definition: mcc.php:33
const CACHE_VERSION
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
array cacheSetTree( $text, $flags, $tree)
Store a document tree in the cache.
newPartNodeArray( $values)
Create a new custom node for programmatic use of parameter replacement as used in some extensions...
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
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
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
newFrame()
Create a new top-level frame for expansion of a page.
preprocessToObj( $text, $flags=0)
Preprocess text to a PPNode.