MediaWiki  1.32.0
MagicWordFactory.php
Go to the documentation of this file.
1 <?php
38  private $mVariableIDsInitialised = false;
39 
41  private $mVariableIDs = [
42  '!',
43  'currentmonth',
44  'currentmonth1',
45  'currentmonthname',
46  'currentmonthnamegen',
47  'currentmonthabbrev',
48  'currentday',
49  'currentday2',
50  'currentdayname',
51  'currentyear',
52  'currenttime',
53  'currenthour',
54  'localmonth',
55  'localmonth1',
56  'localmonthname',
57  'localmonthnamegen',
58  'localmonthabbrev',
59  'localday',
60  'localday2',
61  'localdayname',
62  'localyear',
63  'localtime',
64  'localhour',
65  'numberofarticles',
66  'numberoffiles',
67  'numberofedits',
68  'articlepath',
69  'pageid',
70  'sitename',
71  'server',
72  'servername',
73  'scriptpath',
74  'stylepath',
75  'pagename',
76  'pagenamee',
77  'fullpagename',
78  'fullpagenamee',
79  'namespace',
80  'namespacee',
81  'namespacenumber',
82  'currentweek',
83  'currentdow',
84  'localweek',
85  'localdow',
86  'revisionid',
87  'revisionday',
88  'revisionday2',
89  'revisionmonth',
90  'revisionmonth1',
91  'revisionyear',
92  'revisiontimestamp',
93  'revisionuser',
94  'revisionsize',
95  'subpagename',
96  'subpagenamee',
97  'talkspace',
98  'talkspacee',
99  'subjectspace',
100  'subjectspacee',
101  'talkpagename',
102  'talkpagenamee',
103  'subjectpagename',
104  'subjectpagenamee',
105  'numberofusers',
106  'numberofactiveusers',
107  'numberofpages',
108  'currentversion',
109  'rootpagename',
110  'rootpagenamee',
111  'basepagename',
112  'basepagenamee',
113  'currenttimestamp',
114  'localtimestamp',
115  'directionmark',
116  'contentlanguage',
117  'pagelanguage',
118  'numberofadmins',
119  'cascadingsources',
120  ];
121 
125  private $mCacheTTLs = [
126  'currentmonth' => 86400,
127  'currentmonth1' => 86400,
128  'currentmonthname' => 86400,
129  'currentmonthnamegen' => 86400,
130  'currentmonthabbrev' => 86400,
131  'currentday' => 3600,
132  'currentday2' => 3600,
133  'currentdayname' => 3600,
134  'currentyear' => 86400,
135  'currenttime' => 3600,
136  'currenthour' => 3600,
137  'localmonth' => 86400,
138  'localmonth1' => 86400,
139  'localmonthname' => 86400,
140  'localmonthnamegen' => 86400,
141  'localmonthabbrev' => 86400,
142  'localday' => 3600,
143  'localday2' => 3600,
144  'localdayname' => 3600,
145  'localyear' => 86400,
146  'localtime' => 3600,
147  'localhour' => 3600,
148  'numberofarticles' => 3600,
149  'numberoffiles' => 3600,
150  'numberofedits' => 3600,
151  'currentweek' => 3600,
152  'currentdow' => 3600,
153  'localweek' => 3600,
154  'localdow' => 3600,
155  'numberofusers' => 3600,
156  'numberofactiveusers' => 3600,
157  'numberofpages' => 3600,
158  'currentversion' => 86400,
159  'currenttimestamp' => 3600,
160  'localtimestamp' => 3600,
161  'pagesinnamespace' => 3600,
162  'numberofadmins' => 3600,
163  'numberingroup' => 3600,
164  ];
165 
168  'notoc',
169  'nogallery',
170  'forcetoc',
171  'toc',
172  'noeditsection',
173  'newsectionlink',
174  'nonewsectionlink',
175  'hiddencat',
176  'index',
177  'noindex',
178  'staticredirect',
179  'notitleconvert',
180  'nocontentconvert',
181  ];
182 
184  private $mSubstIDs = [
185  'subst',
186  'safesubst',
187  ];
188 
190  private $mObjects = [];
191 
193  private $mDoubleUnderscoreArray = null;
194 
196  private $contLang;
197 
203  public function __construct( Language $contLang ) {
204  $this->contLang = $contLang;
205  }
206 
207  public function getContentLanguage() {
208  return $this->contLang;
209  }
210 
218  public function get( $id ) {
219  if ( !isset( $this->mObjects[$id] ) ) {
220  $mw = new MagicWord( null, [], false, $this->contLang );
221  $mw->load( $id );
222  $this->mObjects[$id] = $mw;
223  }
224  return $this->mObjects[$id];
225  }
226 
232  public function getVariableIDs() {
233  if ( !$this->mVariableIDsInitialised ) {
234  # Get variable IDs
235  Hooks::run( 'MagicWordwgVariableIDs', [ &$this->mVariableIDs ] );
236  $this->mVariableIDsInitialised = true;
237  }
238  return $this->mVariableIDs;
239  }
240 
245  public function getSubstIDs() {
246  return $this->mSubstIDs;
247  }
248 
255  public function getCacheTTL( $id ) {
256  if ( array_key_exists( $id, $this->mCacheTTLs ) ) {
257  return $this->mCacheTTLs[$id];
258  } else {
259  return -1;
260  }
261  }
262 
268  public function getDoubleUnderscoreArray() {
269  if ( is_null( $this->mDoubleUnderscoreArray ) ) {
270  Hooks::run( 'GetDoubleUnderscoreIDs', [ &$this->mDoubleUnderscoreIDs ] );
271  $this->mDoubleUnderscoreArray = $this->newArray( $this->mDoubleUnderscoreIDs );
272  }
274  }
275 
282  public function newArray( array $names = [] ) : MagicWordArray {
283  return new MagicWordArray( $names, $this );
284  }
285 }
MagicWordArray
Class for handling an array of magic words.
Definition: MagicWordArray.php:32
MagicWordFactory
A factory that stores information about MagicWords, and creates them on demand with caching.
Definition: MagicWordFactory.php:34
MagicWordFactory\$mVariableIDs
string[] $mVariableIDs
Definition: MagicWordFactory.php:41
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
MagicWordFactory\newArray
newArray(array $names=[])
Get a new MagicWordArray with provided $names.
Definition: MagicWordFactory.php:282
MagicWordFactory\getDoubleUnderscoreArray
getDoubleUnderscoreArray()
Get a MagicWordArray of double-underscore entities.
Definition: MagicWordFactory.php:268
MagicWordFactory\$contLang
Language $contLang
Definition: MagicWordFactory.php:196
MagicWord
This class encapsulates "magic words" such as "#redirect", NOTOC, etc.
Definition: MagicWord.php:57
MagicWordFactory\$mVariableIDsInitialised
bool $mVariableIDsInitialised
#-
Definition: MagicWordFactory.php:38
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))
MagicWordFactory\$mDoubleUnderscoreIDs
string[] $mDoubleUnderscoreIDs
Definition: MagicWordFactory.php:167
MagicWordFactory\getVariableIDs
getVariableIDs()
Get an array of parser variable IDs.
Definition: MagicWordFactory.php:232
MagicWordFactory\getContentLanguage
getContentLanguage()
Definition: MagicWordFactory.php:207
MagicWordFactory\$mSubstIDs
string[] $mSubstIDs
Definition: MagicWordFactory.php:184
MagicWordFactory\$mCacheTTLs
array $mCacheTTLs
Array of caching hints for ParserCache [ string => int ].
Definition: MagicWordFactory.php:125
MagicWordFactory\getCacheTTL
getCacheTTL( $id)
Allow external reads of TTL array.
Definition: MagicWordFactory.php:255
MagicWordFactory\$mDoubleUnderscoreArray
MagicWordArray $mDoubleUnderscoreArray
Definition: MagicWordFactory.php:193
MagicWordFactory\$mObjects
array $mObjects
[ string => MagicWord ]
Definition: MagicWordFactory.php:190
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
MagicWordFactory\getSubstIDs
getSubstIDs()
Get an array of parser substitution modifier IDs.
Definition: MagicWordFactory.php:245
Language
Internationalisation code.
Definition: Language.php:35
MagicWordFactory\__construct
__construct(Language $contLang)
#-
Definition: MagicWordFactory.php:203