LinksUpdate uses SELECT FOR UPDATE, thus starting a new transaction. So we have to...
[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
13 define( "MEDIAWIKI", true );
14 require_once( "./LocalSettings.php" );
15 require_once( "includes/Setup.php" );
16
17 wfProfileIn( "main-misc-setup" );
18 OutputPage::setEncodings(); # Not really used yet
19
20 # Query string fields
21 $action = $wgRequest->getVal( "action", "view" );
22
23 if( isset( $_SERVER['PATH_INFO'] ) && $wgUsePathInfo ) {
24 $title = substr( $_SERVER['PATH_INFO'], 1 );
25 } else {
26 $title = $wgRequest->getVal( "title" );
27 }
28
29 # Placeholders in case of DB error
30 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
31 $wgArticle = new Article($wgTitle);
32
33 $action = strtolower( trim( $action ) );
34 if ($wgRequest->getVal( "printable" ) == "yes") {
35 $wgOut->setPrintable();
36 }
37
38 if ( "" == $title && "delete" != $action ) {
39 $wgTitle = Title::newFromText( wfMsg( "mainpage" ) );
40 } elseif ( $curid = $wgRequest->getInt( 'curid' ) ) {
41 # URLs like this are generated by RC, because rc_title isn't always accurate
42 $wgTitle = Title::newFromID( $curid );
43 } else {
44 $wgTitle = Title::newFromURL( $title );
45 }
46 wfProfileOut( "main-misc-setup" );
47
48 # If the user is not logged in, the Namespace:title of the article must be in
49 # the Read array in order for the user to see it. (We have to check here to
50 # catch special pages etc. We check again in Article::view())
51 if ( !is_null( $wgTitle ) && !$wgTitle->userCanRead() ) {
52 $wgOut->loginToUse();
53 $wgOut->output();
54 exit;
55 }
56
57 if ( $search = $wgRequest->getText( 'search' ) ) {
58 $wgTitle = Title::makeTitle( NS_SPECIAL, "Search" );
59 if( $wgRequest->getVal( 'fulltext' ) || !is_null( $wgRequest->getVal( 'offset' ) ) ) {
60 wfSearch( $search );
61 } else {
62 wfGo( $search );
63 }
64 } else if( !$wgTitle or $wgTitle->getDBkey() == "" ) {
65 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
66 $wgOut->errorpage( "badtitle", "badtitletext" );
67 } else if ( $wgTitle->getInterwiki() != "" ) {
68 $url = $wgTitle->getFullURL();
69 # Check for a redirect loop
70 if ( !preg_match( "/^" . preg_quote( $wgServer, "/" ) . "/", $url ) && $wgTitle->isLocal() ) {
71 $wgOut->redirect( $url );
72 } else {
73 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
74 $wgOut->errorpage( "badtitle", "badtitletext" );
75 }
76 } else if ( ( $action == "view" ) && $wgTitle->getPrefixedDBKey() != $title ) {
77 /* redirect to canonical url, make it a 301 to allow caching */
78 $wgOut->redirect( $wgTitle->getFullURL(), '301');
79 } else if ( Namespace::getSpecial() == $wgTitle->getNamespace() ) {
80 # actions that need to be made when we have a special pages
81 require_once( 'includes/SpecialPage.php' );
82 if ( !$wgAllowSysopQueries ) {SpecialPage::removePage( 'Asksql' ); }
83 SpecialPage::executePath( $wgTitle );
84 } else {
85 if ( Namespace::getMedia() == $wgTitle->getNamespace() ) {
86 $wgTitle = Title::makeTitle( Namespace::getImage(), $wgTitle->getDBkey() );
87 }
88
89 switch( $wgTitle->getNamespace() ) {
90 case NS_IMAGE:
91 require_once( "includes/ImagePage.php" );
92 $wgArticle = new ImagePage( $wgTitle );
93 break;
94 default:
95 $wgArticle = new Article( $wgTitle );
96 }
97
98 wfQuery("BEGIN", DB_WRITE);
99 switch( $action ) {
100 case "view":
101 $wgOut->setSquidMaxage( $wgSquidMaxage );
102 $wgArticle->view();
103 break;
104 case "watch":
105 case "unwatch":
106 case "delete":
107 case "revert":
108 case "rollback":
109 case "protect":
110 case "unprotect":
111 case "info":
112 $wgArticle->$action();
113 break;
114 case "print":
115 $wgArticle->view();
116 break;
117 case "dublincore":
118 if( !$wgEnableDublinCoreRdf ) {
119 wfHttpError( 403, "Forbidden", wfMsg( "nodublincore" ) );
120 } else {
121 require_once( "includes/Metadata.php" );
122 wfDublinCoreRdf( $wgArticle );
123 }
124 break;
125 case "creativecommons":
126 if( !$wgEnableCreativeCommonsRdf ) {
127 wfHttpError( 403, "Forbidden", wfMsg("nocreativecommons") );
128 } else {
129 require_once( "includes/Metadata.php" );
130 wfCreativeCommonsRdf( $wgArticle );
131 }
132 break;
133 case "credits":
134 require_once( "includes/Credits.php" );
135 showCreditsPage( $wgArticle );
136 break;
137 case "edit":
138 case "submit":
139 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
140 User::SetupSession();
141 }
142 require_once( "includes/EditPage.php" );
143 $editor = new EditPage( $wgArticle );
144 $editor->$action();
145 break;
146 case "history":
147 if ($_SERVER["REQUEST_URI"] == $wgTitle->getInternalURL('action=history')) {
148 $wgOut->setSquidMaxage( $wgSquidMaxage );
149 }
150 require_once( "includes/PageHistory.php" );
151 $history = new PageHistory( $wgArticle );
152 $history->history();
153 break;
154 case "raw":
155 require_once( "includes/RawPage.php" );
156 $raw = new RawPage( $wgArticle );
157 $raw->view();
158 break;
159 case "purge":
160 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
161 $wgOut->setSquidMaxage( $wgSquidMaxage );
162 $wgTitle->invalidateCache();
163 $wgArticle->view();
164 break;
165 default:
166 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
167 }
168 wfQuery("COMMIT", DB_WRITE);
169 }
170
171 $wgOut->output();
172
173 foreach ( $wgDeferredUpdateList as $up ) {
174 wfQuery("BEGIN", DB_WRITE);
175 $up->doUpdate();
176 wfQuery("COMMIT", DB_WRITE);
177 }
178 logProfilingData();
179 wfDebug( "Request ended normally\n" );
180 ?>