Article validation code (as a tab now)
[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 $db =& wfGetDB( DB_MASTER );
58
59 if ( $search = $wgRequest->getText( 'search' ) ) {
60 $wgTitle = Title::makeTitle( NS_SPECIAL, "Search" );
61 if( $wgRequest->getVal( 'fulltext' ) || !is_null( $wgRequest->getVal( 'offset' ) ) ) {
62 wfSearch( $search );
63 } else {
64 wfGo( $search );
65 }
66 } else if( !$wgTitle or $wgTitle->getDBkey() == "" ) {
67 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
68 $wgOut->errorpage( "badtitle", "badtitletext" );
69 } else if ( $wgTitle->getInterwiki() != "" ) {
70 $url = $wgTitle->getFullURL();
71 # Check for a redirect loop
72 if ( !preg_match( "/^" . preg_quote( $wgServer, "/" ) . "/", $url ) && $wgTitle->isLocal() ) {
73 $wgOut->redirect( $url );
74 } else {
75 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
76 $wgOut->errorpage( "badtitle", "badtitletext" );
77 }
78 } else if ( ( $action == "view" ) && $wgTitle->getPrefixedDBKey() != $title ) {
79 /* redirect to canonical url, make it a 301 to allow caching */
80 $wgOut->redirect( $wgTitle->getFullURL(), '301');
81 } else if ( Namespace::getSpecial() == $wgTitle->getNamespace() ) {
82 # actions that need to be made when we have a special pages
83 require_once( 'includes/SpecialPage.php' );
84 if ( !$wgAllowSysopQueries ) {SpecialPage::removePage( 'Asksql' ); }
85 SpecialPage::executePath( $wgTitle );
86 } else {
87 if ( Namespace::getMedia() == $wgTitle->getNamespace() ) {
88 $wgTitle = Title::makeTitle( Namespace::getImage(), $wgTitle->getDBkey() );
89 }
90
91 switch( $wgTitle->getNamespace() ) {
92 case NS_IMAGE:
93 require_once( "includes/ImagePage.php" );
94 $wgArticle = new ImagePage( $wgTitle );
95 break;
96 default:
97 $wgArticle = new Article( $wgTitle );
98 }
99
100 $db->query("BEGIN");
101 switch( $action ) {
102 case "view":
103 $wgOut->setSquidMaxage( $wgSquidMaxage );
104 $wgArticle->view();
105 break;
106 case "watch":
107 case "unwatch":
108 case "delete":
109 case "revert":
110 case "rollback":
111 case "protect":
112 case "unprotect":
113 case "validate":
114 case "info":
115 $wgArticle->$action();
116 break;
117 case "print":
118 $wgArticle->view();
119 break;
120 case "dublincore":
121 if( !$wgEnableDublinCoreRdf ) {
122 wfHttpError( 403, "Forbidden", wfMsg( "nodublincore" ) );
123 } else {
124 require_once( "includes/Metadata.php" );
125 wfDublinCoreRdf( $wgArticle );
126 }
127 break;
128 case "creativecommons":
129 if( !$wgEnableCreativeCommonsRdf ) {
130 wfHttpError( 403, "Forbidden", wfMsg("nocreativecommons") );
131 } else {
132 require_once( "includes/Metadata.php" );
133 wfCreativeCommonsRdf( $wgArticle );
134 }
135 break;
136 case "credits":
137 require_once( "includes/Credits.php" );
138 showCreditsPage( $wgArticle );
139 break;
140 case "edit":
141 case "submit":
142 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
143 User::SetupSession();
144 }
145 require_once( "includes/EditPage.php" );
146 $editor = new EditPage( $wgArticle );
147 $editor->$action();
148 break;
149 case "history":
150 if ($_SERVER["REQUEST_URI"] == $wgTitle->getInternalURL('action=history')) {
151 $wgOut->setSquidMaxage( $wgSquidMaxage );
152 }
153 require_once( "includes/PageHistory.php" );
154 $history = new PageHistory( $wgArticle );
155 $history->history();
156 break;
157 case "raw":
158 require_once( "includes/RawPage.php" );
159 $raw = new RawPage( $wgArticle );
160 $raw->view();
161 break;
162 case "purge":
163 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
164 $wgOut->setSquidMaxage( $wgSquidMaxage );
165 $wgTitle->invalidateCache();
166 $wgArticle->view();
167 break;
168 default:
169 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
170 }
171 $db->query("COMMIT");
172 }
173
174 $wgLoadBalancer->saveMasterPos();
175 $wgOut->output();
176
177 foreach ( $wgDeferredUpdateList as $up ) {
178 $db->query("BEGIN");
179 $up->doUpdate();
180 $db->query("COMMIT");
181 }
182 logProfilingData();
183 wfDebug( "Request ended normally\n" );
184 ?>