]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - index.php
MediaWiki 1.5.8 (initial commit)
[autoinstalls/mediawiki.git] / index.php
1 <?php
2 /**
3  * Main wiki script; see docs/design.txt
4  * @package MediaWiki
5  */
6
7 $wgRequestTime = microtime();
8
9 unset( $IP );
10 @ini_set( 'allow_url_fopen', 0 ); # For security...
11
12 # Valid web server entry point, enable includes.
13 # Please don't move this line to includes/Defines.php. This line essentially defines
14 # a valid entry point. If you put it in includes/Defines.php, then any script that includes
15 # it becomes an entry point, thereby defeating its purpose.
16 define( 'MEDIAWIKI', true );
17 require_once( './includes/Defines.php' );
18
19 if( !file_exists( 'LocalSettings.php' ) ) {
20         $IP = "." ;
21         require_once( 'includes/DefaultSettings.php' ); # used for printing the version
22 ?>
23 <!DOCTYPE html PUBLIC "-//W3C/DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
24 <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
25         <head>
26                 <title>MediaWiki <?php echo $wgVersion ?></title>
27                 <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
28
29                 <style type='text/css' media='screen, projection'>
30                         html, body {
31                                 color: #000;
32                                 background-color: #fff;
33                                 font-family: serif;
34                                 text-align:center;
35                         }
36
37                         h1 {
38                                 font-size: 150%;
39                         }
40                 </style>
41         </head>
42         <body>
43                 <img src='skins/common/images/mediawiki.png' alt='The MediaWiki logo' />
44
45                 <h1>MediaWiki <?php echo $wgVersion ?></h1>
46                 <div class='error'>
47                 <?php
48                 if ( file_exists( 'config/LocalSettings.php' ) ) {
49                         echo( "To complete the installation, move <tt>config/LocalSettings.php</tt> to the parent directory." );
50                 } else {
51                         echo( "You'll have to <a href='config/index.php' title='setup'>set the wiki up</a> first!" );
52                 }
53                 ?>
54
55                 </div>
56         </body>
57 </html>
58 <?php
59         die();
60 }
61
62 require_once( './LocalSettings.php' );
63 require_once( 'includes/Setup.php' );
64
65 wfProfileIn( 'main-misc-setup' );
66 OutputPage::setEncodings(); # Not really used yet
67
68 # Query string fields
69 $action = $wgRequest->getVal( 'action', 'view' );
70 $title = $wgRequest->getVal( 'title' );
71
72 if ($wgRequest->getVal( 'printable' ) == 'yes') {
73         $wgOut->setPrintable();
74 }
75
76 if ( '' == $title && 'delete' != $action ) {
77         $wgTitle = Title::newFromText( wfMsgForContent( 'mainpage' ) );
78 } elseif ( $curid = $wgRequest->getInt( 'curid' ) ) {
79         # URLs like this are generated by RC, because rc_title isn't always accurate
80         $wgTitle = Title::newFromID( $curid );
81 } else {
82         $wgTitle = Title::newFromURL( $title );
83         /* check variant links so that interwiki links don't have to worry about
84            the possible different language variants
85         */
86         if( !is_null($wgTitle) && $wgTitle->getArticleID() == 0 )
87                 $wgContLang->findVariantLink( $title, $wgTitle );
88
89 }
90 wfProfileOut( 'main-misc-setup' );
91
92 # Debug statement for user levels
93 // print_r($wgUser);
94
95 $search = $wgRequest->getText( 'search' );
96 if( !is_null( $search ) && $search !== '' ) {
97         // Compatibility with old search URLs which didn't use Special:Search
98         // Do this above the read whitelist check for security...
99         $wgTitle = Title::makeTitle( NS_SPECIAL, 'Search' );
100 }
101
102 # If the user is not logged in, the Namespace:title of the article must be in
103 # the Read array in order for the user to see it. (We have to check here to
104 # catch special pages etc. We check again in Article::view())
105 if ( !is_null( $wgTitle ) && !$wgTitle->userCanRead() ) {
106         $wgOut->loginToUse();
107         $wgOut->output();
108         exit;
109 }
110
111 wfProfileIn( 'main-action' );
112
113 if( !$wgDisableInternalSearch && !is_null( $search ) && $search !== '' ) {
114         require_once( 'includes/SpecialSearch.php' );
115         $wgTitle = Title::makeTitle( NS_SPECIAL, 'Search' );
116         wfSpecialSearch();
117 } else if( !$wgTitle or $wgTitle->getDBkey() == '' ) {
118         $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) );
119         $wgOut->errorpage( 'badtitle', 'badtitletext' );
120 } else if ( $wgTitle->getInterwiki() != '' ) {
121         if( $rdfrom = $wgRequest->getVal( 'rdfrom' ) ) {
122                 $url = $wgTitle->getFullURL( 'rdfrom=' . urlencode( $rdfrom ) );
123         } else {
124                 $url = $wgTitle->getFullURL();
125         }
126         # Check for a redirect loop
127         if ( !preg_match( '/^' . preg_quote( $wgServer, '/' ) . '/', $url ) && $wgTitle->isLocal() ) {
128                 $wgOut->redirect( $url );
129         } else {
130                 $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) );
131                 $wgOut->errorpage( 'badtitle', 'badtitletext' );
132         }
133 } else if ( ( $action == 'view' ) &&
134         (!isset( $_GET['title'] ) || $wgTitle->getPrefixedDBKey() != $_GET['title'] ) &&
135         !count( array_diff( array_keys( $_GET ), array( 'action', 'title' ) ) ) )
136 {
137         /* redirect to canonical url, make it a 301 to allow caching */
138         $wgOut->setSquidMaxage( 1200 );
139         $wgOut->redirect( $wgTitle->getFullURL(), '301');
140 } else if ( NS_SPECIAL == $wgTitle->getNamespace() ) {
141         # actions that need to be made when we have a special pages
142         SpecialPage::executePath( $wgTitle );
143 } else {
144         if ( NS_MEDIA == $wgTitle->getNamespace() ) {
145                 $wgTitle = Title::makeTitle( NS_IMAGE, $wgTitle->getDBkey() );
146         }
147
148         $ns = $wgTitle->getNamespace();
149         if ( $ns == NS_IMAGE ) {
150                 require_once( 'includes/ImagePage.php' );
151                 $wgArticle = new ImagePage( $wgTitle );
152         } elseif ( $wgUseCategoryMagic && $ns == NS_CATEGORY ) {
153                 require_once( 'includes/CategoryPage.php' );
154                 $wgArticle = new CategoryPage( $wgTitle );
155         } else {
156                 $wgArticle = new Article( $wgTitle );
157         }
158
159         if ( in_array( $action, $wgDisabledActions ) ) {
160                 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
161         } else {
162                 switch( $action ) {
163                         case 'view':
164                                 $wgOut->setSquidMaxage( $wgSquidMaxage );
165                                 $wgArticle->view();
166                                 break;
167                         case 'watch':
168                         case 'unwatch':
169                         case 'delete':
170                         case 'revert':
171                         case 'rollback':
172                         case 'protect':
173                         case 'unprotect':
174                         case 'info':
175                         case 'markpatrolled':
176                         case 'validate':
177                         case 'render':
178                         case 'deletetrackback':
179                                 $wgArticle->$action();
180                                 break;
181                         case 'print':
182                                 $wgArticle->view();
183                                 break;
184                         case 'dublincore':
185                                 if( !$wgEnableDublinCoreRdf ) {
186                                         wfHttpError( 403, 'Forbidden', wfMsg( 'nodublincore' ) );
187                                 } else {
188                                         require_once( 'includes/Metadata.php' );
189                                         wfDublinCoreRdf( $wgArticle );
190                                 }
191                                 break;
192                         case 'creativecommons':
193                                 if( !$wgEnableCreativeCommonsRdf ) {
194                                         wfHttpError( 403, 'Forbidden', wfMsg('nocreativecommons') );
195                                 } else {
196                                         require_once( 'includes/Metadata.php' );
197                                         wfCreativeCommonsRdf( $wgArticle );
198                                 }
199                                 break;
200                         case 'credits':
201                                 require_once( 'includes/Credits.php' );
202                                 showCreditsPage( $wgArticle );
203                                 break;
204                         case 'submit':
205                                 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
206                                         # Send a cookie so anons get talk message notifications
207                                         User::SetupSession();
208                                 }
209                                 # Continue...
210                         case 'edit':
211                                 $internal = $wgRequest->getVal( 'internaledit' );
212                                 $external = $wgRequest->getVal( 'externaledit' );
213                                 $section = $wgRequest->getVal( 'section' );
214                                 $oldid = $wgRequest->getVal( 'oldid' );
215                                 if(!$wgUseExternalEditor || $action=='submit' || $internal ||
216                                    $section || $oldid || (!$wgUser->getOption('externaleditor') && !$external)) {
217                                         require_once( 'includes/EditPage.php' );
218                                         $editor = new EditPage( $wgArticle );
219                                         $editor->submit();
220                                 } elseif($wgUseExternalEditor && ($external || $wgUser->getOption('externaleditor'))) {
221                                         require_once( 'includes/ExternalEdit.php' );
222                                         $mode = $wgRequest->getVal( 'mode' );
223                                         $extedit = new ExternalEdit( $wgArticle, $mode );
224                                         $extedit->edit();
225                                 }
226                                 break;
227                         case 'history':
228                                 if ($_SERVER['REQUEST_URI'] == $wgTitle->getInternalURL('action=history')) {
229                                         $wgOut->setSquidMaxage( $wgSquidMaxage );
230                                 }
231                                 require_once( 'includes/PageHistory.php' );
232                                 $history = new PageHistory( $wgArticle );
233                                 $history->history();
234                                 break;
235                         case 'raw':
236                                 require_once( 'includes/RawPage.php' );
237                                 $raw = new RawPage( $wgArticle );
238                                 $raw->view();
239                                 break;
240                         case 'purge':
241                                 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
242                                 $wgOut->setSquidMaxage( $wgSquidMaxage );
243                                 $wgTitle->invalidateCache();
244                                 $wgArticle->view();
245                                 break;
246                         default:
247                                 if (wfRunHooks('UnknownAction', array($action, $wgArticle))) {
248                                         $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
249                                 }
250                 }
251         }
252 }
253 wfProfileOut( 'main-action' );
254
255 # Deferred updates aren't really deferred anymore. It's important to report errors to the
256 # user, and that means doing this before OutputPage::output(). Note that for page saves,
257 # the client will wait until the script exits anyway before following the redirect.
258 wfProfileIn( 'main-updates' );
259 foreach ( $wgDeferredUpdateList as $up ) {
260         $up->doUpdate();
261 }
262 wfProfileOut( 'main-updates' );
263
264 wfProfileIn( 'main-cleanup' );
265 $wgLoadBalancer->saveMasterPos();
266
267 # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
268 $wgLoadBalancer->commitAll();
269
270 $wgOut->output();
271
272 foreach ( $wgPostCommitUpdateList as $up ) {
273         $up->doUpdate();
274 }
275
276 wfProfileOut( 'main-cleanup' );
277
278 logProfilingData();
279 $wgLoadBalancer->closeAll();
280 wfDebug( "Request ended normally\n" );
281 ?>