Use PATH_INFO for prettier default URLs: index.php/Foo instead of index.php?title=Foo
[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 if( isset( $_SERVER['PATH_INFO'] ) ) {
33 $title = substr( $_SERVER['PATH_INFO'], 1 );
34 } else {
35 $title = $_REQUEST['title'];
36 }
37
38 # Placeholders in case of DB error
39 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
40 $wgArticle = new Article($wgTitle);
41
42 $action = strtolower( trim( $action ) );
43 if ( "" == $action ) { $action = "view"; }
44 if ( "yes" == $_REQUEST['printable'] ) { $wgOut->setPrintable(); }
45
46 if ( "" == $title && "delete" != $action ) {
47 $wgTitle = Title::newFromText( wfMsg( "mainpage" ) );
48 } elseif ( $_REQUEST['curid'] ) {
49 # URLs like this are generated by RC, because rc_title isn't always accurate
50 $wgTitle = Title::newFromID( $_REQUEST['curid'] );
51 } else {
52 $wgTitle = Title::newFromURL( $title );
53 }
54 wfProfileOut( "main-misc-setup" );
55
56 # If the user is not logged in, the Namespace:title of the article must be in the Read array in
57 # order for the user to see it.
58 if ( !$wgUser->getID() && is_array( $wgWhitelistRead ) && $wgTitle) {
59 if ( !in_array( $wgLang->getNsText( $wgTitle->getNamespace() ) . ":" . $wgTitle->getDBkey(), $wgWhitelistRead ) ) {
60 $wgOut->loginToUse();
61 $wgOut->output();
62 exit;
63 }
64 }
65
66 if ( "" != $_REQUEST['search'] ) {
67 if( isset($_REQUEST['fulltext']) ) {
68 wfSearch( $_REQUEST['search'] );
69 } else {
70 wfGo( $_REQUEST['search'] );
71 }
72 } else if( !$wgTitle or $wgTitle->getInterwiki() != "" or $wgTitle->getDBkey() == "" ) {
73 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
74 $wgOut->errorpage( "badtitle", "badtitletext" );
75 } else if ( ( $action == "view" ) && $wgTitle->getPrefixedDBKey() != $title ) {
76 /* redirect to canonical url, make it a 301 to allow caching */
77 $wgOut->redirect( wfLocalUrl( $wgTitle->getPrefixedURL() ), '301');
78 } else if ( Namespace::getSpecial() == $wgTitle->getNamespace() ) {
79 wfSpecialPage();
80 } else {
81 if ( Namespace::getMedia() == $wgTitle->getNamespace() ) {
82 $wgTitle = Title::makeTitle( Namespace::getImage(), $wgTitle->getDBkey() );
83 }
84
85 switch( $wgTitle->getNamespace() ) {
86 case 6:
87 include_once( "ImagePage.php" );
88 $wgArticle = new ImagePage( $wgTitle );
89 break;
90 default:
91 $wgArticle = new Article( $wgTitle );
92 }
93
94 wfQuery("BEGIN", DB_WRITE);
95 switch( $action ) {
96 case "view":
97 case "watch":
98 case "unwatch":
99 case "delete":
100 case "revert":
101 case "rollback":
102 case "protect":
103 case "unprotect":
104 $wgArticle->$action();
105 break;
106 case "print":
107 $wgArticle->view();
108 break;
109 case "edit":
110 case "submit":
111 if( !$wgCommandLineMode && !isset( $_COOKIE[ini_get("session.name")] ) ) {
112 User::SetupSession();
113 }
114 include_once( "EditPage.php" );
115 $editor = new EditPage( $wgArticle );
116 $editor->$action();
117 break;
118 case "history":
119 include_once( "PageHistory.php" );
120 $history = new PageHistory( $wgArticle );
121 $history->history();
122 break;
123 default:
124 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
125 }
126 wfQuery("COMMIT", DB_WRITE);
127 }
128
129 $wgOut->output();
130 foreach ( $wgDeferredUpdateList as $up ) { $up->doUpdate(); }
131 logProfilingData();
132 wfDebug( "Request ended normally\n" );
133 ?>