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 # Valid web server entry point, enable includes
14 define( "MEDIAWIKI", true );
16 require_once( "./includes/Defines.php" );
17 require_once( "./LocalSettings.php" );
18 require_once( "includes/Setup.php" );
20 wfProfileIn( "main-misc-setup" );
21 OutputPage
::setEncodings(); # Not really used yet
24 $action = $wgRequest->getVal( "action", "view" );
26 if( isset( $_SERVER['PATH_INFO'] ) && $wgUsePathInfo ) {
27 $title = substr( $_SERVER['PATH_INFO'], 1 );
29 $title = $wgRequest->getVal( "title" );
32 # Placeholders in case of DB error
33 $wgTitle = Title
::newFromText( wfMsg( "badtitle" ) );
34 $wgArticle = new Article($wgTitle);
36 $action = strtolower( trim( $action ) );
37 if ($wgRequest->getVal( "printable" ) == "yes") {
38 $wgOut->setPrintable();
41 if ( "" == $title && "delete" != $action ) {
42 $wgTitle = Title
::newFromText( wfMsg( "mainpage" ) );
43 } elseif ( $curid = $wgRequest->getInt( 'curid' ) ) {
44 # URLs like this are generated by RC, because rc_title isn't always accurate
45 $wgTitle = Title
::newFromID( $curid );
47 $wgTitle = Title
::newFromURL( $title );
49 wfProfileOut( "main-misc-setup" );
51 # If the user is not logged in, the Namespace:title of the article must be in
52 # the Read array in order for the user to see it. (We have to check here to
53 # catch special pages etc. We check again in Article::view())
54 if ( !is_null( $wgTitle ) && !$wgTitle->userCanRead() ) {
60 if ( $search = $wgRequest->getText( 'search' ) ) {
61 $wgTitle = Title
::makeTitle( NS_SPECIAL
, "Search" );
62 if( $wgRequest->getVal( 'fulltext' ) ||
63 !is_null( $wgRequest->getVal( 'offset' ) ) ||
64 !is_null ($wgRequest->getVal( 'searchx' ) ) ) {
69 } else if( !$wgTitle or $wgTitle->getDBkey() == "" ) {
70 $wgTitle = Title
::newFromText( wfMsg( "badtitle" ) );
71 $wgOut->errorpage( "badtitle", "badtitletext" );
72 } else if ( $wgTitle->getInterwiki() != "" ) {
73 $url = $wgTitle->getFullURL();
74 # Check for a redirect loop
75 if ( !preg_match( "/^" . preg_quote( $wgServer, "/" ) . "/", $url ) && $wgTitle->isLocal() ) {
76 $wgOut->redirect( $url );
78 $wgTitle = Title
::newFromText( wfMsg( "badtitle" ) );
79 $wgOut->errorpage( "badtitle", "badtitletext" );
81 } else if ( ( $action == "view" ) && $wgTitle->getPrefixedDBKey() != $title &&
82 !count( array_diff( array_keys( $_GET ), array( 'action', 'title' ) ) ) )
84 /* redirect to canonical url, make it a 301 to allow caching */
85 $wgOut->redirect( $wgTitle->getFullURL(), '301');
86 } else if ( Namespace::getSpecial() == $wgTitle->getNamespace() ) {
87 # actions that need to be made when we have a special pages
88 require_once( 'includes/SpecialPage.php' );
89 if ( !$wgAllowSysopQueries ) {SpecialPage
::removePage( 'Asksql' ); }
90 SpecialPage
::executePath( $wgTitle );
92 if ( Namespace::getMedia() == $wgTitle->getNamespace() ) {
93 $wgTitle = Title
::makeTitle( Namespace::getImage(), $wgTitle->getDBkey() );
96 switch( $wgTitle->getNamespace() ) {
98 require_once( "includes/ImagePage.php" );
99 $wgArticle = new ImagePage( $wgTitle );
102 $wgArticle = new Article( $wgTitle );
107 $wgOut->setSquidMaxage( $wgSquidMaxage );
119 case "markpatrolled":
120 $wgArticle->$action();
126 if( !$wgEnableDublinCoreRdf ) {
127 wfHttpError( 403, "Forbidden", wfMsg( "nodublincore" ) );
129 require_once( "includes/Metadata.php" );
130 wfDublinCoreRdf( $wgArticle );
133 case "creativecommons":
134 if( !$wgEnableCreativeCommonsRdf ) {
135 wfHttpError( 403, "Forbidden", wfMsg("nocreativecommons") );
137 require_once( "includes/Metadata.php" );
138 wfCreativeCommonsRdf( $wgArticle );
142 require_once( "includes/Credits.php" );
143 showCreditsPage( $wgArticle );
147 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
148 User
::SetupSession();
150 require_once( "includes/EditPage.php" );
151 $editor = new EditPage( $wgArticle );
155 if ($_SERVER["REQUEST_URI"] == $wgTitle->getInternalURL('action=history')) {
156 $wgOut->setSquidMaxage( $wgSquidMaxage );
158 require_once( "includes/PageHistory.php" );
159 $history = new PageHistory( $wgArticle );
163 require_once( "includes/RawPage.php" );
164 $raw = new RawPage( $wgArticle );
168 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
169 $wgOut->setSquidMaxage( $wgSquidMaxage );
170 $wgTitle->invalidateCache();
174 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
178 # Deferred updates aren't really deferred anymore. It's important to report errors to the
179 # user, and that means doing this before OutputPage::output(). Note that for page saves,
180 # the client will wait until the script exits anyway before following the redirect.
181 foreach ( $wgDeferredUpdateList as $up ) {
185 $wgLoadBalancer->saveMasterPos();
187 # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
188 $wgLoadBalancer->commitAll();
193 $wgLoadBalancer->closeAll();
194 wfDebug( "Request ended normally\n" );