Un-break large number of actions. Timwi, please read http://www.php.net/switch
[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 # PATH_SEPARATOR avaialble only from 4.3.0
18 $sep = (DIRECTORY_SEPARATOR == "\\") ? ";" : ":";
19 ini_set( "include_path", $IP . $sep . ini_get( "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 $action = $wgRequest->getVal( "action", "view" );
28
29 if( isset( $_SERVER['PATH_INFO'] ) && $wgUsePathInfo ) {
30 $title = substr( $_SERVER['PATH_INFO'], 1 );
31 } else {
32 $title = $wgRequest->getVal( "title" );
33 }
34
35 # Placeholders in case of DB error
36 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
37 $wgArticle = new Article($wgTitle);
38
39 $action = strtolower( trim( $action ) );
40 if ( "" == $action ) { $action = "view"; }
41 if ($wgRequest->getVal( "printable" ) == "yes") {
42 $wgOut->setPrintable();
43 }
44
45 if ( "" == $title && "delete" != $action ) {
46 $wgTitle = Title::newFromText( wfMsg( "mainpage" ) );
47 } elseif ( $curid = $wgRequest->getInt( '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 the user is not logged in, the Namespace:title of the article must be in the Read array in
56 # order for the user to see it.
57 if ( !$wgUser->getID() && is_array( $wgWhitelistRead ) && $wgTitle) {
58 if ( !in_array( $wgLang->getNsText( $wgTitle->getNamespace() ) . ":" . $wgTitle->getDBkey(), $wgWhitelistRead ) ) {
59 $wgOut->loginToUse();
60 $wgOut->output();
61 exit;
62 }
63 }
64
65 if ( $search = $wgRequest->getText( 'search' ) ) {
66 if( $wgRequest->getVal( 'fulltext' ) ) {
67 wfSearch( $search );
68 } else {
69 wfGo( $search );
70 }
71 } else if( !$wgTitle or $wgTitle->getInterwiki() != "" or $wgTitle->getDBkey() == "" ) {
72 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
73 $wgOut->errorpage( "badtitle", "badtitletext" );
74 } else if ( ( $action == "view" ) && $wgTitle->getPrefixedDBKey() != $title ) {
75 /* redirect to canonical url, make it a 301 to allow caching */
76 $wgOut->redirect( $wgTitle->getFullURL(), '301');
77 } else if ( Namespace::getSpecial() == $wgTitle->getNamespace() ) {
78 wfSpecialPage();
79 } else {
80 if ( Namespace::getMedia() == $wgTitle->getNamespace() ) {
81 $wgTitle = Title::makeTitle( Namespace::getImage(), $wgTitle->getDBkey() );
82 }
83
84 switch( $wgTitle->getNamespace() ) {
85 case NS_IMAGE:
86 include_once( "ImagePage.php" );
87 $wgArticle = new ImagePage( $wgTitle );
88 break;
89 default:
90 $wgArticle = new Article( $wgTitle );
91 }
92
93 wfQuery("BEGIN", DB_WRITE);
94 switch( $action ) {
95 case "view":
96 $wgOut->setSquidMaxage( $wgSquidMaxage );
97 $wgArticle->view();
98 break;
99 case "watch":
100 case "unwatch":
101 case "delete":
102 case "revert":
103 case "rollback":
104 case "protect":
105 case "unprotect":
106 $wgArticle->$action();
107 break;
108 case "print":
109 $wgArticle->view();
110 break;
111 case "dublincore":
112 if( !$wgEnableDublinCoreRdf ) {
113 wfHttpError( 403, "Forbidden", wfMsg( "nodublincore" ) );
114 } else {
115 include_once( "Metadata.php" );
116 wfDublinCoreRdf( $wgArticle );
117 }
118 break;
119 case "creativecommons":
120 if( !$wgEnableCreativeCommonsRdf ) {
121 wfHttpError( 403, "Forbidden", wfMsg("nocreativecommons") );
122 } else {
123 include_once( "Metadata.php" );
124 wfCreativeCommonsRdf( $wgArticle );
125 }
126 break;
127 case "edit":
128 case "submit":
129 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
130 User::SetupSession();
131 }
132 include_once( "EditPage.php" );
133 $editor = new EditPage( $wgArticle );
134 $editor->$action();
135 break;
136 case "history":
137 if ($_SERVER["REQUEST_URI"] == $wgTitle->getInternalURL('action=history')) {
138 $wgOut->setSquidMaxage( $wgSquidMaxage );
139 }
140 include_once( "PageHistory.php" );
141 $history = new PageHistory( $wgArticle );
142 $history->history();
143 break;
144 case "purge":
145 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
146 $wgOut->setSquidMaxage( $wgSquidMaxage );
147 $wgArticle->view();
148 break;
149 default:
150 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
151 }
152 wfQuery("COMMIT", DB_WRITE);
153 }
154
155 $wgOut->output();
156
157 foreach ( $wgDeferredUpdateList as $up ) { $up->doUpdate(); }
158 logProfilingData();
159 wfDebug( "Request ended normally\n" );
160 ?>