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 ($wgRequest->getVal( "printable" ) == "yes") {
35 $wgOut->setPrintable();
38 if ( "" == $title && "delete" != $action ) {
39 $wgTitle = Title
::newFromText( wfMsg( "mainpage" ) );
40 } elseif ( $curid = $wgRequest->getInt( 'curid' ) ) {
41 # URLs like this are generated by RC, because rc_title isn't always accurate
42 $wgTitle = Title
::newFromID( $curid );
44 $wgTitle = Title
::newFromURL( $title );
46 wfProfileOut( "main-misc-setup" );
48 # If the user is not logged in, the Namespace:title of the article must be in
49 # the Read array in order for the user to see it. (We have to check here to
50 # catch special pages etc. We check again in Article::view())
51 if ( !$wgTitle->userCanRead() ) {
57 if ( $search = $wgRequest->getText( 'search' ) ) {
58 $wgTitle = Title
::makeTitle( NS_SPECIAL
, "Search" );
59 if( $wgRequest->getVal( 'fulltext' ) ) {
64 } else if( !$wgTitle or $wgTitle->getDBkey() == "" ) {
65 $wgTitle = Title
::newFromText( wfMsg( "badtitle" ) );
66 $wgOut->errorpage( "badtitle", "badtitletext" );
67 } else if ( $wgTitle->getInterwiki() != "" ) {
68 $url = $wgTitle->getFullURL();
69 # Check for a redirect loop
70 if ( !preg_match( "/^" . preg_quote( $wgServer ) . "/", $url ) && $wgTitle->isLocal() ) {
71 $wgOut->redirect( $url );
73 $wgTitle = Title
::newFromText( wfMsg( "badtitle" ) );
74 $wgOut->errorpage( "badtitle", "badtitletext" );
76 } else if ( ( $action == "view" ) && $wgTitle->getPrefixedDBKey() != $title ) {
77 /* redirect to canonical url, make it a 301 to allow caching */
78 $wgOut->redirect( $wgTitle->getFullURL(), '301');
79 } else if ( Namespace::getSpecial() == $wgTitle->getNamespace() ) {
80 SpecialPage
::executePath( $wgTitle );
82 if ( Namespace::getMedia() == $wgTitle->getNamespace() ) {
83 $wgTitle = Title
::makeTitle( Namespace::getImage(), $wgTitle->getDBkey() );
86 switch( $wgTitle->getNamespace() ) {
88 require_once( "includes/ImagePage.php" );
89 $wgArticle = new ImagePage( $wgTitle );
92 $wgArticle = new Article( $wgTitle );
95 wfQuery("BEGIN", DB_WRITE
);
98 $wgOut->setSquidMaxage( $wgSquidMaxage );
108 $wgArticle->$action();
114 if( !$wgEnableDublinCoreRdf ) {
115 wfHttpError( 403, "Forbidden", wfMsg( "nodublincore" ) );
117 require_once( "includes/Metadata.php" );
118 wfDublinCoreRdf( $wgArticle );
121 case "creativecommons":
122 if( !$wgEnableCreativeCommonsRdf ) {
123 wfHttpError( 403, "Forbidden", wfMsg("nocreativecommons") );
125 require_once( "includes/Metadata.php" );
126 wfCreativeCommonsRdf( $wgArticle );
131 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
132 User
::SetupSession();
134 require_once( "includes/EditPage.php" );
135 $editor = new EditPage( $wgArticle );
139 if ($_SERVER["REQUEST_URI"] == $wgTitle->getInternalURL('action=history')) {
140 $wgOut->setSquidMaxage( $wgSquidMaxage );
142 require_once( "includes/PageHistory.php" );
143 $history = new PageHistory( $wgArticle );
147 require_once( "includes/RawPage.php" );
148 $raw = new RawPage( $wgArticle );
152 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
153 $wgOut->setSquidMaxage( $wgSquidMaxage );
157 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
159 wfQuery("COMMIT", DB_WRITE
);
164 foreach ( $wgDeferredUpdateList as $up ) { $up->doUpdate(); }
166 wfDebug( "Request ended normally\n" );