f1d52cacabca54e9bcb778c00398f1dc2cb623bc
3 #apd_set_pprof_trace();
4 # Main wiki script; see design.doc
6 $wgRequestTime = microtime();
9 @ini_set
( 'allow_url_fopen', 0 ); # For security...
10 if( !file_exists( 'LocalSettings.php' ) ) {
11 if ( file_exists( 'config/LocalSettings.php' ) ) {
12 die( "To complete the installation, move <tt>config/LocalSettings.php</tt> to the parent directory.\n" );
14 die( "You'll have to <a href='config/index.php'>set the wiki up</a> first!" );
18 # Valid web server entry point, enable includes.
19 # Please don't move this line to includes/Defines.php. This line essentially defines
20 # a valid entry point. If you put it in includes/Defines.php, then any script that includes
21 # it becomes an entry point, thereby defeating its purpose.
22 define( 'MEDIAWIKI', true );
24 require_once( './includes/Defines.php' );
25 require_once( './LocalSettings.php' );
26 require_once( 'includes/Setup.php' );
28 wfProfileIn( 'main-misc-setup' );
29 OutputPage
::setEncodings(); # Not really used yet
32 $action = $wgRequest->getVal( 'action', 'view' );
33 $title = $wgRequest->getVal( 'title' );
35 $action = strtolower( trim( $action ) );
36 if ($wgRequest->getVal( 'printable' ) == 'yes') {
37 $wgOut->setPrintable();
40 if ( '' == $title && 'delete' != $action ) {
41 $wgTitle = Title
::newFromText( wfMsgForContent( 'mainpage' ) );
42 } elseif ( $curid = $wgRequest->getInt( 'curid' ) ) {
43 # URLs like this are generated by RC, because rc_title isn't always accurate
44 $wgTitle = Title
::newFromID( $curid );
46 $wgTitle = Title
::newFromURL( $title );
48 wfProfileOut( 'main-misc-setup' );
50 # Debug statement for user levels
53 # If the user is not logged in, the Namespace:title of the article must be in
54 # the Read array in order for the user to see it. (We have to check here to
55 # catch special pages etc. We check again in Article::view())
56 if ( !is_null( $wgTitle ) && !$wgTitle->userCanRead() ) {
62 wfProfileIn( 'main-action' );
64 $search = $wgRequest->getText( 'search' );
65 if( !$wgDisableInternalSearch && !is_null( $search ) && $search !== '' ) {
66 require_once( 'includes/SpecialSearch.php' );
67 $wgTitle = Title
::makeTitle( NS_SPECIAL
, 'Search' );
69 } else if( !$wgTitle or $wgTitle->getDBkey() == '' ) {
70 $wgTitle = Title
::newFromText( wfMsgForContent( 'badtitle' ) );
71 $wgOut->errorpage( 'badtitle', 'badtitletext' );
72 } else if ( $wgTitle->getInterwiki() != '' ) {
73 if( $rdfrom = $wgRequest->getVal( 'rdfrom' ) ) {
74 $url = $wgTitle->getFullURL( 'rdfrom=' . urlencode( $rdfrom ) );
76 $url = $wgTitle->getFullURL();
78 # Check for a redirect loop
79 if ( !preg_match( '/^' . preg_quote( $wgServer, '/' ) . '/', $url ) && $wgTitle->isLocal() ) {
80 $wgOut->redirect( $url );
82 $wgTitle = Title
::newFromText( wfMsgForContent( 'badtitle' ) );
83 $wgOut->errorpage( 'badtitle', 'badtitletext' );
85 } else if ( ( $action == 'view' ) &&
86 (!isset( $_GET['title'] ) ||
$wgTitle->getPrefixedDBKey() != $_GET['title'] ) &&
87 !count( array_diff( array_keys( $_GET ), array( 'action', 'title' ) ) ) )
89 /* redirect to canonical url, make it a 301 to allow caching */
90 $wgOut->setSquidMaxage( 1200 );
91 $wgOut->redirect( $wgTitle->getFullURL(), '301');
92 } else if ( NS_SPECIAL
== $wgTitle->getNamespace() ) {
93 # actions that need to be made when we have a special pages
94 require_once( 'includes/SpecialPage.php' );
95 SpecialPage
::executePath( $wgTitle );
97 if ( NS_MEDIA
== $wgTitle->getNamespace() ) {
98 $wgTitle = Title
::makeTitle( NS_IMAGE
, $wgTitle->getDBkey() );
101 switch( $wgTitle->getNamespace() ) {
103 require_once( 'includes/ImagePage.php' );
104 $wgArticle = new ImagePage( $wgTitle );
107 if ( $wgUseCategoryMagic ) {
108 require_once( 'includes/CategoryPage.php' );
109 $wgArticle = new CategoryPage( $wgTitle );
112 # NO break if wgUseCategoryMagic is false, drop through to next (default).
113 # Don't insert other cases between NS_CATEGORY and default.
115 $wgArticle = new Article( $wgTitle );
118 if ( in_array( $action, $wgDisabledActions ) ) {
119 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
123 $wgOut->setSquidMaxage( $wgSquidMaxage );
134 case 'markpatrolled':
136 $wgArticle->$action();
142 if( !$wgEnableDublinCoreRdf ) {
143 wfHttpError( 403, 'Forbidden', wfMsg( 'nodublincore' ) );
145 require_once( 'includes/Metadata.php' );
146 wfDublinCoreRdf( $wgArticle );
149 case 'creativecommons':
150 if( !$wgEnableCreativeCommonsRdf ) {
151 wfHttpError( 403, 'Forbidden', wfMsg('nocreativecommons') );
153 require_once( 'includes/Metadata.php' );
154 wfCreativeCommonsRdf( $wgArticle );
158 require_once( 'includes/Credits.php' );
159 showCreditsPage( $wgArticle );
162 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
163 # Send a cookie so anons get talk message notifications
164 User
::SetupSession();
168 $internal = $wgRequest->getVal( 'internaledit' );
169 $external = $wgRequest->getVal( 'externaledit' );
170 $section = $wgRequest->getVal( 'section' );
171 $oldid = $wgRequest->getVal( 'oldid' );
172 if(!$wgUseExternalEditor ||
$action=='submit' ||
$internal ||
173 $section ||
$oldid ||
(!$wgUser->getOption('externaleditor') && !$external)) {
174 require_once( 'includes/EditPage.php' );
175 $editor = new EditPage( $wgArticle );
177 } elseif($wgUseExternalEditor && ($external ||
$wgUser->getOption('externaleditor'))) {
178 require_once( 'includes/ExternalEdit.php' );
179 $mode = $wgRequest->getVal( 'mode' );
180 $extedit = new ExternalEdit( $wgArticle, $mode );
185 if ($_SERVER['REQUEST_URI'] == $wgTitle->getInternalURL('action=history')) {
186 $wgOut->setSquidMaxage( $wgSquidMaxage );
188 require_once( 'includes/PageHistory.php' );
189 $history = new PageHistory( $wgArticle );
193 require_once( 'includes/RawPage.php' );
194 $raw = new RawPage( $wgArticle );
198 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
199 $wgOut->setSquidMaxage( $wgSquidMaxage );
200 $wgTitle->invalidateCache();
204 if (wfRunHooks('UnknownAction', $action, $wgArticle)) {
205 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
210 wfProfileOut( 'main-action' );
212 # Deferred updates aren't really deferred anymore. It's important to report errors to the
213 # user, and that means doing this before OutputPage::output(). Note that for page saves,
214 # the client will wait until the script exits anyway before following the redirect.
215 wfProfileIn( 'main-updates' );
216 foreach ( $wgDeferredUpdateList as $up ) {
219 wfProfileOut( 'main-updates' );
221 wfProfileIn( 'main-cleanup' );
222 $wgLoadBalancer->saveMasterPos();
224 # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
225 $wgLoadBalancer->commitAll();
229 foreach ( $wgPostCommitUpdateList as $up ) {
233 wfProfileOut( 'main-cleanup' );
236 $wgLoadBalancer->closeAll();
237 wfDebug( "Request ended normally\n" );