summaryrefslogtreecommitdiff
path: root/maintenance/dev
diff options
context:
space:
mode:
Diffstat (limited to 'maintenance/dev')
-rw-r--r--maintenance/dev/README7
-rw-r--r--maintenance/dev/includes/php.sh12
-rw-r--r--maintenance/dev/includes/require-php.sh8
-rw-r--r--maintenance/dev/includes/router.php82
-rw-r--r--maintenance/dev/install.sh8
-rw-r--r--maintenance/dev/installmw.sh18
-rw-r--r--maintenance/dev/installphp.sh57
-rw-r--r--maintenance/dev/start.sh14
8 files changed, 206 insertions, 0 deletions
diff --git a/maintenance/dev/README b/maintenance/dev/README
new file mode 100644
index 00000000..ca47d136
--- /dev/null
+++ b/maintenance/dev/README
@@ -0,0 +1,7 @@
+maintenance/dev/ scripts can help quickly setup a local MediaWiki for development purposes.
+
+Wikis setup in this way are NOT meant to be publicly available. They use a development database not acceptible for use in production. Place a sqlite database in an unsafe location a real wiki should never place it in. And use predictable default logins for the initial administrator user.
+
+Running maintenance/dev/install.sh will download and install a local copy of php 5.4, install a sqlite powered instance of MW for development, and then start up a local webserver to view the wiki.
+
+After installation you can bring the webserver back up at any time you want with maintenance/dev/start.sh
diff --git a/maintenance/dev/includes/php.sh b/maintenance/dev/includes/php.sh
new file mode 100644
index 00000000..3021b93b
--- /dev/null
+++ b/maintenance/dev/includes/php.sh
@@ -0,0 +1,12 @@
+# Include-able script to determine the location of our php if any
+
+if [ -d "$DEV/php" -a -x "$DEV/php/bin/php" ]; then
+ # Quick local copy
+ PHP="$DEV/php/bin/php"
+elif [ -d "$HOME/.mediawiki/php" -a -x "$HOME/.mediawiki/php/bin/php" ]; then
+ # Previous home directory location to install php in
+ PHP="$HOME/.mediawiki/php/bin/php"
+elif [ -d "$HOME/.mwphp" -a -x "$HOME/.mwphp/bin/php" ]; then
+ # Previous home directory location to install php in
+ PHP="$HOME/.mwphp/bin/php"
+fi
diff --git a/maintenance/dev/includes/require-php.sh b/maintenance/dev/includes/require-php.sh
new file mode 100644
index 00000000..470e6eb8
--- /dev/null
+++ b/maintenance/dev/includes/require-php.sh
@@ -0,0 +1,8 @@
+# Include-able script to require that we have a known php binary we can execute
+
+. "$DEV/includes/php.sh"
+
+if [ "x$PHP" == "x" -o ! -x "$PHP" ]; then
+ echo "Local copy of PHP is not installed"
+ exit 1
+fi
diff --git a/maintenance/dev/includes/router.php b/maintenance/dev/includes/router.php
new file mode 100644
index 00000000..f6a062b6
--- /dev/null
+++ b/maintenance/dev/includes/router.php
@@ -0,0 +1,82 @@
+<?php
+
+# Router for the php cli-server built-in webserver
+# http://ca2.php.net/manual/en/features.commandline.webserver.php
+
+if ( php_sapi_name() != 'cli-server' ) {
+ die( "This script can only be run by php's cli-server sapi." );
+}
+
+ini_set('display_errors', 1);
+error_reporting(E_ALL);
+
+if ( isset( $_SERVER["SCRIPT_FILENAME"] ) ) {
+ # Known resource, sometimes a script sometimes a file
+ $file = $_SERVER["SCRIPT_FILENAME"];
+} elseif ( isset( $_SERVER["SCRIPT_NAME"] ) ) {
+ # Usually unknown, document root relative rather than absolute
+ # Happens with some cases like /wiki/File:Image.png
+ if ( is_readable( $_SERVER['DOCUMENT_ROOT'] . $_SERVER["SCRIPT_NAME"] ) ) {
+ # Just in case this actually IS a file, set it here
+ $file = $_SERVER['DOCUMENT_ROOT'] . $_SERVER["SCRIPT_NAME"];
+ } else {
+ # Otherwise let's pretend that this is supposed to go to index.php
+ $file = $_SERVER['DOCUMENT_ROOT'] . '/index.php';
+ }
+} else {
+ # Meh, we'll just give up
+ return false;
+}
+
+# And now do handling for that $file
+
+if ( !is_readable( $file ) ) {
+ # Let the server throw the error if it doesn't exist
+ return false;
+}
+$ext = pathinfo( $file, PATHINFO_EXTENSION );
+if ( $ext == 'php' || $ext == 'php5' ) {
+ # Execute php files
+ # We use require and return true here because when you return false
+ # the php webserver will discard post data and things like login
+ # will not function in the dev environment.
+ require( $file );
+ return true;
+}
+$mime = false;
+$lines = explode( "\n", file_get_contents( "includes/mime.types" ) );
+foreach ( $lines as $line ) {
+ $exts = explode( " ", $line );
+ $mime = array_shift( $exts );
+ if ( in_array( $ext, $exts ) ) {
+ break; # this is the right value for $mime
+ }
+ $mime = false;
+}
+if ( !$mime ) {
+ $basename = basename( $file );
+ if ( $basename == strtoupper( $basename ) ) {
+ # IF it's something like README serve it as text
+ $mime = "text/plain";
+ }
+}
+if ( $mime ) {
+ # Use custom handling to serve files with a known mime type
+ # This way we can serve things like .svg files that the built-in
+ # PHP webserver doesn't understand.
+ # ;) Nicely enough we just happen to bundle a mime.types file
+ $f = fopen($file, 'rb');
+ if ( preg_match( '^text/', $mime ) ) {
+ # Text should have a charset=UTF-8 (php's webserver does this too)
+ header("Content-Type: $mime; charset=UTF-8");
+ } else {
+ header("Content-Type: $mime");
+ }
+ header("Content-Length: " . filesize($file));
+ // Stream that out to the browser
+ fpassthru($f);
+ return true;
+}
+
+# Let the php server handle things on it's own otherwise
+return false;
diff --git a/maintenance/dev/install.sh b/maintenance/dev/install.sh
new file mode 100644
index 00000000..2219894d
--- /dev/null
+++ b/maintenance/dev/install.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+if [ "x$BASH_SOURCE" == "x" ]; then echo '$BASH_SOURCE not set'; exit 1; fi
+DEV=$(cd -P "$(dirname "${BASH_SOURCE[0]}" )" && pwd)
+
+"$DEV/installphp.sh"
+"$DEV/installmw.sh"
+"$DEV/start.sh"
diff --git a/maintenance/dev/installmw.sh b/maintenance/dev/installmw.sh
new file mode 100644
index 00000000..9ae3c593
--- /dev/null
+++ b/maintenance/dev/installmw.sh
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+if [ "x$BASH_SOURCE" == "x" ]; then echo '$BASH_SOURCE not set'; exit 1; fi
+DEV=$(cd -P "$(dirname "${BASH_SOURCE[0]}" )" && pwd)
+
+. "$DEV/includes/require-php.sh"
+
+set -e
+
+PORT=4881
+
+cd "$DEV/../../"; # $IP
+
+mkdir -p "$DEV/data"
+"$PHP" maintenance/install.php --server="http://localhost:$PORT" --scriptpath="" --dbtype=sqlite --dbpath="$DEV/data" --pass=admin "Trunk Test" "$USER"
+echo ""
+echo "Development wiki created with admin user $USER and password 'admin'."
+echo ""
diff --git a/maintenance/dev/installphp.sh b/maintenance/dev/installphp.sh
new file mode 100644
index 00000000..d26ffa67
--- /dev/null
+++ b/maintenance/dev/installphp.sh
@@ -0,0 +1,57 @@
+#!/bin/bash
+
+if [ "x$BASH_SOURCE" == "x" ]; then echo '$BASH_SOURCE not set'; exit 1; fi
+DEV=$(cd -P "$(dirname "${BASH_SOURCE[0]}" )" && pwd)
+
+set -e # DO NOT USE PIPES unless this is rewritten
+
+. "$DEV/includes/php.sh"
+
+if [ "x$PHP" != "x" -a -x "$PHP" ]; then
+ echo "PHP is already installed"
+ exit 0
+fi
+
+TAR=php5.4-latest.tar.gz
+PHPURL="http://snaps.php.net/$TAR"
+
+cd "$DEV"
+
+echo "Preparing to download and install a local copy of PHP 5.4, note that this can take some time to do."
+echo "If you wish to avoid re-doing this for uture dev installations of MediaWiki we suggest installing php in ~/.mediawiki/php"
+echo -n "Install PHP in ~/.mediawiki/php [y/N]: "
+read INSTALLINHOME
+
+case "$INSTALLINHOME" in
+ [Yy] | [Yy][Ee][Ss] )
+ PREFIX="$HOME/.mediawiki/php"
+ ;;
+ *)
+ PREFIX="$DEV/php/"
+ ;;
+esac
+
+# Some debain-like systems bundle wget but not curl, some other systems
+# like os x bundle curl but not wget... use whatever is available
+echo -n "Downloading PHP 5.4"
+if command -v wget &>/dev/null; then
+ echo "- using wget"
+ wget "$PHPURL"
+elif command -v curl &>/dev/null; then
+ echo "- using curl"
+ curl -O "$PHPURL"
+else
+ echo "- aborting"
+ echo "Could not find curl or wget." >&2;
+ exit 1;
+fi
+
+echo "Extracting php 5.4"
+tar -xzf "$TAR"
+
+cd php5.4-*/
+
+echo "Configuring and installing php 5.4 in $PREFIX"
+./configure --prefix="$PREFIX"
+make
+make install
diff --git a/maintenance/dev/start.sh b/maintenance/dev/start.sh
new file mode 100644
index 00000000..dd7363a8
--- /dev/null
+++ b/maintenance/dev/start.sh
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+if [ "x$BASH_SOURCE" == "x" ]; then echo '$BASH_SOURCE not set'; exit 1; fi
+DEV=$(cd -P "$(dirname "${BASH_SOURCE[0]}" )" && pwd)
+
+. "$DEV/includes/require-php.sh"
+
+PORT=4881
+
+echo "Starting up MediaWiki at http://localhost:$PORT/"
+echo ""
+
+cd "$DEV/../../"; # $IP
+"$PHP" -S "localhost:$PORT" "$DEV/includes/router.php"