* Introducing bit field for database parameters
[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( "./includes/Defines.php" );
15 require_once( "./LocalSettings.php" );
16 require_once( "includes/Setup.php" );
17
18 wfProfileIn( "main-misc-setup" );
19 OutputPage::setEncodings(); # Not really used yet
20
21 # Query string fields
22 $action = $wgRequest->getVal( "action", "view" );
23
24 if( isset( $_SERVER['PATH_INFO'] ) && $wgUsePathInfo ) {
25 $title = substr( $_SERVER['PATH_INFO'], 1 );
26 } else {
27 $title = $wgRequest->getVal( "title" );
28 }
29
30 # Placeholders in case of DB error
31 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
32 $wgArticle = new Article($wgTitle);
33
34 $action = strtolower( trim( $action ) );
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 ( !is_null( $wgTitle ) && !$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' ) || !is_null( $wgRequest->getVal( 'offset' ) ) ) {
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 # actions that need to be made when we have a special pages
82 require_once( 'includes/SpecialPage.php' );
83 if ( !$wgAllowSysopQueries ) {SpecialPage::removePage( 'Asksql' ); }
84 SpecialPage::executePath( $wgTitle );
85 } else {
86 if ( Namespace::getMedia() == $wgTitle->getNamespace() ) {
87 $wgTitle = Title::makeTitle( Namespace::getImage(), $wgTitle->getDBkey() );
88 }
89
90 switch( $wgTitle->getNamespace() ) {
91 case NS_IMAGE:
92 require_once( "includes/ImagePage.php" );
93 $wgArticle = new ImagePage( $wgTitle );
94 break;
95 default:
96 $wgArticle = new Article( $wgTitle );
97 }
98
99 switch( $action ) {
100 case "view":
101 $wgOut->setSquidMaxage( $wgSquidMaxage );
102 $wgArticle->view();
103 break;
104 case "watch":
105 case "unwatch":
106 case "delete":
107 case "revert":
108 case "rollback":
109 case "protect":
110 case "unprotect":
111 case "validate":
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 }
170
171 # Deferred updates aren't really deferred anymore. It's important to report errors to the
172 # user, and that means doing this before OutputPage::output(). Note that for page saves,
173 # the client will wait until the script exits anyway before following the redirect.
174 foreach ( $wgDeferredUpdateList as $up ) {
175 $up->doUpdate();
176 }
177
178 $wgLoadBalancer->saveMasterPos();
179
180 # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
181 $wgLoadBalancer->commitAll();
182
183 $wgOut->output();
184
185 logProfilingData();
186 $wgLoadBalancer->closeAll();
187 wfDebug( "Request ended normally\n" );
188 ?>