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 die( "You'll have to <a href='config/index.php'>set the wiki up</a> first!" );
13 define( "MEDIAWIKI", true );
14 require_once( "./includes/Defines.php" );
15 require_once( "./LocalSettings.php" );
16 require_once( "includes/Setup.php" );
18 wfProfileIn( "main-misc-setup" );
19 OutputPage
::setEncodings(); # Not really used yet
22 $action = $wgRequest->getVal( "action", "view" );
24 if( isset( $_SERVER['PATH_INFO'] ) && $wgUsePathInfo ) {
25 $title = substr( $_SERVER['PATH_INFO'], 1 );
27 $title = $wgRequest->getVal( "title" );
30 # Placeholders in case of DB error
31 $wgTitle = Title
::newFromText( wfMsg( "badtitle" ) );
32 $wgArticle = new Article($wgTitle);
34 $action = strtolower( trim( $action ) );
35 if ($wgRequest->getVal( "printable" ) == "yes") {
36 $wgOut->setPrintable();
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 );
45 $wgTitle = Title
::newFromURL( $title );
47 wfProfileOut( "main-misc-setup" );
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() ) {
58 if ( $search = $wgRequest->getText( 'search' ) ) {
59 $wgTitle = Title
::makeTitle( NS_SPECIAL
, "Search" );
60 if( $wgRequest->getVal( 'fulltext' ) ||
!is_null( $wgRequest->getVal( 'offset' ) ) ) {
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 );
74 $wgTitle = Title
::newFromText( wfMsg( "badtitle" ) );
75 $wgOut->errorpage( "badtitle", "badtitletext" );
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 );
86 if ( Namespace::getMedia() == $wgTitle->getNamespace() ) {
87 $wgTitle = Title
::makeTitle( Namespace::getImage(), $wgTitle->getDBkey() );
90 switch( $wgTitle->getNamespace() ) {
92 require_once( "includes/ImagePage.php" );
93 $wgArticle = new ImagePage( $wgTitle );
96 $wgArticle = new Article( $wgTitle );
101 $wgOut->setSquidMaxage( $wgSquidMaxage );
113 $wgArticle->$action();
119 if( !$wgEnableDublinCoreRdf ) {
120 wfHttpError( 403, "Forbidden", wfMsg( "nodublincore" ) );
122 require_once( "includes/Metadata.php" );
123 wfDublinCoreRdf( $wgArticle );
126 case "creativecommons":
127 if( !$wgEnableCreativeCommonsRdf ) {
128 wfHttpError( 403, "Forbidden", wfMsg("nocreativecommons") );
130 require_once( "includes/Metadata.php" );
131 wfCreativeCommonsRdf( $wgArticle );
135 require_once( "includes/Credits.php" );
136 showCreditsPage( $wgArticle );
140 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
141 User
::SetupSession();
143 require_once( "includes/EditPage.php" );
144 $editor = new EditPage( $wgArticle );
148 if ($_SERVER["REQUEST_URI"] == $wgTitle->getInternalURL('action=history')) {
149 $wgOut->setSquidMaxage( $wgSquidMaxage );
151 require_once( "includes/PageHistory.php" );
152 $history = new PageHistory( $wgArticle );
156 require_once( "includes/RawPage.php" );
157 $raw = new RawPage( $wgArticle );
161 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
162 $wgOut->setSquidMaxage( $wgSquidMaxage );
163 $wgTitle->invalidateCache();
167 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
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 ) {
178 $wgLoadBalancer->saveMasterPos();
180 # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
181 $wgLoadBalancer->commitAll();
186 $wgLoadBalancer->closeAll();
187 wfDebug( "Request ended normally\n" );