| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\Parser; |
| 22 |
|
| 23 |
use MediaWiki\HookContainer\HookContainer; |
| 24 |
use MediaWiki\HookContainer\HookRunner; |
| 25 |
use MediaWiki\Language\Language; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
class MagicWordFactory { |
| 40 |
|
| 41 |
private bool $mVariableIDsInitialised = false; |
| 42 |
|
| 43 |
|
| 44 |
private array $mVariableIDs = [ |
| 45 |
'!', |
| 46 |
'=', |
| 47 |
'currentmonth', |
| 48 |
'currentmonth1', |
| 49 |
'currentmonthname', |
| 50 |
'currentmonthnamegen', |
| 51 |
'currentmonthabbrev', |
| 52 |
'currentday', |
| 53 |
'currentday2', |
| 54 |
'currentdayname', |
| 55 |
'currentyear', |
| 56 |
'currenttime', |
| 57 |
'currenthour', |
| 58 |
'localmonth', |
| 59 |
'localmonth1', |
| 60 |
'localmonthname', |
| 61 |
'localmonthnamegen', |
| 62 |
'localmonthabbrev', |
| 63 |
'localday', |
| 64 |
'localday2', |
| 65 |
'localdayname', |
| 66 |
'localyear', |
| 67 |
'localtime', |
| 68 |
'localhour', |
| 69 |
'numberofarticles', |
| 70 |
'numberoffiles', |
| 71 |
'numberofedits', |
| 72 |
'articlepath', |
| 73 |
'pageid', |
| 74 |
'sitename', |
| 75 |
'server', |
| 76 |
'servername', |
| 77 |
'scriptpath', |
| 78 |
'stylepath', |
| 79 |
'pagename', |
| 80 |
'pagenamee', |
| 81 |
'fullpagename', |
| 82 |
'fullpagenamee', |
| 83 |
'namespace', |
| 84 |
'namespacee', |
| 85 |
'namespacenumber', |
| 86 |
'currentweek', |
| 87 |
'currentdow', |
| 88 |
'localweek', |
| 89 |
'localdow', |
| 90 |
'revisionid', |
| 91 |
'revisionday', |
| 92 |
'revisionday2', |
| 93 |
'revisionmonth', |
| 94 |
'revisionmonth1', |
| 95 |
'revisionyear', |
| 96 |
'revisiontimestamp', |
| 97 |
'revisionuser', |
| 98 |
'revisionsize', |
| 99 |
'subpagename', |
| 100 |
'subpagenamee', |
| 101 |
'talkspace', |
| 102 |
'talkspacee', |
| 103 |
'subjectspace', |
| 104 |
'subjectspacee', |
| 105 |
'talkpagename', |
| 106 |
'talkpagenamee', |
| 107 |
'subjectpagename', |
| 108 |
'subjectpagenamee', |
| 109 |
'numberofusers', |
| 110 |
'numberofactiveusers', |
| 111 |
'numberofpages', |
| 112 |
'currentversion', |
| 113 |
'rootpagename', |
| 114 |
'rootpagenamee', |
| 115 |
'basepagename', |
| 116 |
'basepagenamee', |
| 117 |
'currenttimestamp', |
| 118 |
'localtimestamp', |
| 119 |
'directionmark', |
| 120 |
'contentlanguage', |
| 121 |
'userlanguage', |
| 122 |
'pagelanguage', |
| 123 |
'numberofadmins', |
| 124 |
'cascadingsources', |
| 125 |
'bcp47', |
| 126 |
'dir', |
| 127 |
'language', |
| 128 |
]; |
| 129 |
|
| 130 |
|
| 131 |
private array $mDoubleUnderscoreIDs = [ |
| 132 |
'notoc', |
| 133 |
'nogallery', |
| 134 |
'forcetoc', |
| 135 |
'toc', |
| 136 |
'noeditsection', |
| 137 |
'newsectionlink', |
| 138 |
'nonewsectionlink', |
| 139 |
'hiddencat', |
| 140 |
'expectunusedcategory', |
| 141 |
'expectunusedtemplate', |
| 142 |
'index', |
| 143 |
'noindex', |
| 144 |
'staticredirect', |
| 145 |
'notitleconvert', |
| 146 |
'nocontentconvert', |
| 147 |
]; |
| 148 |
|
| 149 |
|
| 150 |
private array $mObjects = []; |
| 151 |
private ?MagicWordArray $mDoubleUnderscoreArray = null; |
| 152 |
|
| 153 |
private Language $contLang; |
| 154 |
private HookRunner $hookRunner; |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
public function __construct( Language $contentLanguage, HookContainer $hookContainer ) { |
| 160 |
$this->contLang = $contentLanguage; |
| 161 |
$this->hookRunner = new HookRunner( $hookContainer ); |
| 162 |
} |
| 163 |
|
| 164 |
public function getContentLanguage(): Language { |
| 165 |
return $this->contLang; |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
public function get( $id ): MagicWord { |
| 175 |
if ( !isset( $this->mObjects[$id] ) ) { |
| 176 |
$mw = new MagicWord( null, [], false, $this->contLang ); |
| 177 |
$mw->load( $id ); |
| 178 |
$this->mObjects[$id] = $mw; |
| 179 |
} |
| 180 |
return $this->mObjects[$id]; |
| 181 |
} |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
public function getVariableIDs(): array { |
| 189 |
if ( !$this->mVariableIDsInitialised ) { |
| 190 |
|
| 191 |
$this->hookRunner->onMagicWordwgVariableIDs( $this->mVariableIDs ); |
| 192 |
$this->hookRunner->onGetMagicVariableIDs( $this->mVariableIDs ); |
| 193 |
$this->mVariableIDsInitialised = true; |
| 194 |
} |
| 195 |
return $this->mVariableIDs; |
| 196 |
} |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
public function getSubstIDs(): array { |
| 205 |
wfDeprecated( __METHOD__, '1.42' ); |
| 206 |
return [ 'subst', 'safesubst' ]; |
| 207 |
} |
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
public function getSubstArray(): MagicWordArray { |
| 213 |
return $this->newArray( [ 'subst', 'safesubst' ] ); |
| 214 |
} |
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
public function getCacheTTL( $id ) { |
| 224 |
return -1; |
| 225 |
} |
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
public function getDoubleUnderscoreArray(): MagicWordArray { |
| 233 |
if ( $this->mDoubleUnderscoreArray === null ) { |
| 234 |
$this->hookRunner->onGetDoubleUnderscoreIDs( $this->mDoubleUnderscoreIDs ); |
| 235 |
$this->mDoubleUnderscoreArray = $this->newArray( $this->mDoubleUnderscoreIDs ); |
| 236 |
} |
| 237 |
return $this->mDoubleUnderscoreArray; |
| 238 |
} |
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
public function newArray( array $names = [] ): MagicWordArray { |
| 247 |
return new MagicWordArray( $names, $this ); |
| 248 |
} |
| 249 |
} |
| 250 |
|
| 251 |
|
| 252 |
class_alias( MagicWordFactory::class, 'MagicWordFactory' ); |