space after colour code to avoid strange colours with titles like 19..
[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 $db =& wfGetDB( DB_MASTER );
58
59 if ( $search = $wgRequest->getText( 'search' ) ) {
60 $wgTitle = Title::makeTitle( NS_SPECIAL, "Search" );
61 if( $wgRequest->getVal( 'fulltext' ) || !is_null( $wgRequest->getVal( 'offset' ) ) ) {
62 wfSearch( $search );
63 } else {
64 wfGo( $search );
65 }
66 } else if( !$wgTitle or $wgTitle->getDBkey() == "" ) {
67 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
68 $wgOut->errorpage( "badtitle", "badtitletext" );
69 } else if ( $wgTitle->getInterwiki() != "" ) {
70 $url = $wgTitle->getFullURL();
71 # Check for a redirect loop
72 if ( !preg_match( "/^" . preg_quote( $wgServer, "/" ) . "/", $url ) && $wgTitle->isLocal() ) {
73 $wgOut->redirect( $url );
74 } else {
75 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
76 $wgOut->errorpage( "badtitle", "badtitletext" );
77 }
78 } else if ( ( $action == "view" ) && $wgTitle->getPrefixedDBKey() != $title ) {
79 /* redirect to canonical url, make it a 301 to allow caching */
80 $wgOut->redirect( $wgTitle->getFullURL(), '301');
81 } else if ( Namespace::getSpecial() == $wgTitle->getNamespace() ) {
82 # actions that need to be made when we have a special pages
83 require_once( 'includes/SpecialPage.php' );
84 if ( !$wgAllowSysopQueries ) {SpecialPage::removePage( 'Asksql' ); }
85 SpecialPage::executePath( $wgTitle );
86 } else {
87 if ( Namespace::getMedia() == $wgTitle->getNamespace() ) {
88 $wgTitle = Title::makeTitle( Namespace::getImage(), $wgTitle->getDBkey() );
89 }
90
91 switch( $wgTitle->getNamespace() ) {
92 case NS_IMAGE:
93 require_once( "includes/ImagePage.php" );
94 $wgArticle = new ImagePage( $wgTitle );
95 break;
96 default:
97 $wgArticle = new Article( $wgTitle );
98 }
99
100 $db->query("BEGIN");
101 switch( $action ) {
102 case "view":
103 $wgOut->setSquidMaxage( $wgSquidMaxage );
104 $wgArticle->view();
105 break;
106 case "watch":
107 case "unwatch":
108 case "delete":
109 case "revert":
110 case "rollback":
111 case "protect":
112 case "unprotect":
113 case "info":
114 $wgArticle->$action();
115 break;
116 case "print":
117 $wgArticle->view();
118 break;
119 case "dublincore":
120 if( !$wgEnableDublinCoreRdf ) {
121 wfHttpError( 403, "Forbidden", wfMsg( "nodublincore" ) );
122 } else {
123 require_once( "includes/Metadata.php" );
124 wfDublinCoreRdf( $wgArticle );
125 }
126 break;
127 case "creativecommons":
128 if( !$wgEnableCreativeCommonsRdf ) {
129 wfHttpError( 403, "Forbidden", wfMsg("nocreativecommons") );
130 } else {
131 require_once( "includes/Metadata.php" );
132 wfCreativeCommonsRdf( $wgArticle );
133 }
134 break;
135 case "credits":
136 require_once( "includes/Credits.php" );
137 showCreditsPage( $wgArticle );
138 break;
139 case "edit":
140 case "submit":
141 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
142 User::SetupSession();
143 }
144 require_once( "includes/EditPage.php" );
145 $editor = new EditPage( $wgArticle );
146 $editor->$action();
147 break;
148 case "history":
149 if ($_SERVER["REQUEST_URI"] == $wgTitle->getInternalURL('action=history')) {
150 $wgOut->setSquidMaxage( $wgSquidMaxage );
151 }
152 require_once( "includes/PageHistory.php" );
153 $history = new PageHistory( $wgArticle );
154 $history->history();
155 break;
156 case "raw":
157 require_once( "includes/RawPage.php" );
158 $raw = new RawPage( $wgArticle );
159 $raw->view();
160 break;
161 case "purge":
162 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
163 $wgOut->setSquidMaxage( $wgSquidMaxage );
164 $wgTitle->invalidateCache();
165 $wgArticle->view();
166 break;
167 default:
168 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
169 }
170 $db->query("COMMIT");
171 }
172
173 $wgLoadBalancer->saveMasterPos();
174 $wgOut->output();
175
176 foreach ( $wgDeferredUpdateList as $up ) {
177 $db->query("BEGIN");
178 $up->doUpdate();
179 $db->query("COMMIT");
180 }
181 logProfilingData();
182 wfDebug( "Request ended normally\n" );
183 ?>