* Fixed magic quotes in $_REQUEST, in Setup.php
[lhc/web/wiklou.git] / index.php
1 <?php
2 # Main wiki script; see design.doc
3 #
4 $wgRequestTime = microtime();
5
6 unset( $IP );
7 ini_set( "allow_url_fopen", 0 ); # For security...
8 if(!file_exists("LocalSettings.php")) {
9 die( "You'll have to <a href='config/index.php'>set the wiki up</a> first!" );
10 }
11 include_once( "./LocalSettings.php" );
12
13 if( $wgSitename == "MediaWiki" ) {
14 die( "You must set the site name in \$wgSitename before installation.\n\n" );
15 }
16
17 # Windows requires ';' as separator, ':' for Unix
18 $sep = strchr( $include_path = ini_get( "include_path" ), ";" ) ? ";" : ":";
19 ini_set( "include_path", "$IP$sep$include_path" );
20
21 include_once( "Setup.php" );
22
23 wfProfileIn( "main-misc-setup" );
24 OutputPage::setEncodings(); # Not really used yet
25
26 # Query string fields
27 #
28 #global $action, $title, $search, $go, $target, $printable;
29 #global $returnto, $diff, $oldid, $curid;
30
31 $action = $_REQUEST['action'];
32 $title = $_REQUEST['title'];
33
34 # Placeholders in case of DB error
35 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
36 $wgArticle = new Article($wgTitle);
37
38 $action = strtolower( trim( $action ) );
39 if ( "" == $action ) { $action = "view"; }
40 if ( "yes" == $_REQUEST['printable'] ) { $wgOut->setPrintable(); }
41
42 if ( "" == $title && "delete" != $action ) {
43 $wgTitle = Title::newFromText( wfMsg( "mainpage" ) );
44 } elseif ( $_REQUEST['curid'] ) {
45 # URLs like this are generated by RC, because rc_title isn't always accurate
46 $wgTitle = Title::newFromID( $_REQUEST['curid'] );
47 } else {
48 $wgTitle = Title::newFromURL( $title );
49 }
50 wfProfileOut( "main-misc-setup" );
51
52 # If the user is not logged in, the Namespace:title of the article must be in the Read array in
53 # order for the user to see it.
54 if ( !$wgUser->getID() && is_array( $wgWhitelistRead ) && $wgTitle) {
55 if ( !in_array( $wgLang->getNsText( $wgTitle->getNamespace() ) . ":" . $wgTitle->getDBkey(), $wgWhitelistRead ) ) {
56 $wgOut->loginToUse();
57 $wgOut->output();
58 exit;
59 }
60 }
61
62 if ( "" != $_REQUEST['search'] ) {
63 if( isset($_REQUEST['fulltext']) ) {
64 wfSearch( $_REQUEST['search'] );
65 } else {
66 wfGo( $_REQUEST['search'] );
67 }
68 } else if( !$wgTitle or $wgTitle->getInterwiki() != "" or $wgTitle->getDBkey() == "" ) {
69 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
70 $wgOut->errorpage( "badtitle", "badtitletext" );
71 } else if ( ( $action == "view" ) && $wgTitle->getPrefixedDBKey() != $title ) {
72 /* redirect to canonical url, make it a 301 to allow caching */
73 $wgOut->redirect( wfLocalUrl( $wgTitle->getPrefixedURL() ), '301');
74 } else if ( Namespace::getSpecial() == $wgTitle->getNamespace() ) {
75 wfSpecialPage();
76 } else {
77 if ( Namespace::getMedia() == $wgTitle->getNamespace() ) {
78 $wgTitle = Title::makeTitle( Namespace::getImage(), $wgTitle->getDBkey() );
79 }
80
81 switch( $wgTitle->getNamespace() ) {
82 case 6:
83 include_once( "ImagePage.php" );
84 $wgArticle = new ImagePage( $wgTitle );
85 break;
86 default:
87 $wgArticle = new Article( $wgTitle );
88 }
89
90 wfQuery("BEGIN", DB_WRITE);
91 switch( $action ) {
92 case "view":
93 case "watch":
94 case "unwatch":
95 case "delete":
96 case "revert":
97 case "rollback":
98 case "protect":
99 case "unprotect":
100 $wgArticle->$action();
101 break;
102 case "print":
103 $wgArticle->view();
104 break;
105 case "edit":
106 case "submit":
107 if( !$wgCommandLineMode && !isset( $_COOKIE[ini_get("session.name")] ) ) {
108 User::SetupSession();
109 }
110 include_once( "EditPage.php" );
111 $editor = new EditPage( $wgArticle );
112 $editor->$action();
113 break;
114 case "history":
115 include_once( "PageHistory.php" );
116 $history = new PageHistory( $wgArticle );
117 $history->history();
118 break;
119 default:
120 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
121 }
122 wfQuery("COMMIT", DB_WRITE);
123 }
124
125 $wgOut->output();
126 foreach ( $wgDeferredUpdateList as $up ) { $up->doUpdate(); }
127 logProfilingData();
128 wfDebug( "Request ended normally\n" );
129 ?>