Experimental in-place installer.
[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 # Placeholders in case of DB error
32 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
33 $wgArticle = new Article($wgTitle);
34
35 $action = strtolower( trim( $action ) );
36 if ( "" == $action ) { $action = "view"; }
37 if ( "yes" == $printable ) { $wgOut->setPrintable(); }
38
39 if ( "" == $title && "delete" != $action ) {
40 $wgTitle = Title::newFromText( wfMsg( "mainpage" ) );
41 } elseif ( $curid ) {
42 # URLs like this are generated by RC, because rc_title isn't always accurate
43 $wgTitle = Title::newFromID( $curid );
44 } else {
45 $wgTitle = Title::newFromURL( $title );
46 }
47 wfProfileOut( "main-misc-setup" );
48
49 if ( "" != $search ) {
50 if( isset($_REQUEST['fulltext']) ) {
51 wfSearch( $search );
52 } else {
53 wfGo( $search );
54 }
55 } else if( !$wgTitle or $wgTitle->getInterwiki() != "" or $wgTitle->getDBkey() == "" ) {
56 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
57 $wgOut->errorpage( "badtitle", "badtitletext" );
58 } else if ( ( $action == "view" ) && $wgTitle->getPrefixedDBKey() != $title ) {
59 /* redirect to canonical url */
60 $wgOut->redirect( wfLocalUrl( $wgTitle->getPrefixedURL() ) );
61 } else if ( Namespace::getSpecial() == $wgTitle->getNamespace() ) {
62 wfSpecialPage();
63 } else {
64 if ( Namespace::getMedia() == $wgTitle->getNamespace() ) {
65 $wgTitle = Title::makeTitle( Namespace::getImage(), $wgTitle->getDBkey() );
66 }
67
68 switch( $wgTitle->getNamespace() ) {
69 case 6:
70 include_once( "ImagePage.php" );
71 $wgArticle = new ImagePage( $wgTitle );
72 break;
73 default:
74 $wgArticle = new Article( $wgTitle );
75 }
76
77 wfQuery("BEGIN", DB_WRITE);
78 switch( $action ) {
79 case "view":
80 case "watch":
81 case "unwatch":
82 case "delete":
83 case "revert":
84 case "rollback":
85 case "protect":
86 case "unprotect":
87 $wgArticle->$action();
88 break;
89 case "print":
90 $wgArticle->view();
91 break;
92 case "edit":
93 case "submit":
94 if( !$wgCommandLineMode && !isset( $_COOKIE[ini_get("session.name")] ) ) {
95 User::SetupSession();
96 }
97 include_once( "EditPage.php" );
98 $editor = new EditPage( $wgArticle );
99 $editor->$action();
100 break;
101 case "history":
102 include_once( "PageHistory.php" );
103 $history = new PageHistory( $wgArticle );
104 $history->history();
105 break;
106 default:
107 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
108 }
109 wfQuery("COMMIT", DB_WRITE);
110 }
111
112 $wgOut->output();
113 foreach ( $wgDeferredUpdateList as $up ) { $up->doUpdate(); }
114 logProfilingData();
115 wfDebug( "Request ended normally\n" );
116 ?>