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( "./LocalSettings.php" );
15 require_once( "includes/Setup.php" );
17 wfProfileIn( "main-misc-setup" );
18 OutputPage
::setEncodings(); # Not really used yet
21 $action = $wgRequest->getVal( "action", "view" );
23 if( isset( $_SERVER['PATH_INFO'] ) && $wgUsePathInfo ) {
24 $title = substr( $_SERVER['PATH_INFO'], 1 );
26 $title = $wgRequest->getVal( "title" );
29 # Placeholders in case of DB error
30 $wgTitle = Title
::newFromText( wfMsg( "badtitle" ) );
31 $wgArticle = new Article($wgTitle);
33 $action = strtolower( trim( $action ) );
34 if ( "" == $action ) { $action = "view"; }
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 the Read array in
50 # order for the user to see it.
51 if ( !$wgUser->getID() && is_array( $wgWhitelistRead ) && $wgTitle) {
52 if ( !in_array( $wgLang->getNsText( $wgTitle->getNamespace() ) . ":" . $wgTitle->getDBkey(), $wgWhitelistRead ) ) {
59 if ( $search = $wgRequest->getText( 'search' ) ) {
60 $wgTitle = Title
::makeTitle( NS_SPECIAL
, "Search" );
61 if( $wgRequest->getVal( 'fulltext' ) ) {
66 } else if( !$wgTitle or $wgTitle->getDBkey() == "" ) {
67 $wgTitle = Title
::newFromText( wfMsg( "badtitle" ) );
68 $wgOut->errorpage( "badtitle", "badtitletext" );
69 } else if ( $wgTitle->getInterwiki() != "" ) {
70 $url = $wgTitle->getFullURL();
71 # Check for a redirect loop
72 if ( !preg_match( "/^" . preg_quote( $wgServer ) . "/", $url ) && $wgTitle->isLocal() ) {
73 $wgOut->redirect( $url );
75 $wgTitle = Title
::newFromText( wfMsg( "badtitle" ) );
76 $wgOut->errorpage( "badtitle", "badtitletext" );
78 } else if ( ( $action == "view" ) && $wgTitle->getPrefixedDBKey() != $title ) {
79 /* redirect to canonical url, make it a 301 to allow caching */
80 $wgOut->redirect( $wgTitle->getFullURL(), '301');
81 } else if ( Namespace::getSpecial() == $wgTitle->getNamespace() ) {
84 if ( Namespace::getMedia() == $wgTitle->getNamespace() ) {
85 $wgTitle = Title
::makeTitle( Namespace::getImage(), $wgTitle->getDBkey() );
88 switch( $wgTitle->getNamespace() ) {
90 require_once( "includes/ImagePage.php" );
91 $wgArticle = new ImagePage( $wgTitle );
94 $wgArticle = new Article( $wgTitle );
97 wfQuery("BEGIN", DB_WRITE
);
100 $wgOut->setSquidMaxage( $wgSquidMaxage );
110 $wgArticle->$action();
116 if( !$wgEnableDublinCoreRdf ) {
117 wfHttpError( 403, "Forbidden", wfMsg( "nodublincore" ) );
119 require_once( "includes/Metadata.php" );
120 wfDublinCoreRdf( $wgArticle );
123 case "creativecommons":
124 if( !$wgEnableCreativeCommonsRdf ) {
125 wfHttpError( 403, "Forbidden", wfMsg("nocreativecommons") );
127 require_once( "includes/Metadata.php" );
128 wfCreativeCommonsRdf( $wgArticle );
133 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
134 User
::SetupSession();
136 require_once( "includes/EditPage.php" );
137 $editor = new EditPage( $wgArticle );
141 if ($_SERVER["REQUEST_URI"] == $wgTitle->getInternalURL('action=history')) {
142 $wgOut->setSquidMaxage( $wgSquidMaxage );
144 require_once( "includes/PageHistory.php" );
145 $history = new PageHistory( $wgArticle );
149 require_once( "includes/RawPage.php" );
150 $raw = new RawPage( $wgArticle );
154 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
155 $wgOut->setSquidMaxage( $wgSquidMaxage );
159 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
161 wfQuery("COMMIT", DB_WRITE
);
166 foreach ( $wgDeferredUpdateList as $up ) { $up->doUpdate(); }
168 wfDebug( "Request ended normally\n" );