Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Installer often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Installer, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 40 | abstract class Installer { |
||
| 41 | |||
| 42 | /** |
||
| 43 | * The oldest version of PCRE we can support. |
||
| 44 | * |
||
| 45 | * Defining this is necessary because PHP may be linked with a system version |
||
| 46 | * of PCRE, which may be older than that bundled with the minimum PHP version. |
||
| 47 | */ |
||
| 48 | const MINIMUM_PCRE_VERSION = '7.2'; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @var array |
||
| 52 | */ |
||
| 53 | protected $settings; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * List of detected DBs, access using getCompiledDBs(). |
||
| 57 | * |
||
| 58 | * @var array |
||
| 59 | */ |
||
| 60 | protected $compiledDBs; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Cached DB installer instances, access using getDBInstaller(). |
||
| 64 | * |
||
| 65 | * @var array |
||
| 66 | */ |
||
| 67 | protected $dbInstallers = []; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Minimum memory size in MB. |
||
| 71 | * |
||
| 72 | * @var int |
||
| 73 | */ |
||
| 74 | protected $minMemorySize = 50; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Cached Title, used by parse(). |
||
| 78 | * |
||
| 79 | * @var Title |
||
| 80 | */ |
||
| 81 | protected $parserTitle; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Cached ParserOptions, used by parse(). |
||
| 85 | * |
||
| 86 | * @var ParserOptions |
||
| 87 | */ |
||
| 88 | protected $parserOptions; |
||
| 89 | |||
| 90 | /** |
||
| 91 | * Known database types. These correspond to the class names <type>Installer, |
||
| 92 | * and are also MediaWiki database types valid for $wgDBtype. |
||
| 93 | * |
||
| 94 | * To add a new type, create a <type>Installer class and a Database<type> |
||
| 95 | * class, and add a config-type-<type> message to MessagesEn.php. |
||
| 96 | * |
||
| 97 | * @var array |
||
| 98 | */ |
||
| 99 | protected static $dbTypes = [ |
||
| 100 | 'mysql', |
||
| 101 | 'postgres', |
||
| 102 | 'oracle', |
||
| 103 | 'mssql', |
||
| 104 | 'sqlite', |
||
| 105 | ]; |
||
| 106 | |||
| 107 | /** |
||
| 108 | * A list of environment check methods called by doEnvironmentChecks(). |
||
| 109 | * These may output warnings using showMessage(), and/or abort the |
||
| 110 | * installation process by returning false. |
||
| 111 | * |
||
| 112 | * For the WebInstaller these are only called on the Welcome page, |
||
| 113 | * if these methods have side-effects that should affect later page loads |
||
| 114 | * (as well as the generated stylesheet), use envPreps instead. |
||
| 115 | * |
||
| 116 | * @var array |
||
| 117 | */ |
||
| 118 | protected $envChecks = [ |
||
| 119 | 'envCheckDB', |
||
| 120 | 'envCheckBrokenXML', |
||
| 121 | 'envCheckMbstring', |
||
| 122 | 'envCheckXML', |
||
| 123 | 'envCheckPCRE', |
||
| 124 | 'envCheckMemory', |
||
| 125 | 'envCheckCache', |
||
| 126 | 'envCheckModSecurity', |
||
| 127 | 'envCheckDiff3', |
||
| 128 | 'envCheckGraphics', |
||
| 129 | 'envCheckGit', |
||
| 130 | 'envCheckServer', |
||
| 131 | 'envCheckPath', |
||
| 132 | 'envCheckShellLocale', |
||
| 133 | 'envCheckUploadsDirectory', |
||
| 134 | 'envCheckLibicu', |
||
| 135 | 'envCheckSuhosinMaxValueLength', |
||
| 136 | 'envCheckCtype', |
||
| 137 | 'envCheckIconv', |
||
| 138 | 'envCheckJSON', |
||
| 139 | ]; |
||
| 140 | |||
| 141 | /** |
||
| 142 | * A list of environment preparation methods called by doEnvironmentPreps(). |
||
| 143 | * |
||
| 144 | * @var array |
||
| 145 | */ |
||
| 146 | protected $envPreps = [ |
||
| 147 | 'envPrepServer', |
||
| 148 | 'envPrepPath', |
||
| 149 | ]; |
||
| 150 | |||
| 151 | /** |
||
| 152 | * MediaWiki configuration globals that will eventually be passed through |
||
| 153 | * to LocalSettings.php. The names only are given here, the defaults |
||
| 154 | * typically come from DefaultSettings.php. |
||
| 155 | * |
||
| 156 | * @var array |
||
| 157 | */ |
||
| 158 | protected $defaultVarNames = [ |
||
| 159 | 'wgSitename', |
||
| 160 | 'wgPasswordSender', |
||
| 161 | 'wgLanguageCode', |
||
| 162 | 'wgRightsIcon', |
||
| 163 | 'wgRightsText', |
||
| 164 | 'wgRightsUrl', |
||
| 165 | 'wgEnableEmail', |
||
| 166 | 'wgEnableUserEmail', |
||
| 167 | 'wgEnotifUserTalk', |
||
| 168 | 'wgEnotifWatchlist', |
||
| 169 | 'wgEmailAuthentication', |
||
| 170 | 'wgDBname', |
||
| 171 | 'wgDBtype', |
||
| 172 | 'wgDiff3', |
||
| 173 | 'wgImageMagickConvertCommand', |
||
| 174 | 'wgGitBin', |
||
| 175 | 'IP', |
||
| 176 | 'wgScriptPath', |
||
| 177 | 'wgMetaNamespace', |
||
| 178 | 'wgDeletedDirectory', |
||
| 179 | 'wgEnableUploads', |
||
| 180 | 'wgShellLocale', |
||
| 181 | 'wgSecretKey', |
||
| 182 | 'wgUseInstantCommons', |
||
| 183 | 'wgUpgradeKey', |
||
| 184 | 'wgDefaultSkin', |
||
| 185 | ]; |
||
| 186 | |||
| 187 | /** |
||
| 188 | * Variables that are stored alongside globals, and are used for any |
||
| 189 | * configuration of the installation process aside from the MediaWiki |
||
| 190 | * configuration. Map of names to defaults. |
||
| 191 | * |
||
| 192 | * @var array |
||
| 193 | */ |
||
| 194 | protected $internalDefaults = [ |
||
| 195 | '_UserLang' => 'en', |
||
| 196 | '_Environment' => false, |
||
| 197 | '_RaiseMemory' => false, |
||
| 198 | '_UpgradeDone' => false, |
||
| 199 | '_InstallDone' => false, |
||
| 200 | '_Caches' => [], |
||
| 201 | '_InstallPassword' => '', |
||
| 202 | '_SameAccount' => true, |
||
| 203 | '_CreateDBAccount' => false, |
||
| 204 | '_NamespaceType' => 'site-name', |
||
| 205 | '_AdminName' => '', // will be set later, when the user selects language |
||
| 206 | '_AdminPassword' => '', |
||
| 207 | '_AdminPasswordConfirm' => '', |
||
| 208 | '_AdminEmail' => '', |
||
| 209 | '_Subscribe' => false, |
||
| 210 | '_SkipOptional' => 'continue', |
||
| 211 | '_RightsProfile' => 'wiki', |
||
| 212 | '_LicenseCode' => 'none', |
||
| 213 | '_CCDone' => false, |
||
| 214 | '_Extensions' => [], |
||
| 215 | '_Skins' => [], |
||
| 216 | '_MemCachedServers' => '', |
||
| 217 | '_UpgradeKeySupplied' => false, |
||
| 218 | '_ExistingDBSettings' => false, |
||
| 219 | |||
| 220 | // $wgLogo is probably wrong (bug 48084); set something that will work. |
||
| 221 | // Single quotes work fine here, as LocalSettingsGenerator outputs this unescaped. |
||
| 222 | 'wgLogo' => '$wgResourceBasePath/resources/assets/wiki.png', |
||
| 223 | 'wgAuthenticationTokenVersion' => 1, |
||
| 224 | ]; |
||
| 225 | |||
| 226 | /** |
||
| 227 | * The actual list of installation steps. This will be initialized by getInstallSteps() |
||
| 228 | * |
||
| 229 | * @var array |
||
| 230 | */ |
||
| 231 | private $installSteps = []; |
||
| 232 | |||
| 233 | /** |
||
| 234 | * Extra steps for installation, for things like DatabaseInstallers to modify |
||
| 235 | * |
||
| 236 | * @var array |
||
| 237 | */ |
||
| 238 | protected $extraInstallSteps = []; |
||
| 239 | |||
| 240 | /** |
||
| 241 | * Known object cache types and the functions used to test for their existence. |
||
| 242 | * |
||
| 243 | * @var array |
||
| 244 | */ |
||
| 245 | protected $objectCaches = [ |
||
| 246 | 'xcache' => 'xcache_get', |
||
| 247 | 'apc' => 'apc_fetch', |
||
| 248 | 'wincache' => 'wincache_ucache_get' |
||
| 249 | ]; |
||
| 250 | |||
| 251 | /** |
||
| 252 | * User rights profiles. |
||
| 253 | * |
||
| 254 | * @var array |
||
| 255 | */ |
||
| 256 | public $rightsProfiles = [ |
||
| 257 | 'wiki' => [], |
||
| 258 | 'no-anon' => [ |
||
| 259 | '*' => [ 'edit' => false ] |
||
| 260 | ], |
||
| 261 | 'fishbowl' => [ |
||
| 262 | '*' => [ |
||
| 263 | 'createaccount' => false, |
||
| 264 | 'edit' => false, |
||
| 265 | ], |
||
| 266 | ], |
||
| 267 | 'private' => [ |
||
| 268 | '*' => [ |
||
| 269 | 'createaccount' => false, |
||
| 270 | 'edit' => false, |
||
| 271 | 'read' => false, |
||
| 272 | ], |
||
| 273 | ], |
||
| 274 | ]; |
||
| 275 | |||
| 276 | /** |
||
| 277 | * License types. |
||
| 278 | * |
||
| 279 | * @var array |
||
| 280 | */ |
||
| 281 | public $licenses = [ |
||
| 282 | 'cc-by' => [ |
||
| 283 | 'url' => 'https://creativecommons.org/licenses/by/4.0/', |
||
| 284 | 'icon' => '$wgResourceBasePath/resources/assets/licenses/cc-by.png', |
||
| 285 | ], |
||
| 286 | 'cc-by-sa' => [ |
||
| 287 | 'url' => 'https://creativecommons.org/licenses/by-sa/4.0/', |
||
| 288 | 'icon' => '$wgResourceBasePath/resources/assets/licenses/cc-by-sa.png', |
||
| 289 | ], |
||
| 290 | 'cc-by-nc-sa' => [ |
||
| 291 | 'url' => 'https://creativecommons.org/licenses/by-nc-sa/4.0/', |
||
| 292 | 'icon' => '$wgResourceBasePath/resources/assets/licenses/cc-by-nc-sa.png', |
||
| 293 | ], |
||
| 294 | 'cc-0' => [ |
||
| 295 | 'url' => 'https://creativecommons.org/publicdomain/zero/1.0/', |
||
| 296 | 'icon' => '$wgResourceBasePath/resources/assets/licenses/cc-0.png', |
||
| 297 | ], |
||
| 298 | 'pd' => [ |
||
| 299 | 'url' => '', |
||
| 300 | 'icon' => '$wgResourceBasePath/resources/assets/licenses/public-domain.png', |
||
| 301 | ], |
||
| 302 | 'gfdl' => [ |
||
| 303 | 'url' => 'https://www.gnu.org/copyleft/fdl.html', |
||
| 304 | 'icon' => '$wgResourceBasePath/resources/assets/licenses/gnu-fdl.png', |
||
| 305 | ], |
||
| 306 | 'none' => [ |
||
| 307 | 'url' => '', |
||
| 308 | 'icon' => '', |
||
| 309 | 'text' => '' |
||
| 310 | ], |
||
| 311 | 'cc-choose' => [ |
||
| 312 | // Details will be filled in by the selector. |
||
| 313 | 'url' => '', |
||
| 314 | 'icon' => '', |
||
| 315 | 'text' => '', |
||
| 316 | ], |
||
| 317 | ]; |
||
| 318 | |||
| 319 | /** |
||
| 320 | * URL to mediawiki-announce subscription |
||
| 321 | */ |
||
| 322 | protected $mediaWikiAnnounceUrl = |
||
| 323 | 'https://lists.wikimedia.org/mailman/subscribe/mediawiki-announce'; |
||
| 324 | |||
| 325 | /** |
||
| 326 | * Supported language codes for Mailman |
||
| 327 | */ |
||
| 328 | protected $mediaWikiAnnounceLanguages = [ |
||
| 329 | 'ca', 'cs', 'da', 'de', 'en', 'es', 'et', 'eu', 'fi', 'fr', 'hr', 'hu', |
||
| 330 | 'it', 'ja', 'ko', 'lt', 'nl', 'no', 'pl', 'pt', 'pt-br', 'ro', 'ru', |
||
| 331 | 'sl', 'sr', 'sv', 'tr', 'uk' |
||
| 332 | ]; |
||
| 333 | |||
| 334 | /** |
||
| 335 | * UI interface for displaying a short message |
||
| 336 | * The parameters are like parameters to wfMessage(). |
||
| 337 | * The messages will be in wikitext format, which will be converted to an |
||
| 338 | * output format such as HTML or text before being sent to the user. |
||
| 339 | * @param string $msg |
||
| 340 | */ |
||
| 341 | abstract public function showMessage( $msg /*, ... */ ); |
||
| 342 | |||
| 343 | /** |
||
| 344 | * Same as showMessage(), but for displaying errors |
||
| 345 | * @param string $msg |
||
| 346 | */ |
||
| 347 | abstract public function showError( $msg /*, ... */ ); |
||
| 348 | |||
| 349 | /** |
||
| 350 | * Show a message to the installing user by using a Status object |
||
| 351 | * @param Status $status |
||
| 352 | */ |
||
| 353 | abstract public function showStatusMessage( Status $status ); |
||
| 354 | |||
| 355 | /** |
||
| 356 | * Constructs a Config object that contains configuration settings that should be |
||
| 357 | * overwritten for the installation process. |
||
| 358 | * |
||
| 359 | * @since 1.27 |
||
| 360 | * |
||
| 361 | * @param Config $baseConfig |
||
| 362 | * |
||
| 363 | * @return Config The config to use during installation. |
||
| 364 | */ |
||
| 365 | public static function getInstallerConfig( Config $baseConfig ) { |
||
| 366 | $configOverrides = new HashConfig(); |
||
| 367 | |||
| 368 | // disable (problematic) object cache types explicitly, preserving all other (working) ones |
||
| 369 | // bug T113843 |
||
| 370 | $emptyCache = [ 'class' => 'EmptyBagOStuff' ]; |
||
| 371 | |||
| 372 | $objectCaches = [ |
||
| 373 | CACHE_NONE => $emptyCache, |
||
| 374 | CACHE_DB => $emptyCache, |
||
| 375 | CACHE_ANYTHING => $emptyCache, |
||
| 376 | CACHE_MEMCACHED => $emptyCache, |
||
| 377 | ] + $baseConfig->get( 'ObjectCaches' ); |
||
| 378 | |||
| 379 | $configOverrides->set( 'ObjectCaches', $objectCaches ); |
||
| 380 | |||
| 381 | // Load the installer's i18n. |
||
| 382 | $messageDirs = $baseConfig->get( 'MessagesDirs' ); |
||
| 383 | $messageDirs['MediawikiInstaller'] = __DIR__ . '/i18n'; |
||
| 384 | |||
| 385 | $configOverrides->set( 'MessagesDirs', $messageDirs ); |
||
| 386 | |||
| 387 | $installerConfig = new MultiConfig( [ $configOverrides, $baseConfig ] ); |
||
| 388 | |||
| 389 | // make sure we use the installer config as the main config |
||
| 390 | $configRegistry = $baseConfig->get( 'ConfigRegistry' ); |
||
| 391 | $configRegistry['main'] = function() use ( $installerConfig ) { |
||
| 392 | return $installerConfig; |
||
| 393 | }; |
||
| 394 | |||
| 395 | $configOverrides->set( 'ConfigRegistry', $configRegistry ); |
||
| 396 | |||
| 397 | return $installerConfig; |
||
| 398 | } |
||
| 399 | |||
| 400 | /** |
||
| 401 | * Constructor, always call this from child classes. |
||
| 402 | */ |
||
| 403 | public function __construct() { |
||
|
|
|||
| 404 | global $wgMemc, $wgUser, $wgObjectCaches; |
||
| 405 | |||
| 406 | $defaultConfig = new GlobalVarConfig(); // all the stuff from DefaultSettings.php |
||
| 407 | $installerConfig = self::getInstallerConfig( $defaultConfig ); |
||
| 408 | |||
| 409 | // Reset all services and inject config overrides |
||
| 410 | MediaWiki\MediaWikiServices::resetGlobalInstance( $installerConfig ); |
||
| 411 | |||
| 412 | // Don't attempt to load user language options (T126177) |
||
| 413 | // This will be overridden in the web installer with the user-specified language |
||
| 414 | RequestContext::getMain()->setLanguage( 'en' ); |
||
| 415 | |||
| 416 | // Disable the i18n cache |
||
| 417 | // TODO: manage LocalisationCache singleton in MediaWikiServices |
||
| 418 | Language::getLocalisationCache()->disableBackend(); |
||
| 419 | |||
| 420 | // Disable all global services, since we don't have any configuration yet! |
||
| 421 | MediaWiki\MediaWikiServices::disableStorageBackend(); |
||
| 422 | |||
| 423 | // Disable object cache (otherwise CACHE_ANYTHING will try CACHE_DB and |
||
| 424 | // SqlBagOStuff will then throw since we just disabled wfGetDB) |
||
| 425 | $wgObjectCaches = MediaWikiServices::getInstance()->getMainConfig()->get( 'ObjectCaches' ); |
||
| 426 | $wgMemc = ObjectCache::getInstance( CACHE_NONE ); |
||
| 427 | |||
| 428 | // Having a user with id = 0 safeguards us from DB access via User::loadOptions(). |
||
| 429 | $wgUser = User::newFromId( 0 ); |
||
| 430 | RequestContext::getMain()->setUser( $wgUser ); |
||
| 431 | |||
| 432 | $this->settings = $this->internalDefaults; |
||
| 433 | |||
| 434 | foreach ( $this->defaultVarNames as $var ) { |
||
| 435 | $this->settings[$var] = $GLOBALS[$var]; |
||
| 436 | } |
||
| 437 | |||
| 438 | $this->doEnvironmentPreps(); |
||
| 439 | |||
| 440 | $this->compiledDBs = []; |
||
| 441 | foreach ( self::getDBTypes() as $type ) { |
||
| 442 | $installer = $this->getDBInstaller( $type ); |
||
| 443 | |||
| 444 | if ( !$installer->isCompiled() ) { |
||
| 445 | continue; |
||
| 446 | } |
||
| 447 | $this->compiledDBs[] = $type; |
||
| 448 | } |
||
| 449 | |||
| 450 | $this->parserTitle = Title::newFromText( 'Installer' ); |
||
| 451 | $this->parserOptions = new ParserOptions( $wgUser ); // language will be wrong :( |
||
| 452 | $this->parserOptions->setEditSection( false ); |
||
| 453 | } |
||
| 454 | |||
| 455 | /** |
||
| 456 | * Get a list of known DB types. |
||
| 457 | * |
||
| 458 | * @return array |
||
| 459 | */ |
||
| 460 | public static function getDBTypes() { |
||
| 463 | |||
| 464 | /** |
||
| 465 | * Do initial checks of the PHP environment. Set variables according to |
||
| 466 | * the observed environment. |
||
| 467 | * |
||
| 468 | * It's possible that this may be called under the CLI SAPI, not the SAPI |
||
| 469 | * that the wiki will primarily run under. In that case, the subclass should |
||
| 470 | * initialise variables such as wgScriptPath, before calling this function. |
||
| 471 | * |
||
| 472 | * Under the web subclass, it can already be assumed that PHP 5+ is in use |
||
| 473 | * and that sessions are working. |
||
| 474 | * |
||
| 475 | * @return Status |
||
| 476 | */ |
||
| 477 | public function doEnvironmentChecks() { |
||
| 505 | |||
| 506 | public function doEnvironmentPreps() { |
||
| 511 | |||
| 512 | /** |
||
| 513 | * Set a MW configuration variable, or internal installer configuration variable. |
||
| 514 | * |
||
| 515 | * @param string $name |
||
| 516 | * @param mixed $value |
||
| 517 | */ |
||
| 518 | public function setVar( $name, $value ) { |
||
| 521 | |||
| 522 | /** |
||
| 523 | * Get an MW configuration variable, or internal installer configuration variable. |
||
| 524 | * The defaults come from $GLOBALS (ultimately DefaultSettings.php). |
||
| 525 | * Installer variables are typically prefixed by an underscore. |
||
| 526 | * |
||
| 527 | * @param string $name |
||
| 528 | * @param mixed $default |
||
| 529 | * |
||
| 530 | * @return mixed |
||
| 531 | */ |
||
| 532 | View Code Duplication | public function getVar( $name, $default = null ) { |
|
| 539 | |||
| 540 | /** |
||
| 541 | * Get a list of DBs supported by current PHP setup |
||
| 542 | * |
||
| 543 | * @return array |
||
| 544 | */ |
||
| 545 | public function getCompiledDBs() { |
||
| 548 | |||
| 549 | /** |
||
| 550 | * Get an instance of DatabaseInstaller for the specified DB type. |
||
| 551 | * |
||
| 552 | * @param mixed $type DB installer for which is needed, false to use default. |
||
| 553 | * |
||
| 554 | * @return DatabaseInstaller |
||
| 555 | */ |
||
| 556 | public function getDBInstaller( $type = false ) { |
||
| 570 | |||
| 571 | /** |
||
| 572 | * Determine if LocalSettings.php exists. If it does, return its variables. |
||
| 573 | * |
||
| 574 | * @return array |
||
| 575 | */ |
||
| 576 | public static function getExistingLocalSettings() { |
||
| 607 | |||
| 608 | /** |
||
| 609 | * Get a fake password for sending back to the user in HTML. |
||
| 610 | * This is a security mechanism to avoid compromise of the password in the |
||
| 611 | * event of session ID compromise. |
||
| 612 | * |
||
| 613 | * @param string $realPassword |
||
| 614 | * |
||
| 615 | * @return string |
||
| 616 | */ |
||
| 617 | public function getFakePassword( $realPassword ) { |
||
| 620 | |||
| 621 | /** |
||
| 622 | * Set a variable which stores a password, except if the new value is a |
||
| 623 | * fake password in which case leave it as it is. |
||
| 624 | * |
||
| 625 | * @param string $name |
||
| 626 | * @param mixed $value |
||
| 627 | */ |
||
| 628 | public function setPassword( $name, $value ) { |
||
| 633 | |||
| 634 | /** |
||
| 635 | * On POSIX systems return the primary group of the webserver we're running under. |
||
| 636 | * On other systems just returns null. |
||
| 637 | * |
||
| 638 | * This is used to advice the user that he should chgrp his mw-config/data/images directory as the |
||
| 639 | * webserver user before he can install. |
||
| 640 | * |
||
| 641 | * Public because SqliteInstaller needs it, and doesn't subclass Installer. |
||
| 642 | * |
||
| 643 | * @return mixed |
||
| 644 | */ |
||
| 645 | public static function maybeGetWebserverPrimaryGroup() { |
||
| 658 | |||
| 659 | /** |
||
| 660 | * Convert wikitext $text to HTML. |
||
| 661 | * |
||
| 662 | * This is potentially error prone since many parser features require a complete |
||
| 663 | * installed MW database. The solution is to just not use those features when you |
||
| 664 | * write your messages. This appears to work well enough. Basic formatting and |
||
| 665 | * external links work just fine. |
||
| 666 | * |
||
| 667 | * But in case a translator decides to throw in a "#ifexist" or internal link or |
||
| 668 | * whatever, this function is guarded to catch the attempted DB access and to present |
||
| 669 | * some fallback text. |
||
| 670 | * |
||
| 671 | * @param string $text |
||
| 672 | * @param bool $lineStart |
||
| 673 | * @return string |
||
| 674 | */ |
||
| 675 | public function parse( $text, $lineStart = false ) { |
||
| 691 | |||
| 692 | /** |
||
| 693 | * @return ParserOptions |
||
| 694 | */ |
||
| 695 | public function getParserOptions() { |
||
| 698 | |||
| 699 | public function disableLinkPopups() { |
||
| 702 | |||
| 703 | public function restoreLinkPopups() { |
||
| 707 | |||
| 708 | /** |
||
| 709 | * Install step which adds a row to the site_stats table with appropriate |
||
| 710 | * initial values. |
||
| 711 | * |
||
| 712 | * @param DatabaseInstaller $installer |
||
| 713 | * |
||
| 714 | * @return Status |
||
| 715 | */ |
||
| 716 | public function populateSiteStats( DatabaseInstaller $installer ) { |
||
| 736 | |||
| 737 | /** |
||
| 738 | * Environment check for DB types. |
||
| 739 | * @return bool |
||
| 740 | */ |
||
| 741 | protected function envCheckDB() { |
||
| 775 | |||
| 776 | /** |
||
| 777 | * Some versions of libxml+PHP break < and > encoding horribly |
||
| 778 | * @return bool |
||
| 779 | */ |
||
| 780 | protected function envCheckBrokenXML() { |
||
| 790 | |||
| 791 | /** |
||
| 792 | * Environment check for mbstring.func_overload. |
||
| 793 | * @return bool |
||
| 794 | */ |
||
| 795 | protected function envCheckMbstring() { |
||
| 810 | |||
| 811 | /** |
||
| 812 | * Environment check for the XML module. |
||
| 813 | * @return bool |
||
| 814 | */ |
||
| 815 | protected function envCheckXML() { |
||
| 824 | |||
| 825 | /** |
||
| 826 | * Environment check for the PCRE module. |
||
| 827 | * |
||
| 828 | * @note If this check were to fail, the parser would |
||
| 829 | * probably throw an exception before the result |
||
| 830 | * of this check is shown to the user. |
||
| 831 | * @return bool |
||
| 832 | */ |
||
| 833 | protected function envCheckPCRE() { |
||
| 850 | |||
| 851 | /** |
||
| 852 | * Environment check for available memory. |
||
| 853 | * @return bool |
||
| 854 | */ |
||
| 855 | protected function envCheckMemory() { |
||
| 877 | |||
| 878 | /** |
||
| 879 | * Environment check for compiled object cache types. |
||
| 880 | */ |
||
| 881 | protected function envCheckCache() { |
||
| 899 | |||
| 900 | /** |
||
| 901 | * Scare user to death if they have mod_security or mod_security2 |
||
| 902 | * @return bool |
||
| 903 | */ |
||
| 904 | protected function envCheckModSecurity() { |
||
| 912 | |||
| 913 | /** |
||
| 914 | * Search for GNU diff3. |
||
| 915 | * @return bool |
||
| 916 | */ |
||
| 917 | protected function envCheckDiff3() { |
||
| 932 | |||
| 933 | /** |
||
| 934 | * Environment check for ImageMagick and GD. |
||
| 935 | * @return bool |
||
| 936 | */ |
||
| 937 | protected function envCheckGraphics() { |
||
| 956 | |||
| 957 | /** |
||
| 958 | * Search for git. |
||
| 959 | * |
||
| 960 | * @since 1.22 |
||
| 961 | * @return bool |
||
| 962 | */ |
||
| 963 | protected function envCheckGit() { |
||
| 979 | |||
| 980 | /** |
||
| 981 | * Environment check to inform user which server we've assumed. |
||
| 982 | * |
||
| 983 | * @return bool |
||
| 984 | */ |
||
| 985 | protected function envCheckServer() { |
||
| 992 | |||
| 993 | /** |
||
| 994 | * Environment check to inform user which paths we've assumed. |
||
| 995 | * |
||
| 996 | * @return bool |
||
| 997 | */ |
||
| 998 | protected function envCheckPath() { |
||
| 1006 | |||
| 1007 | /** |
||
| 1008 | * Environment check for preferred locale in shell |
||
| 1009 | * @return bool |
||
| 1010 | */ |
||
| 1011 | protected function envCheckShellLocale() { |
||
| 1084 | |||
| 1085 | /** |
||
| 1086 | * Environment check for the permissions of the uploads directory |
||
| 1087 | * @return bool |
||
| 1088 | */ |
||
| 1089 | protected function envCheckUploadsDirectory() { |
||
| 1102 | |||
| 1103 | /** |
||
| 1104 | * Checks if suhosin.get.max_value_length is set, and if so generate |
||
| 1105 | * a warning because it decreases ResourceLoader performance. |
||
| 1106 | * @return bool |
||
| 1107 | */ |
||
| 1108 | protected function envCheckSuhosinMaxValueLength() { |
||
| 1117 | |||
| 1118 | /** |
||
| 1119 | * Convert a hex string representing a Unicode code point to that code point. |
||
| 1120 | * @param string $c |
||
| 1121 | * @return string |
||
| 1122 | */ |
||
| 1123 | protected function unicodeChar( $c ) { |
||
| 1140 | |||
| 1141 | /** |
||
| 1142 | * Check the libicu version |
||
| 1143 | */ |
||
| 1144 | protected function envCheckLibicu() { |
||
| 1176 | |||
| 1177 | /** |
||
| 1178 | * @return bool |
||
| 1179 | */ |
||
| 1180 | protected function envCheckCtype() { |
||
| 1189 | |||
| 1190 | /** |
||
| 1191 | * @return bool |
||
| 1192 | */ |
||
| 1193 | protected function envCheckIconv() { |
||
| 1202 | |||
| 1203 | /** |
||
| 1204 | * @return bool |
||
| 1205 | */ |
||
| 1206 | protected function envCheckJSON() { |
||
| 1215 | |||
| 1216 | /** |
||
| 1217 | * Environment prep for the server hostname. |
||
| 1218 | */ |
||
| 1219 | protected function envPrepServer() { |
||
| 1225 | |||
| 1226 | /** |
||
| 1227 | * Helper function to be called from envPrepServer() |
||
| 1228 | * @return string |
||
| 1229 | */ |
||
| 1230 | abstract protected function envGetDefaultServer(); |
||
| 1231 | |||
| 1232 | /** |
||
| 1233 | * Environment prep for setting $IP and $wgScriptPath. |
||
| 1234 | */ |
||
| 1235 | protected function envPrepPath() { |
||
| 1240 | |||
| 1241 | /** |
||
| 1242 | * Get an array of likely places we can find executables. Check a bunch |
||
| 1243 | * of known Unix-like defaults, as well as the PATH environment variable |
||
| 1244 | * (which should maybe make it work for Windows?) |
||
| 1245 | * |
||
| 1246 | * @return array |
||
| 1247 | */ |
||
| 1248 | protected static function getPossibleBinPaths() { |
||
| 1255 | |||
| 1256 | /** |
||
| 1257 | * Search a path for any of the given executable names. Returns the |
||
| 1258 | * executable name if found. Also checks the version string returned |
||
| 1259 | * by each executable. |
||
| 1260 | * |
||
| 1261 | * Used only by environment checks. |
||
| 1262 | * |
||
| 1263 | * @param string $path Path to search |
||
| 1264 | * @param array $names Array of executable names |
||
| 1265 | * @param array|bool $versionInfo False or array with two members: |
||
| 1266 | * 0 => Command to run for version check, with $1 for the full executable name |
||
| 1267 | * 1 => String to compare the output with |
||
| 1268 | * |
||
| 1269 | * If $versionInfo is not false, only executables with a version |
||
| 1270 | * matching $versionInfo[1] will be returned. |
||
| 1271 | * @return bool|string |
||
| 1272 | */ |
||
| 1273 | public static function locateExecutable( $path, $names, $versionInfo = false ) { |
||
| 1299 | |||
| 1300 | /** |
||
| 1301 | * Same as locateExecutable(), but checks in getPossibleBinPaths() by default |
||
| 1302 | * @see locateExecutable() |
||
| 1303 | * @param array $names Array of possible names. |
||
| 1304 | * @param array|bool $versionInfo Default: false or array with two members: |
||
| 1305 | * 0 => Command to run for version check, with $1 for the full executable name |
||
| 1306 | * 1 => String to compare the output with |
||
| 1307 | * |
||
| 1308 | * If $versionInfo is not false, only executables with a version |
||
| 1309 | * matching $versionInfo[1] will be returned. |
||
| 1310 | * @return bool|string |
||
| 1311 | */ |
||
| 1312 | public static function locateExecutableInDefaultPaths( $names, $versionInfo = false ) { |
||
| 1322 | |||
| 1323 | /** |
||
| 1324 | * Checks if scripts located in the given directory can be executed via the given URL. |
||
| 1325 | * |
||
| 1326 | * Used only by environment checks. |
||
| 1327 | * @param string $dir |
||
| 1328 | * @param string $url |
||
| 1329 | * @return bool|int|string |
||
| 1330 | */ |
||
| 1331 | public function dirIsExecutable( $dir, $url ) { |
||
| 1371 | |||
| 1372 | /** |
||
| 1373 | * Checks for presence of an Apache module. Works only if PHP is running as an Apache module, too. |
||
| 1374 | * |
||
| 1375 | * @param string $moduleName Name of module to check. |
||
| 1376 | * @return bool |
||
| 1377 | */ |
||
| 1378 | public static function apacheModulePresent( $moduleName ) { |
||
| 1389 | |||
| 1390 | /** |
||
| 1391 | * ParserOptions are constructed before we determined the language, so fix it |
||
| 1392 | * |
||
| 1393 | * @param Language $lang |
||
| 1394 | */ |
||
| 1395 | public function setParserLanguage( $lang ) { |
||
| 1399 | |||
| 1400 | /** |
||
| 1401 | * Overridden by WebInstaller to provide lastPage parameters. |
||
| 1402 | * @param string $page |
||
| 1403 | * @return string |
||
| 1404 | */ |
||
| 1405 | protected function getDocUrl( $page ) { |
||
| 1408 | |||
| 1409 | /** |
||
| 1410 | * Finds extensions that follow the format /$directory/Name/Name.php, |
||
| 1411 | * and returns an array containing the value for 'Name' for each found extension. |
||
| 1412 | * |
||
| 1413 | * Reasonable values for $directory include 'extensions' (the default) and 'skins'. |
||
| 1414 | * |
||
| 1415 | * @param string $directory Directory to search in |
||
| 1416 | * @return array |
||
| 1417 | */ |
||
| 1418 | public function findExtensions( $directory = 'extensions' ) { |
||
| 1446 | |||
| 1447 | /** |
||
| 1448 | * Returns a default value to be used for $wgDefaultSkin: normally the one set in DefaultSettings, |
||
| 1449 | * but will fall back to another if the default skin is missing and some other one is present |
||
| 1450 | * instead. |
||
| 1451 | * |
||
| 1452 | * @param string[] $skinNames Names of installed skins. |
||
| 1453 | * @return string |
||
| 1454 | */ |
||
| 1455 | public function getDefaultSkin( array $skinNames ) { |
||
| 1463 | |||
| 1464 | /** |
||
| 1465 | * Installs the auto-detected extensions. |
||
| 1466 | * |
||
| 1467 | * @return Status |
||
| 1468 | */ |
||
| 1469 | protected function includeExtensions() { |
||
| 1515 | |||
| 1516 | /** |
||
| 1517 | * Get an array of install steps. Should always be in the format of |
||
| 1518 | * array( |
||
| 1519 | * 'name' => 'someuniquename', |
||
| 1520 | * 'callback' => array( $obj, 'method' ), |
||
| 1521 | * ) |
||
| 1522 | * There must be a config-install-$name message defined per step, which will |
||
| 1523 | * be shown on install. |
||
| 1524 | * |
||
| 1525 | * @param DatabaseInstaller $installer DatabaseInstaller so we can make callbacks |
||
| 1526 | * @return array |
||
| 1527 | */ |
||
| 1528 | protected function getInstallSteps( DatabaseInstaller $installer ) { |
||
| 1573 | |||
| 1574 | /** |
||
| 1575 | * Actually perform the installation. |
||
| 1576 | * |
||
| 1577 | * @param callable $startCB A callback array for the beginning of each step |
||
| 1578 | * @param callable $endCB A callback array for the end of each step |
||
| 1579 | * |
||
| 1580 | * @return array Array of Status objects |
||
| 1581 | */ |
||
| 1582 | public function performInstallation( $startCB, $endCB ) { |
||
| 1610 | |||
| 1611 | /** |
||
| 1612 | * Generate $wgSecretKey. Will warn if we had to use an insecure random source. |
||
| 1613 | * |
||
| 1614 | * @return Status |
||
| 1615 | */ |
||
| 1616 | public function generateKeys() { |
||
| 1624 | |||
| 1625 | /** |
||
| 1626 | * Generate a secret value for variables using our CryptRand generator. |
||
| 1627 | * Produce a warning if the random source was insecure. |
||
| 1628 | * |
||
| 1629 | * @param array $keys |
||
| 1630 | * @return Status |
||
| 1631 | */ |
||
| 1632 | protected function doGenerateKeys( $keys ) { |
||
| 1654 | |||
| 1655 | /** |
||
| 1656 | * Create the first user account, grant it sysop and bureaucrat rights |
||
| 1657 | * |
||
| 1658 | * @return Status |
||
| 1659 | */ |
||
| 1660 | protected function createSysop() { |
||
| 1697 | |||
| 1698 | /** |
||
| 1699 | * @param Status $s |
||
| 1700 | */ |
||
| 1701 | private function subscribeToMediaWikiAnnounce( Status $s ) { |
||
| 1726 | |||
| 1727 | /** |
||
| 1728 | * Insert Main Page with default content. |
||
| 1729 | * |
||
| 1730 | * @param DatabaseInstaller $installer |
||
| 1731 | * @return Status |
||
| 1732 | */ |
||
| 1733 | protected function createMainpage( DatabaseInstaller $installer ) { |
||
| 1755 | |||
| 1756 | /** |
||
| 1757 | * Override the necessary bits of the config to run an installation. |
||
| 1758 | */ |
||
| 1759 | public static function overrideConfig() { |
||
| 1800 | |||
| 1801 | /** |
||
| 1802 | * Add an installation step following the given step. |
||
| 1803 | * |
||
| 1804 | * @param callable $callback A valid installation callback array, in this form: |
||
| 1805 | * array( 'name' => 'some-unique-name', 'callback' => array( $obj, 'function' ) ); |
||
| 1806 | * @param string $findStep The step to find. Omit to put the step at the beginning |
||
| 1807 | */ |
||
| 1808 | public function addInstallStep( $callback, $findStep = 'BEGINNING' ) { |
||
| 1811 | |||
| 1812 | /** |
||
| 1813 | * Disable the time limit for execution. |
||
| 1814 | * Some long-running pages (Install, Upgrade) will want to do this |
||
| 1815 | */ |
||
| 1816 | protected function disableTimeLimit() { |
||
| 1821 | } |
||
| 1822 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: