2 #apd_set_pprof_trace();
3 # Main wiki script; see design.doc
5 $wgRequestTime = microtime();
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" );
13 die( "You'll have to <a href='config/index.php'>set the wiki up</a> first!" );
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 );
23 require_once( './includes/Defines.php' );
24 require_once( './LocalSettings.php' );
25 require_once( 'includes/Setup.php' );
27 wfProfileIn( 'main-misc-setup' );
28 OutputPage
::setEncodings(); # Not really used yet
31 $action = $wgRequest->getVal( 'action', 'view' );
32 $title = $wgRequest->getVal( 'title' );
34 $action = strtolower( trim( $action ) );
35 if ($wgRequest->getVal( 'printable' ) == 'yes') {
36 $wgOut->setPrintable();
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 );
45 $wgTitle = Title
::newFromURL( $title );
47 wfProfileOut( 'main-misc-setup' );
49 # Debug statement for user levels
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() ) {
61 wfProfileIn( 'main-action' );
63 $search = $wgRequest->getText( 'search' );
64 if( !$wgDisableInternalSearch && !is_null( $search ) && $search !== '' ) {
65 require_once( 'includes/SpecialSearch.php' );
66 $wgTitle = Title
::makeTitle( NS_SPECIAL
, 'Search' );
68 } else if( !$wgTitle or $wgTitle->getDBkey() == '' ) {
69 $wgTitle = Title
::newFromText( wfMsgForContent( 'badtitle' ) );
70 $wgOut->errorpage( 'badtitle', 'badtitletext' );
71 } else if ( $wgTitle->getInterwiki() != '' ) {
72 $url = $wgTitle->getFullURL();
73 # Check for a redirect loop
74 if ( !preg_match( '/^' . preg_quote( $wgServer, '/' ) . '/', $url ) && $wgTitle->isLocal() ) {
75 $wgOut->redirect( $url );
77 $wgTitle = Title
::newFromText( wfMsgForContent( 'badtitle' ) );
78 $wgOut->errorpage( 'badtitle', 'badtitletext' );
80 } else if ( ( $action == 'view' ) &&
81 (!isset( $_GET['title'] ) ||
$wgTitle->getPrefixedDBKey() != $_GET['title'] ) &&
82 !count( array_diff( array_keys( $_GET ), array( 'action', 'title' ) ) ) )
84 /* redirect to canonical url, make it a 301 to allow caching */
85 $wgOut->setSquidMaxage( 1200 );
86 $wgOut->redirect( $wgTitle->getFullURL(), '301');
87 } else if ( Namespace::getSpecial() == $wgTitle->getNamespace() ) {
88 # actions that need to be made when we have a special pages
89 require_once( 'includes/SpecialPage.php' );
90 if ( !$wgAllowSysopQueries ) {SpecialPage
::removePage( 'Asksql' ); }
91 SpecialPage
::executePath( $wgTitle );
93 if ( Namespace::getMedia() == $wgTitle->getNamespace() ) {
94 $wgTitle = Title
::makeTitle( NS_IMAGE
, $wgTitle->getDBkey() );
97 switch( $wgTitle->getNamespace() ) {
99 require_once( 'includes/ImagePage.php' );
100 $wgArticle = new ImagePage( $wgTitle );
103 if ( $wgUseCategoryMagic ) {
104 require_once( 'includes/CategoryPage.php' );
105 $wgArticle = new CategoryPage( $wgTitle );
108 # NO break if wgUseCategoryMagic is false, drop through to next (default).
109 # Don't insert other cases between NS_CATEGORY and default.
111 $wgArticle = new Article( $wgTitle );
116 $wgOut->setSquidMaxage( $wgSquidMaxage );
128 case 'markpatrolled':
129 $wgArticle->$action();
135 if( !$wgEnableDublinCoreRdf ) {
136 wfHttpError( 403, 'Forbidden', wfMsg( 'nodublincore' ) );
138 require_once( 'includes/Metadata.php' );
139 wfDublinCoreRdf( $wgArticle );
142 case 'creativecommons':
143 if( !$wgEnableCreativeCommonsRdf ) {
144 wfHttpError( 403, 'Forbidden', wfMsg('nocreativecommons') );
146 require_once( 'includes/Metadata.php' );
147 wfCreativeCommonsRdf( $wgArticle );
151 require_once( 'includes/Credits.php' );
152 showCreditsPage( $wgArticle );
155 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
156 # Send a cookie so anons get talk message notifications
157 User
::SetupSession();
161 require_once( 'includes/EditPage.php' );
162 $editor = new EditPage( $wgArticle );
166 if ($_SERVER['REQUEST_URI'] == $wgTitle->getInternalURL('action=history')) {
167 $wgOut->setSquidMaxage( $wgSquidMaxage );
169 require_once( 'includes/PageHistory.php' );
170 $history = new PageHistory( $wgArticle );
174 require_once( 'includes/RawPage.php' );
175 $raw = new RawPage( $wgArticle );
179 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
180 $wgOut->setSquidMaxage( $wgSquidMaxage );
181 $wgTitle->invalidateCache();
185 if (wfRunHooks('UnknownAction', $action, $wgArticle)) {
186 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
190 wfProfileOut( 'main-action' );
192 # Deferred updates aren't really deferred anymore. It's important to report errors to the
193 # user, and that means doing this before OutputPage::output(). Note that for page saves,
194 # the client will wait until the script exits anyway before following the redirect.
195 wfProfileIn( 'main-updates' );
196 foreach ( $wgDeferredUpdateList as $up ) {
199 wfProfileOut( 'main-updates' );
201 wfProfileIn( 'main-cleanup' );
202 $wgLoadBalancer->saveMasterPos();
204 # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
205 $wgLoadBalancer->commitAll();
208 wfProfileOut( 'main-cleanup' );
211 $wgLoadBalancer->closeAll();
212 wfDebug( "Request ended normally\n" );