minor cleanup
[lhc/web/wiklou.git] / includes / installer / Installer.php
index 3677e78..5f982d7 100644 (file)
@@ -23,6 +23,9 @@
  */
 abstract class Installer {
 
+       // This is the absolute minimum PHP version we can support
+       const MINIMUM_PHP_VERSION = '5.2.3';
+
        /**
         * @var array
         */
@@ -240,6 +243,10 @@ abstract class Installer {
                        'url' => 'http://creativecommons.org/licenses/by-nc-sa/3.0/',
                        'icon' => '{$wgStylePath}/common/images/cc-by-nc-sa.png',
                ),
+               'cc-0' => array(
+                       'url' => 'https://creativecommons.org/publicdomain/zero/1.0/',
+                       'icon' => '{$wgStylePath}/common/images/cc-0.png',
+               ),
                'pd' => array(
                        'url' => 'http://creativecommons.org/licenses/publicdomain/',
                        'icon' => '{$wgStylePath}/common/images/public-domain.png',
@@ -297,7 +304,7 @@ abstract class Installer {
         * Constructor, always call this from child classes.
         */
        public function __construct() {
-               global $wgExtensionMessagesFiles, $wgUser, $wgHooks;
+               global $wgExtensionMessagesFiles, $wgUser;
 
                // Disable the i18n cache and LoadBalancer
                Language::getLocalisationCache()->disableBackend();
@@ -310,9 +317,6 @@ abstract class Installer {
                // Having a user with id = 0 safeguards us from DB access via User::loadOptions().
                $wgUser = User::newFromId( 0 );
 
-               // Set our custom <doclink> hook.
-               $wgHooks['ParserFirstCallInit'][] = array( $this, 'registerDocLink' );
-
                $this->settings = $this->internalDefaults;
 
                foreach ( $this->defaultVarNames as $var ) {
@@ -363,14 +367,21 @@ abstract class Installer {
         * @return Status
         */
        public function doEnvironmentChecks() {
-               $this->showMessage( 'config-env-php', phpversion() );
-
-               $good = true;
+               $phpVersion = phpversion();
+               if( version_compare( $phpVersion, self::MINIMUM_PHP_VERSION, '>=' ) ) {
+                       $this->showMessage( 'config-env-php', $phpVersion );
+                       $good = true;
+               } else {
+                       $this->showMessage( 'config-env-php-toolow', $phpVersion, self::MINIMUM_PHP_VERSION );
+                       $good = false;
+               }
 
-               foreach ( $this->envChecks as $check ) {
-                       $status = $this->$check();
-                       if ( $status === false ) {
-                               $good = false;
+               if( $good ) {
+                       foreach ( $this->envChecks as $check ) {
+                               $status = $this->$check();
+                               if ( $status === false ) {
+                                       $good = false;
+                               }
                        }
                }
 
@@ -485,7 +496,7 @@ abstract class Installer {
         * On POSIX systems return the primary group of the webserver we're running under.
         * On other systems just returns null.
         *
-        * This is used to advice the user that he should chgrp his config/data/images directory as the
+        * This is used to advice the user that he should chgrp his mw-config/data/images directory as the
         * webserver user before he can install.
         *
         * Public because SqliteInstaller needs it, and doesn't subclass Installer.
@@ -570,7 +581,8 @@ abstract class Installer {
                        'ss_total_pages' => 0,
                        'ss_users' => 0,
                        'ss_admins' => 0,
-                       'ss_images' => 0 ) );
+                       'ss_images' => 0 ),
+                       __METHOD__, 'IGNORE' );
                return Status::newGood();
        }
 
@@ -595,13 +607,10 @@ abstract class Installer {
                $allNames = array();
 
                foreach ( self::getDBTypes() as $name ) {
-                       $db = $this->getDBInstaller( $name );
-                       $readableName = wfMsg( 'config-type-' . $name );
-
-                       if ( $db->isCompiled() ) {
+                       if ( $this->getDBInstaller( $name )->isCompiled() ) {
                                $compiledDBs[] = $name;
                        }
-                       $allNames[] = $readableName;
+                       $allNames[] = wfMsg( 'config-type-' . $name );;
                }
 
                $this->setVar( '_CompiledDBs', $compiledDBs );
@@ -651,7 +660,7 @@ abstract class Installer {
                $test = new PhpRefCallBugTester;
                $test->execute();
                if ( !$test->ok ) {
-                       $this->showMessage( 'config-using531' );
+                       $this->showMessage( 'config-using531', phpversion() );
                        return false;
                }
        }
@@ -725,7 +734,7 @@ abstract class Installer {
                        return false;
                }
                wfSuppressWarnings();
-               $regexd = preg_replace( '/[\x{0400}-\x{04FF}]/u', '', '-АБВГД-' );
+               $regexd = preg_replace( '/[\x{0430}-\x{04FF}]/iu', '', '-АБВГД-' );
                wfRestoreWarnings();
                if ( $regexd != '--' ) {
                        $this->showMessage( 'config-pcre-no-utf8' );
@@ -801,6 +810,7 @@ abstract class Installer {
                $names = array( wfIsWindows() ? 'convert.exe' : 'convert' );
                $convert = self::locateExecutableInDefaultPaths( $names, array( '$1 -version', 'ImageMagick' ) );
 
+               $this->setVar( 'wgImageMagickConvertCommand', '' );
                if ( $convert ) {
                        $this->setVar( 'wgImageMagickConvertCommand', $convert );
                        $this->showMessage( 'config-imagemagick', $convert );
@@ -837,7 +847,7 @@ abstract class Installer {
                        return false;
                }
 
-               $uri = preg_replace( '{^(.*)/config.*$}', '$1', $path );
+               $uri = preg_replace( '{^(.*)/(mw-)?config.*$}', '$1', $path );
                $this->setVar( 'wgScriptPath', $uri );
        }
 
@@ -1125,18 +1135,6 @@ abstract class Installer {
                return false;
        }
 
-       /**
-        * Register tag hook below.
-        *
-        * @todo Move this to WebInstaller with the two things below?
-        *
-        * @param $parser Parser
-        */
-       public function registerDocLink( Parser &$parser ) {
-               $parser->setHook( 'doclink', array( $this, 'docLink' ) );
-               return true;
-       }
-
        /**
         * ParserOptions are constructed before we determined the language, so fix it
         */
@@ -1145,16 +1143,6 @@ abstract class Installer {
                $this->parserOptions->setUserLang( $lang->getCode() );
        }
 
-       /**
-        * Extension tag hook for a documentation link.
-        */
-       public function docLink( $linkText, $attribs, $parser ) {
-               $url = $this->getDocUrl( $attribs['href'] );
-               return '<a href="' . htmlspecialchars( $url ) . '">' .
-                       htmlspecialchars( $linkText ) .
-                       '</a>';
-       }
-
        /**
         * Overridden by WebInstaller to provide lastPage parameters.
         */
@@ -1205,12 +1193,20 @@ abstract class Installer {
                 * but we're not opening that can of worms
                 * @see https://bugzilla.wikimedia.org/show_bug.cgi?id=26857
                 */
+               global $wgAutoloadClasses;
                require( "$IP/includes/DefaultSettings.php" );
 
                foreach( $exts as $e ) {
-                       require( "$path/$e/$e.php" );
+                       require_once( "$path/$e/$e.php" );
                }
 
+               $hooksWeWant = isset( $wgHooks['LoadExtensionSchemaUpdates'] ) ?
+                       $wgHooks['LoadExtensionSchemaUpdates'] : array();
+
+               // Unset everyone else's hooks. Lord knows what someone might be doing
+               // in ParserFirstCallInit (see bug 27171)
+               $GLOBALS['wgHooks'] = array( 'LoadExtensionSchemaUpdates' => $hooksWeWant );
+
                return Status::newGood();
        }
 
@@ -1313,7 +1309,7 @@ abstract class Installer {
         *
         * @return Status
         */
-       protected function generateSecretKey() {
+       public function generateSecretKey() {
                return $this->generateSecret( 'wgSecretKey' );
        }