Imported the register_globals hack from REL1_2. Also starting work on
[lhc/web/wiklou.git] / index.php
1 <?php
2 # Main wiki script; see design.doc
3 #
4 $wgRequestTime = microtime();
5
6 ## Enable this to debug total elimination of register_globals
7 #define( "DEBUG_GLOBALS", 1 );
8
9 if( defined('DEBUG_GLOBALS') ) error_reporting(E_ALL);
10
11 function &fix_magic_quotes( &$arr ) {
12 foreach( $arr as $key => $val ) {
13 if( is_array( $val ) ) {
14 fix_magic_quotes( $arr[$key] );
15 } else {
16 $arr[$key] = stripslashes( $val );
17 }
18 }
19 return $arr;
20 }
21
22 if ( get_magic_quotes_gpc() ) {
23 fix_magic_quotes( $_COOKIE );
24 fix_magic_quotes( $_ENV );
25 fix_magic_quotes( $_GET );
26 fix_magic_quotes( $_POST );
27 fix_magic_quotes( $_REQUEST );
28 fix_magic_quotes( $_SERVER );
29 } elseif( defined('DEBUG_GLOBALS') ) {
30 die("DEBUG_GLOBALS: turn on magic_quotes_gpc" );
31 }
32
33 if( defined('DEBUG_GLOBALS') ) {
34 if( ini_get( "register_globals" ) ) {
35 die( "DEBUG_GLOBALS: turn off register_globals" );
36 }
37 } elseif( !ini_get( "register_globals" ) ) {
38 # Insecure, but at least it'll run
39 import_request_variables( "GPC" );
40 }
41
42 unset( $IP );
43 ini_set( "allow_url_fopen", 0 ); # For security...
44 if(!file_exists("LocalSettings.php")) {
45 die( "You'll have to <a href='$wgScriptPath/config/index.php'>set the wiki up</a> first!" );
46 }
47 include_once( "./LocalSettings.php" );
48
49 if( $wgSitename == "MediaWiki" ) {
50 die( "You must set the site name in \$wgSitename before installation.\n\n" );
51 }
52
53 # PATH_SEPARATOR avaialble only from 4.3.0
54 $sep = (DIRECTORY_SEPARATOR == "\\") ? ";" : ":";
55 ini_set( "include_path", $IP . $sep . ini_get( "include_path" ) );
56
57 include_once( "Setup.php" );
58
59 wfProfileIn( "main-misc-setup" );
60 OutputPage::setEncodings(); # Not really used yet
61
62 # Query string fields
63 #
64 #global $action, $title, $search, $go, $target, $printable;
65 #global $returnto, $diff, $oldid, $curid;
66
67 $action = $_REQUEST['action'];
68 if( isset( $_SERVER['PATH_INFO'] ) ) {
69 $title = substr( $_SERVER['PATH_INFO'], 1 );
70 } else {
71 $title = $_REQUEST['title'];
72 }
73
74 # Placeholders in case of DB error
75 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
76 $wgArticle = new Article($wgTitle);
77
78 $action = strtolower( trim( $action ) );
79 if ( "" == $action ) { $action = "view"; }
80 if ( !empty( $_REQUEST['printable'] ) && $_REQUEST['printable'] == "yes") {
81 $wgOut->setPrintable();
82 }
83
84 if ( "" == $title && "delete" != $action ) {
85 $wgTitle = Title::newFromText( wfMsg( "mainpage" ) );
86 } elseif ( !empty( $_REQUEST['curid'] ) ) {
87 # URLs like this are generated by RC, because rc_title isn't always accurate
88 $wgTitle = Title::newFromID( $_REQUEST['curid'] );
89 } else {
90 $wgTitle = Title::newFromURL( $title );
91 }
92 wfProfileOut( "main-misc-setup" );
93
94 # If the user is not logged in, the Namespace:title of the article must be in the Read array in
95 # order for the user to see it.
96 if ( !$wgUser->getID() && is_array( $wgWhitelistRead ) && $wgTitle) {
97 if ( !in_array( $wgLang->getNsText( $wgTitle->getNamespace() ) . ":" . $wgTitle->getDBkey(), $wgWhitelistRead ) ) {
98 $wgOut->loginToUse();
99 $wgOut->output();
100 exit;
101 }
102 }
103
104 if ( !empty( $_REQUEST['search'] ) ) {
105 if( isset($_REQUEST['fulltext']) ) {
106 wfSearch( $_REQUEST['search'] );
107 } else {
108 wfGo( $_REQUEST['search'] );
109 }
110 } else if( !$wgTitle or $wgTitle->getInterwiki() != "" or $wgTitle->getDBkey() == "" ) {
111 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
112 $wgOut->errorpage( "badtitle", "badtitletext" );
113 } else if ( ( $action == "view" ) && $wgTitle->getPrefixedDBKey() != $title ) {
114 /* redirect to canonical url, make it a 301 to allow caching */
115 $wgOut->redirect( wfLocalUrl( $wgTitle->getPrefixedURL() ), '301');
116 } else if ( Namespace::getSpecial() == $wgTitle->getNamespace() ) {
117 wfSpecialPage();
118 } else {
119 if ( Namespace::getMedia() == $wgTitle->getNamespace() ) {
120 $wgTitle = Title::makeTitle( Namespace::getImage(), $wgTitle->getDBkey() );
121 }
122
123 switch( $wgTitle->getNamespace() ) {
124 case 6:
125 include_once( "ImagePage.php" );
126 $wgArticle = new ImagePage( $wgTitle );
127 break;
128 default:
129 $wgArticle = new Article( $wgTitle );
130 }
131
132 wfQuery("BEGIN", DB_WRITE);
133 switch( $action ) {
134 case "view":
135 case "watch":
136 case "unwatch":
137 case "delete":
138 case "revert":
139 case "rollback":
140 case "protect":
141 case "unprotect":
142 $wgArticle->$action();
143 break;
144 case "print":
145 $wgArticle->view();
146 break;
147 case "edit":
148 case "submit":
149 if( !$wgCommandLineMode && !isset( $_COOKIE[ini_get("session.name")] ) ) {
150 User::SetupSession();
151 }
152 include_once( "EditPage.php" );
153 $editor = new EditPage( $wgArticle );
154 $editor->$action();
155 break;
156 case "history":
157 include_once( "PageHistory.php" );
158 $history = new PageHistory( $wgArticle );
159 $history->history();
160 break;
161 default:
162 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
163 }
164 wfQuery("COMMIT", DB_WRITE);
165 }
166
167 $wgOut->output();
168 foreach ( $wgDeferredUpdateList as $up ) { $up->doUpdate(); }
169 logProfilingData();
170 wfDebug( "Request ended normally\n" );
171 ?>