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 # Please don't move this line to includes/Defines.php. This line essentially defines
15 # a valid entry point. If you put it in includes/Defines.php, then any script that includes
16 # it becomes an entry point, thereby defeating its purpose.
17 define( "MEDIAWIKI", true );
19 require_once( "./includes/Defines.php" );
20 require_once( "./LocalSettings.php" );
21 require_once( "includes/Setup.php" );
23 wfProfileIn( "main-misc-setup" );
24 OutputPage
::setEncodings(); # Not really used yet
27 $action = $wgRequest->getVal( "action", "view" );
29 if( isset( $_SERVER['PATH_INFO'] ) && $wgUsePathInfo ) {
30 $title = substr( $_SERVER['PATH_INFO'], 1 );
32 $title = $wgRequest->getVal( "title" );
35 # Placeholders in case of DB error
36 $wgTitle = Title
::newFromText( wfMsg( "badtitle" ) );
37 $wgArticle = new Article($wgTitle);
39 $action = strtolower( trim( $action ) );
40 if ($wgRequest->getVal( "printable" ) == "yes") {
41 $wgOut->setPrintable();
44 if ( "" == $title && "delete" != $action ) {
45 $wgTitle = Title
::newFromText( wfMsg( "mainpage" ) );
46 } elseif ( $curid = $wgRequest->getInt( 'curid' ) ) {
47 # URLs like this are generated by RC, because rc_title isn't always accurate
48 $wgTitle = Title
::newFromID( $curid );
50 $wgTitle = Title
::newFromURL( $title );
52 wfProfileOut( "main-misc-setup" );
54 # If the user is not logged in, the Namespace:title of the article must be in
55 # the Read array in order for the user to see it. (We have to check here to
56 # catch special pages etc. We check again in Article::view())
57 if ( !is_null( $wgTitle ) && !$wgTitle->userCanRead() ) {
63 if ( $search = $wgRequest->getText( 'search' ) ) {
64 $wgTitle = Title
::makeTitle( NS_SPECIAL
, "Search" );
65 $searchEngine = new SearchEngine( $search );
66 if( $wgRequest->getVal( 'fulltext' ) ||
67 !is_null( $wgRequest->getVal( 'offset' ) ) ||
68 !is_null ($wgRequest->getVal( 'searchx' ) ) ) {
69 $searchEngine->showResults();
71 $searchEngine->goResult();
73 } else if( !$wgTitle or $wgTitle->getDBkey() == "" ) {
74 $wgTitle = Title
::newFromText( wfMsg( "badtitle" ) );
75 $wgOut->errorpage( "badtitle", "badtitletext" );
76 } else if ( $wgTitle->getInterwiki() != "" ) {
77 $url = $wgTitle->getFullURL();
78 # Check for a redirect loop
79 if ( !preg_match( "/^" . preg_quote( $wgServer, "/" ) . "/", $url ) && $wgTitle->isLocal() ) {
80 $wgOut->redirect( $url );
82 $wgTitle = Title
::newFromText( wfMsg( "badtitle" ) );
83 $wgOut->errorpage( "badtitle", "badtitletext" );
85 } else if ( ( $action == "view" ) && $wgTitle->getPrefixedDBKey() != $title &&
86 !count( array_diff( array_keys( $_GET ), array( 'action', 'title' ) ) ) )
88 /* redirect to canonical url, make it a 301 to allow caching */
89 $wgOut->redirect( $wgTitle->getFullURL(), '301');
90 } else if ( Namespace::getSpecial() == $wgTitle->getNamespace() ) {
91 # actions that need to be made when we have a special pages
92 require_once( 'includes/SpecialPage.php' );
93 if ( !$wgAllowSysopQueries ) {SpecialPage
::removePage( 'Asksql' ); }
94 SpecialPage
::executePath( $wgTitle );
96 if ( Namespace::getMedia() == $wgTitle->getNamespace() ) {
97 $wgTitle = Title
::makeTitle( Namespace::getImage(), $wgTitle->getDBkey() );
100 switch( $wgTitle->getNamespace() ) {
102 require_once( "includes/ImagePage.php" );
103 $wgArticle = new ImagePage( $wgTitle );
106 $wgArticle = new Article( $wgTitle );
111 $wgOut->setSquidMaxage( $wgSquidMaxage );
123 case "markpatrolled":
124 $wgArticle->$action();
130 if( !$wgEnableDublinCoreRdf ) {
131 wfHttpError( 403, "Forbidden", wfMsg( "nodublincore" ) );
133 require_once( "includes/Metadata.php" );
134 wfDublinCoreRdf( $wgArticle );
137 case "creativecommons":
138 if( !$wgEnableCreativeCommonsRdf ) {
139 wfHttpError( 403, "Forbidden", wfMsg("nocreativecommons") );
141 require_once( "includes/Metadata.php" );
142 wfCreativeCommonsRdf( $wgArticle );
146 require_once( "includes/Credits.php" );
147 showCreditsPage( $wgArticle );
151 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
152 User
::SetupSession();
154 require_once( "includes/EditPage.php" );
155 $editor = new EditPage( $wgArticle );
159 if ($_SERVER["REQUEST_URI"] == $wgTitle->getInternalURL('action=history')) {
160 $wgOut->setSquidMaxage( $wgSquidMaxage );
162 require_once( "includes/PageHistory.php" );
163 $history = new PageHistory( $wgArticle );
167 require_once( "includes/RawPage.php" );
168 $raw = new RawPage( $wgArticle );
172 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
173 $wgOut->setSquidMaxage( $wgSquidMaxage );
174 $wgTitle->invalidateCache();
178 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
182 # Deferred updates aren't really deferred anymore. It's important to report errors to the
183 # user, and that means doing this before OutputPage::output(). Note that for page saves,
184 # the client will wait until the script exits anyway before following the redirect.
185 foreach ( $wgDeferredUpdateList as $up ) {
189 $wgLoadBalancer->saveMasterPos();
191 # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
192 $wgLoadBalancer->commitAll();
197 $wgLoadBalancer->closeAll();
198 wfDebug( "Request ended normally\n" );