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 |
||
| 43 | abstract class Installer { |
||
| 44 | |||
| 45 | /** |
||
| 46 | * The oldest version of PCRE we can support. |
||
| 47 | * |
||
| 48 | * Defining this is necessary because PHP may be linked with a system version |
||
| 49 | * of PCRE, which may be older than that bundled with the minimum PHP version. |
||
| 50 | */ |
||
| 51 | const MINIMUM_PCRE_VERSION = '7.2'; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @var array |
||
| 55 | */ |
||
| 56 | protected $settings; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * List of detected DBs, access using getCompiledDBs(). |
||
| 60 | * |
||
| 61 | * @var array |
||
| 62 | */ |
||
| 63 | protected $compiledDBs; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Cached DB installer instances, access using getDBInstaller(). |
||
| 67 | * |
||
| 68 | * @var array |
||
| 69 | */ |
||
| 70 | protected $dbInstallers = []; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Minimum memory size in MB. |
||
| 74 | * |
||
| 75 | * @var int |
||
| 76 | */ |
||
| 77 | protected $minMemorySize = 50; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Cached Title, used by parse(). |
||
| 81 | * |
||
| 82 | * @var Title |
||
| 83 | */ |
||
| 84 | protected $parserTitle; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Cached ParserOptions, used by parse(). |
||
| 88 | * |
||
| 89 | * @var ParserOptions |
||
| 90 | */ |
||
| 91 | protected $parserOptions; |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Known database types. These correspond to the class names <type>Installer, |
||
| 95 | * and are also MediaWiki database types valid for $wgDBtype. |
||
| 96 | * |
||
| 97 | * To add a new type, create a <type>Installer class and a Database<type> |
||
| 98 | * class, and add a config-type-<type> message to MessagesEn.php. |
||
| 99 | * |
||
| 100 | * @var array |
||
| 101 | */ |
||
| 102 | protected static $dbTypes = [ |
||
| 103 | 'mysql', |
||
| 104 | 'postgres', |
||
| 105 | 'oracle', |
||
| 106 | 'mssql', |
||
| 107 | 'sqlite', |
||
| 108 | ]; |
||
| 109 | |||
| 110 | /** |
||
| 111 | * A list of environment check methods called by doEnvironmentChecks(). |
||
| 112 | * These may output warnings using showMessage(), and/or abort the |
||
| 113 | * installation process by returning false. |
||
| 114 | * |
||
| 115 | * For the WebInstaller these are only called on the Welcome page, |
||
| 116 | * if these methods have side-effects that should affect later page loads |
||
| 117 | * (as well as the generated stylesheet), use envPreps instead. |
||
| 118 | * |
||
| 119 | * @var array |
||
| 120 | */ |
||
| 121 | protected $envChecks = [ |
||
| 122 | 'envCheckDB', |
||
| 123 | 'envCheckBrokenXML', |
||
| 124 | 'envCheckPCRE', |
||
| 125 | 'envCheckMemory', |
||
| 126 | 'envCheckCache', |
||
| 127 | 'envCheckModSecurity', |
||
| 128 | 'envCheckDiff3', |
||
| 129 | 'envCheckGraphics', |
||
| 130 | 'envCheckGit', |
||
| 131 | 'envCheckServer', |
||
| 132 | 'envCheckPath', |
||
| 133 | 'envCheckShellLocale', |
||
| 134 | 'envCheckUploadsDirectory', |
||
| 135 | 'envCheckLibicu', |
||
| 136 | 'envCheckSuhosinMaxValueLength', |
||
| 137 | ]; |
||
| 138 | |||
| 139 | /** |
||
| 140 | * A list of environment preparation methods called by doEnvironmentPreps(). |
||
| 141 | * |
||
| 142 | * @var array |
||
| 143 | */ |
||
| 144 | protected $envPreps = [ |
||
| 145 | 'envPrepServer', |
||
| 146 | 'envPrepPath', |
||
| 147 | ]; |
||
| 148 | |||
| 149 | /** |
||
| 150 | * MediaWiki configuration globals that will eventually be passed through |
||
| 151 | * to LocalSettings.php. The names only are given here, the defaults |
||
| 152 | * typically come from DefaultSettings.php. |
||
| 153 | * |
||
| 154 | * @var array |
||
| 155 | */ |
||
| 156 | protected $defaultVarNames = [ |
||
| 157 | 'wgSitename', |
||
| 158 | 'wgPasswordSender', |
||
| 159 | 'wgLanguageCode', |
||
| 160 | 'wgRightsIcon', |
||
| 161 | 'wgRightsText', |
||
| 162 | 'wgRightsUrl', |
||
| 163 | 'wgEnableEmail', |
||
| 164 | 'wgEnableUserEmail', |
||
| 165 | 'wgEnotifUserTalk', |
||
| 166 | 'wgEnotifWatchlist', |
||
| 167 | 'wgEmailAuthentication', |
||
| 168 | 'wgDBname', |
||
| 169 | 'wgDBtype', |
||
| 170 | 'wgDiff3', |
||
| 171 | 'wgImageMagickConvertCommand', |
||
| 172 | 'wgGitBin', |
||
| 173 | 'IP', |
||
| 174 | 'wgScriptPath', |
||
| 175 | 'wgMetaNamespace', |
||
| 176 | 'wgDeletedDirectory', |
||
| 177 | 'wgEnableUploads', |
||
| 178 | 'wgShellLocale', |
||
| 179 | 'wgSecretKey', |
||
| 180 | 'wgUseInstantCommons', |
||
| 181 | 'wgUpgradeKey', |
||
| 182 | 'wgDefaultSkin', |
||
| 183 | 'wgPingback', |
||
| 184 | ]; |
||
| 185 | |||
| 186 | /** |
||
| 187 | * Variables that are stored alongside globals, and are used for any |
||
| 188 | * configuration of the installation process aside from the MediaWiki |
||
| 189 | * configuration. Map of names to defaults. |
||
| 190 | * |
||
| 191 | * @var array |
||
| 192 | */ |
||
| 193 | protected $internalDefaults = [ |
||
| 194 | '_UserLang' => 'en', |
||
| 195 | '_Environment' => false, |
||
| 196 | '_RaiseMemory' => false, |
||
| 197 | '_UpgradeDone' => false, |
||
| 198 | '_InstallDone' => false, |
||
| 199 | '_Caches' => [], |
||
| 200 | '_InstallPassword' => '', |
||
| 201 | '_SameAccount' => true, |
||
| 202 | '_CreateDBAccount' => false, |
||
| 203 | '_NamespaceType' => 'site-name', |
||
| 204 | '_AdminName' => '', // will be set later, when the user selects language |
||
| 205 | '_AdminPassword' => '', |
||
| 206 | '_AdminPasswordConfirm' => '', |
||
| 207 | '_AdminEmail' => '', |
||
| 208 | '_Subscribe' => false, |
||
| 209 | '_SkipOptional' => 'continue', |
||
| 210 | '_RightsProfile' => 'wiki', |
||
| 211 | '_LicenseCode' => 'none', |
||
| 212 | '_CCDone' => false, |
||
| 213 | '_Extensions' => [], |
||
| 214 | '_Skins' => [], |
||
| 215 | '_MemCachedServers' => '', |
||
| 216 | '_UpgradeKeySupplied' => false, |
||
| 217 | '_ExistingDBSettings' => false, |
||
| 218 | |||
| 219 | // $wgLogo is probably wrong (bug 48084); set something that will work. |
||
| 220 | // Single quotes work fine here, as LocalSettingsGenerator outputs this unescaped. |
||
| 221 | 'wgLogo' => '$wgResourceBasePath/resources/assets/wiki.png', |
||
| 222 | 'wgAuthenticationTokenVersion' => 1, |
||
| 223 | ]; |
||
| 224 | |||
| 225 | /** |
||
| 226 | * The actual list of installation steps. This will be initialized by getInstallSteps() |
||
| 227 | * |
||
| 228 | * @var array |
||
| 229 | */ |
||
| 230 | private $installSteps = []; |
||
| 231 | |||
| 232 | /** |
||
| 233 | * Extra steps for installation, for things like DatabaseInstallers to modify |
||
| 234 | * |
||
| 235 | * @var array |
||
| 236 | */ |
||
| 237 | protected $extraInstallSteps = []; |
||
| 238 | |||
| 239 | /** |
||
| 240 | * Known object cache types and the functions used to test for their existence. |
||
| 241 | * |
||
| 242 | * @var array |
||
| 243 | */ |
||
| 244 | protected $objectCaches = [ |
||
| 245 | 'xcache' => 'xcache_get', |
||
| 246 | 'apc' => 'apc_fetch', |
||
| 247 | 'apcu' => 'apcu_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 | 'gfdl' => [ |
||
| 299 | 'url' => 'https://www.gnu.org/copyleft/fdl.html', |
||
| 300 | 'icon' => '$wgResourceBasePath/resources/assets/licenses/gnu-fdl.png', |
||
| 301 | ], |
||
| 302 | 'none' => [ |
||
| 303 | 'url' => '', |
||
| 304 | 'icon' => '', |
||
| 305 | 'text' => '' |
||
| 306 | ], |
||
| 307 | 'cc-choose' => [ |
||
| 308 | // Details will be filled in by the selector. |
||
| 309 | 'url' => '', |
||
| 310 | 'icon' => '', |
||
| 311 | 'text' => '', |
||
| 312 | ], |
||
| 313 | ]; |
||
| 314 | |||
| 315 | /** |
||
| 316 | * URL to mediawiki-announce subscription |
||
| 317 | */ |
||
| 318 | protected $mediaWikiAnnounceUrl = |
||
| 319 | 'https://lists.wikimedia.org/mailman/subscribe/mediawiki-announce'; |
||
| 320 | |||
| 321 | /** |
||
| 322 | * Supported language codes for Mailman |
||
| 323 | */ |
||
| 324 | protected $mediaWikiAnnounceLanguages = [ |
||
| 325 | 'ca', 'cs', 'da', 'de', 'en', 'es', 'et', 'eu', 'fi', 'fr', 'hr', 'hu', |
||
| 326 | 'it', 'ja', 'ko', 'lt', 'nl', 'no', 'pl', 'pt', 'pt-br', 'ro', 'ru', |
||
| 327 | 'sl', 'sr', 'sv', 'tr', 'uk' |
||
| 328 | ]; |
||
| 329 | |||
| 330 | /** |
||
| 331 | * UI interface for displaying a short message |
||
| 332 | * The parameters are like parameters to wfMessage(). |
||
| 333 | * The messages will be in wikitext format, which will be converted to an |
||
| 334 | * output format such as HTML or text before being sent to the user. |
||
| 335 | * @param string $msg |
||
| 336 | */ |
||
| 337 | abstract public function showMessage( $msg /*, ... */ ); |
||
| 338 | |||
| 339 | /** |
||
| 340 | * Same as showMessage(), but for displaying errors |
||
| 341 | * @param string $msg |
||
| 342 | */ |
||
| 343 | abstract public function showError( $msg /*, ... */ ); |
||
| 344 | |||
| 345 | /** |
||
| 346 | * Show a message to the installing user by using a Status object |
||
| 347 | * @param Status $status |
||
| 348 | */ |
||
| 349 | abstract public function showStatusMessage( Status $status ); |
||
| 350 | |||
| 351 | /** |
||
| 352 | * Constructs a Config object that contains configuration settings that should be |
||
| 353 | * overwritten for the installation process. |
||
| 354 | * |
||
| 355 | * @since 1.27 |
||
| 356 | * |
||
| 357 | * @param Config $baseConfig |
||
| 358 | * |
||
| 359 | * @return Config The config to use during installation. |
||
| 360 | */ |
||
| 361 | public static function getInstallerConfig( Config $baseConfig ) { |
||
| 395 | |||
| 396 | /** |
||
| 397 | * Constructor, always call this from child classes. |
||
| 398 | */ |
||
| 399 | public function __construct() { |
||
| 450 | |||
| 451 | /** |
||
| 452 | * Get a list of known DB types. |
||
| 453 | * |
||
| 454 | * @return array |
||
| 455 | */ |
||
| 456 | public static function getDBTypes() { |
||
| 459 | |||
| 460 | /** |
||
| 461 | * Do initial checks of the PHP environment. Set variables according to |
||
| 462 | * the observed environment. |
||
| 463 | * |
||
| 464 | * It's possible that this may be called under the CLI SAPI, not the SAPI |
||
| 465 | * that the wiki will primarily run under. In that case, the subclass should |
||
| 466 | * initialise variables such as wgScriptPath, before calling this function. |
||
| 467 | * |
||
| 468 | * Under the web subclass, it can already be assumed that PHP 5+ is in use |
||
| 469 | * and that sessions are working. |
||
| 470 | * |
||
| 471 | * @return Status |
||
| 472 | */ |
||
| 473 | public function doEnvironmentChecks() { |
||
| 501 | |||
| 502 | public function doEnvironmentPreps() { |
||
| 507 | |||
| 508 | /** |
||
| 509 | * Set a MW configuration variable, or internal installer configuration variable. |
||
| 510 | * |
||
| 511 | * @param string $name |
||
| 512 | * @param mixed $value |
||
| 513 | */ |
||
| 514 | public function setVar( $name, $value ) { |
||
| 517 | |||
| 518 | /** |
||
| 519 | * Get an MW configuration variable, or internal installer configuration variable. |
||
| 520 | * The defaults come from $GLOBALS (ultimately DefaultSettings.php). |
||
| 521 | * Installer variables are typically prefixed by an underscore. |
||
| 522 | * |
||
| 523 | * @param string $name |
||
| 524 | * @param mixed $default |
||
| 525 | * |
||
| 526 | * @return mixed |
||
| 527 | */ |
||
| 528 | View Code Duplication | public function getVar( $name, $default = null ) { |
|
| 535 | |||
| 536 | /** |
||
| 537 | * Get a list of DBs supported by current PHP setup |
||
| 538 | * |
||
| 539 | * @return array |
||
| 540 | */ |
||
| 541 | public function getCompiledDBs() { |
||
| 544 | |||
| 545 | /** |
||
| 546 | * Get an instance of DatabaseInstaller for the specified DB type. |
||
| 547 | * |
||
| 548 | * @param mixed $type DB installer for which is needed, false to use default. |
||
| 549 | * |
||
| 550 | * @return DatabaseInstaller |
||
| 551 | */ |
||
| 552 | public function getDBInstaller( $type = false ) { |
||
| 566 | |||
| 567 | /** |
||
| 568 | * Determine if LocalSettings.php exists. If it does, return its variables. |
||
| 569 | * |
||
| 570 | * @return array |
||
| 571 | */ |
||
| 572 | public static function getExistingLocalSettings() { |
||
| 603 | |||
| 604 | /** |
||
| 605 | * Get a fake password for sending back to the user in HTML. |
||
| 606 | * This is a security mechanism to avoid compromise of the password in the |
||
| 607 | * event of session ID compromise. |
||
| 608 | * |
||
| 609 | * @param string $realPassword |
||
| 610 | * |
||
| 611 | * @return string |
||
| 612 | */ |
||
| 613 | public function getFakePassword( $realPassword ) { |
||
| 616 | |||
| 617 | /** |
||
| 618 | * Set a variable which stores a password, except if the new value is a |
||
| 619 | * fake password in which case leave it as it is. |
||
| 620 | * |
||
| 621 | * @param string $name |
||
| 622 | * @param mixed $value |
||
| 623 | */ |
||
| 624 | public function setPassword( $name, $value ) { |
||
| 629 | |||
| 630 | /** |
||
| 631 | * On POSIX systems return the primary group of the webserver we're running under. |
||
| 632 | * On other systems just returns null. |
||
| 633 | * |
||
| 634 | * This is used to advice the user that he should chgrp his mw-config/data/images directory as the |
||
| 635 | * webserver user before he can install. |
||
| 636 | * |
||
| 637 | * Public because SqliteInstaller needs it, and doesn't subclass Installer. |
||
| 638 | * |
||
| 639 | * @return mixed |
||
| 640 | */ |
||
| 641 | public static function maybeGetWebserverPrimaryGroup() { |
||
| 654 | |||
| 655 | /** |
||
| 656 | * Convert wikitext $text to HTML. |
||
| 657 | * |
||
| 658 | * This is potentially error prone since many parser features require a complete |
||
| 659 | * installed MW database. The solution is to just not use those features when you |
||
| 660 | * write your messages. This appears to work well enough. Basic formatting and |
||
| 661 | * external links work just fine. |
||
| 662 | * |
||
| 663 | * But in case a translator decides to throw in a "#ifexist" or internal link or |
||
| 664 | * whatever, this function is guarded to catch the attempted DB access and to present |
||
| 665 | * some fallback text. |
||
| 666 | * |
||
| 667 | * @param string $text |
||
| 668 | * @param bool $lineStart |
||
| 669 | * @return string |
||
| 670 | */ |
||
| 671 | public function parse( $text, $lineStart = false ) { |
||
| 687 | |||
| 688 | /** |
||
| 689 | * @return ParserOptions |
||
| 690 | */ |
||
| 691 | public function getParserOptions() { |
||
| 694 | |||
| 695 | public function disableLinkPopups() { |
||
| 698 | |||
| 699 | public function restoreLinkPopups() { |
||
| 703 | |||
| 704 | /** |
||
| 705 | * Install step which adds a row to the site_stats table with appropriate |
||
| 706 | * initial values. |
||
| 707 | * |
||
| 708 | * @param DatabaseInstaller $installer |
||
| 709 | * |
||
| 710 | * @return Status |
||
| 711 | */ |
||
| 712 | public function populateSiteStats( DatabaseInstaller $installer ) { |
||
| 732 | |||
| 733 | /** |
||
| 734 | * Environment check for DB types. |
||
| 735 | * @return bool |
||
| 736 | */ |
||
| 737 | protected function envCheckDB() { |
||
| 771 | |||
| 772 | /** |
||
| 773 | * Some versions of libxml+PHP break < and > encoding horribly |
||
| 774 | * @return bool |
||
| 775 | */ |
||
| 776 | protected function envCheckBrokenXML() { |
||
| 786 | |||
| 787 | /** |
||
| 788 | * Environment check for the PCRE module. |
||
| 789 | * |
||
| 790 | * @note If this check were to fail, the parser would |
||
| 791 | * probably throw an exception before the result |
||
| 792 | * of this check is shown to the user. |
||
| 793 | * @return bool |
||
| 794 | */ |
||
| 795 | protected function envCheckPCRE() { |
||
| 812 | |||
| 813 | /** |
||
| 814 | * Environment check for available memory. |
||
| 815 | * @return bool |
||
| 816 | */ |
||
| 817 | protected function envCheckMemory() { |
||
| 839 | |||
| 840 | /** |
||
| 841 | * Environment check for compiled object cache types. |
||
| 842 | */ |
||
| 843 | protected function envCheckCache() { |
||
| 861 | |||
| 862 | /** |
||
| 863 | * Scare user to death if they have mod_security or mod_security2 |
||
| 864 | * @return bool |
||
| 865 | */ |
||
| 866 | protected function envCheckModSecurity() { |
||
| 874 | |||
| 875 | /** |
||
| 876 | * Search for GNU diff3. |
||
| 877 | * @return bool |
||
| 878 | */ |
||
| 879 | protected function envCheckDiff3() { |
||
| 894 | |||
| 895 | /** |
||
| 896 | * Environment check for ImageMagick and GD. |
||
| 897 | * @return bool |
||
| 898 | */ |
||
| 899 | protected function envCheckGraphics() { |
||
| 918 | |||
| 919 | /** |
||
| 920 | * Search for git. |
||
| 921 | * |
||
| 922 | * @since 1.22 |
||
| 923 | * @return bool |
||
| 924 | */ |
||
| 925 | protected function envCheckGit() { |
||
| 941 | |||
| 942 | /** |
||
| 943 | * Environment check to inform user which server we've assumed. |
||
| 944 | * |
||
| 945 | * @return bool |
||
| 946 | */ |
||
| 947 | protected function envCheckServer() { |
||
| 954 | |||
| 955 | /** |
||
| 956 | * Environment check to inform user which paths we've assumed. |
||
| 957 | * |
||
| 958 | * @return bool |
||
| 959 | */ |
||
| 960 | protected function envCheckPath() { |
||
| 968 | |||
| 969 | /** |
||
| 970 | * Environment check for preferred locale in shell |
||
| 971 | * @return bool |
||
| 972 | */ |
||
| 973 | protected function envCheckShellLocale() { |
||
| 1046 | |||
| 1047 | /** |
||
| 1048 | * Environment check for the permissions of the uploads directory |
||
| 1049 | * @return bool |
||
| 1050 | */ |
||
| 1051 | protected function envCheckUploadsDirectory() { |
||
| 1064 | |||
| 1065 | /** |
||
| 1066 | * Checks if suhosin.get.max_value_length is set, and if so generate |
||
| 1067 | * a warning because it decreases ResourceLoader performance. |
||
| 1068 | * @return bool |
||
| 1069 | */ |
||
| 1070 | protected function envCheckSuhosinMaxValueLength() { |
||
| 1079 | |||
| 1080 | /** |
||
| 1081 | * Convert a hex string representing a Unicode code point to that code point. |
||
| 1082 | * @param string $c |
||
| 1083 | * @return string |
||
| 1084 | */ |
||
| 1085 | protected function unicodeChar( $c ) { |
||
| 1102 | |||
| 1103 | /** |
||
| 1104 | * Check the libicu version |
||
| 1105 | */ |
||
| 1106 | protected function envCheckLibicu() { |
||
| 1138 | |||
| 1139 | /** |
||
| 1140 | * Environment prep for the server hostname. |
||
| 1141 | */ |
||
| 1142 | protected function envPrepServer() { |
||
| 1148 | |||
| 1149 | /** |
||
| 1150 | * Helper function to be called from envPrepServer() |
||
| 1151 | * @return string |
||
| 1152 | */ |
||
| 1153 | abstract protected function envGetDefaultServer(); |
||
| 1154 | |||
| 1155 | /** |
||
| 1156 | * Environment prep for setting $IP and $wgScriptPath. |
||
| 1157 | */ |
||
| 1158 | protected function envPrepPath() { |
||
| 1163 | |||
| 1164 | /** |
||
| 1165 | * Get an array of likely places we can find executables. Check a bunch |
||
| 1166 | * of known Unix-like defaults, as well as the PATH environment variable |
||
| 1167 | * (which should maybe make it work for Windows?) |
||
| 1168 | * |
||
| 1169 | * @return array |
||
| 1170 | */ |
||
| 1171 | protected static function getPossibleBinPaths() { |
||
| 1178 | |||
| 1179 | /** |
||
| 1180 | * Search a path for any of the given executable names. Returns the |
||
| 1181 | * executable name if found. Also checks the version string returned |
||
| 1182 | * by each executable. |
||
| 1183 | * |
||
| 1184 | * Used only by environment checks. |
||
| 1185 | * |
||
| 1186 | * @param string $path Path to search |
||
| 1187 | * @param array $names Array of executable names |
||
| 1188 | * @param array|bool $versionInfo False or array with two members: |
||
| 1189 | * 0 => Command to run for version check, with $1 for the full executable name |
||
| 1190 | * 1 => String to compare the output with |
||
| 1191 | * |
||
| 1192 | * If $versionInfo is not false, only executables with a version |
||
| 1193 | * matching $versionInfo[1] will be returned. |
||
| 1194 | * @return bool|string |
||
| 1195 | */ |
||
| 1196 | public static function locateExecutable( $path, $names, $versionInfo = false ) { |
||
| 1222 | |||
| 1223 | /** |
||
| 1224 | * Same as locateExecutable(), but checks in getPossibleBinPaths() by default |
||
| 1225 | * @see locateExecutable() |
||
| 1226 | * @param array $names Array of possible names. |
||
| 1227 | * @param array|bool $versionInfo Default: false or array with two members: |
||
| 1228 | * 0 => Command to run for version check, with $1 for the full executable name |
||
| 1229 | * 1 => String to compare the output with |
||
| 1230 | * |
||
| 1231 | * If $versionInfo is not false, only executables with a version |
||
| 1232 | * matching $versionInfo[1] will be returned. |
||
| 1233 | * @return bool|string |
||
| 1234 | */ |
||
| 1235 | public static function locateExecutableInDefaultPaths( $names, $versionInfo = false ) { |
||
| 1245 | |||
| 1246 | /** |
||
| 1247 | * Checks if scripts located in the given directory can be executed via the given URL. |
||
| 1248 | * |
||
| 1249 | * Used only by environment checks. |
||
| 1250 | * @param string $dir |
||
| 1251 | * @param string $url |
||
| 1252 | * @return bool|int|string |
||
| 1253 | */ |
||
| 1254 | public function dirIsExecutable( $dir, $url ) { |
||
| 1294 | |||
| 1295 | /** |
||
| 1296 | * Checks for presence of an Apache module. Works only if PHP is running as an Apache module, too. |
||
| 1297 | * |
||
| 1298 | * @param string $moduleName Name of module to check. |
||
| 1299 | * @return bool |
||
| 1300 | */ |
||
| 1301 | public static function apacheModulePresent( $moduleName ) { |
||
| 1312 | |||
| 1313 | /** |
||
| 1314 | * ParserOptions are constructed before we determined the language, so fix it |
||
| 1315 | * |
||
| 1316 | * @param Language $lang |
||
| 1317 | */ |
||
| 1318 | public function setParserLanguage( $lang ) { |
||
| 1322 | |||
| 1323 | /** |
||
| 1324 | * Overridden by WebInstaller to provide lastPage parameters. |
||
| 1325 | * @param string $page |
||
| 1326 | * @return string |
||
| 1327 | */ |
||
| 1328 | protected function getDocUrl( $page ) { |
||
| 1331 | |||
| 1332 | /** |
||
| 1333 | * Finds extensions that follow the format /$directory/Name/Name.php, |
||
| 1334 | * and returns an array containing the value for 'Name' for each found extension. |
||
| 1335 | * |
||
| 1336 | * Reasonable values for $directory include 'extensions' (the default) and 'skins'. |
||
| 1337 | * |
||
| 1338 | * @param string $directory Directory to search in |
||
| 1339 | * @return array |
||
| 1340 | */ |
||
| 1341 | public function findExtensions( $directory = 'extensions' ) { |
||
| 1369 | |||
| 1370 | /** |
||
| 1371 | * Returns a default value to be used for $wgDefaultSkin: normally the one set in DefaultSettings, |
||
| 1372 | * but will fall back to another if the default skin is missing and some other one is present |
||
| 1373 | * instead. |
||
| 1374 | * |
||
| 1375 | * @param string[] $skinNames Names of installed skins. |
||
| 1376 | * @return string |
||
| 1377 | */ |
||
| 1378 | public function getDefaultSkin( array $skinNames ) { |
||
| 1386 | |||
| 1387 | /** |
||
| 1388 | * Installs the auto-detected extensions. |
||
| 1389 | * |
||
| 1390 | * @return Status |
||
| 1391 | */ |
||
| 1392 | protected function includeExtensions() { |
||
| 1438 | |||
| 1439 | /** |
||
| 1440 | * Get an array of install steps. Should always be in the format of |
||
| 1441 | * [ |
||
| 1442 | * 'name' => 'someuniquename', |
||
| 1443 | * 'callback' => [ $obj, 'method' ], |
||
| 1444 | * ] |
||
| 1445 | * There must be a config-install-$name message defined per step, which will |
||
| 1446 | * be shown on install. |
||
| 1447 | * |
||
| 1448 | * @param DatabaseInstaller $installer DatabaseInstaller so we can make callbacks |
||
| 1449 | * @return array |
||
| 1450 | */ |
||
| 1451 | protected function getInstallSteps( DatabaseInstaller $installer ) { |
||
| 1496 | |||
| 1497 | /** |
||
| 1498 | * Actually perform the installation. |
||
| 1499 | * |
||
| 1500 | * @param callable $startCB A callback array for the beginning of each step |
||
| 1501 | * @param callable $endCB A callback array for the end of each step |
||
| 1502 | * |
||
| 1503 | * @return array Array of Status objects |
||
| 1504 | */ |
||
| 1505 | public function performInstallation( $startCB, $endCB ) { |
||
| 1533 | |||
| 1534 | /** |
||
| 1535 | * Generate $wgSecretKey. Will warn if we had to use an insecure random source. |
||
| 1536 | * |
||
| 1537 | * @return Status |
||
| 1538 | */ |
||
| 1539 | public function generateKeys() { |
||
| 1547 | |||
| 1548 | /** |
||
| 1549 | * Generate a secret value for variables using our CryptRand generator. |
||
| 1550 | * Produce a warning if the random source was insecure. |
||
| 1551 | * |
||
| 1552 | * @param array $keys |
||
| 1553 | * @return Status |
||
| 1554 | */ |
||
| 1555 | protected function doGenerateKeys( $keys ) { |
||
| 1577 | |||
| 1578 | /** |
||
| 1579 | * Create the first user account, grant it sysop and bureaucrat rights |
||
| 1580 | * |
||
| 1581 | * @return Status |
||
| 1582 | */ |
||
| 1583 | protected function createSysop() { |
||
| 1620 | |||
| 1621 | /** |
||
| 1622 | * @param Status $s |
||
| 1623 | */ |
||
| 1624 | private function subscribeToMediaWikiAnnounce( Status $s ) { |
||
| 1649 | |||
| 1650 | /** |
||
| 1651 | * Insert Main Page with default content. |
||
| 1652 | * |
||
| 1653 | * @param DatabaseInstaller $installer |
||
| 1654 | * @return Status |
||
| 1655 | */ |
||
| 1656 | protected function createMainpage( DatabaseInstaller $installer ) { |
||
| 1678 | |||
| 1679 | /** |
||
| 1680 | * Override the necessary bits of the config to run an installation. |
||
| 1681 | */ |
||
| 1682 | public static function overrideConfig() { |
||
| 1723 | |||
| 1724 | /** |
||
| 1725 | * Add an installation step following the given step. |
||
| 1726 | * |
||
| 1727 | * @param callable $callback A valid installation callback array, in this form: |
||
| 1728 | * [ 'name' => 'some-unique-name', 'callback' => [ $obj, 'function' ] ]; |
||
| 1729 | * @param string $findStep The step to find. Omit to put the step at the beginning |
||
| 1730 | */ |
||
| 1731 | public function addInstallStep( $callback, $findStep = 'BEGINNING' ) { |
||
| 1734 | |||
| 1735 | /** |
||
| 1736 | * Disable the time limit for execution. |
||
| 1737 | * Some long-running pages (Install, Upgrade) will want to do this |
||
| 1738 | */ |
||
| 1739 | protected function disableTimeLimit() { |
||
| 1744 | } |
||
| 1745 |
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: