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' ) ||
61 !is_null( $wgRequest->getVal( 'offset' ) ) ||
62 !is_null ($wgRequest->getVal( 'searchx' ) ) ) {
67 } else if( !$wgTitle or $wgTitle->getDBkey() == "" ) {
68 $wgTitle = Title
::newFromText( wfMsg( "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 );
76 $wgTitle = Title
::newFromText( wfMsg( "badtitle" ) );
77 $wgOut->errorpage( "badtitle", "badtitletext" );
79 } else if ( ( $action == "view" ) && $wgTitle->getPrefixedDBKey() != $title &&
80 !count( array_diff( array_keys( $_GET ), array( 'action', 'title' ) ) ) )
82 /* redirect to canonical url, make it a 301 to allow caching */
83 $wgOut->redirect( $wgTitle->getFullURL(), '301');
84 } else if ( Namespace::getSpecial() == $wgTitle->getNamespace() ) {
85 # actions that need to be made when we have a special pages
86 require_once( 'includes/SpecialPage.php' );
87 if ( !$wgAllowSysopQueries ) {SpecialPage
::removePage( 'Asksql' ); }
88 SpecialPage
::executePath( $wgTitle );
90 if ( Namespace::getMedia() == $wgTitle->getNamespace() ) {
91 $wgTitle = Title
::makeTitle( Namespace::getImage(), $wgTitle->getDBkey() );
94 switch( $wgTitle->getNamespace() ) {
96 require_once( "includes/ImagePage.php" );
97 $wgArticle = new ImagePage( $wgTitle );
100 $wgArticle = new Article( $wgTitle );
105 $wgOut->setSquidMaxage( $wgSquidMaxage );
117 $wgArticle->$action();
123 if( !$wgEnableDublinCoreRdf ) {
124 wfHttpError( 403, "Forbidden", wfMsg( "nodublincore" ) );
126 require_once( "includes/Metadata.php" );
127 wfDublinCoreRdf( $wgArticle );
130 case "creativecommons":
131 if( !$wgEnableCreativeCommonsRdf ) {
132 wfHttpError( 403, "Forbidden", wfMsg("nocreativecommons") );
134 require_once( "includes/Metadata.php" );
135 wfCreativeCommonsRdf( $wgArticle );
139 require_once( "includes/Credits.php" );
140 showCreditsPage( $wgArticle );
144 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
145 User
::SetupSession();
147 require_once( "includes/EditPage.php" );
148 $editor = new EditPage( $wgArticle );
152 if ($_SERVER["REQUEST_URI"] == $wgTitle->getInternalURL('action=history')) {
153 $wgOut->setSquidMaxage( $wgSquidMaxage );
155 require_once( "includes/PageHistory.php" );
156 $history = new PageHistory( $wgArticle );
160 require_once( "includes/RawPage.php" );
161 $raw = new RawPage( $wgArticle );
165 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
166 $wgOut->setSquidMaxage( $wgSquidMaxage );
167 $wgTitle->invalidateCache();
171 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
175 # Deferred updates aren't really deferred anymore. It's important to report errors to the
176 # user, and that means doing this before OutputPage::output(). Note that for page saves,
177 # the client will wait until the script exits anyway before following the redirect.
178 foreach ( $wgDeferredUpdateList as $up ) {
182 $wgLoadBalancer->saveMasterPos();
184 # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
185 $wgLoadBalancer->commitAll();
190 $wgLoadBalancer->closeAll();
191 wfDebug( "Request ended normally\n" );