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() != '' ) {
74 # Conversion from UTF-8 may truncate or corrupt non-Latin links.
75 # Grab a fresh copy without doing the automated conversion checks.
76 $interwiki = Title
::newFromUrl( $_REQUEST['title'] );
77 if( !is_null( $interwiki ) ) $wgTitle = $interwiki;
79 if( $rdfrom = $wgRequest->getVal( 'rdfrom' ) ) {
80 $url = $wgTitle->getFullURL( 'rdfrom=' . urlencode( $rdfrom ) );
82 $url = $wgTitle->getFullURL();
84 # Check for a redirect loop
85 if ( !preg_match( '/^' . preg_quote( $wgServer, '/' ) . '/', $url ) && $wgTitle->isLocal() ) {
86 $wgOut->redirect( $url );
88 $wgTitle = Title
::newFromText( wfMsgForContent( 'badtitle' ) );
89 $wgOut->errorpage( 'badtitle', 'badtitletext' );
91 } else if ( ( $action == 'view' ) &&
92 (!isset( $_GET['title'] ) ||
$wgTitle->getPrefixedDBKey() != $_GET['title'] ) &&
93 !count( array_diff( array_keys( $_GET ), array( 'action', 'title' ) ) ) )
95 /* redirect to canonical url, make it a 301 to allow caching */
96 $wgOut->setSquidMaxage( 1200 );
97 $wgOut->redirect( $wgTitle->getFullURL(), '301');
98 } else if ( NS_SPECIAL
== $wgTitle->getNamespace() ) {
99 # actions that need to be made when we have a special pages
100 require_once( 'includes/SpecialPage.php' );
101 SpecialPage
::executePath( $wgTitle );
103 if ( NS_MEDIA
== $wgTitle->getNamespace() ) {
104 $wgTitle = Title
::makeTitle( NS_IMAGE
, $wgTitle->getDBkey() );
107 switch( $wgTitle->getNamespace() ) {
109 require_once( 'includes/ImagePage.php' );
110 $wgArticle = new ImagePage( $wgTitle );
113 if ( $wgUseCategoryMagic ) {
114 require_once( 'includes/CategoryPage.php' );
115 $wgArticle = new CategoryPage( $wgTitle );
118 # NO break if wgUseCategoryMagic is false, drop through to next (default).
119 # Don't insert other cases between NS_CATEGORY and default.
121 $wgArticle = new Article( $wgTitle );
126 $wgOut->setSquidMaxage( $wgSquidMaxage );
137 case 'markpatrolled':
139 $wgArticle->$action();
145 if( !$wgEnableDublinCoreRdf ) {
146 wfHttpError( 403, 'Forbidden', wfMsg( 'nodublincore' ) );
148 require_once( 'includes/Metadata.php' );
149 wfDublinCoreRdf( $wgArticle );
152 case 'creativecommons':
153 if( !$wgEnableCreativeCommonsRdf ) {
154 wfHttpError( 403, 'Forbidden', wfMsg('nocreativecommons') );
156 require_once( 'includes/Metadata.php' );
157 wfCreativeCommonsRdf( $wgArticle );
161 require_once( 'includes/Credits.php' );
162 showCreditsPage( $wgArticle );
165 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
166 # Send a cookie so anons get talk message notifications
167 User
::SetupSession();
171 $internal = $wgRequest->getVal( 'internaledit' );
172 $external = $wgRequest->getVal( 'externaledit' );
173 $section = $wgRequest->getVal( 'section' );
174 $oldid = $wgRequest->getVal( 'oldid' );
175 if(!$wgUseExternalEditor ||
$action=='submit' ||
$internal ||
176 $section ||
$oldid ||
(!$wgUser->getOption('externaleditor') && !$external)) {
177 require_once( 'includes/EditPage.php' );
178 $editor = new EditPage( $wgArticle );
180 } elseif($wgUseExternalEditor && ($external ||
$wgUser->getOption('externaleditor'))) {
181 require_once( 'includes/ExternalEdit.php' );
182 $mode = $wgRequest->getVal( 'mode' );
183 $extedit = new ExternalEdit( $wgArticle, $mode );
188 if ($_SERVER['REQUEST_URI'] == $wgTitle->getInternalURL('action=history')) {
189 $wgOut->setSquidMaxage( $wgSquidMaxage );
191 require_once( 'includes/PageHistory.php' );
192 $history = new PageHistory( $wgArticle );
196 require_once( 'includes/RawPage.php' );
197 $raw = new RawPage( $wgArticle );
201 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
202 $wgOut->setSquidMaxage( $wgSquidMaxage );
203 $wgTitle->invalidateCache();
207 if (wfRunHooks('UnknownAction', $action, $wgArticle)) {
208 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
212 wfProfileOut( 'main-action' );
214 # Deferred updates aren't really deferred anymore. It's important to report errors to the
215 # user, and that means doing this before OutputPage::output(). Note that for page saves,
216 # the client will wait until the script exits anyway before following the redirect.
217 wfProfileIn( 'main-updates' );
218 foreach ( $wgDeferredUpdateList as $up ) {
221 wfProfileOut( 'main-updates' );
223 wfProfileIn( 'main-cleanup' );
224 $wgLoadBalancer->saveMasterPos();
226 # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
227 $wgLoadBalancer->commitAll();
231 foreach ( $wgPostCommitUpdateList as $up ) {
235 wfProfileOut( 'main-cleanup' );
238 $wgLoadBalancer->closeAll();
239 wfDebug( "Request ended normally\n" );