1c2a53109b53fe5ee8e7997e5a34d80ccd245962
[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 include_once( "./LocalSettings.php" );
9
10 if( $wgSitename == "MediaWiki" ) {
11 die( "You must set the site name in \$wgSitename before installation.\n\n" );
12 }
13
14 # Windows requires ';' as separator, ':' for Unix
15 $sep = strchr( $include_path = ini_get( "include_path" ), ";" ) ? ";" : ":";
16 ini_set( "include_path", "$IP$sep$include_path" );
17
18 include_once( "Setup.php" );
19
20 wfProfileIn( "main-misc-setup" );
21 OutputPage::setEncodings(); # Not really used yet
22
23 # Query string fields
24 #
25 global $action, $title, $search, $go, $target, $printable;
26 global $returnto, $diff, $oldid, $curid;
27
28 # Placeholders in case of DB error
29 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
30 $wgArticle = new Article($wgTitle);
31
32 $action = strtolower( trim( $action ) );
33 if ( "" == $action ) { $action = "view"; }
34 if ( "yes" == $printable ) { $wgOut->setPrintable(); }
35
36 if ( "" == $title && "delete" != $action ) {
37 $wgTitle = Title::newFromText( wfMsg( "mainpage" ) );
38 } elseif ( $curid ) {
39 # URLs like this are generated by RC, because rc_title isn't always accurate
40 $wgTitle = Title::newFromID( $curid );
41 } else {
42 $wgTitle = Title::newFromURL( $title );
43 }
44 wfProfileOut( "main-misc-setup" );
45
46 if ( "" != $search ) {
47 if( isset($_REQUEST['fulltext']) ) {
48 wfSearch( $search );
49 } else {
50 wfGo( $search );
51 }
52 } else if( !$wgTitle or $wgTitle->getInterwiki() != "" or $wgTitle->getDBkey() == "" ) {
53 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
54 $wgOut->errorpage( "badtitle", "badtitletext" );
55 } else if ( ( $action == "view" ) && $wgTitle->getPrefixedDBKey() != $title ) {
56 /* redirect to canonical url */
57 $wgOut->redirect( wfLocalUrl( $wgTitle->getPrefixedURL() ) );
58 } else if ( Namespace::getSpecial() == $wgTitle->getNamespace() ) {
59 wfSpecialPage();
60 } else {
61 if ( Namespace::getMedia() == $wgTitle->getNamespace() ) {
62 $wgTitle = Title::makeTitle( Namespace::getImage(), $wgTitle->getDBkey() );
63 }
64
65 switch( $wgTitle->getNamespace() ) {
66 case 6:
67 include_once( "ImagePage.php" );
68 $wgArticle = new ImagePage( $wgTitle );
69 break;
70 default:
71 $wgArticle = new Article( $wgTitle );
72 }
73
74 wfQuery("BEGIN", DB_WRITE);
75 switch( $action ) {
76 case "view":
77 case "watch":
78 case "unwatch":
79 case "delete":
80 case "revert":
81 case "rollback":
82 case "protect":
83 case "unprotect":
84 $wgArticle->$action();
85 break;
86 case "print":
87 $wgArticle->view();
88 break;
89 case "edit":
90 case "submit":
91 if( !$wgCommandLineMode && !isset( $_COOKIE[ini_get("session.name")] ) ) {
92 User::SetupSession();
93 }
94 include_once( "EditPage.php" );
95 $editor = new EditPage( $wgArticle );
96 $editor->$action();
97 break;
98 case "history":
99 include_once( "PageHistory.php" );
100 $history = new PageHistory( $wgArticle );
101 $history->history();
102 break;
103 default:
104 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
105 }
106 wfQuery("COMMIT", DB_WRITE);
107 }
108
109 $wgOut->output();
110 foreach ( $wgDeferredUpdateList as $up ) { $up->doUpdate(); }
111 logProfilingData();
112 wfDebug( "Request ended normally\n" );
113 ?>