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 require_once( 'includes/normal/UtfNormal.php' );
33 $title = UtfNormal
::toNFC( $title );
36 $title = $wgRequest->getVal( "title" );
39 # Placeholders in case of DB error
40 $wgTitle = Title
::newFromText( wfMsg( "badtitle" ) );
41 $wgArticle = new Article($wgTitle);
43 $action = strtolower( trim( $action ) );
44 if ($wgRequest->getVal( "printable" ) == "yes") {
45 $wgOut->setPrintable();
48 if ( "" == $title && "delete" != $action ) {
49 $wgTitle = Title
::newFromText( wfMsg( "mainpage" ) );
50 } elseif ( $curid = $wgRequest->getInt( 'curid' ) ) {
51 # URLs like this are generated by RC, because rc_title isn't always accurate
52 $wgTitle = Title
::newFromID( $curid );
54 $wgTitle = Title
::newFromURL( $title );
56 wfProfileOut( "main-misc-setup" );
58 # If the user is not logged in, the Namespace:title of the article must be in
59 # the Read array in order for the user to see it. (We have to check here to
60 # catch special pages etc. We check again in Article::view())
61 if ( !is_null( $wgTitle ) && !$wgTitle->userCanRead() ) {
67 wfProfileIn( "main-action" );
68 $search = $wgRequest->getText( 'search' );
69 if( !is_null( $search ) && $search !== '' ) {
70 require_once( 'SearchEngine.php' );
71 $wgTitle = Title
::makeTitle( NS_SPECIAL
, "Search" );
72 $searchEngine = new SearchEngine( $search );
73 if( $wgRequest->getVal( 'fulltext' ) ||
74 !is_null( $wgRequest->getVal( 'offset' ) ) ||
75 !is_null ($wgRequest->getVal( 'searchx' ) ) ) {
76 $searchEngine->showResults();
78 $searchEngine->goResult();
80 } else if( !$wgTitle or $wgTitle->getDBkey() == "" ) {
81 $wgTitle = Title
::newFromText( wfMsg( "badtitle" ) );
82 $wgOut->errorpage( "badtitle", "badtitletext" );
83 } else if ( $wgTitle->getInterwiki() != "" ) {
84 $url = $wgTitle->getFullURL();
85 # Check for a redirect loop
86 if ( !preg_match( "/^" . preg_quote( $wgServer, "/" ) . "/", $url ) && $wgTitle->isLocal() ) {
87 $wgOut->redirect( $url );
89 $wgTitle = Title
::newFromText( wfMsg( "badtitle" ) );
90 $wgOut->errorpage( "badtitle", "badtitletext" );
92 } else if ( ( $action == "view" ) && $wgTitle->getPrefixedDBKey() != $title &&
93 !count( array_diff( array_keys( $_GET ), array( 'action', 'title' ) ) ) )
95 /* redirect to canonical url, make it a 301 to allow caching */
96 $wgOut->redirect( $wgTitle->getFullURL(), '301');
97 } else if ( Namespace::getSpecial() == $wgTitle->getNamespace() ) {
98 # actions that need to be made when we have a special pages
99 require_once( 'includes/SpecialPage.php' );
100 if ( !$wgAllowSysopQueries ) {SpecialPage
::removePage( 'Asksql' ); }
101 SpecialPage
::executePath( $wgTitle );
103 if ( Namespace::getMedia() == $wgTitle->getNamespace() ) {
104 $wgTitle = Title
::makeTitle( NS_IMAGE
, $wgTitle->getDBkey() );
107 switch( $wgTitle->getNamespace() ) {
109 require_once( "includes/ImagePage.php" );
110 $wgArticle = new ImagePage( $wgTitle );
113 if ( $wgUseCategoryMagic ) {
114 require_once( "includes/CategoryPage.php" );
115 $wgArticle = new CategoryPage( $wgTitle );
118 # NO break if wgUseCategoryMagic is false, drop through to next (default).
119 # Don't insert other cases between NS_CATEGORY and default.
121 $wgArticle = new Article( $wgTitle );
126 $wgOut->setSquidMaxage( $wgSquidMaxage );
138 case "markpatrolled":
139 $wgArticle->$action();
145 if( !$wgEnableDublinCoreRdf ) {
146 wfHttpError( 403, "Forbidden", wfMsg( "nodublincore" ) );
148 require_once( "includes/Metadata.php" );
149 wfDublinCoreRdf( $wgArticle );
152 case "creativecommons":
153 if( !$wgEnableCreativeCommonsRdf ) {
154 wfHttpError( 403, "Forbidden", wfMsg("nocreativecommons") );
156 require_once( "includes/Metadata.php" );
157 wfCreativeCommonsRdf( $wgArticle );
161 require_once( "includes/Credits.php" );
162 showCreditsPage( $wgArticle );
166 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
167 User
::SetupSession();
169 require_once( "includes/EditPage.php" );
170 $editor = new EditPage( $wgArticle );
174 if ($_SERVER["REQUEST_URI"] == $wgTitle->getInternalURL('action=history')) {
175 $wgOut->setSquidMaxage( $wgSquidMaxage );
177 require_once( "includes/PageHistory.php" );
178 $history = new PageHistory( $wgArticle );
182 require_once( "includes/RawPage.php" );
183 $raw = new RawPage( $wgArticle );
187 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
188 $wgOut->setSquidMaxage( $wgSquidMaxage );
189 $wgTitle->invalidateCache();
193 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
196 wfProfileOut( "main-action" );
198 # Deferred updates aren't really deferred anymore. It's important to report errors to the
199 # user, and that means doing this before OutputPage::output(). Note that for page saves,
200 # the client will wait until the script exits anyway before following the redirect.
201 wfProfileIn( "main-updates" );
202 foreach ( $wgDeferredUpdateList as $up ) {
205 wfProfileOut( "main-updates" );
207 wfProfileIn( "main-cleanup" );
208 $wgLoadBalancer->saveMasterPos();
210 # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
211 $wgLoadBalancer->commitAll();
214 wfProfileOut( "main-cleanup" );
217 $wgLoadBalancer->closeAll();
218 wfDebug( "Request ended normally\n" );