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!" );
12 include_once( "./LocalSettings.php" );
14 if( $wgSitename == "MediaWiki" ) {
15 die( "You must set the site name in \$wgSitename before installation.\n\n" );
18 # PATH_SEPARATOR avaialble only from 4.3.0
19 $sep = (DIRECTORY_SEPARATOR
== "\\") ?
";" : ":";
20 ini_set( "include_path", $IP . $sep . ini_get( "include_path" ) );
22 include_once( "Setup.php" );
24 wfProfileIn( "main-misc-setup" );
25 OutputPage
::setEncodings(); # Not really used yet
28 $action = $wgRequest->getVal( "action", "view" );
30 if( isset( $_SERVER['PATH_INFO'] ) && $wgUsePathInfo ) {
31 $title = substr( $_SERVER['PATH_INFO'], 1 );
33 $title = $wgRequest->getVal( "title" );
36 # Placeholders in case of DB error
37 $wgTitle = Title
::newFromText( wfMsg( "badtitle" ) );
38 $wgArticle = new Article($wgTitle);
40 $action = strtolower( trim( $action ) );
41 if ( "" == $action ) { $action = "view"; }
42 if ($wgRequest->getVal( "printable" ) == "yes") {
43 $wgOut->setPrintable();
46 if ( "" == $title && "delete" != $action ) {
47 $wgTitle = Title
::newFromText( wfMsg( "mainpage" ) );
48 } elseif ( $curid = $wgRequest->getInt( 'curid' ) ) {
49 # URLs like this are generated by RC, because rc_title isn't always accurate
50 $wgTitle = Title
::newFromID( $curid );
52 $wgTitle = Title
::newFromURL( $title );
54 wfProfileOut( "main-misc-setup" );
56 # If the user is not logged in, the Namespace:title of the article must be in the Read array in
57 # order for the user to see it.
58 if ( !$wgUser->getID() && is_array( $wgWhitelistRead ) && $wgTitle) {
59 if ( !in_array( $wgLang->getNsText( $wgTitle->getNamespace() ) . ":" . $wgTitle->getDBkey(), $wgWhitelistRead ) ) {
66 if ( $search = $wgRequest->getText( 'search' ) ) {
67 $wgTitle = Title
::makeTitle( NS_SPECIAL
, "Search" );
68 if( $wgRequest->getVal( 'fulltext' ) ) {
73 } else if( !$wgTitle or $wgTitle->getInterwiki() != "" or $wgTitle->getDBkey() == "" ) {
74 $wgTitle = Title
::newFromText( wfMsg( "badtitle" ) );
75 $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() ) {
82 if ( Namespace::getMedia() == $wgTitle->getNamespace() ) {
83 $wgTitle = Title
::makeTitle( Namespace::getImage(), $wgTitle->getDBkey() );
86 switch( $wgTitle->getNamespace() ) {
88 include_once( "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 include_once( "Metadata.php" );
118 wfDublinCoreRdf( $wgArticle );
121 case "creativecommons":
122 if( !$wgEnableCreativeCommonsRdf ) {
123 wfHttpError( 403, "Forbidden", wfMsg("nocreativecommons") );
125 include_once( "Metadata.php" );
126 wfCreativeCommonsRdf( $wgArticle );
131 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
132 User
::SetupSession();
134 include_once( "EditPage.php" );
135 $editor = new EditPage( $wgArticle );
139 if ($_SERVER["REQUEST_URI"] == $wgTitle->getInternalURL('action=history')) {
140 $wgOut->setSquidMaxage( $wgSquidMaxage );
142 include_once( "PageHistory.php" );
143 $history = new PageHistory( $wgArticle );
147 include_once( "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" );