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