45c8bc681d9c8c89c4d8edca07e291587522d5ab
2 # Main wiki script; see design.doc
4 $wgRequestTime = microtime();
6 ## Enable this to debug total elimination of register_globals
7 #define( "DEBUG_GLOBALS", 1 );
9 if( defined('DEBUG_GLOBALS') ) error_reporting(E_ALL
);
11 function &fix_magic_quotes( &$arr ) {
12 foreach( $arr as $key => $val ) {
13 if( is_array( $val ) ) {
14 fix_magic_quotes( $arr[$key] );
16 $arr[$key] = stripslashes( $val );
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" );
33 if( defined('DEBUG_GLOBALS') ) {
34 if( ini_get( "register_globals" ) ) {
35 die( "DEBUG_GLOBALS: turn off register_globals" );
37 } elseif( !ini_get( "register_globals" ) ) {
38 # Insecure, but at least it'll run
39 import_request_variables( "GPC" );
43 ini_set( "allow_url_fopen", 0 ); # For security...
44 if(!file_exists("LocalSettings.php")) {
45 die( "You'll have to <a href='config/index.php'>set the wiki up</a> first!" );
47 include_once( "./LocalSettings.php" );
49 if( $wgSitename == "MediaWiki" ) {
50 die( "You must set the site name in \$wgSitename before installation.\n\n" );
53 # PATH_SEPARATOR avaialble only from 4.3.0
54 $sep = (DIRECTORY_SEPARATOR
== "\\") ?
";" : ":";
55 ini_set( "include_path", $IP . $sep . ini_get( "include_path" ) );
57 include_once( "Setup.php" );
59 wfProfileIn( "main-misc-setup" );
60 OutputPage
::setEncodings(); # Not really used yet
63 if( empty( $_REQUEST['action'] ) ) {
66 $action = $_REQUEST['action'];
69 if( isset( $_SERVER['PATH_INFO'] ) ) {
70 $title = substr( $_SERVER['PATH_INFO'], 1 );
71 } elseif( !empty( $_REQUEST['title'] ) ) {
72 $title = $_REQUEST['title'];
77 # Placeholders in case of DB error
78 $wgTitle = Title
::newFromText( wfMsg( "badtitle" ) );
79 $wgArticle = new Article($wgTitle);
81 $action = strtolower( trim( $action ) );
82 if ( "" == $action ) { $action = "view"; }
83 if ( !empty( $_REQUEST['printable'] ) && $_REQUEST['printable'] == "yes") {
84 $wgOut->setPrintable();
87 if ( "" == $title && "delete" != $action ) {
88 $wgTitle = Title
::newFromText( wfMsg( "mainpage" ) );
89 } elseif ( !empty( $_REQUEST['curid'] ) ) {
90 # URLs like this are generated by RC, because rc_title isn't always accurate
91 $wgTitle = Title
::newFromID( $_REQUEST['curid'] );
93 $wgTitle = Title
::newFromURL( $title );
95 wfProfileOut( "main-misc-setup" );
97 # If the user is not logged in, the Namespace:title of the article must be in the Read array in
98 # order for the user to see it.
99 if ( !$wgUser->getID() && is_array( $wgWhitelistRead ) && $wgTitle) {
100 if ( !in_array( $wgLang->getNsText( $wgTitle->getNamespace() ) . ":" . $wgTitle->getDBkey(), $wgWhitelistRead ) ) {
101 $wgOut->loginToUse();
107 if ( !empty( $_REQUEST['search'] ) ) {
108 if( isset($_REQUEST['fulltext']) ) {
109 wfSearch( $_REQUEST['search'] );
111 wfGo( $_REQUEST['search'] );
113 } else if( !$wgTitle or $wgTitle->getInterwiki() != "" or $wgTitle->getDBkey() == "" ) {
114 $wgTitle = Title
::newFromText( wfMsg( "badtitle" ) );
115 $wgOut->errorpage( "badtitle", "badtitletext" );
116 } else if ( ( $action == "view" ) && $wgTitle->getPrefixedDBKey() != $title ) {
117 /* redirect to canonical url, make it a 301 to allow caching */
118 $wgOut->redirect( wfLocalUrl( $wgTitle->getPrefixedURL() ), '301');
119 } else if ( Namespace::getSpecial() == $wgTitle->getNamespace() ) {
122 if ( Namespace::getMedia() == $wgTitle->getNamespace() ) {
123 $wgTitle = Title
::makeTitle( Namespace::getImage(), $wgTitle->getDBkey() );
126 switch( $wgTitle->getNamespace() ) {
128 include_once( "ImagePage.php" );
129 $wgArticle = new ImagePage( $wgTitle );
132 $wgArticle = new Article( $wgTitle );
135 wfQuery("BEGIN", DB_WRITE
);
145 $wgArticle->$action();
152 if( !$wgCommandLineMode && !isset( $_COOKIE[ini_get("session.name")] ) ) {
153 User
::SetupSession();
155 include_once( "EditPage.php" );
156 $editor = new EditPage( $wgArticle );
160 include_once( "PageHistory.php" );
161 $history = new PageHistory( $wgArticle );
165 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
167 wfQuery("COMMIT", DB_WRITE
);
171 foreach ( $wgDeferredUpdateList as $up ) { $up->doUpdate(); }
173 wfDebug( "Request ended normally\n" );