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 | ]; |
||
| 184 | |||
| 185 | /** |
||
| 186 | * Variables that are stored alongside globals, and are used for any |
||
| 187 | * configuration of the installation process aside from the MediaWiki |
||
| 188 | * configuration. Map of names to defaults. |
||
| 189 | * |
||
| 190 | * @var array |
||
| 191 | */ |
||
| 192 | protected $internalDefaults = [ |
||
| 193 | '_UserLang' => 'en', |
||
| 194 | '_Environment' => false, |
||
| 195 | '_RaiseMemory' => false, |
||
| 196 | '_UpgradeDone' => false, |
||
| 197 | '_InstallDone' => false, |
||
| 198 | '_Caches' => [], |
||
| 199 | '_InstallPassword' => '', |
||
| 200 | '_SameAccount' => true, |
||
| 201 | '_CreateDBAccount' => false, |
||
| 202 | '_NamespaceType' => 'site-name', |
||
| 203 | '_AdminName' => '', // will be set later, when the user selects language |
||
| 204 | '_AdminPassword' => '', |
||
| 205 | '_AdminPasswordConfirm' => '', |
||
| 206 | '_AdminEmail' => '', |
||
| 207 | '_Subscribe' => false, |
||
| 208 | '_SkipOptional' => 'continue', |
||
| 209 | '_RightsProfile' => 'wiki', |
||
| 210 | '_LicenseCode' => 'none', |
||
| 211 | '_CCDone' => false, |
||
| 212 | '_Extensions' => [], |
||
| 213 | '_Skins' => [], |
||
| 214 | '_MemCachedServers' => '', |
||
| 215 | '_UpgradeKeySupplied' => false, |
||
| 216 | '_ExistingDBSettings' => false, |
||
| 217 | |||
| 218 | // $wgLogo is probably wrong (bug 48084); set something that will work. |
||
| 219 | // Single quotes work fine here, as LocalSettingsGenerator outputs this unescaped. |
||
| 220 | 'wgLogo' => '$wgResourceBasePath/resources/assets/wiki.png', |
||
| 221 | 'wgAuthenticationTokenVersion' => 1, |
||
| 222 | ]; |
||
| 223 | |||
| 224 | /** |
||
| 225 | * The actual list of installation steps. This will be initialized by getInstallSteps() |
||
| 226 | * |
||
| 227 | * @var array |
||
| 228 | */ |
||
| 229 | private $installSteps = []; |
||
| 230 | |||
| 231 | /** |
||
| 232 | * Extra steps for installation, for things like DatabaseInstallers to modify |
||
| 233 | * |
||
| 234 | * @var array |
||
| 235 | */ |
||
| 236 | protected $extraInstallSteps = []; |
||
| 237 | |||
| 238 | /** |
||
| 239 | * Known object cache types and the functions used to test for their existence. |
||
| 240 | * |
||
| 241 | * @var array |
||
| 242 | */ |
||
| 243 | protected $objectCaches = [ |
||
| 244 | 'xcache' => 'xcache_get', |
||
| 245 | 'apc' => 'apc_fetch', |
||
| 246 | 'wincache' => 'wincache_ucache_get' |
||
| 247 | ]; |
||
| 248 | |||
| 249 | /** |
||
| 250 | * User rights profiles. |
||
| 251 | * |
||
| 252 | * @var array |
||
| 253 | */ |
||
| 254 | public $rightsProfiles = [ |
||
| 255 | 'wiki' => [], |
||
| 256 | 'no-anon' => [ |
||
| 257 | '*' => [ 'edit' => false ] |
||
| 258 | ], |
||
| 259 | 'fishbowl' => [ |
||
| 260 | '*' => [ |
||
| 261 | 'createaccount' => false, |
||
| 262 | 'edit' => false, |
||
| 263 | ], |
||
| 264 | ], |
||
| 265 | 'private' => [ |
||
| 266 | '*' => [ |
||
| 267 | 'createaccount' => false, |
||
| 268 | 'edit' => false, |
||
| 269 | 'read' => false, |
||
| 270 | ], |
||
| 271 | ], |
||
| 272 | ]; |
||
| 273 | |||
| 274 | /** |
||
| 275 | * License types. |
||
| 276 | * |
||
| 277 | * @var array |
||
| 278 | */ |
||
| 279 | public $licenses = [ |
||
| 280 | 'cc-by' => [ |
||
| 281 | 'url' => 'https://creativecommons.org/licenses/by/4.0/', |
||
| 282 | 'icon' => '$wgResourceBasePath/resources/assets/licenses/cc-by.png', |
||
| 283 | ], |
||
| 284 | 'cc-by-sa' => [ |
||
| 285 | 'url' => 'https://creativecommons.org/licenses/by-sa/4.0/', |
||
| 286 | 'icon' => '$wgResourceBasePath/resources/assets/licenses/cc-by-sa.png', |
||
| 287 | ], |
||
| 288 | 'cc-by-nc-sa' => [ |
||
| 289 | 'url' => 'https://creativecommons.org/licenses/by-nc-sa/4.0/', |
||
| 290 | 'icon' => '$wgResourceBasePath/resources/assets/licenses/cc-by-nc-sa.png', |
||
| 291 | ], |
||
| 292 | 'cc-0' => [ |
||
| 293 | 'url' => 'https://creativecommons.org/publicdomain/zero/1.0/', |
||
| 294 | 'icon' => '$wgResourceBasePath/resources/assets/licenses/cc-0.png', |
||
| 295 | ], |
||
| 296 | 'pd' => [ |
||
| 297 | 'url' => '', |
||
| 298 | 'icon' => '$wgResourceBasePath/resources/assets/licenses/public-domain.png', |
||
| 299 | ], |
||
| 300 | 'gfdl' => [ |
||
| 301 | 'url' => 'https://www.gnu.org/copyleft/fdl.html', |
||
| 302 | 'icon' => '$wgResourceBasePath/resources/assets/licenses/gnu-fdl.png', |
||
| 303 | ], |
||
| 304 | 'none' => [ |
||
| 305 | 'url' => '', |
||
| 306 | 'icon' => '', |
||
| 307 | 'text' => '' |
||
| 308 | ], |
||
| 309 | 'cc-choose' => [ |
||
| 310 | // Details will be filled in by the selector. |
||
| 311 | 'url' => '', |
||
| 312 | 'icon' => '', |
||
| 313 | 'text' => '', |
||
| 314 | ], |
||
| 315 | ]; |
||
| 316 | |||
| 317 | /** |
||
| 318 | * URL to mediawiki-announce subscription |
||
| 319 | */ |
||
| 320 | protected $mediaWikiAnnounceUrl = |
||
| 321 | 'https://lists.wikimedia.org/mailman/subscribe/mediawiki-announce'; |
||
| 322 | |||
| 323 | /** |
||
| 324 | * Supported language codes for Mailman |
||
| 325 | */ |
||
| 326 | protected $mediaWikiAnnounceLanguages = [ |
||
| 327 | 'ca', 'cs', 'da', 'de', 'en', 'es', 'et', 'eu', 'fi', 'fr', 'hr', 'hu', |
||
| 328 | 'it', 'ja', 'ko', 'lt', 'nl', 'no', 'pl', 'pt', 'pt-br', 'ro', 'ru', |
||
| 329 | 'sl', 'sr', 'sv', 'tr', 'uk' |
||
| 330 | ]; |
||
| 331 | |||
| 332 | /** |
||
| 333 | * UI interface for displaying a short message |
||
| 334 | * The parameters are like parameters to wfMessage(). |
||
| 335 | * The messages will be in wikitext format, which will be converted to an |
||
| 336 | * output format such as HTML or text before being sent to the user. |
||
| 337 | * @param string $msg |
||
| 338 | */ |
||
| 339 | abstract public function showMessage( $msg /*, ... */ ); |
||
| 340 | |||
| 341 | /** |
||
| 342 | * Same as showMessage(), but for displaying errors |
||
| 343 | * @param string $msg |
||
| 344 | */ |
||
| 345 | abstract public function showError( $msg /*, ... */ ); |
||
| 346 | |||
| 347 | /** |
||
| 348 | * Show a message to the installing user by using a Status object |
||
| 349 | * @param Status $status |
||
| 350 | */ |
||
| 351 | abstract public function showStatusMessage( Status $status ); |
||
| 352 | |||
| 353 | /** |
||
| 354 | * Constructs a Config object that contains configuration settings that should be |
||
| 355 | * overwritten for the installation process. |
||
| 356 | * |
||
| 357 | * @since 1.27 |
||
| 358 | * |
||
| 359 | * @param Config $baseConfig |
||
| 360 | * |
||
| 361 | * @return Config The config to use during installation. |
||
| 362 | */ |
||
| 363 | public static function getInstallerConfig( Config $baseConfig ) { |
||
| 397 | |||
| 398 | /** |
||
| 399 | * Constructor, always call this from child classes. |
||
| 400 | */ |
||
| 401 | public function __construct() { |
||
| 452 | |||
| 453 | /** |
||
| 454 | * Get a list of known DB types. |
||
| 455 | * |
||
| 456 | * @return array |
||
| 457 | */ |
||
| 458 | public static function getDBTypes() { |
||
| 461 | |||
| 462 | /** |
||
| 463 | * Do initial checks of the PHP environment. Set variables according to |
||
| 464 | * the observed environment. |
||
| 465 | * |
||
| 466 | * It's possible that this may be called under the CLI SAPI, not the SAPI |
||
| 467 | * that the wiki will primarily run under. In that case, the subclass should |
||
| 468 | * initialise variables such as wgScriptPath, before calling this function. |
||
| 469 | * |
||
| 470 | * Under the web subclass, it can already be assumed that PHP 5+ is in use |
||
| 471 | * and that sessions are working. |
||
| 472 | * |
||
| 473 | * @return Status |
||
| 474 | */ |
||
| 475 | public function doEnvironmentChecks() { |
||
| 503 | |||
| 504 | public function doEnvironmentPreps() { |
||
| 509 | |||
| 510 | /** |
||
| 511 | * Set a MW configuration variable, or internal installer configuration variable. |
||
| 512 | * |
||
| 513 | * @param string $name |
||
| 514 | * @param mixed $value |
||
| 515 | */ |
||
| 516 | public function setVar( $name, $value ) { |
||
| 519 | |||
| 520 | /** |
||
| 521 | * Get an MW configuration variable, or internal installer configuration variable. |
||
| 522 | * The defaults come from $GLOBALS (ultimately DefaultSettings.php). |
||
| 523 | * Installer variables are typically prefixed by an underscore. |
||
| 524 | * |
||
| 525 | * @param string $name |
||
| 526 | * @param mixed $default |
||
| 527 | * |
||
| 528 | * @return mixed |
||
| 529 | */ |
||
| 530 | View Code Duplication | public function getVar( $name, $default = null ) { |
|
| 537 | |||
| 538 | /** |
||
| 539 | * Get a list of DBs supported by current PHP setup |
||
| 540 | * |
||
| 541 | * @return array |
||
| 542 | */ |
||
| 543 | public function getCompiledDBs() { |
||
| 546 | |||
| 547 | /** |
||
| 548 | * Get an instance of DatabaseInstaller for the specified DB type. |
||
| 549 | * |
||
| 550 | * @param mixed $type DB installer for which is needed, false to use default. |
||
| 551 | * |
||
| 552 | * @return DatabaseInstaller |
||
| 553 | */ |
||
| 554 | public function getDBInstaller( $type = false ) { |
||
| 568 | |||
| 569 | /** |
||
| 570 | * Determine if LocalSettings.php exists. If it does, return its variables. |
||
| 571 | * |
||
| 572 | * @return array |
||
| 573 | */ |
||
| 574 | public static function getExistingLocalSettings() { |
||
| 605 | |||
| 606 | /** |
||
| 607 | * Get a fake password for sending back to the user in HTML. |
||
| 608 | * This is a security mechanism to avoid compromise of the password in the |
||
| 609 | * event of session ID compromise. |
||
| 610 | * |
||
| 611 | * @param string $realPassword |
||
| 612 | * |
||
| 613 | * @return string |
||
| 614 | */ |
||
| 615 | public function getFakePassword( $realPassword ) { |
||
| 618 | |||
| 619 | /** |
||
| 620 | * Set a variable which stores a password, except if the new value is a |
||
| 621 | * fake password in which case leave it as it is. |
||
| 622 | * |
||
| 623 | * @param string $name |
||
| 624 | * @param mixed $value |
||
| 625 | */ |
||
| 626 | public function setPassword( $name, $value ) { |
||
| 631 | |||
| 632 | /** |
||
| 633 | * On POSIX systems return the primary group of the webserver we're running under. |
||
| 634 | * On other systems just returns null. |
||
| 635 | * |
||
| 636 | * This is used to advice the user that he should chgrp his mw-config/data/images directory as the |
||
| 637 | * webserver user before he can install. |
||
| 638 | * |
||
| 639 | * Public because SqliteInstaller needs it, and doesn't subclass Installer. |
||
| 640 | * |
||
| 641 | * @return mixed |
||
| 642 | */ |
||
| 643 | public static function maybeGetWebserverPrimaryGroup() { |
||
| 656 | |||
| 657 | /** |
||
| 658 | * Convert wikitext $text to HTML. |
||
| 659 | * |
||
| 660 | * This is potentially error prone since many parser features require a complete |
||
| 661 | * installed MW database. The solution is to just not use those features when you |
||
| 662 | * write your messages. This appears to work well enough. Basic formatting and |
||
| 663 | * external links work just fine. |
||
| 664 | * |
||
| 665 | * But in case a translator decides to throw in a "#ifexist" or internal link or |
||
| 666 | * whatever, this function is guarded to catch the attempted DB access and to present |
||
| 667 | * some fallback text. |
||
| 668 | * |
||
| 669 | * @param string $text |
||
| 670 | * @param bool $lineStart |
||
| 671 | * @return string |
||
| 672 | */ |
||
| 673 | public function parse( $text, $lineStart = false ) { |
||
| 689 | |||
| 690 | /** |
||
| 691 | * @return ParserOptions |
||
| 692 | */ |
||
| 693 | public function getParserOptions() { |
||
| 696 | |||
| 697 | public function disableLinkPopups() { |
||
| 700 | |||
| 701 | public function restoreLinkPopups() { |
||
| 705 | |||
| 706 | /** |
||
| 707 | * Install step which adds a row to the site_stats table with appropriate |
||
| 708 | * initial values. |
||
| 709 | * |
||
| 710 | * @param DatabaseInstaller $installer |
||
| 711 | * |
||
| 712 | * @return Status |
||
| 713 | */ |
||
| 714 | public function populateSiteStats( DatabaseInstaller $installer ) { |
||
| 734 | |||
| 735 | /** |
||
| 736 | * Environment check for DB types. |
||
| 737 | * @return bool |
||
| 738 | */ |
||
| 739 | protected function envCheckDB() { |
||
| 773 | |||
| 774 | /** |
||
| 775 | * Some versions of libxml+PHP break < and > encoding horribly |
||
| 776 | * @return bool |
||
| 777 | */ |
||
| 778 | protected function envCheckBrokenXML() { |
||
| 788 | |||
| 789 | /** |
||
| 790 | * Environment check for the PCRE module. |
||
| 791 | * |
||
| 792 | * @note If this check were to fail, the parser would |
||
| 793 | * probably throw an exception before the result |
||
| 794 | * of this check is shown to the user. |
||
| 795 | * @return bool |
||
| 796 | */ |
||
| 797 | protected function envCheckPCRE() { |
||
| 814 | |||
| 815 | /** |
||
| 816 | * Environment check for available memory. |
||
| 817 | * @return bool |
||
| 818 | */ |
||
| 819 | protected function envCheckMemory() { |
||
| 841 | |||
| 842 | /** |
||
| 843 | * Environment check for compiled object cache types. |
||
| 844 | */ |
||
| 845 | protected function envCheckCache() { |
||
| 863 | |||
| 864 | /** |
||
| 865 | * Scare user to death if they have mod_security or mod_security2 |
||
| 866 | * @return bool |
||
| 867 | */ |
||
| 868 | protected function envCheckModSecurity() { |
||
| 876 | |||
| 877 | /** |
||
| 878 | * Search for GNU diff3. |
||
| 879 | * @return bool |
||
| 880 | */ |
||
| 881 | protected function envCheckDiff3() { |
||
| 896 | |||
| 897 | /** |
||
| 898 | * Environment check for ImageMagick and GD. |
||
| 899 | * @return bool |
||
| 900 | */ |
||
| 901 | protected function envCheckGraphics() { |
||
| 920 | |||
| 921 | /** |
||
| 922 | * Search for git. |
||
| 923 | * |
||
| 924 | * @since 1.22 |
||
| 925 | * @return bool |
||
| 926 | */ |
||
| 927 | protected function envCheckGit() { |
||
| 943 | |||
| 944 | /** |
||
| 945 | * Environment check to inform user which server we've assumed. |
||
| 946 | * |
||
| 947 | * @return bool |
||
| 948 | */ |
||
| 949 | protected function envCheckServer() { |
||
| 956 | |||
| 957 | /** |
||
| 958 | * Environment check to inform user which paths we've assumed. |
||
| 959 | * |
||
| 960 | * @return bool |
||
| 961 | */ |
||
| 962 | protected function envCheckPath() { |
||
| 970 | |||
| 971 | /** |
||
| 972 | * Environment check for preferred locale in shell |
||
| 973 | * @return bool |
||
| 974 | */ |
||
| 975 | protected function envCheckShellLocale() { |
||
| 1048 | |||
| 1049 | /** |
||
| 1050 | * Environment check for the permissions of the uploads directory |
||
| 1051 | * @return bool |
||
| 1052 | */ |
||
| 1053 | protected function envCheckUploadsDirectory() { |
||
| 1066 | |||
| 1067 | /** |
||
| 1068 | * Checks if suhosin.get.max_value_length is set, and if so generate |
||
| 1069 | * a warning because it decreases ResourceLoader performance. |
||
| 1070 | * @return bool |
||
| 1071 | */ |
||
| 1072 | protected function envCheckSuhosinMaxValueLength() { |
||
| 1081 | |||
| 1082 | /** |
||
| 1083 | * Convert a hex string representing a Unicode code point to that code point. |
||
| 1084 | * @param string $c |
||
| 1085 | * @return string |
||
| 1086 | */ |
||
| 1087 | protected function unicodeChar( $c ) { |
||
| 1104 | |||
| 1105 | /** |
||
| 1106 | * Check the libicu version |
||
| 1107 | */ |
||
| 1108 | protected function envCheckLibicu() { |
||
| 1140 | |||
| 1141 | /** |
||
| 1142 | * Environment prep for the server hostname. |
||
| 1143 | */ |
||
| 1144 | protected function envPrepServer() { |
||
| 1150 | |||
| 1151 | /** |
||
| 1152 | * Helper function to be called from envPrepServer() |
||
| 1153 | * @return string |
||
| 1154 | */ |
||
| 1155 | abstract protected function envGetDefaultServer(); |
||
| 1156 | |||
| 1157 | /** |
||
| 1158 | * Environment prep for setting $IP and $wgScriptPath. |
||
| 1159 | */ |
||
| 1160 | protected function envPrepPath() { |
||
| 1165 | |||
| 1166 | /** |
||
| 1167 | * Get an array of likely places we can find executables. Check a bunch |
||
| 1168 | * of known Unix-like defaults, as well as the PATH environment variable |
||
| 1169 | * (which should maybe make it work for Windows?) |
||
| 1170 | * |
||
| 1171 | * @return array |
||
| 1172 | */ |
||
| 1173 | protected static function getPossibleBinPaths() { |
||
| 1180 | |||
| 1181 | /** |
||
| 1182 | * Search a path for any of the given executable names. Returns the |
||
| 1183 | * executable name if found. Also checks the version string returned |
||
| 1184 | * by each executable. |
||
| 1185 | * |
||
| 1186 | * Used only by environment checks. |
||
| 1187 | * |
||
| 1188 | * @param string $path Path to search |
||
| 1189 | * @param array $names Array of executable names |
||
| 1190 | * @param array|bool $versionInfo False or array with two members: |
||
| 1191 | * 0 => Command to run for version check, with $1 for the full executable name |
||
| 1192 | * 1 => String to compare the output with |
||
| 1193 | * |
||
| 1194 | * If $versionInfo is not false, only executables with a version |
||
| 1195 | * matching $versionInfo[1] will be returned. |
||
| 1196 | * @return bool|string |
||
| 1197 | */ |
||
| 1198 | public static function locateExecutable( $path, $names, $versionInfo = false ) { |
||
| 1224 | |||
| 1225 | /** |
||
| 1226 | * Same as locateExecutable(), but checks in getPossibleBinPaths() by default |
||
| 1227 | * @see locateExecutable() |
||
| 1228 | * @param array $names Array of possible names. |
||
| 1229 | * @param array|bool $versionInfo Default: false or array with two members: |
||
| 1230 | * 0 => Command to run for version check, with $1 for the full executable name |
||
| 1231 | * 1 => String to compare the output with |
||
| 1232 | * |
||
| 1233 | * If $versionInfo is not false, only executables with a version |
||
| 1234 | * matching $versionInfo[1] will be returned. |
||
| 1235 | * @return bool|string |
||
| 1236 | */ |
||
| 1237 | public static function locateExecutableInDefaultPaths( $names, $versionInfo = false ) { |
||
| 1247 | |||
| 1248 | /** |
||
| 1249 | * Checks if scripts located in the given directory can be executed via the given URL. |
||
| 1250 | * |
||
| 1251 | * Used only by environment checks. |
||
| 1252 | * @param string $dir |
||
| 1253 | * @param string $url |
||
| 1254 | * @return bool|int|string |
||
| 1255 | */ |
||
| 1256 | public function dirIsExecutable( $dir, $url ) { |
||
| 1296 | |||
| 1297 | /** |
||
| 1298 | * Checks for presence of an Apache module. Works only if PHP is running as an Apache module, too. |
||
| 1299 | * |
||
| 1300 | * @param string $moduleName Name of module to check. |
||
| 1301 | * @return bool |
||
| 1302 | */ |
||
| 1303 | public static function apacheModulePresent( $moduleName ) { |
||
| 1314 | |||
| 1315 | /** |
||
| 1316 | * ParserOptions are constructed before we determined the language, so fix it |
||
| 1317 | * |
||
| 1318 | * @param Language $lang |
||
| 1319 | */ |
||
| 1320 | public function setParserLanguage( $lang ) { |
||
| 1324 | |||
| 1325 | /** |
||
| 1326 | * Overridden by WebInstaller to provide lastPage parameters. |
||
| 1327 | * @param string $page |
||
| 1328 | * @return string |
||
| 1329 | */ |
||
| 1330 | protected function getDocUrl( $page ) { |
||
| 1333 | |||
| 1334 | /** |
||
| 1335 | * Finds extensions that follow the format /$directory/Name/Name.php, |
||
| 1336 | * and returns an array containing the value for 'Name' for each found extension. |
||
| 1337 | * |
||
| 1338 | * Reasonable values for $directory include 'extensions' (the default) and 'skins'. |
||
| 1339 | * |
||
| 1340 | * @param string $directory Directory to search in |
||
| 1341 | * @return array |
||
| 1342 | */ |
||
| 1343 | public function findExtensions( $directory = 'extensions' ) { |
||
| 1371 | |||
| 1372 | /** |
||
| 1373 | * Returns a default value to be used for $wgDefaultSkin: normally the one set in DefaultSettings, |
||
| 1374 | * but will fall back to another if the default skin is missing and some other one is present |
||
| 1375 | * instead. |
||
| 1376 | * |
||
| 1377 | * @param string[] $skinNames Names of installed skins. |
||
| 1378 | * @return string |
||
| 1379 | */ |
||
| 1380 | public function getDefaultSkin( array $skinNames ) { |
||
| 1388 | |||
| 1389 | /** |
||
| 1390 | * Installs the auto-detected extensions. |
||
| 1391 | * |
||
| 1392 | * @return Status |
||
| 1393 | */ |
||
| 1394 | protected function includeExtensions() { |
||
| 1440 | |||
| 1441 | /** |
||
| 1442 | * Get an array of install steps. Should always be in the format of |
||
| 1443 | * array( |
||
| 1444 | * 'name' => 'someuniquename', |
||
| 1445 | * 'callback' => array( $obj, 'method' ), |
||
| 1446 | * ) |
||
| 1447 | * There must be a config-install-$name message defined per step, which will |
||
| 1448 | * be shown on install. |
||
| 1449 | * |
||
| 1450 | * @param DatabaseInstaller $installer DatabaseInstaller so we can make callbacks |
||
| 1451 | * @return array |
||
| 1452 | */ |
||
| 1453 | protected function getInstallSteps( DatabaseInstaller $installer ) { |
||
| 1498 | |||
| 1499 | /** |
||
| 1500 | * Actually perform the installation. |
||
| 1501 | * |
||
| 1502 | * @param callable $startCB A callback array for the beginning of each step |
||
| 1503 | * @param callable $endCB A callback array for the end of each step |
||
| 1504 | * |
||
| 1505 | * @return array Array of Status objects |
||
| 1506 | */ |
||
| 1507 | public function performInstallation( $startCB, $endCB ) { |
||
| 1535 | |||
| 1536 | /** |
||
| 1537 | * Generate $wgSecretKey. Will warn if we had to use an insecure random source. |
||
| 1538 | * |
||
| 1539 | * @return Status |
||
| 1540 | */ |
||
| 1541 | public function generateKeys() { |
||
| 1549 | |||
| 1550 | /** |
||
| 1551 | * Generate a secret value for variables using our CryptRand generator. |
||
| 1552 | * Produce a warning if the random source was insecure. |
||
| 1553 | * |
||
| 1554 | * @param array $keys |
||
| 1555 | * @return Status |
||
| 1556 | */ |
||
| 1557 | protected function doGenerateKeys( $keys ) { |
||
| 1579 | |||
| 1580 | /** |
||
| 1581 | * Create the first user account, grant it sysop and bureaucrat rights |
||
| 1582 | * |
||
| 1583 | * @return Status |
||
| 1584 | */ |
||
| 1585 | protected function createSysop() { |
||
| 1622 | |||
| 1623 | /** |
||
| 1624 | * @param Status $s |
||
| 1625 | */ |
||
| 1626 | private function subscribeToMediaWikiAnnounce( Status $s ) { |
||
| 1651 | |||
| 1652 | /** |
||
| 1653 | * Insert Main Page with default content. |
||
| 1654 | * |
||
| 1655 | * @param DatabaseInstaller $installer |
||
| 1656 | * @return Status |
||
| 1657 | */ |
||
| 1658 | protected function createMainpage( DatabaseInstaller $installer ) { |
||
| 1680 | |||
| 1681 | /** |
||
| 1682 | * Override the necessary bits of the config to run an installation. |
||
| 1683 | */ |
||
| 1684 | public static function overrideConfig() { |
||
| 1725 | |||
| 1726 | /** |
||
| 1727 | * Add an installation step following the given step. |
||
| 1728 | * |
||
| 1729 | * @param callable $callback A valid installation callback array, in this form: |
||
| 1730 | * array( 'name' => 'some-unique-name', 'callback' => array( $obj, 'function' ) ); |
||
| 1731 | * @param string $findStep The step to find. Omit to put the step at the beginning |
||
| 1732 | */ |
||
| 1733 | public function addInstallStep( $callback, $findStep = 'BEGINNING' ) { |
||
| 1736 | |||
| 1737 | /** |
||
| 1738 | * Disable the time limit for execution. |
||
| 1739 | * Some long-running pages (Install, Upgrade) will want to do this |
||
| 1740 | */ |
||
| 1741 | protected function disableTimeLimit() { |
||
| 1746 | } |
||
| 1747 |
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: