MediaWiki  master
MagicWordFactory.php
Go to the documentation of this file.
1 <?php
26 
41  private $mVariableIDsInitialised = false;
42 
44  private $mVariableIDs = [
45  '!',
46  'currentmonth',
47  'currentmonth1',
48  'currentmonthname',
49  'currentmonthnamegen',
50  'currentmonthabbrev',
51  'currentday',
52  'currentday2',
53  'currentdayname',
54  'currentyear',
55  'currenttime',
56  'currenthour',
57  'localmonth',
58  'localmonth1',
59  'localmonthname',
60  'localmonthnamegen',
61  'localmonthabbrev',
62  'localday',
63  'localday2',
64  'localdayname',
65  'localyear',
66  'localtime',
67  'localhour',
68  'numberofarticles',
69  'numberoffiles',
70  'numberofedits',
71  'articlepath',
72  'pageid',
73  'sitename',
74  'server',
75  'servername',
76  'scriptpath',
77  'stylepath',
78  'pagename',
79  'pagenamee',
80  'fullpagename',
81  'fullpagenamee',
82  'namespace',
83  'namespacee',
84  'namespacenumber',
85  'currentweek',
86  'currentdow',
87  'localweek',
88  'localdow',
89  'revisionid',
90  'revisionday',
91  'revisionday2',
92  'revisionmonth',
93  'revisionmonth1',
94  'revisionyear',
95  'revisiontimestamp',
96  'revisionuser',
97  'revisionsize',
98  'subpagename',
99  'subpagenamee',
100  'talkspace',
101  'talkspacee',
102  'subjectspace',
103  'subjectspacee',
104  'talkpagename',
105  'talkpagenamee',
106  'subjectpagename',
107  'subjectpagenamee',
108  'numberofusers',
109  'numberofactiveusers',
110  'numberofpages',
111  'currentversion',
112  'rootpagename',
113  'rootpagenamee',
114  'basepagename',
115  'basepagenamee',
116  'currenttimestamp',
117  'localtimestamp',
118  'directionmark',
119  'contentlanguage',
120  'pagelanguage',
121  'numberofadmins',
122  'cascadingsources',
123  ];
124 
128  private $mCacheTTLs = [
129  'currentmonth' => 86400,
130  'currentmonth1' => 86400,
131  'currentmonthname' => 86400,
132  'currentmonthnamegen' => 86400,
133  'currentmonthabbrev' => 86400,
134  'currentday' => 3600,
135  'currentday2' => 3600,
136  'currentdayname' => 3600,
137  'currentyear' => 86400,
138  'currenttime' => 3600,
139  'currenthour' => 3600,
140  'localmonth' => 86400,
141  'localmonth1' => 86400,
142  'localmonthname' => 86400,
143  'localmonthnamegen' => 86400,
144  'localmonthabbrev' => 86400,
145  'localday' => 3600,
146  'localday2' => 3600,
147  'localdayname' => 3600,
148  'localyear' => 86400,
149  'localtime' => 3600,
150  'localhour' => 3600,
151  'numberofarticles' => 3600,
152  'numberoffiles' => 3600,
153  'numberofedits' => 3600,
154  'currentweek' => 3600,
155  'currentdow' => 3600,
156  'localweek' => 3600,
157  'localdow' => 3600,
158  'numberofusers' => 3600,
159  'numberofactiveusers' => 3600,
160  'numberofpages' => 3600,
161  'currentversion' => 86400,
162  'currenttimestamp' => 3600,
163  'localtimestamp' => 3600,
164  'pagesinnamespace' => 3600,
165  'numberofadmins' => 3600,
166  'numberingroup' => 3600,
167  ];
168 
171  'notoc',
172  'nogallery',
173  'forcetoc',
174  'toc',
175  'noeditsection',
176  'newsectionlink',
177  'nonewsectionlink',
178  'hiddencat',
179  'expectunusedcategory',
180  'index',
181  'noindex',
182  'staticredirect',
183  'notitleconvert',
184  'nocontentconvert',
185  ];
186 
188  private $mSubstIDs = [
189  'subst',
190  'safesubst',
191  ];
192 
194  private $mObjects = [];
195 
197  private $mDoubleUnderscoreArray = null;
198 
200  private $contLang;
201 
203  private $hookRunner;
204 
211  public function __construct( Language $contLang, HookContainer $hookContainer ) {
212  $this->contLang = $contLang;
213  $this->hookRunner = new HookRunner( $hookContainer );
214  }
215 
216  public function getContentLanguage() {
217  return $this->contLang;
218  }
219 
227  public function get( $id ) {
228  if ( !isset( $this->mObjects[$id] ) ) {
229  $mw = new MagicWord( null, [], false, $this->contLang );
230  $mw->load( $id );
231  $this->mObjects[$id] = $mw;
232  }
233  return $this->mObjects[$id];
234  }
235 
241  public function getVariableIDs() {
242  if ( !$this->mVariableIDsInitialised ) {
243  # Get variable IDs
244  $this->hookRunner->onMagicWordwgVariableIDs( $this->mVariableIDs );
245  $this->mVariableIDsInitialised = true;
246  }
247  return $this->mVariableIDs;
248  }
249 
254  public function getSubstIDs() {
255  return $this->mSubstIDs;
256  }
257 
264  public function getCacheTTL( $id ) {
265  if ( array_key_exists( $id, $this->mCacheTTLs ) ) {
266  return $this->mCacheTTLs[$id];
267  } else {
268  return -1;
269  }
270  }
271 
277  public function getDoubleUnderscoreArray() {
278  if ( $this->mDoubleUnderscoreArray === null ) {
279  $this->hookRunner->onGetDoubleUnderscoreIDs( $this->mDoubleUnderscoreIDs );
280  $this->mDoubleUnderscoreArray = $this->newArray( $this->mDoubleUnderscoreIDs );
281  }
283  }
284 
291  public function newArray( array $names = [] ) : MagicWordArray {
292  return new MagicWordArray( $names, $this );
293  }
294 }
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:37
MagicWordFactory\$mVariableIDs
string[] $mVariableIDs
Definition: MagicWordFactory.php:44
MagicWordFactory\__construct
__construct(Language $contLang, HookContainer $hookContainer)
#-
Definition: MagicWordFactory.php:211
MagicWordFactory\newArray
newArray(array $names=[])
Get a new MagicWordArray with provided $names.
Definition: MagicWordFactory.php:291
MagicWordFactory\getDoubleUnderscoreArray
getDoubleUnderscoreArray()
Get a MagicWordArray of double-underscore entities.
Definition: MagicWordFactory.php:277
MagicWordFactory\$contLang
Language $contLang
Definition: MagicWordFactory.php:200
MagicWord
This class encapsulates "magic words" such as "#redirect", NOTOC, etc.
Definition: MagicWord.php:57
MagicWordFactory\$mVariableIDsInitialised
bool $mVariableIDsInitialised
#-
Definition: MagicWordFactory.php:41
MagicWordFactory\$mDoubleUnderscoreIDs
string[] $mDoubleUnderscoreIDs
Definition: MagicWordFactory.php:170
MagicWordFactory\getVariableIDs
getVariableIDs()
Get an array of parser variable IDs.
Definition: MagicWordFactory.php:241
MagicWordFactory\getContentLanguage
getContentLanguage()
Definition: MagicWordFactory.php:216
MagicWordFactory\$mSubstIDs
string[] $mSubstIDs
Definition: MagicWordFactory.php:188
MagicWordFactory\$mCacheTTLs
array $mCacheTTLs
Array of caching hints for ParserCache [ string => int ].
Definition: MagicWordFactory.php:128
MagicWordFactory\getCacheTTL
getCacheTTL( $id)
Allow external reads of TTL array.
Definition: MagicWordFactory.php:264
MediaWiki\HookContainer\HookContainer
HookContainer class.
Definition: HookContainer.php:44
MagicWordFactory\$mDoubleUnderscoreArray
MagicWordArray $mDoubleUnderscoreArray
Definition: MagicWordFactory.php:197
MagicWordFactory\$mObjects
array $mObjects
[ string => MagicWord ]
Definition: MagicWordFactory.php:194
MediaWiki\HookContainer\HookRunner
This class provides an implementation of the core hook interfaces, forwarding hook calls to HookConta...
Definition: HookRunner.php:23
MagicWordFactory\getSubstIDs
getSubstIDs()
Get an array of parser substitution modifier IDs.
Definition: MagicWordFactory.php:254
Language
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
Definition: Language.php:41
MagicWordFactory\$hookRunner
HookRunner $hookRunner
Definition: MagicWordFactory.php:203