r105821 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105820‎ | r105821 | r105822 >
Date:19:45, 11 December 2011
Author:dantman
Status:ok
Tags:
Comment:
Follow up r102210:
- Update maintenance/dev/ to install php inside ~/.mediawiki/php instead of ~/.mwphp
- Tweak README a bit
- Move the router.php into an includes along with two helper .sh files to cut out some of the repetition
Modified paths:
  • /trunk/phase3/maintenance/dev/README (modified) (history)
  • /trunk/phase3/maintenance/dev/includes (added) (history)
  • /trunk/phase3/maintenance/dev/includes/router.php (added) (history)
  • /trunk/phase3/maintenance/dev/installmw.sh (modified) (history)
  • /trunk/phase3/maintenance/dev/installphp.sh (modified) (history)
  • /trunk/phase3/maintenance/dev/router.php (deleted) (history)
  • /trunk/phase3/maintenance/dev/start.sh (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/dev/router.php
@@ -1,78 +0,0 @@
2 -<?php
3 -
4 -# Router for the php cli-server built-in webserver
5 -# http://ca2.php.net/manual/en/features.commandline.webserver.php
6 -
7 -ini_set('display_errors', 1);
8 -error_reporting(E_ALL);
9 -
10 -if ( isset( $_SERVER["SCRIPT_FILENAME"] ) ) {
11 - # Known resource, sometimes a script sometimes a file
12 - $file = $_SERVER["SCRIPT_FILENAME"];
13 -} elseif ( isset( $_SERVER["SCRIPT_NAME"] ) ) {
14 - # Usually unknown, document root relative rather than absolute
15 - # Happens with some cases like /wiki/File:Image.png
16 - if ( is_readable( $_SERVER['DOCUMENT_ROOT'] . $_SERVER["SCRIPT_NAME"] ) ) {
17 - # Just in case this actually IS a file, set it here
18 - $file = $_SERVER['DOCUMENT_ROOT'] . $_SERVER["SCRIPT_NAME"];
19 - } else {
20 - # Otherwise let's pretend that this is supposed to go to index.php
21 - $file = $_SERVER['DOCUMENT_ROOT'] . '/index.php';
22 - }
23 -} else {
24 - # Meh, we'll just give up
25 - return false;
26 -}
27 -
28 -# And now do handling for that $file
29 -
30 -if ( !is_readable( $file ) ) {
31 - # Let the server throw the error if it doesn't exist
32 - return false;
33 -}
34 -$ext = pathinfo( $file, PATHINFO_EXTENSION );
35 -if ( $ext == 'php' || $ext == 'php5' ) {
36 - # Execute php files
37 - # We use require and return true here because when you return false
38 - # the php webserver will discard post data and things like login
39 - # will not function in the dev environment.
40 - require( $file );
41 - return true;
42 -}
43 -$mime = false;
44 -$lines = explode( "\n", file_get_contents( "includes/mime.types" ) );
45 -foreach ( $lines as $line ) {
46 - $exts = explode( " ", $line );
47 - $mime = array_shift( $exts );
48 - if ( in_array( $ext, $exts ) ) {
49 - break; # this is the right value for $mime
50 - }
51 - $mime = false;
52 -}
53 -if ( !$mime ) {
54 - $basename = basename( $file );
55 - if ( $basename == strtoupper( $basename ) ) {
56 - # IF it's something like README serve it as text
57 - $mime = "text/plain";
58 - }
59 -}
60 -if ( $mime ) {
61 - # Use custom handling to serve files with a known mime type
62 - # This way we can serve things like .svg files that the built-in
63 - # PHP webserver doesn't understand.
64 - # ;) Nicely enough we just happen to bundle a mime.types file
65 - $f = fopen($file, 'rb');
66 - if ( preg_match( '^text/', $mime ) ) {
67 - # Text should have a charset=UTF-8 (php's webserver does this too)
68 - header("Content-Type: $mime; charset=UTF-8");
69 - } else {
70 - header("Content-Type: $mime");
71 - }
72 - header("Content-Length: " . filesize($file));
73 - // Stream that out to the browser
74 - fpassthru($f);
75 - return true;
76 -}
77 -
78 -# Let the php server handle things on it's own otherwise
79 -return false;
Index: trunk/phase3/maintenance/dev/installmw.sh
@@ -3,14 +3,7 @@
44 if [ "x$BASH_SOURCE" == "x" ]; then echo '$BASH_SOURCE not set'; exit 1; fi
55 DEV=$(cd -P "$(dirname "${BASH_SOURCE[0]}" )" && pwd)
66
7 -if [ -d "$DEV/php" -a -x "$DEV/php/bin/php" ]; then
8 - PHP="$DEV/php/bin/php"
9 -elif [ -d "$HOME/.mwphp" -a -x "$HOME/.mwphp/bin/php" ]; then
10 - PHP="$HOME/.mwphp/bin/php"
11 -else
12 - echo "Local copy of PHP is not installed"
13 - echo 1
14 -fi
 7+. "$DEV/includes/require-php.sh"
158
169 set -e
1710
Index: trunk/phase3/maintenance/dev/includes/router.php
@@ -0,0 +1,78 @@
 2+<?php
 3+
 4+# Router for the php cli-server built-in webserver
 5+# http://ca2.php.net/manual/en/features.commandline.webserver.php
 6+
 7+ini_set('display_errors', 1);
 8+error_reporting(E_ALL);
 9+
 10+if ( isset( $_SERVER["SCRIPT_FILENAME"] ) ) {
 11+ # Known resource, sometimes a script sometimes a file
 12+ $file = $_SERVER["SCRIPT_FILENAME"];
 13+} elseif ( isset( $_SERVER["SCRIPT_NAME"] ) ) {
 14+ # Usually unknown, document root relative rather than absolute
 15+ # Happens with some cases like /wiki/File:Image.png
 16+ if ( is_readable( $_SERVER['DOCUMENT_ROOT'] . $_SERVER["SCRIPT_NAME"] ) ) {
 17+ # Just in case this actually IS a file, set it here
 18+ $file = $_SERVER['DOCUMENT_ROOT'] . $_SERVER["SCRIPT_NAME"];
 19+ } else {
 20+ # Otherwise let's pretend that this is supposed to go to index.php
 21+ $file = $_SERVER['DOCUMENT_ROOT'] . '/index.php';
 22+ }
 23+} else {
 24+ # Meh, we'll just give up
 25+ return false;
 26+}
 27+
 28+# And now do handling for that $file
 29+
 30+if ( !is_readable( $file ) ) {
 31+ # Let the server throw the error if it doesn't exist
 32+ return false;
 33+}
 34+$ext = pathinfo( $file, PATHINFO_EXTENSION );
 35+if ( $ext == 'php' || $ext == 'php5' ) {
 36+ # Execute php files
 37+ # We use require and return true here because when you return false
 38+ # the php webserver will discard post data and things like login
 39+ # will not function in the dev environment.
 40+ require( $file );
 41+ return true;
 42+}
 43+$mime = false;
 44+$lines = explode( "\n", file_get_contents( "includes/mime.types" ) );
 45+foreach ( $lines as $line ) {
 46+ $exts = explode( " ", $line );
 47+ $mime = array_shift( $exts );
 48+ if ( in_array( $ext, $exts ) ) {
 49+ break; # this is the right value for $mime
 50+ }
 51+ $mime = false;
 52+}
 53+if ( !$mime ) {
 54+ $basename = basename( $file );
 55+ if ( $basename == strtoupper( $basename ) ) {
 56+ # IF it's something like README serve it as text
 57+ $mime = "text/plain";
 58+ }
 59+}
 60+if ( $mime ) {
 61+ # Use custom handling to serve files with a known mime type
 62+ # This way we can serve things like .svg files that the built-in
 63+ # PHP webserver doesn't understand.
 64+ # ;) Nicely enough we just happen to bundle a mime.types file
 65+ $f = fopen($file, 'rb');
 66+ if ( preg_match( '^text/', $mime ) ) {
 67+ # Text should have a charset=UTF-8 (php's webserver does this too)
 68+ header("Content-Type: $mime; charset=UTF-8");
 69+ } else {
 70+ header("Content-Type: $mime");
 71+ }
 72+ header("Content-Length: " . filesize($file));
 73+ // Stream that out to the browser
 74+ fpassthru($f);
 75+ return true;
 76+}
 77+
 78+# Let the php server handle things on it's own otherwise
 79+return false;
Property changes on: trunk/phase3/maintenance/dev/includes/router.php
___________________________________________________________________
Added: svn:eol-style
180 + native
Index: trunk/phase3/maintenance/dev/start.sh
@@ -3,14 +3,7 @@
44 if [ "x$BASH_SOURCE" == "x" ]; then echo '$BASH_SOURCE not set'; exit 1; fi
55 DEV=$(cd -P "$(dirname "${BASH_SOURCE[0]}" )" && pwd)
66
7 -if [ -d "$DEV/php" -a -x "$DEV/php/bin/php" ]; then
8 - PHP="$DEV/php/bin/php"
9 -elif [ -d "$HOME/.mwphp" -a -x "$HOME/.mwphp/bin/php" ]; then
10 - PHP="$HOME/.mwphp/bin/php"
11 -else
12 - echo "Local copy of PHP is not installed"
13 - echo 1
14 -fi
 7+. "$DEV/includes/require-php.sh"
158
169 PORT=4881
1710
@@ -18,4 +11,4 @@
1912 echo ""
2013
2114 cd "$DEV/../../"; # $IP
22 -"$PHP" -S "localhost:$PORT" "$DEV/router.php"
 15+"$PHP" -S "localhost:$PORT" "$DEV/includes/router.php"
Index: trunk/phase3/maintenance/dev/installphp.sh
@@ -5,7 +5,9 @@
66
77 set -e # DO NOT USE PIPES unless this is rewritten
88
9 -if [ -d "$DEV/php" -a -x "$DEV/php/bin/php" ] || [ -d "$HOME/.mwphp" -a -x "$HOME/.mwphp/bin/php" ]; then
 9+. "$DEV/includes/php.sh"
 10+
 11+if [ "x$PHP" != "x" -a -x "$PHP" ]; then
1012 echo "PHP is already installed"
1113 exit 0
1214 fi
@@ -16,13 +18,13 @@
1719 cd "$DEV"
1820
1921 echo "Preparing to download and install a local copy of PHP 5.4, note that this can take some time to do."
20 -echo "If you wish to avoid re-doing this for uture dev installations of MediaWiki we suggest installing php in ~/.mwphp"
21 -echo -n "Install PHP in ~/.mwphp [y/N]: "
 22+echo "If you wish to avoid re-doing this for uture dev installations of MediaWiki we suggest installing php in ~/.mediawiki/php"
 23+echo -n "Install PHP in ~/.mediawiki/php [y/N]: "
2224 read INSTALLINHOME
2325
2426 case "$INSTALLINHOME" in
2527 [Yy] | [Yy][Ee][Ss] )
26 - PREFIX="$HOME/.mwphp"
 28+ PREFIX="$HOME/.mediawiki/php"
2729 ;;
2830 *)
2931 PREFIX="$DEV/php/"
Index: trunk/phase3/maintenance/dev/README
@@ -1,6 +1,6 @@
22 maintenance/dev/ scripts can help quickly setup a local MediaWiki for development purposes.
33
4 -Wikis setup in this way are NOT meant to be publicly available. They use a development database not acceptible for use in production and place a sqlite database in an unsafe location a real wiki should never place it in.
 4+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.
55
66 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.
77

Follow-up revisions

RevisionCommit summaryAuthorDate
r105822Follow up r105821, as usual, commit the files I forgot to `svn add`dantman19:49, 11 December 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r102210Allow for installation of php in ~/.mwphp and don't die if maintenance/dev/da...dantman23:49, 6 November 2011

Status & tagging log