5486408c2ebe0865757525347976f57fab49fcf0
[lhc/web/wiklou.git] / index.php
1 <?php
2 #apd_set_pprof_trace();
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 if ( file_exists( 'config/LocalSettings.php' ) ) {
11 die( "To complete the installation, move <tt>config/LocalSettings.php</tt> to the parent directory.\n" );
12 } else {
13 die( "You'll have to <a href='config/index.php'>set the wiki up</a> first!" );
14 }
15 }
16
17 # Valid web server entry point, enable includes.
18 # Please don't move this line to includes/Defines.php. This line essentially defines
19 # a valid entry point. If you put it in includes/Defines.php, then any script that includes
20 # it becomes an entry point, thereby defeating its purpose.
21 define( "MEDIAWIKI", true );
22
23 require_once( "./includes/Defines.php" );
24 require_once( "./LocalSettings.php" );
25 require_once( "includes/Setup.php" );
26
27 wfProfileIn( "main-misc-setup" );
28 OutputPage::setEncodings(); # Not really used yet
29
30 # Query string fields
31 $action = $wgRequest->getVal( "action", "view" );
32 $title = $wgRequest->getVal( "title" );
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( wfMsgForContent( "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 # Debug statement for user levels
50 // print_r($wgUser);
51
52 # If the user is not logged in, the Namespace:title of the article must be in
53 # the Read array in order for the user to see it. (We have to check here to
54 # catch special pages etc. We check again in Article::view())
55 if ( !is_null( $wgTitle ) && !$wgTitle->userCanRead() ) {
56 $wgOut->loginToUse();
57 $wgOut->output();
58 exit;
59 }
60
61 wfProfileIn( "main-action" );
62 $search = $wgRequest->getText( 'search' );
63 if( !is_null( $search ) && $search !== '' ) {
64 require_once( 'includes/SpecialSearch.php' );
65 $wgTitle = Title::makeTitle( NS_SPECIAL, "Search" );
66 wfSpecialSearch();
67 } else if( !$wgTitle or $wgTitle->getDBkey() == "" ) {
68 $wgTitle = Title::newFromText( wfMsgForContent( "badtitle" ) );
69 $wgOut->errorpage( "badtitle", "badtitletext" );
70 } else if ( $wgTitle->getInterwiki() != "" ) {
71 $url = $wgTitle->getFullURL();
72 # Check for a redirect loop
73 if ( !preg_match( "/^" . preg_quote( $wgServer, "/" ) . "/", $url ) && $wgTitle->isLocal() ) {
74 $wgOut->redirect( $url );
75 } else {
76 $wgTitle = Title::newFromText( wfMsgForContent( "badtitle" ) );
77 $wgOut->errorpage( "badtitle", "badtitletext" );
78 }
79 } else if ( ( $action == "view" ) &&
80 (!isset( $_GET['title'] ) || $wgTitle->getPrefixedDBKey() != $_GET['title'] ) &&
81 !count( array_diff( array_keys( $_GET ), array( 'action', 'title' ) ) ) )
82 {
83 /* redirect to canonical url, make it a 301 to allow caching */
84 $wgOut->redirect( $wgTitle->getFullURL(), '301');
85 } else if ( Namespace::getSpecial() == $wgTitle->getNamespace() ) {
86 # actions that need to be made when we have a special pages
87 require_once( 'includes/SpecialPage.php' );
88 if ( !$wgAllowSysopQueries ) {SpecialPage::removePage( 'Asksql' ); }
89 SpecialPage::executePath( $wgTitle );
90 } else {
91 if ( Namespace::getMedia() == $wgTitle->getNamespace() ) {
92 $wgTitle = Title::makeTitle( NS_IMAGE, $wgTitle->getDBkey() );
93 }
94
95 switch( $wgTitle->getNamespace() ) {
96 case NS_IMAGE:
97 require_once( "includes/ImagePage.php" );
98 $wgArticle = new ImagePage( $wgTitle );
99 break;
100 case NS_CATEGORY:
101 if ( $wgUseCategoryMagic ) {
102 require_once( "includes/CategoryPage.php" );
103 $wgArticle = new CategoryPage( $wgTitle );
104 break;
105 }
106 # NO break if wgUseCategoryMagic is false, drop through to next (default).
107 # Don't insert other cases between NS_CATEGORY and default.
108 default:
109 $wgArticle = new Article( $wgTitle );
110 }
111
112 switch( $action ) {
113 case "view":
114 $wgOut->setSquidMaxage( $wgSquidMaxage );
115 $wgArticle->view();
116 break;
117 case "watch":
118 case "unwatch":
119 case "delete":
120 case "revert":
121 case "rollback":
122 case "protect":
123 case "unprotect":
124 case "validate":
125 case "info":
126 case "markpatrolled":
127 $wgArticle->$action();
128 break;
129 case "print":
130 $wgArticle->view();
131 break;
132 case "dublincore":
133 if( !$wgEnableDublinCoreRdf ) {
134 wfHttpError( 403, "Forbidden", wfMsg( "nodublincore" ) );
135 } else {
136 require_once( "includes/Metadata.php" );
137 wfDublinCoreRdf( $wgArticle );
138 }
139 break;
140 case "creativecommons":
141 if( !$wgEnableCreativeCommonsRdf ) {
142 wfHttpError( 403, "Forbidden", wfMsg("nocreativecommons") );
143 } else {
144 require_once( "includes/Metadata.php" );
145 wfCreativeCommonsRdf( $wgArticle );
146 }
147 break;
148 case "credits":
149 require_once( "includes/Credits.php" );
150 showCreditsPage( $wgArticle );
151 break;
152 case "edit":
153 case "submit":
154 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
155 User::SetupSession();
156 }
157 require_once( "includes/EditPage.php" );
158 $editor = new EditPage( $wgArticle );
159 $editor->submit();
160 break;
161 case "history":
162 if ($_SERVER["REQUEST_URI"] == $wgTitle->getInternalURL('action=history')) {
163 $wgOut->setSquidMaxage( $wgSquidMaxage );
164 }
165 require_once( "includes/PageHistory.php" );
166 $history = new PageHistory( $wgArticle );
167 $history->history();
168 break;
169 case "raw":
170 require_once( "includes/RawPage.php" );
171 $raw = new RawPage( $wgArticle );
172 $raw->view();
173 break;
174 case "purge":
175 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
176 $wgOut->setSquidMaxage( $wgSquidMaxage );
177 $wgTitle->invalidateCache();
178 $wgArticle->view();
179 break;
180 default:
181 if (wfRunHooks('UnknownAction', $action, $wgArticle)) {
182 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
183 }
184 }
185 }
186 wfProfileOut( "main-action" );
187
188 # Deferred updates aren't really deferred anymore. It's important to report errors to the
189 # user, and that means doing this before OutputPage::output(). Note that for page saves,
190 # the client will wait until the script exits anyway before following the redirect.
191 wfProfileIn( "main-updates" );
192 foreach ( $wgDeferredUpdateList as $up ) {
193 $up->doUpdate();
194 }
195 wfProfileOut( "main-updates" );
196
197 wfProfileIn( "main-cleanup" );
198 $wgLoadBalancer->saveMasterPos();
199
200 # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
201 $wgLoadBalancer->commitAll();
202
203 $wgOut->output();
204 wfProfileOut( "main-cleanup" );
205
206 logProfilingData();
207 $wgLoadBalancer->closeAll();
208 wfDebug( "Request ended normally\n" );
209 ?>