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
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 ( !$wgTitle->userCanRead() ) {
58 if ( $search = $wgRequest->getText( 'search' ) ) {
59 $wgTitle = Title
::makeTitle( NS_SPECIAL
, "Search" );
60 if( $wgRequest->getVal( 'fulltext' ) ) {
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() ) {
83 if ( Namespace::getMedia() == $wgTitle->getNamespace() ) {
84 $wgTitle = Title
::makeTitle( Namespace::getImage(), $wgTitle->getDBkey() );
87 switch( $wgTitle->getNamespace() ) {
89 require_once( "includes/ImagePage.php" );
90 $wgArticle = new ImagePage( $wgTitle );
93 $wgArticle = new Article( $wgTitle );
96 wfQuery("BEGIN", DB_WRITE
);
99 $wgOut->setSquidMaxage( $wgSquidMaxage );
109 $wgArticle->$action();
115 if( !$wgEnableDublinCoreRdf ) {
116 wfHttpError( 403, "Forbidden", wfMsg( "nodublincore" ) );
118 require_once( "includes/Metadata.php" );
119 wfDublinCoreRdf( $wgArticle );
122 case "creativecommons":
123 if( !$wgEnableCreativeCommonsRdf ) {
124 wfHttpError( 403, "Forbidden", wfMsg("nocreativecommons") );
126 require_once( "includes/Metadata.php" );
127 wfCreativeCommonsRdf( $wgArticle );
132 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
133 User
::SetupSession();
135 require_once( "includes/EditPage.php" );
136 $editor = new EditPage( $wgArticle );
140 if ($_SERVER["REQUEST_URI"] == $wgTitle->getInternalURL('action=history')) {
141 $wgOut->setSquidMaxage( $wgSquidMaxage );
143 require_once( "includes/PageHistory.php" );
144 $history = new PageHistory( $wgArticle );
148 require_once( "includes/RawPage.php" );
149 $raw = new RawPage( $wgArticle );
153 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
154 $wgOut->setSquidMaxage( $wgSquidMaxage );
158 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
160 wfQuery("COMMIT", DB_WRITE
);
165 foreach ( $wgDeferredUpdateList as $up ) { $up->doUpdate(); }
167 wfDebug( "Request ended normally\n" );