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 case "markpatrolled":
118 $wgArticle->$action();
124 if( !$wgEnableDublinCoreRdf ) {
125 wfHttpError( 403, "Forbidden", wfMsg( "nodublincore" ) );
127 require_once( "includes/Metadata.php" );
128 wfDublinCoreRdf( $wgArticle );
131 case "creativecommons":
132 if( !$wgEnableCreativeCommonsRdf ) {
133 wfHttpError( 403, "Forbidden", wfMsg("nocreativecommons") );
135 require_once( "includes/Metadata.php" );
136 wfCreativeCommonsRdf( $wgArticle );
140 require_once( "includes/Credits.php" );
141 showCreditsPage( $wgArticle );
145 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
146 User
::SetupSession();
148 require_once( "includes/EditPage.php" );
149 $editor = new EditPage( $wgArticle );
153 if ($_SERVER["REQUEST_URI"] == $wgTitle->getInternalURL('action=history')) {
154 $wgOut->setSquidMaxage( $wgSquidMaxage );
156 require_once( "includes/PageHistory.php" );
157 $history = new PageHistory( $wgArticle );
161 require_once( "includes/RawPage.php" );
162 $raw = new RawPage( $wgArticle );
166 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
167 $wgOut->setSquidMaxage( $wgSquidMaxage );
168 $wgTitle->invalidateCache();
172 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
176 # Deferred updates aren't really deferred anymore. It's important to report errors to the
177 # user, and that means doing this before OutputPage::output(). Note that for page saves,
178 # the client will wait until the script exits anyway before following the redirect.
179 foreach ( $wgDeferredUpdateList as $up ) {
183 $wgLoadBalancer->saveMasterPos();
185 # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
186 $wgLoadBalancer->commitAll();
191 $wgLoadBalancer->closeAll();
192 wfDebug( "Request ended normally\n" );