clear bodytext on OutputPage after link parsing
[lhc/web/wiklou.git] / index.php
1 <?php
2 #apd_set_pprof_trace();
3 # Main wiki script; see design.doc
4 #
5 $wgRequestTime = microtime();
6
7 unset( $IP );
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!" );
11 }
12
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 );
18
19 require_once( "./includes/Defines.php" );
20 require_once( "./LocalSettings.php" );
21 require_once( "includes/Setup.php" );
22
23 wfProfileIn( "main-misc-setup" );
24 OutputPage::setEncodings(); # Not really used yet
25
26 # Query string fields
27 $action = $wgRequest->getVal( "action", "view" );
28 $title = $wgRequest->getVal( "title" );
29
30 # Placeholders in case of DB error
31 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
32 $wgArticle = new Article($wgTitle);
33
34 $action = strtolower( trim( $action ) );
35 if ($wgRequest->getVal( "printable" ) == "yes") {
36 $wgOut->setPrintable();
37 }
38
39 if ( "" == $title && "delete" != $action ) {
40 $wgTitle = Title::newFromText( wfMsg( "mainpage" ) );
41 } elseif ( $curid = $wgRequest->getInt( 'curid' ) ) {
42 # URLs like this are generated by RC, because rc_title isn't always accurate
43 $wgTitle = Title::newFromID( $curid );
44 } else {
45 $wgTitle = Title::newFromURL( $title );
46 }
47 wfProfileOut( "main-misc-setup" );
48
49 # If the user is not logged in, the Namespace:title of the article must be in
50 # the Read array in order for the user to see it. (We have to check here to
51 # catch special pages etc. We check again in Article::view())
52 if ( !is_null( $wgTitle ) && !$wgTitle->userCanRead() ) {
53 $wgOut->loginToUse();
54 $wgOut->output();
55 exit;
56 }
57
58 wfProfileIn( "main-action" );
59 $search = $wgRequest->getText( 'search' );
60 if( !is_null( $search ) && $search !== '' ) {
61 require_once( 'SearchEngine.php' );
62 $wgTitle = Title::makeTitle( NS_SPECIAL, "Search" );
63 $searchEngine = new SearchEngine( $search );
64 if( $wgRequest->getVal( 'fulltext' ) ||
65 !is_null( $wgRequest->getVal( 'offset' ) ) ||
66 !is_null ($wgRequest->getVal( 'searchx' ) ) ) {
67 $searchEngine->showResults();
68 } else {
69 $searchEngine->goResult();
70 }
71 } else if( !$wgTitle or $wgTitle->getDBkey() == "" ) {
72 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
73 $wgOut->errorpage( "badtitle", "badtitletext" );
74 } else if ( $wgTitle->getInterwiki() != "" ) {
75 $url = $wgTitle->getFullURL();
76 # Check for a redirect loop
77 if ( !preg_match( "/^" . preg_quote( $wgServer, "/" ) . "/", $url ) && $wgTitle->isLocal() ) {
78 $wgOut->redirect( $url );
79 } else {
80 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
81 $wgOut->errorpage( "badtitle", "badtitletext" );
82 }
83 } else if ( ( $action == "view" ) &&
84 (!isset( $_GET['title'] ) || $wgTitle->getPrefixedDBKey() != $_GET['title'] ) &&
85 !count( array_diff( array_keys( $_GET ), array( 'action', 'title' ) ) ) )
86 {
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 );
94 } else {
95 if ( Namespace::getMedia() == $wgTitle->getNamespace() ) {
96 $wgTitle = Title::makeTitle( NS_IMAGE, $wgTitle->getDBkey() );
97 }
98
99 switch( $wgTitle->getNamespace() ) {
100 case NS_IMAGE:
101 require_once( "includes/ImagePage.php" );
102 $wgArticle = new ImagePage( $wgTitle );
103 break;
104 case NS_CATEGORY:
105 if ( $wgUseCategoryMagic ) {
106 require_once( "includes/CategoryPage.php" );
107 $wgArticle = new CategoryPage( $wgTitle );
108 break;
109 }
110 # NO break if wgUseCategoryMagic is false, drop through to next (default).
111 # Don't insert other cases between NS_CATEGORY and default.
112 default:
113 $wgArticle = new Article( $wgTitle );
114 }
115
116 switch( $action ) {
117 case "view":
118 $wgOut->setSquidMaxage( $wgSquidMaxage );
119 $wgArticle->view();
120 break;
121 case "watch":
122 case "unwatch":
123 case "delete":
124 case "revert":
125 case "rollback":
126 case "protect":
127 case "unprotect":
128 case "validate":
129 case "info":
130 case "markpatrolled":
131 $wgArticle->$action();
132 break;
133 case "print":
134 $wgArticle->view();
135 break;
136 case "dublincore":
137 if( !$wgEnableDublinCoreRdf ) {
138 wfHttpError( 403, "Forbidden", wfMsg( "nodublincore" ) );
139 } else {
140 require_once( "includes/Metadata.php" );
141 wfDublinCoreRdf( $wgArticle );
142 }
143 break;
144 case "creativecommons":
145 if( !$wgEnableCreativeCommonsRdf ) {
146 wfHttpError( 403, "Forbidden", wfMsg("nocreativecommons") );
147 } else {
148 require_once( "includes/Metadata.php" );
149 wfCreativeCommonsRdf( $wgArticle );
150 }
151 break;
152 case "credits":
153 require_once( "includes/Credits.php" );
154 showCreditsPage( $wgArticle );
155 break;
156 case "edit":
157 case "submit":
158 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
159 User::SetupSession();
160 }
161 require_once( "includes/EditPage.php" );
162 $editor = new EditPage( $wgArticle );
163 $editor->submit();
164 break;
165 case "history":
166 if ($_SERVER["REQUEST_URI"] == $wgTitle->getInternalURL('action=history')) {
167 $wgOut->setSquidMaxage( $wgSquidMaxage );
168 }
169 require_once( "includes/PageHistory.php" );
170 $history = new PageHistory( $wgArticle );
171 $history->history();
172 break;
173 case "raw":
174 require_once( "includes/RawPage.php" );
175 $raw = new RawPage( $wgArticle );
176 $raw->view();
177 break;
178 case "purge":
179 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
180 $wgOut->setSquidMaxage( $wgSquidMaxage );
181 $wgTitle->invalidateCache();
182 $wgArticle->view();
183 break;
184 default:
185 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
186 }
187 }
188 wfProfileOut( "main-action" );
189
190 # Deferred updates aren't really deferred anymore. It's important to report errors to the
191 # user, and that means doing this before OutputPage::output(). Note that for page saves,
192 # the client will wait until the script exits anyway before following the redirect.
193 wfProfileIn( "main-updates" );
194 foreach ( $wgDeferredUpdateList as $up ) {
195 $up->doUpdate();
196 }
197 wfProfileOut( "main-updates" );
198
199 wfProfileIn( "main-cleanup" );
200 $wgLoadBalancer->saveMasterPos();
201
202 # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
203 $wgLoadBalancer->commitAll();
204
205 $wgOut->output();
206 wfProfileOut( "main-cleanup" );
207
208 logProfilingData();
209 $wgLoadBalancer->closeAll();
210 wfDebug( "Request ended normally\n" );
211 ?>