2014-04-14 15:26:48 +01:00
|
|
|
|
{ config, lib, pkgs, serverInfo, php, ... }:
|
2009-12-02 17:59:17 +00:00
|
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
|
with lib;
|
2009-12-02 17:59:17 +00:00
|
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
2014-11-26 15:41:50 +00:00
|
|
|
|
httpd = serverInfo.serverConfig.package;
|
|
|
|
|
|
|
|
|
|
version24 = !versionOlder httpd.version "2.4";
|
|
|
|
|
|
|
|
|
|
allGranted = if version24 then ''
|
|
|
|
|
Require all granted
|
|
|
|
|
'' else ''
|
|
|
|
|
Order allow,deny
|
|
|
|
|
Allow from all
|
|
|
|
|
'';
|
|
|
|
|
|
2009-12-02 17:59:17 +00:00
|
|
|
|
mediawikiConfig = pkgs.writeText "LocalSettings.php"
|
|
|
|
|
''
|
|
|
|
|
<?php
|
|
|
|
|
# Copied verbatim from the default (generated) LocalSettings.php.
|
|
|
|
|
if( defined( 'MW_INSTALL_PATH' ) ) {
|
|
|
|
|
$IP = MW_INSTALL_PATH;
|
|
|
|
|
} else {
|
|
|
|
|
$IP = dirname( __FILE__ );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$path = array( $IP, "$IP/includes", "$IP/languages" );
|
|
|
|
|
set_include_path( implode( PATH_SEPARATOR, $path ) . PATH_SEPARATOR . get_include_path() );
|
|
|
|
|
|
|
|
|
|
require_once( "$IP/includes/DefaultSettings.php" );
|
|
|
|
|
|
|
|
|
|
if ( $wgCommandLineMode ) {
|
|
|
|
|
if ( isset( $_SERVER ) && array_key_exists( 'REQUEST_METHOD', $_SERVER ) ) {
|
|
|
|
|
die( "This script must be run from the command line\n" );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$wgScriptPath = "${config.urlPrefix}";
|
|
|
|
|
|
|
|
|
|
# We probably need to set $wgSecretKey and $wgCacheEpoch.
|
|
|
|
|
|
|
|
|
|
# Paths to external programs.
|
|
|
|
|
$wgDiff3 = "${pkgs.diffutils}/bin/diff3";
|
|
|
|
|
$wgDiff = "${pkgs.diffutils}/bin/diff";
|
|
|
|
|
$wgImageMagickConvertCommand = "${pkgs.imagemagick}/bin/convert";
|
|
|
|
|
|
2010-07-13 22:11:35 +01:00
|
|
|
|
#$wgDebugLogFile = "/tmp/mediawiki_debug_log.txt";
|
2009-12-02 17:59:17 +00:00
|
|
|
|
|
|
|
|
|
# Database configuration.
|
2009-12-03 08:44:54 +00:00
|
|
|
|
$wgDBtype = "${config.dbType}";
|
|
|
|
|
$wgDBserver = "${config.dbServer}";
|
|
|
|
|
$wgDBuser = "${config.dbUser}";
|
|
|
|
|
$wgDBpassword = "${config.dbPassword}";
|
|
|
|
|
$wgDBname = "${config.dbName}";
|
2009-12-03 08:25:16 +00:00
|
|
|
|
|
2009-12-03 08:44:54 +00:00
|
|
|
|
# E-mail.
|
|
|
|
|
$wgEmergencyContact = "${config.emergencyContact}";
|
|
|
|
|
$wgPasswordSender = "${config.passwordSender}";
|
|
|
|
|
|
|
|
|
|
$wgSitename = "${config.siteName}";
|
|
|
|
|
|
2009-12-03 13:34:36 +00:00
|
|
|
|
${optionalString (config.logo != "") ''
|
|
|
|
|
$wgLogo = "${config.logo}";
|
|
|
|
|
''}
|
|
|
|
|
|
|
|
|
|
${optionalString (config.articleUrlPrefix != "") ''
|
|
|
|
|
$wgArticlePath = "${config.articleUrlPrefix}/$1";
|
|
|
|
|
''}
|
|
|
|
|
|
2010-12-15 13:21:21 +00:00
|
|
|
|
${optionalString config.enableUploads ''
|
|
|
|
|
$wgEnableUploads = true;
|
|
|
|
|
$wgUploadDirectory = "${config.uploadDir}";
|
|
|
|
|
''}
|
|
|
|
|
|
2011-06-23 21:56:37 +01:00
|
|
|
|
${optionalString (config.defaultSkin != "") ''
|
|
|
|
|
$wgDefaultSkin = "${config.defaultSkin}";
|
|
|
|
|
''}
|
|
|
|
|
|
2009-12-03 08:44:54 +00:00
|
|
|
|
${config.extraConfig}
|
2009-12-02 17:59:17 +00:00
|
|
|
|
?>
|
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
# Unpack Mediawiki and put the config file in its root directory.
|
|
|
|
|
mediawikiRoot = pkgs.stdenv.mkDerivation rec {
|
2014-09-07 16:50:51 +01:00
|
|
|
|
name= "mediawiki-1.23.3";
|
2011-09-14 19:20:50 +01:00
|
|
|
|
|
2009-12-02 17:59:17 +00:00
|
|
|
|
src = pkgs.fetchurl {
|
2014-07-04 16:34:37 +01:00
|
|
|
|
url = "http://download.wikimedia.org/mediawiki/1.23/${name}.tar.gz";
|
2014-09-07 16:50:51 +01:00
|
|
|
|
sha256 = "0l6798jwjwk2khfnm84mgc65ij53a8pnv30wdnn15ys4ivia4bpf";
|
2009-12-02 17:59:17 +00:00
|
|
|
|
};
|
|
|
|
|
|
2012-07-05 20:02:54 +01:00
|
|
|
|
skins = config.skins;
|
2011-06-23 21:56:37 +01:00
|
|
|
|
|
2012-07-05 20:02:54 +01:00
|
|
|
|
buildPhase =
|
|
|
|
|
''
|
|
|
|
|
for skin in $skins; do
|
|
|
|
|
cp -prvd $skin/* skins/
|
|
|
|
|
done
|
|
|
|
|
''; # */
|
2009-12-02 17:59:17 +00:00
|
|
|
|
|
|
|
|
|
installPhase =
|
|
|
|
|
''
|
2014-06-30 13:56:10 +01:00
|
|
|
|
mkdir -p $out
|
2009-12-02 17:59:17 +00:00
|
|
|
|
cp -r * $out
|
|
|
|
|
cp ${mediawikiConfig} $out/LocalSettings.php
|
2014-07-04 16:34:37 +01:00
|
|
|
|
sed -i \
|
|
|
|
|
-e 's|/bin/bash|${pkgs.bash}/bin/bash|g' \
|
|
|
|
|
-e 's|/usr/bin/timeout|${pkgs.coreutils}/bin/timeout|g' \
|
|
|
|
|
$out/includes/limit.sh \
|
2014-02-10 14:14:30 +00:00
|
|
|
|
$out/includes/GlobalFunctions.php
|
2009-12-02 17:59:17 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
2009-12-03 12:20:24 +00:00
|
|
|
|
|
|
|
|
|
mediawikiScripts = pkgs.runCommand "mediawiki-${config.id}-scripts"
|
|
|
|
|
{ buildInputs = [ pkgs.makeWrapper ]; }
|
|
|
|
|
''
|
2014-06-30 13:56:10 +01:00
|
|
|
|
mkdir -p $out/bin
|
2013-04-11 16:28:16 +01:00
|
|
|
|
for i in changePassword.php createAndPromote.php userOptions.php edit.php nukePage.php update.php; do
|
2012-07-30 16:19:14 +01:00
|
|
|
|
makeWrapper ${php}/bin/php $out/bin/mediawiki-${config.id}-$(basename $i .php) \
|
2009-12-03 12:20:24 +00:00
|
|
|
|
--add-flags ${mediawikiRoot}/maintenance/$i
|
|
|
|
|
done
|
|
|
|
|
'';
|
2011-09-14 19:20:50 +01:00
|
|
|
|
|
2009-12-02 17:59:17 +00:00
|
|
|
|
in
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
extraConfig =
|
|
|
|
|
''
|
2010-12-15 13:21:21 +00:00
|
|
|
|
${optionalString config.enableUploads ''
|
|
|
|
|
Alias ${config.urlPrefix}/images ${config.uploadDir}
|
|
|
|
|
|
|
|
|
|
<Directory ${config.uploadDir}>
|
2014-11-26 15:41:50 +00:00
|
|
|
|
${allGranted}
|
2010-12-15 13:21:21 +00:00
|
|
|
|
Options -Indexes
|
|
|
|
|
</Directory>
|
|
|
|
|
''}
|
2011-09-14 19:20:50 +01:00
|
|
|
|
|
2014-02-27 11:37:22 +00:00
|
|
|
|
${if config.urlPrefix != "" then "Alias ${config.urlPrefix} ${mediawikiRoot}" else ''
|
|
|
|
|
RewriteEngine On
|
|
|
|
|
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
|
|
|
|
|
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
|
2014-08-29 12:56:23 +01:00
|
|
|
|
${concatMapStringsSep "\n" (u: "RewriteCond %{REQUEST_URI} !^${u.urlPath}") serverInfo.vhostConfig.servedDirs}
|
2014-02-27 12:17:05 +00:00
|
|
|
|
RewriteRule ${if config.enableUploads
|
|
|
|
|
then "!^/images"
|
|
|
|
|
else "^.*\$"
|
|
|
|
|
} %{DOCUMENT_ROOT}/${if config.articleUrlPrefix == ""
|
2014-02-27 11:37:22 +00:00
|
|
|
|
then ""
|
|
|
|
|
else "${config.articleUrlPrefix}/"
|
|
|
|
|
}index.php [L]
|
|
|
|
|
''}
|
2009-12-02 17:59:17 +00:00
|
|
|
|
|
|
|
|
|
<Directory ${mediawikiRoot}>
|
2014-11-26 15:41:50 +00:00
|
|
|
|
${allGranted}
|
2009-12-02 17:59:17 +00:00
|
|
|
|
DirectoryIndex index.php
|
|
|
|
|
</Directory>
|
2009-12-03 13:34:36 +00:00
|
|
|
|
|
|
|
|
|
${optionalString (config.articleUrlPrefix != "") ''
|
|
|
|
|
Alias ${config.articleUrlPrefix} ${mediawikiRoot}/index.php
|
|
|
|
|
''}
|
2009-12-02 17:59:17 +00:00
|
|
|
|
'';
|
|
|
|
|
|
2014-02-25 12:44:45 +00:00
|
|
|
|
documentRoot = if config.urlPrefix == "" then mediawikiRoot else null;
|
|
|
|
|
|
2010-07-14 13:58:38 +01:00
|
|
|
|
enablePHP = true;
|
|
|
|
|
|
2009-12-02 17:59:17 +00:00
|
|
|
|
options = {
|
|
|
|
|
|
2009-12-03 12:20:24 +00:00
|
|
|
|
id = mkOption {
|
|
|
|
|
default = "main";
|
|
|
|
|
description = ''
|
|
|
|
|
A unique identifier necessary to keep multiple MediaWiki server
|
|
|
|
|
instances on the same machine apart. This is used to
|
|
|
|
|
disambiguate the administrative scripts, which get names like
|
|
|
|
|
mediawiki-$id-change-password.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2009-12-02 17:59:17 +00:00
|
|
|
|
dbType = mkOption {
|
2009-12-03 08:44:54 +00:00
|
|
|
|
default = "postgres";
|
2009-12-02 17:59:17 +00:00
|
|
|
|
example = "mysql";
|
2009-12-03 08:44:54 +00:00
|
|
|
|
description = "Database type.";
|
2009-12-02 17:59:17 +00:00
|
|
|
|
};
|
|
|
|
|
|
2009-12-03 08:44:54 +00:00
|
|
|
|
dbName = mkOption {
|
|
|
|
|
default = "mediawiki";
|
|
|
|
|
description = "Name of the database that holds the MediaWiki data.";
|
|
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
|
2009-12-02 17:59:17 +00:00
|
|
|
|
dbServer = mkOption {
|
2009-12-03 08:44:54 +00:00
|
|
|
|
default = ""; # use a Unix domain socket
|
2009-12-02 17:59:17 +00:00
|
|
|
|
example = "10.0.2.2";
|
2009-12-03 08:44:54 +00:00
|
|
|
|
description = ''
|
2010-04-15 16:47:26 +01:00
|
|
|
|
The location of the database server. Leave empty to use a
|
2009-12-03 08:44:54 +00:00
|
|
|
|
database server running on the same machine through a Unix
|
|
|
|
|
domain socket.
|
|
|
|
|
'';
|
2009-12-02 17:59:17 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
dbUser = mkOption {
|
2009-12-03 11:56:03 +00:00
|
|
|
|
default = "mediawiki";
|
2009-12-03 08:44:54 +00:00
|
|
|
|
description = "The user name for accessing the database.";
|
2009-12-02 17:59:17 +00:00
|
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
|
2009-12-02 17:59:17 +00:00
|
|
|
|
dbPassword = mkOption {
|
|
|
|
|
default = "";
|
2009-12-03 08:44:54 +00:00
|
|
|
|
example = "foobar";
|
|
|
|
|
description = ''
|
|
|
|
|
The password of the database user. Warning: this is stored in
|
|
|
|
|
cleartext in the Nix store!
|
|
|
|
|
'';
|
2009-12-02 17:59:17 +00:00
|
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
|
2009-12-03 08:44:54 +00:00
|
|
|
|
emergencyContact = mkOption {
|
|
|
|
|
default = serverInfo.serverConfig.adminAddr;
|
|
|
|
|
example = "admin@example.com";
|
|
|
|
|
description = ''
|
|
|
|
|
Emergency contact e-mail address. Defaults to the Apache
|
|
|
|
|
admin address.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
|
2009-12-03 08:44:54 +00:00
|
|
|
|
passwordSender = mkOption {
|
|
|
|
|
default = serverInfo.serverConfig.adminAddr;
|
|
|
|
|
example = "password@example.com";
|
|
|
|
|
description = ''
|
|
|
|
|
E-mail address from which password confirmations originate.
|
|
|
|
|
Defaults to the Apache admin address.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
siteName = mkOption {
|
|
|
|
|
default = "MediaWiki";
|
|
|
|
|
example = "Foobar Wiki";
|
|
|
|
|
description = "Name of the wiki";
|
2009-12-02 17:59:17 +00:00
|
|
|
|
};
|
|
|
|
|
|
2009-12-03 13:34:36 +00:00
|
|
|
|
logo = mkOption {
|
|
|
|
|
default = "";
|
|
|
|
|
example = "/images/logo.png";
|
|
|
|
|
description = "The URL of the site's logo (which should be a 135x135px image).";
|
|
|
|
|
};
|
|
|
|
|
|
2009-12-02 17:59:17 +00:00
|
|
|
|
urlPrefix = mkOption {
|
2009-12-03 13:34:36 +00:00
|
|
|
|
default = "/w";
|
2009-12-02 17:59:17 +00:00
|
|
|
|
description = ''
|
|
|
|
|
The URL prefix under which the Mediawiki service appears.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2009-12-03 13:34:36 +00:00
|
|
|
|
articleUrlPrefix = mkOption {
|
|
|
|
|
default = "/wiki";
|
|
|
|
|
example = "";
|
|
|
|
|
description = ''
|
|
|
|
|
The URL prefix under which article pages appear,
|
|
|
|
|
e.g. http://server/wiki/Page. Leave empty to use the main URL
|
|
|
|
|
prefix, e.g. http://server/w/index.php?title=Page.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2010-12-15 13:21:21 +00:00
|
|
|
|
enableUploads = mkOption {
|
|
|
|
|
default = false;
|
|
|
|
|
description = "Whether to enable file uploads.";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
uploadDir = mkOption {
|
|
|
|
|
default = throw "You must specify `uploadDir'.";
|
|
|
|
|
example = "/data/mediawiki-upload";
|
|
|
|
|
description = "The directory that stores uploaded files.";
|
|
|
|
|
};
|
|
|
|
|
|
2011-06-23 21:56:37 +01:00
|
|
|
|
defaultSkin = mkOption {
|
2011-07-04 16:51:38 +01:00
|
|
|
|
default = "";
|
2011-06-23 21:56:37 +01:00
|
|
|
|
example = "nostalgia";
|
2011-07-04 16:51:38 +01:00
|
|
|
|
description = "Set this value to change the default skin used by MediaWiki.";
|
2011-06-23 21:56:37 +01:00
|
|
|
|
};
|
|
|
|
|
|
2012-07-05 20:02:54 +01:00
|
|
|
|
skins = mkOption {
|
|
|
|
|
default = [];
|
|
|
|
|
type = types.listOf types.path;
|
|
|
|
|
description =
|
|
|
|
|
''
|
|
|
|
|
List of paths whose content is copied to the ‘skins’
|
|
|
|
|
subdirectory of the MediaWiki installation.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2009-12-03 08:44:54 +00:00
|
|
|
|
extraConfig = mkOption {
|
|
|
|
|
default = "";
|
|
|
|
|
example =
|
|
|
|
|
''
|
|
|
|
|
$wgEnableEmail = false;
|
|
|
|
|
'';
|
|
|
|
|
description = ''
|
|
|
|
|
Any additional text to be appended to MediaWiki's
|
|
|
|
|
configuration file. This is a PHP script. For configuration
|
|
|
|
|
settings, see <link xlink:href='http://www.mediawiki.org/wiki/Manual:Configuration_settings'/>.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2009-12-02 17:59:17 +00:00
|
|
|
|
};
|
|
|
|
|
|
2009-12-03 12:20:24 +00:00
|
|
|
|
extraPath = [ mediawikiScripts ];
|
2009-12-10 09:22:45 +00:00
|
|
|
|
|
|
|
|
|
# !!! Need to specify that Apache has a dependency on PostgreSQL!
|
2011-09-14 19:20:50 +01:00
|
|
|
|
|
2009-12-02 17:59:17 +00:00
|
|
|
|
startupScript = pkgs.writeScript "mediawiki_startup.sh"
|
2009-12-03 08:44:54 +00:00
|
|
|
|
# Initialise the database automagically if we're using a Postgres
|
|
|
|
|
# server on localhost.
|
|
|
|
|
(optionalString (config.dbType == "postgres" && config.dbServer == "") ''
|
|
|
|
|
if ! ${pkgs.postgresql}/bin/psql -l | grep -q ' ${config.dbName} ' ; then
|
|
|
|
|
${pkgs.postgresql}/bin/createuser --no-superuser --no-createdb --no-createrole "${config.dbUser}" || true
|
|
|
|
|
${pkgs.postgresql}/bin/createdb "${config.dbName}" -O "${config.dbUser}"
|
2009-12-03 11:56:03 +00:00
|
|
|
|
( echo 'CREATE LANGUAGE plpgsql;'
|
|
|
|
|
cat ${mediawikiRoot}/maintenance/postgres/tables.sql
|
|
|
|
|
echo 'CREATE TEXT SEARCH CONFIGURATION public.default ( COPY = pg_catalog.english );'
|
|
|
|
|
echo COMMIT
|
|
|
|
|
) | ${pkgs.postgresql}/bin/psql -U "${config.dbUser}" "${config.dbName}"
|
2009-12-02 17:59:17 +00:00
|
|
|
|
fi
|
2014-02-10 13:56:16 +00:00
|
|
|
|
${php}/bin/php ${mediawikiRoot}/maintenance/update.php
|
2009-12-03 08:44:54 +00:00
|
|
|
|
'');
|
2009-12-03 13:34:36 +00:00
|
|
|
|
|
|
|
|
|
robotsEntries = optionalString (config.articleUrlPrefix != "")
|
|
|
|
|
''
|
|
|
|
|
User-agent: *
|
|
|
|
|
Disallow: ${config.urlPrefix}/
|
|
|
|
|
Disallow: ${config.articleUrlPrefix}/Special:Search
|
|
|
|
|
Disallow: ${config.articleUrlPrefix}/Special:Random
|
|
|
|
|
'';
|
|
|
|
|
|
2009-12-02 17:59:17 +00:00
|
|
|
|
}
|