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 ( !is_null( $wgTitle ) && !$wgTitle->userCanRead() ) {
57 $db =& wfGetDB( DB_MASTER
);
59 if ( $search = $wgRequest->getText( 'search' ) ) {
60 $wgTitle = Title
::makeTitle( NS_SPECIAL
, "Search" );
61 if( $wgRequest->getVal( 'fulltext' ) ||
!is_null( $wgRequest->getVal( 'offset' ) ) ) {
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() ) {
82 # actions that need to be made when we have a special pages
83 require_once( 'includes/SpecialPage.php' );
84 if ( !$wgAllowSysopQueries ) {SpecialPage
::removePage( 'Asksql' ); }
85 SpecialPage
::executePath( $wgTitle );
87 if ( Namespace::getMedia() == $wgTitle->getNamespace() ) {
88 $wgTitle = Title
::makeTitle( Namespace::getImage(), $wgTitle->getDBkey() );
91 switch( $wgTitle->getNamespace() ) {
93 require_once( "includes/ImagePage.php" );
94 $wgArticle = new ImagePage( $wgTitle );
97 $wgArticle = new Article( $wgTitle );
103 $wgOut->setSquidMaxage( $wgSquidMaxage );
115 $wgArticle->$action();
121 if( !$wgEnableDublinCoreRdf ) {
122 wfHttpError( 403, "Forbidden", wfMsg( "nodublincore" ) );
124 require_once( "includes/Metadata.php" );
125 wfDublinCoreRdf( $wgArticle );
128 case "creativecommons":
129 if( !$wgEnableCreativeCommonsRdf ) {
130 wfHttpError( 403, "Forbidden", wfMsg("nocreativecommons") );
132 require_once( "includes/Metadata.php" );
133 wfCreativeCommonsRdf( $wgArticle );
137 require_once( "includes/Credits.php" );
138 showCreditsPage( $wgArticle );
142 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
143 User
::SetupSession();
145 require_once( "includes/EditPage.php" );
146 $editor = new EditPage( $wgArticle );
150 if ($_SERVER["REQUEST_URI"] == $wgTitle->getInternalURL('action=history')) {
151 $wgOut->setSquidMaxage( $wgSquidMaxage );
153 require_once( "includes/PageHistory.php" );
154 $history = new PageHistory( $wgArticle );
158 require_once( "includes/RawPage.php" );
159 $raw = new RawPage( $wgArticle );
163 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
164 $wgOut->setSquidMaxage( $wgSquidMaxage );
165 $wgTitle->invalidateCache();
169 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
171 $db->query("COMMIT");
174 $wgLoadBalancer->saveMasterPos();
177 foreach ( $wgDeferredUpdateList as $up ) {
180 $db->query("COMMIT");
183 wfDebug( "Request ended normally\n" );