2 #apd_set_pprof_trace();
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 # The define must not be in ./includes/Defines.php because non valid entry
15 # points can includes it.
16 define( "MEDIAWIKI", true );
18 require_once( "./includes/Defines.php" );
19 require_once( "./LocalSettings.php" );
20 require_once( "includes/Setup.php" );
22 wfProfileIn( "main-misc-setup" );
23 OutputPage
::setEncodings(); # Not really used yet
26 $action = $wgRequest->getVal( "action", "view" );
28 if( isset( $_SERVER['PATH_INFO'] ) && $wgUsePathInfo ) {
29 $title = substr( $_SERVER['PATH_INFO'], 1 );
31 $title = $wgRequest->getVal( "title" );
34 # Placeholders in case of DB error
35 $wgTitle = Title
::newFromText( wfMsg( "badtitle" ) );
36 $wgArticle = new Article($wgTitle);
38 $action = strtolower( trim( $action ) );
39 if ($wgRequest->getVal( "printable" ) == "yes") {
40 $wgOut->setPrintable();
43 if ( "" == $title && "delete" != $action ) {
44 $wgTitle = Title
::newFromText( wfMsg( "mainpage" ) );
45 } elseif ( $curid = $wgRequest->getInt( 'curid' ) ) {
46 # URLs like this are generated by RC, because rc_title isn't always accurate
47 $wgTitle = Title
::newFromID( $curid );
49 $wgTitle = Title
::newFromURL( $title );
51 wfProfileOut( "main-misc-setup" );
53 # If the user is not logged in, the Namespace:title of the article must be in
54 # the Read array in order for the user to see it. (We have to check here to
55 # catch special pages etc. We check again in Article::view())
56 if ( !is_null( $wgTitle ) && !$wgTitle->userCanRead() ) {
62 if ( $search = $wgRequest->getText( 'search' ) ) {
63 $wgTitle = Title
::makeTitle( NS_SPECIAL
, "Search" );
64 $searchEngine = new SearchEngine( $search );
65 if( $wgRequest->getVal( 'fulltext' ) ||
66 !is_null( $wgRequest->getVal( 'offset' ) ) ||
67 !is_null ($wgRequest->getVal( 'searchx' ) ) ) {
68 $searchEngine->showResults();
70 $searchEngine->goResult();
72 } else if( !$wgTitle or $wgTitle->getDBkey() == "" ) {
73 $wgTitle = Title
::newFromText( wfMsg( "badtitle" ) );
74 $wgOut->errorpage( "badtitle", "badtitletext" );
75 } else if ( $wgTitle->getInterwiki() != "" ) {
76 $url = $wgTitle->getFullURL();
77 # Check for a redirect loop
78 if ( !preg_match( "/^" . preg_quote( $wgServer, "/" ) . "/", $url ) && $wgTitle->isLocal() ) {
79 $wgOut->redirect( $url );
81 $wgTitle = Title
::newFromText( wfMsg( "badtitle" ) );
82 $wgOut->errorpage( "badtitle", "badtitletext" );
84 } else if ( ( $action == "view" ) && $wgTitle->getPrefixedDBKey() != $title &&
85 !count( array_diff( array_keys( $_GET ), array( 'action', 'title' ) ) ) )
87 /* redirect to canonical url, make it a 301 to allow caching */
88 $wgOut->redirect( $wgTitle->getFullURL(), '301');
89 } else if ( Namespace::getSpecial() == $wgTitle->getNamespace() ) {
90 # actions that need to be made when we have a special pages
91 require_once( 'includes/SpecialPage.php' );
92 if ( !$wgAllowSysopQueries ) {SpecialPage
::removePage( 'Asksql' ); }
93 SpecialPage
::executePath( $wgTitle );
95 if ( Namespace::getMedia() == $wgTitle->getNamespace() ) {
96 $wgTitle = Title
::makeTitle( Namespace::getImage(), $wgTitle->getDBkey() );
99 switch( $wgTitle->getNamespace() ) {
101 require_once( "includes/ImagePage.php" );
102 $wgArticle = new ImagePage( $wgTitle );
105 $wgArticle = new Article( $wgTitle );
110 $wgOut->setSquidMaxage( $wgSquidMaxage );
122 case "markpatrolled":
123 $wgArticle->$action();
129 if( !$wgEnableDublinCoreRdf ) {
130 wfHttpError( 403, "Forbidden", wfMsg( "nodublincore" ) );
132 require_once( "includes/Metadata.php" );
133 wfDublinCoreRdf( $wgArticle );
136 case "creativecommons":
137 if( !$wgEnableCreativeCommonsRdf ) {
138 wfHttpError( 403, "Forbidden", wfMsg("nocreativecommons") );
140 require_once( "includes/Metadata.php" );
141 wfCreativeCommonsRdf( $wgArticle );
145 require_once( "includes/Credits.php" );
146 showCreditsPage( $wgArticle );
150 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
151 User
::SetupSession();
153 require_once( "includes/EditPage.php" );
154 $editor = new EditPage( $wgArticle );
158 if ($_SERVER["REQUEST_URI"] == $wgTitle->getInternalURL('action=history')) {
159 $wgOut->setSquidMaxage( $wgSquidMaxage );
161 require_once( "includes/PageHistory.php" );
162 $history = new PageHistory( $wgArticle );
166 require_once( "includes/RawPage.php" );
167 $raw = new RawPage( $wgArticle );
171 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
172 $wgOut->setSquidMaxage( $wgSquidMaxage );
173 $wgTitle->invalidateCache();
177 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
181 # Deferred updates aren't really deferred anymore. It's important to report errors to the
182 # user, and that means doing this before OutputPage::output(). Note that for page saves,
183 # the client will wait until the script exits anyway before following the redirect.
184 foreach ( $wgDeferredUpdateList as $up ) {
188 $wgLoadBalancer->saveMasterPos();
190 # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
191 $wgLoadBalancer->commitAll();
196 $wgLoadBalancer->closeAll();
197 wfDebug( "Request ended normally\n" );