Add experimental MathML output option for math (only works with some
[lhc/web/wiklou.git] / index.php
1 <?php
2
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 include_once( "./LocalSettings.php" );
13
14 if( $wgSitename == "MediaWiki" ) {
15 die( "You must set the site name in \$wgSitename before installation.\n\n" );
16 }
17
18 # PATH_SEPARATOR avaialble only from 4.3.0
19 $sep = (DIRECTORY_SEPARATOR == "\\") ? ";" : ":";
20 ini_set( "include_path", $IP . $sep . ini_get( "include_path" ) );
21
22 include_once( "Setup.php" );
23
24 wfProfileIn( "main-misc-setup" );
25 OutputPage::setEncodings(); # Not really used yet
26
27 # Query string fields
28 $action = $wgRequest->getVal( "action", "view" );
29
30 if( isset( $_SERVER['PATH_INFO'] ) && $wgUsePathInfo ) {
31 $title = substr( $_SERVER['PATH_INFO'], 1 );
32 } else {
33 $title = $wgRequest->getVal( "title" );
34 }
35
36 # Placeholders in case of DB error
37 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
38 $wgArticle = new Article($wgTitle);
39
40 $action = strtolower( trim( $action ) );
41 if ( "" == $action ) { $action = "view"; }
42 if ($wgRequest->getVal( "printable" ) == "yes") {
43 $wgOut->setPrintable();
44 }
45
46 if ( "" == $title && "delete" != $action ) {
47 $wgTitle = Title::newFromText( wfMsg( "mainpage" ) );
48 } elseif ( $curid = $wgRequest->getInt( 'curid' ) ) {
49 # URLs like this are generated by RC, because rc_title isn't always accurate
50 $wgTitle = Title::newFromID( $curid );
51 } else {
52 $wgTitle = Title::newFromURL( $title );
53 }
54 wfProfileOut( "main-misc-setup" );
55
56 # If the user is not logged in, the Namespace:title of the article must be in the Read array in
57 # order for the user to see it.
58 if ( !$wgUser->getID() && is_array( $wgWhitelistRead ) && $wgTitle) {
59 if ( !in_array( $wgLang->getNsText( $wgTitle->getNamespace() ) . ":" . $wgTitle->getDBkey(), $wgWhitelistRead ) ) {
60 $wgOut->loginToUse();
61 $wgOut->output();
62 exit;
63 }
64 }
65
66 if ( $search = $wgRequest->getText( 'search' ) ) {
67 if( $wgRequest->getVal( 'fulltext' ) ) {
68 wfSearch( $search );
69 } else {
70 wfGo( $search );
71 }
72 } else if( !$wgTitle or $wgTitle->getInterwiki() != "" or $wgTitle->getDBkey() == "" ) {
73 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
74 $wgOut->errorpage( "badtitle", "badtitletext" );
75 } else if ( ( $action == "view" ) && $wgTitle->getPrefixedDBKey() != $title ) {
76 /* redirect to canonical url, make it a 301 to allow caching */
77 $wgOut->redirect( $wgTitle->getFullURL(), '301');
78 } else if ( Namespace::getSpecial() == $wgTitle->getNamespace() ) {
79 wfSpecialPage();
80 } else {
81 if ( Namespace::getMedia() == $wgTitle->getNamespace() ) {
82 $wgTitle = Title::makeTitle( Namespace::getImage(), $wgTitle->getDBkey() );
83 }
84
85 switch( $wgTitle->getNamespace() ) {
86 case NS_IMAGE:
87 include_once( "ImagePage.php" );
88 $wgArticle = new ImagePage( $wgTitle );
89 break;
90 default:
91 $wgArticle = new Article( $wgTitle );
92 }
93
94 wfQuery("BEGIN", DB_WRITE);
95 switch( $action ) {
96 case "view":
97 $wgOut->setSquidMaxage( $wgSquidMaxage );
98 $wgArticle->view();
99 break;
100 case "watch":
101 case "unwatch":
102 case "delete":
103 case "revert":
104 case "rollback":
105 case "protect":
106 case "unprotect":
107 $wgArticle->$action();
108 break;
109 case "print":
110 $wgArticle->view();
111 break;
112 case "dublincore":
113 if( !$wgEnableDublinCoreRdf ) {
114 wfHttpError( 403, "Forbidden", wfMsg( "nodublincore" ) );
115 } else {
116 include_once( "Metadata.php" );
117 wfDublinCoreRdf( $wgArticle );
118 }
119 break;
120 case "creativecommons":
121 if( !$wgEnableCreativeCommonsRdf ) {
122 wfHttpError( 403, "Forbidden", wfMsg("nocreativecommons") );
123 } else {
124 include_once( "Metadata.php" );
125 wfCreativeCommonsRdf( $wgArticle );
126 }
127 break;
128 case "edit":
129 case "submit":
130 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
131 User::SetupSession();
132 }
133 include_once( "EditPage.php" );
134 $editor = new EditPage( $wgArticle );
135 $editor->$action();
136 break;
137 case "history":
138 if ($_SERVER["REQUEST_URI"] == $wgTitle->getInternalURL('action=history')) {
139 $wgOut->setSquidMaxage( $wgSquidMaxage );
140 }
141 include_once( "PageHistory.php" );
142 $history = new PageHistory( $wgArticle );
143 $history->history();
144 break;
145 case "purge":
146 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
147 $wgOut->setSquidMaxage( $wgSquidMaxage );
148 $wgArticle->view();
149 break;
150 default:
151 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
152 }
153 wfQuery("COMMIT", DB_WRITE);
154 }
155
156 $wgOut->output();
157
158 foreach ( $wgDeferredUpdateList as $up ) { $up->doUpdate(); }
159 logProfilingData();
160 wfDebug( "Request ended normally\n" );
161 ?>