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