Make Creative Commons selection work again; pretty up its display a bit.
[lhc/web/wiklou.git] / config / index.php
index c97d78b..c07a101 100644 (file)
@@ -110,6 +110,7 @@ header( "Content-type: text/html; charset=utf-8" );
 $IP = ".."; # Just to suppress notices, not for anything useful
 define( "MEDIAWIKI", true );
 define( "MEDIAWIKI_INSTALL", true );
+require_once( "../includes/Defines.php" );
 require_once( "../includes/DefaultSettings.php" );
 require_once( "../includes/MagicWord.php" );
 require_once( "../includes/Namespace.php" );
@@ -184,10 +185,31 @@ class ConfigData {
 <?php
 $endl = "
 ";
+$wgConfiguring = true;
 $conf = new ConfigData;
 
 install_version_checks();
-print "<li>PHP " . phpversion() . " ok</li>\n";
+
+print "<li>PHP " . phpversion() . ": ";
+if( version_compare( phpversion(), "5.0", "lt" ) ) {
+       print "ok";
+} else {
+       print " <b>the MonoBook skin will be disabled due to an incompatibility
+               between the PHPTAL template library and PHP 5</b>. The wiki should
+               function normally, but with the older look and feel.";
+}
+print "</li>\n";
+
+if( ini_get( "safe_mode" ) ) {
+       ?>
+       <li class='error'><b>Warning: PHP's
+       <a href='http://www.php.net/features.safe-mode'>safe mode</a> is active!</b>
+       You will likely have problems caused by this. You may need to make the
+       'images' subdirectory writable or specify a TMP environment variable pointing to
+       a writable temporary directory owned by you, since safe mode breaks the system
+       temporary directory.</li>
+       <?php
+}
 
 $sapi = php_sapi_name();
 $conf->prettyURLs = true;
@@ -269,7 +291,6 @@ $conf->UseImageResize = $conf->HaveGD || $conf->ImageMagick;
 # $conf->IP = "/Users/brion/Sites/inplace";
 chdir( ".." );
 $conf->IP = getcwd();
-$conf->IP = preg_replace( "/\\\\/","\\\\\\\\",$conf->IP );  // For Windows, \ -> \\
 chdir( "config" );
 print "<li>Installation directory: <tt>" . htmlspecialchars( $conf->IP ) . "</tt></li>\n";
 
@@ -312,7 +333,7 @@ if( $conf->SysopPass != $conf->SysopPass2 ) {
        $errs["SysopPass2"] = "Passwords don't match!";
 }
 
-$conf->License = importPost( "License", "none" );
+$conf->License = importRequest( "License", "none" );
 if( $conf->License == "gfdl" ) {
        $conf->RightsUrl = "http://www.gnu.org/copyleft/fdl.html";
        $conf->RightsText = "GNU Free Documentation License 1.2";
@@ -321,10 +342,10 @@ if( $conf->License == "gfdl" ) {
 } elseif( $conf->License == "none" ) {
        $conf->RightsUrl = $conf->RightsText = $conf->RightsCode = $conf->RightsIcon = "";
 } else {
-       $conf->RightsUrl = importPost( "RightsUrl", "" );
-       $conf->RightsText = importPost( "RightsText", "" );
-       $conf->RightsCode = importPost( "RightsCode", "" );
-       $conf->RightsIcon = importPost( "RightsIcon", "" );
+       $conf->RightsUrl = importRequest( "RightsUrl", "" );
+       $conf->RightsText = importRequest( "RightsText", "" );
+       $conf->RightsCode = importRequest( "RightsCode", "" );
+       $conf->RightsIcon = importRequest( "RightsIcon", "" );
 }
 
 if( $conf->posted && ( 0 == count( $errs ) ) ) {
@@ -441,6 +462,7 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) {
                        do_querycache_update(); flush();
                        do_objectcache_update(); flush();
                        do_categorylinks_update(); flush();
+                       do_image_name_unique_update(); flush();
 
                        if ( isTemplateInitialised() ) {
                                print "Template namespace already initialised\n";
@@ -622,11 +644,16 @@ if( count( $errs ) ) {
                        $icon = urlencode( "$wgServer$wgUploadPath/wiki.png" );
                        $ccApp = htmlspecialchars( "http://creativecommons.org/license/?partner=$partner&exit_url=$exit&partner_icon_url=$icon" );
                        print "<a href=\"$ccApp\">choose</a>";
-                       ?></li>
-               <li><?php aField( $conf, "RightsUrl", $conf->RightsUrl, "hidden" ); ?></li>
-               <li><?php aField( $conf, "RightsText", $conf->RightsText, "hidden" ); ?></li>
-               <li><?php aField( $conf, "RightsCode", $conf->RightsCode, "hidden" ); ?></li>
-               <li><?php aField( $conf, "RightsIcon", $conf->RightsIcon, "hidden" ); ?></li>
+                       ?> (link will wipe out any other data in this form!)
+               <?php if( $conf->License == "cc" ) { ?>
+                       <ul>
+                               <li><?php aField( $conf, "RightsIcon", "<img src=\"" . htmlspecialchars( $conf->RightsIcon ) . "\" alt='icon' />", "hidden" ); ?></li>
+                               <li><?php aField( $conf, "RightsText", htmlspecialchars( $conf->RightsText ), "hidden" ); ?></li>
+                               <li><?php aField( $conf, "RightsCode", "code: " . htmlspecialchars( $conf->RightsCode ), "hidden" ); ?></li>
+                               <li><?php aField( $conf, "RightsUrl", "<a href=\"" . htmlspecialchars( $conf->RightsUrl ) . "\">" . htmlspecialchars( $conf->RightsUrl ) . "</a>", "hidden" ); ?></li>
+                       </ul>
+               <?php } ?>
+                       </li>
                </ul>
        </dd>
        <dt>
@@ -718,6 +745,18 @@ function writeAdminSettings( $conf ) {
 ";
 }
 
+function escapePhpString( $string ) {
+       return strtr( $string,
+               array(
+                       "\n" => "\\n",
+                       "\r" => "\\r",
+                       "\t" => "\\t",
+                       "\\" => "\\\\",
+                       "\$" => "\\\$",
+                       "\"" => "\\\""
+               ));
+}
+
 function writeLocalSettings( $conf ) {
        $conf->DBmysql4 = @$conf->DBmysql4 ? 'true' : 'false';
        $conf->UseImageResize = $conf->UseImageResize ? 'true' : 'false';
@@ -744,11 +783,11 @@ function writeLocalSettings( $conf ) {
                for ( $i=0; $i<8; $i++ ) {
                        $proxyKey .= dechex(mt_rand(0, 0x7fffffff));
                }
-               print "Warning: \$wgProxyKey is insecure\n";
+               print "<li>Warning: \$wgProxyKey is insecure</li>\n";
        }
 
        # Add slashes to strings for double quoting
-       $slconf = array_map( "addslashes", get_object_vars( $conf ) );
+       $slconf = array_map( "escapePhpString", get_object_vars( $conf ) );
 
 
        $sep = (DIRECTORY_SEPARATOR == "\\") ? ";" : ":";
@@ -768,7 +807,7 @@ if ( \$wgCommandLineMode ) {
        if ( isset( \$_SERVER ) && array_key_exists( 'REQUEST_METHOD', \$_SERVER ) ) {
                die( \"This script must be run from the command line\\n\" );
        }
-} else {
+} elseif ( empty( \$wgConfiguring ) ) {
        ## Compress output if the browser supports it
        {$zlib}if( !ini_get( 'zlib.output_compression' ) ) ob_start( 'ob_gzhandler' );
 }
@@ -851,9 +890,9 @@ function dieout( $text ) {
        die( $text . "\n\n</body>\n</html>" );
 }
 
-function importPost( $name, $default = "" ) {
-       if( isset( $_POST[$name] ) ) {
-               $retval = $_POST[$name];
+function importVar( &$var, $name, $default = "" ) {
+       if( isset( $var[$name] ) ) {
+               $retval = $var[$name];
                if ( get_magic_quotes_gpc() ) {
                        $retval = stripslashes( $retval );
                }
@@ -863,6 +902,14 @@ function importPost( $name, $default = "" ) {
        return $retval;
 }
 
+function importPost( $name, $default = "" ) {
+       return importVar( $_POST, $name, $default );
+}
+
+function importRequest( $name, $default = "" ) {
+       return importVar( $_REQUEST, $name, $default );
+}
+
 function aField( &$conf, $field, $text, $type = "", $value = "" ) {
        if( $type != "" ) {
                $xtype = "type=\"$type\"";