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 require_once( 'SearchEngine.php' );
65 $wgTitle = Title
::makeTitle( NS_SPECIAL
, "Search" );
66 $searchEngine = new SearchEngine( $search );
67 if( $wgRequest->getVal( 'fulltext' ) ||
68 !is_null( $wgRequest->getVal( 'offset' ) ) ||
69 !is_null ($wgRequest->getVal( 'searchx' ) ) ) {
70 $searchEngine->showResults();
72 $searchEngine->goResult();
74 } else if( !$wgTitle or $wgTitle->getDBkey() == "" ) {
75 $wgTitle = Title
::newFromText( wfMsg( "badtitle" ) );
76 $wgOut->errorpage( "badtitle", "badtitletext" );
77 } else if ( $wgTitle->getInterwiki() != "" ) {
78 $url = $wgTitle->getFullURL();
79 # Check for a redirect loop
80 if ( !preg_match( "/^" . preg_quote( $wgServer, "/" ) . "/", $url ) && $wgTitle->isLocal() ) {
81 $wgOut->redirect( $url );
83 $wgTitle = Title
::newFromText( wfMsg( "badtitle" ) );
84 $wgOut->errorpage( "badtitle", "badtitletext" );
86 } else if ( ( $action == "view" ) && $wgTitle->getPrefixedDBKey() != $title &&
87 !count( array_diff( array_keys( $_GET ), array( 'action', 'title' ) ) ) )
89 /* redirect to canonical url, make it a 301 to allow caching */
90 $wgOut->redirect( $wgTitle->getFullURL(), '301');
91 } else if ( Namespace::getSpecial() == $wgTitle->getNamespace() ) {
92 # actions that need to be made when we have a special pages
93 require_once( 'includes/SpecialPage.php' );
94 if ( !$wgAllowSysopQueries ) {SpecialPage
::removePage( 'Asksql' ); }
95 SpecialPage
::executePath( $wgTitle );
97 if ( Namespace::getMedia() == $wgTitle->getNamespace() ) {
98 $wgTitle = Title
::makeTitle( Namespace::getImage(), $wgTitle->getDBkey() );
101 switch( $wgTitle->getNamespace() ) {
103 require_once( "includes/ImagePage.php" );
104 $wgArticle = new ImagePage( $wgTitle );
107 $wgArticle = new Article( $wgTitle );
112 $wgOut->setSquidMaxage( $wgSquidMaxage );
124 case "markpatrolled":
125 $wgArticle->$action();
131 if( !$wgEnableDublinCoreRdf ) {
132 wfHttpError( 403, "Forbidden", wfMsg( "nodublincore" ) );
134 require_once( "includes/Metadata.php" );
135 wfDublinCoreRdf( $wgArticle );
138 case "creativecommons":
139 if( !$wgEnableCreativeCommonsRdf ) {
140 wfHttpError( 403, "Forbidden", wfMsg("nocreativecommons") );
142 require_once( "includes/Metadata.php" );
143 wfCreativeCommonsRdf( $wgArticle );
147 require_once( "includes/Credits.php" );
148 showCreditsPage( $wgArticle );
152 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
153 User
::SetupSession();
155 require_once( "includes/EditPage.php" );
156 $editor = new EditPage( $wgArticle );
160 if ($_SERVER["REQUEST_URI"] == $wgTitle->getInternalURL('action=history')) {
161 $wgOut->setSquidMaxage( $wgSquidMaxage );
163 require_once( "includes/PageHistory.php" );
164 $history = new PageHistory( $wgArticle );
168 require_once( "includes/RawPage.php" );
169 $raw = new RawPage( $wgArticle );
173 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
174 $wgOut->setSquidMaxage( $wgSquidMaxage );
175 $wgTitle->invalidateCache();
179 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
183 # Deferred updates aren't really deferred anymore. It's important to report errors to the
184 # user, and that means doing this before OutputPage::output(). Note that for page saves,
185 # the client will wait until the script exits anyway before following the redirect.
186 foreach ( $wgDeferredUpdateList as $up ) {
190 $wgLoadBalancer->saveMasterPos();
192 # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
193 $wgLoadBalancer->commitAll();
198 $wgLoadBalancer->closeAll();
199 wfDebug( "Request ended normally\n" );