Implemented '$wgWhitelistRead'.
[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 # Windows requires ';' as separator, ':' for Unix
18 $sep = strchr( $include_path = ini_get( "include_path" ), ";" ) ? ";" : ":";
19 ini_set( "include_path", "$IP$sep$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 #
28 global $action, $title, $search, $go, $target, $printable;
29 global $returnto, $diff, $oldid, $curid;
30
31 # Placeholders in case of DB error
32 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
33 $wgArticle = new Article($wgTitle);
34
35 $action = strtolower( trim( $action ) );
36 if ( "" == $action ) { $action = "view"; }
37 if ( "yes" == $printable ) { $wgOut->setPrintable(); }
38
39 if ( "" == $title && "delete" != $action ) {
40 $wgTitle = Title::newFromText( wfMsg( "mainpage" ) );
41 } elseif ( $curid ) {
42 # URLs like this are generated by RC, because rc_title isn't always accurate
43 $wgTitle = Title::newFromID( $curid );
44 } else {
45 $wgTitle = Title::newFromURL( $title );
46 }
47 wfProfileOut( "main-misc-setup" );
48
49 # If the user is not logged in, the Namespace:title of the article must be in the Read array in
50 # order for the user to see it.
51 if ( !$wgUser->getID() && is_array( $wgWhitelistRead ) && $wgTitle) {
52 if ( !in_array( $wgLang->getNsText( $wgTitle->getNamespace() ) . ":" . $wgTitle->getDBkey(), $wgWhitelistRead ) ) {
53 $wgOut->loginToUse();
54 $wgOut->output();
55 exit;
56 }
57 }
58
59 if ( "" != $search ) {
60 if( isset($_REQUEST['fulltext']) ) {
61 wfSearch( $search );
62 } else {
63 wfGo( $search );
64 }
65 } else if( !$wgTitle or $wgTitle->getInterwiki() != "" or $wgTitle->getDBkey() == "" ) {
66 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
67 $wgOut->errorpage( "badtitle", "badtitletext" );
68 } else if ( ( $action == "view" ) && $wgTitle->getPrefixedDBKey() != $title ) {
69 /* redirect to canonical url, make it a 301 to allow caching */
70 $wgOut->redirect( wfLocalUrl( $wgTitle->getPrefixedURL() ), '301');
71 } else if ( Namespace::getSpecial() == $wgTitle->getNamespace() ) {
72 wfSpecialPage();
73 } else {
74 if ( Namespace::getMedia() == $wgTitle->getNamespace() ) {
75 $wgTitle = Title::makeTitle( Namespace::getImage(), $wgTitle->getDBkey() );
76 }
77
78 switch( $wgTitle->getNamespace() ) {
79 case 6:
80 include_once( "ImagePage.php" );
81 $wgArticle = new ImagePage( $wgTitle );
82 break;
83 default:
84 $wgArticle = new Article( $wgTitle );
85 }
86
87 wfQuery("BEGIN", DB_WRITE);
88 switch( $action ) {
89 case "view":
90 case "watch":
91 case "unwatch":
92 case "delete":
93 case "revert":
94 case "rollback":
95 case "protect":
96 case "unprotect":
97 $wgArticle->$action();
98 break;
99 case "print":
100 $wgArticle->view();
101 break;
102 case "edit":
103 case "submit":
104 if( !$wgCommandLineMode && !isset( $_COOKIE[ini_get("session.name")] ) ) {
105 User::SetupSession();
106 }
107 include_once( "EditPage.php" );
108 $editor = new EditPage( $wgArticle );
109 $editor->$action();
110 break;
111 case "history":
112 include_once( "PageHistory.php" );
113 $history = new PageHistory( $wgArticle );
114 $history->history();
115 break;
116 default:
117 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
118 }
119 wfQuery("COMMIT", DB_WRITE);
120 }
121
122 $wgOut->output();
123 foreach ( $wgDeferredUpdateList as $up ) { $up->doUpdate(); }
124 logProfilingData();
125 wfDebug( "Request ended normally\n" );
126 ?>