Whitelist and diff fixes:
[lhc/web/wiklou.git] / index.php
1 <?php
2
3 # Main wiki script; see design.doc
4 #
5 $wgRequestTime = microtime();
6
7 unset( $IP );
8 @ini_set( "allow_url_fopen", 0 ); # For security...
9 if(!file_exists("LocalSettings.php")) {
10 die( "You'll have to <a href='config/index.php'>set the wiki up</a> first!" );
11 }
12
13 define( "MEDIAWIKI", true );
14 require_once( "./LocalSettings.php" );
15 require_once( "includes/Setup.php" );
16
17 wfProfileIn( "main-misc-setup" );
18 OutputPage::setEncodings(); # Not really used yet
19
20 # Query string fields
21 $action = $wgRequest->getVal( "action", "view" );
22
23 if( isset( $_SERVER['PATH_INFO'] ) && $wgUsePathInfo ) {
24 $title = substr( $_SERVER['PATH_INFO'], 1 );
25 } else {
26 $title = $wgRequest->getVal( "title" );
27 }
28
29 # Placeholders in case of DB error
30 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
31 $wgArticle = new Article($wgTitle);
32
33 $action = strtolower( trim( $action ) );
34 if ( "" == $action ) { $action = "view"; }
35 if ($wgRequest->getVal( "printable" ) == "yes") {
36 $wgOut->setPrintable();
37 }
38
39 if ( "" == $title && "delete" != $action ) {
40 $wgTitle = Title::newFromText( wfMsg( "mainpage" ) );
41 } elseif ( $curid = $wgRequest->getInt( '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 the user is not logged in, the Namespace:title of the article must be in
50 # the Read array in order for the user to see it. (We have to check here to
51 # catch special pages etc. We check again in Article::view())
52 if ( !$wgTitle->userCanRead() ) {
53 $wgOut->loginToUse();
54 $wgOut->output();
55 exit;
56 }
57
58 if ( $search = $wgRequest->getText( 'search' ) ) {
59 $wgTitle = Title::makeTitle( NS_SPECIAL, "Search" );
60 if( $wgRequest->getVal( 'fulltext' ) ) {
61 wfSearch( $search );
62 } else {
63 wfGo( $search );
64 }
65 } else if( !$wgTitle or $wgTitle->getDBkey() == "" ) {
66 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
67 $wgOut->errorpage( "badtitle", "badtitletext" );
68 } else if ( $wgTitle->getInterwiki() != "" ) {
69 $url = $wgTitle->getFullURL();
70 # Check for a redirect loop
71 if ( !preg_match( "/^" . preg_quote( $wgServer ) . "/", $url ) && $wgTitle->isLocal() ) {
72 $wgOut->redirect( $url );
73 } else {
74 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
75 $wgOut->errorpage( "badtitle", "badtitletext" );
76 }
77 } else if ( ( $action == "view" ) && $wgTitle->getPrefixedDBKey() != $title ) {
78 /* redirect to canonical url, make it a 301 to allow caching */
79 $wgOut->redirect( $wgTitle->getFullURL(), '301');
80 } else if ( Namespace::getSpecial() == $wgTitle->getNamespace() ) {
81 wfSpecialPage();
82 } else {
83 if ( Namespace::getMedia() == $wgTitle->getNamespace() ) {
84 $wgTitle = Title::makeTitle( Namespace::getImage(), $wgTitle->getDBkey() );
85 }
86
87 switch( $wgTitle->getNamespace() ) {
88 case NS_IMAGE:
89 require_once( "includes/ImagePage.php" );
90 $wgArticle = new ImagePage( $wgTitle );
91 break;
92 default:
93 $wgArticle = new Article( $wgTitle );
94 }
95
96 wfQuery("BEGIN", DB_WRITE);
97 switch( $action ) {
98 case "view":
99 $wgOut->setSquidMaxage( $wgSquidMaxage );
100 $wgArticle->view();
101 break;
102 case "watch":
103 case "unwatch":
104 case "delete":
105 case "revert":
106 case "rollback":
107 case "protect":
108 case "unprotect":
109 $wgArticle->$action();
110 break;
111 case "print":
112 $wgArticle->view();
113 break;
114 case "dublincore":
115 if( !$wgEnableDublinCoreRdf ) {
116 wfHttpError( 403, "Forbidden", wfMsg( "nodublincore" ) );
117 } else {
118 require_once( "includes/Metadata.php" );
119 wfDublinCoreRdf( $wgArticle );
120 }
121 break;
122 case "creativecommons":
123 if( !$wgEnableCreativeCommonsRdf ) {
124 wfHttpError( 403, "Forbidden", wfMsg("nocreativecommons") );
125 } else {
126 require_once( "includes/Metadata.php" );
127 wfCreativeCommonsRdf( $wgArticle );
128 }
129 break;
130 case "edit":
131 case "submit":
132 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
133 User::SetupSession();
134 }
135 require_once( "includes/EditPage.php" );
136 $editor = new EditPage( $wgArticle );
137 $editor->$action();
138 break;
139 case "history":
140 if ($_SERVER["REQUEST_URI"] == $wgTitle->getInternalURL('action=history')) {
141 $wgOut->setSquidMaxage( $wgSquidMaxage );
142 }
143 require_once( "includes/PageHistory.php" );
144 $history = new PageHistory( $wgArticle );
145 $history->history();
146 break;
147 case "raw":
148 require_once( "includes/RawPage.php" );
149 $raw = new RawPage( $wgArticle );
150 $raw->view();
151 break;
152 case "purge":
153 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
154 $wgOut->setSquidMaxage( $wgSquidMaxage );
155 $wgArticle->view();
156 break;
157 default:
158 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
159 }
160 wfQuery("COMMIT", DB_WRITE);
161 }
162
163 $wgOut->output();
164
165 foreach ( $wgDeferredUpdateList as $up ) { $up->doUpdate(); }
166 logProfilingData();
167 wfDebug( "Request ended normally\n" );
168 ?>