075e721b10e880542da0e2d7cb7af9a0cbf3c062
[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 ($wgRequest->getVal( "printable" ) == "yes") {
35 $wgOut->setPrintable();
36 }
37
38 if ( "" == $title && "delete" != $action ) {
39 $wgTitle = Title::newFromText( wfMsg( "mainpage" ) );
40 } elseif ( $curid = $wgRequest->getInt( 'curid' ) ) {
41 # URLs like this are generated by RC, because rc_title isn't always accurate
42 $wgTitle = Title::newFromID( $curid );
43 } else {
44 $wgTitle = Title::newFromURL( $title );
45 }
46 wfProfileOut( "main-misc-setup" );
47
48 # If the user is not logged in, the Namespace:title of the article must be in
49 # the Read array in order for the user to see it. (We have to check here to
50 # catch special pages etc. We check again in Article::view())
51 if ( !is_null( $wgTitle ) && !$wgTitle->userCanRead() ) {
52 $wgOut->loginToUse();
53 $wgOut->output();
54 exit;
55 }
56
57 if ( $search = $wgRequest->getText( 'search' ) ) {
58 $wgTitle = Title::makeTitle( NS_SPECIAL, "Search" );
59 if( $wgRequest->getVal( 'fulltext' ) || !is_null( $wgRequest->getVal( 'offset' ) ) ) {
60 wfSearch( $search );
61 } else {
62 wfGo( $search );
63 }
64 } else if( !$wgTitle or $wgTitle->getDBkey() == "" ) {
65 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
66 $wgOut->errorpage( "badtitle", "badtitletext" );
67 } else if ( $wgTitle->getInterwiki() != "" ) {
68 $url = $wgTitle->getFullURL();
69 # Check for a redirect loop
70 if ( !preg_match( "/^" . preg_quote( $wgServer, "/" ) . "/", $url ) && $wgTitle->isLocal() ) {
71 $wgOut->redirect( $url );
72 } else {
73 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
74 $wgOut->errorpage( "badtitle", "badtitletext" );
75 }
76 } else if ( ( $action == "view" ) && $wgTitle->getPrefixedDBKey() != $title ) {
77 /* redirect to canonical url, make it a 301 to allow caching */
78 $wgOut->redirect( $wgTitle->getFullURL(), '301');
79 } else if ( Namespace::getSpecial() == $wgTitle->getNamespace() ) {
80 # actions that need to be made when we have a special pages
81 require_once( 'includes/SpecialPage.php' );
82 if ( !$wgAllowSysopQueries ) {SpecialPage::removePage( 'Asksql' ); }
83 SpecialPage::executePath( $wgTitle );
84 } else {
85 if ( Namespace::getMedia() == $wgTitle->getNamespace() ) {
86 $wgTitle = Title::makeTitle( Namespace::getImage(), $wgTitle->getDBkey() );
87 }
88
89 switch( $wgTitle->getNamespace() ) {
90 case NS_IMAGE:
91 require_once( "includes/ImagePage.php" );
92 $wgArticle = new ImagePage( $wgTitle );
93 break;
94 default:
95 $wgArticle = new Article( $wgTitle );
96 }
97
98 $db =& wfGetDB( DB_WRITE );
99 $db->query("BEGIN", DB_WRITE);
100 switch( $action ) {
101 case "view":
102 $wgOut->setSquidMaxage( $wgSquidMaxage );
103 $wgArticle->view();
104 break;
105 case "watch":
106 case "unwatch":
107 case "delete":
108 case "revert":
109 case "rollback":
110 case "protect":
111 case "unprotect":
112 case "info":
113 $wgArticle->$action();
114 break;
115 case "print":
116 $wgArticle->view();
117 break;
118 case "dublincore":
119 if( !$wgEnableDublinCoreRdf ) {
120 wfHttpError( 403, "Forbidden", wfMsg( "nodublincore" ) );
121 } else {
122 require_once( "includes/Metadata.php" );
123 wfDublinCoreRdf( $wgArticle );
124 }
125 break;
126 case "creativecommons":
127 if( !$wgEnableCreativeCommonsRdf ) {
128 wfHttpError( 403, "Forbidden", wfMsg("nocreativecommons") );
129 } else {
130 require_once( "includes/Metadata.php" );
131 wfCreativeCommonsRdf( $wgArticle );
132 }
133 break;
134 case "credits":
135 require_once( "includes/Credits.php" );
136 showCreditsPage( $wgArticle );
137 break;
138 case "edit":
139 case "submit":
140 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
141 User::SetupSession();
142 }
143 require_once( "includes/EditPage.php" );
144 $editor = new EditPage( $wgArticle );
145 $editor->$action();
146 break;
147 case "history":
148 if ($_SERVER["REQUEST_URI"] == $wgTitle->getInternalURL('action=history')) {
149 $wgOut->setSquidMaxage( $wgSquidMaxage );
150 }
151 require_once( "includes/PageHistory.php" );
152 $history = new PageHistory( $wgArticle );
153 $history->history();
154 break;
155 case "raw":
156 require_once( "includes/RawPage.php" );
157 $raw = new RawPage( $wgArticle );
158 $raw->view();
159 break;
160 case "purge":
161 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
162 $wgOut->setSquidMaxage( $wgSquidMaxage );
163 $wgTitle->invalidateCache();
164 $wgArticle->view();
165 break;
166 default:
167 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
168 }
169 $db->query("COMMIT");
170 }
171
172 $wgOut->output();
173
174 foreach ( $wgDeferredUpdateList as $up ) {
175 wfQuery("BEGIN", DB_WRITE);
176 $up->doUpdate();
177 wfQuery("COMMIT", DB_WRITE);
178 }
179 logProfilingData();
180 wfDebug( "Request ended normally\n" );
181 ?>