clear footer and small margin-top for fieldsets (especially for CologeBlue)
[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 ( !$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' ) ) {
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 SpecialPage::executePath( $wgTitle );
81 } else {
82 if ( Namespace::getMedia() == $wgTitle->getNamespace() ) {
83 $wgTitle = Title::makeTitle( Namespace::getImage(), $wgTitle->getDBkey() );
84 }
85
86 switch( $wgTitle->getNamespace() ) {
87 case NS_IMAGE:
88 require_once( "includes/ImagePage.php" );
89 $wgArticle = new ImagePage( $wgTitle );
90 break;
91 default:
92 $wgArticle = new Article( $wgTitle );
93 }
94
95 wfQuery("BEGIN", DB_WRITE);
96 switch( $action ) {
97 case "view":
98 $wgOut->setSquidMaxage( $wgSquidMaxage );
99 $wgArticle->view();
100 break;
101 case "watch":
102 case "unwatch":
103 case "delete":
104 case "revert":
105 case "rollback":
106 case "protect":
107 case "unprotect":
108 $wgArticle->$action();
109 break;
110 case "print":
111 $wgArticle->view();
112 break;
113 case "dublincore":
114 if( !$wgEnableDublinCoreRdf ) {
115 wfHttpError( 403, "Forbidden", wfMsg( "nodublincore" ) );
116 } else {
117 require_once( "includes/Metadata.php" );
118 wfDublinCoreRdf( $wgArticle );
119 }
120 break;
121 case "creativecommons":
122 if( !$wgEnableCreativeCommonsRdf ) {
123 wfHttpError( 403, "Forbidden", wfMsg("nocreativecommons") );
124 } else {
125 require_once( "includes/Metadata.php" );
126 wfCreativeCommonsRdf( $wgArticle );
127 }
128 break;
129 case "edit":
130 case "submit":
131 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
132 User::SetupSession();
133 }
134 require_once( "includes/EditPage.php" );
135 $editor = new EditPage( $wgArticle );
136 $editor->$action();
137 break;
138 case "history":
139 if ($_SERVER["REQUEST_URI"] == $wgTitle->getInternalURL('action=history')) {
140 $wgOut->setSquidMaxage( $wgSquidMaxage );
141 }
142 require_once( "includes/PageHistory.php" );
143 $history = new PageHistory( $wgArticle );
144 $history->history();
145 break;
146 case "raw":
147 require_once( "includes/RawPage.php" );
148 $raw = new RawPage( $wgArticle );
149 $raw->view();
150 break;
151 case "purge":
152 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
153 $wgOut->setSquidMaxage( $wgSquidMaxage );
154 $wgArticle->view();
155 break;
156 default:
157 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
158 }
159 wfQuery("COMMIT", DB_WRITE);
160 }
161
162 $wgOut->output();
163
164 foreach ( $wgDeferredUpdateList as $up ) { $up->doUpdate(); }
165 logProfilingData();
166 wfDebug( "Request ended normally\n" );
167 ?>