Moved credits stuff from Skin.php to a separate module. Added a "credits"
[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 $wgArticle->$action();
112 break;
113 case "print":
114 $wgArticle->view();
115 break;
116 case "dublincore":
117 if( !$wgEnableDublinCoreRdf ) {
118 wfHttpError( 403, "Forbidden", wfMsg( "nodublincore" ) );
119 } else {
120 require_once( "includes/Metadata.php" );
121 wfDublinCoreRdf( $wgArticle );
122 }
123 break;
124 case "creativecommons":
125 if( !$wgEnableCreativeCommonsRdf ) {
126 wfHttpError( 403, "Forbidden", wfMsg("nocreativecommons") );
127 } else {
128 require_once( "includes/Metadata.php" );
129 wfCreativeCommonsRdf( $wgArticle );
130 }
131 break;
132 case "credits":
133 require_once( "includes/Credits.php" );
134 showCreditsPage( $wgArticle );
135 break;
136 case "edit":
137 case "submit":
138 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
139 User::SetupSession();
140 }
141 require_once( "includes/EditPage.php" );
142 $editor = new EditPage( $wgArticle );
143 $editor->$action();
144 break;
145 case "history":
146 if ($_SERVER["REQUEST_URI"] == $wgTitle->getInternalURL('action=history')) {
147 $wgOut->setSquidMaxage( $wgSquidMaxage );
148 }
149 require_once( "includes/PageHistory.php" );
150 $history = new PageHistory( $wgArticle );
151 $history->history();
152 break;
153 case "raw":
154 require_once( "includes/RawPage.php" );
155 $raw = new RawPage( $wgArticle );
156 $raw->view();
157 break;
158 case "purge":
159 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
160 $wgOut->setSquidMaxage( $wgSquidMaxage );
161 $wgTitle->invalidateCache();
162 $wgArticle->view();
163 break;
164 default:
165 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
166 }
167 wfQuery("COMMIT", DB_WRITE);
168 }
169
170 $wgOut->output();
171
172 foreach ( $wgDeferredUpdateList as $up ) { $up->doUpdate(); }
173 logProfilingData();
174 wfDebug( "Request ended normally\n" );
175 ?>