* Removed Special:Validate, it's been superseded by the Review extension
[lhc/web/wiklou.git] / includes / Wiki.php
1 <?php
2
3 #__________________________
4 #wiki class
5
6 class MediaWikiType {
7
8 var $mSearch ;
9
10 /**
11 * Constuctor
12 */
13 function MediaWikiType () {
14 OutputPage::setEncodings(); # Not really used yet
15
16 $this->main_setup () ;
17 $this->check_search () ;
18 $this->check_user_read () ;
19 $this->main_action () ;
20 $this->main_updates () ;
21 $this->main_cleanup () ;
22 }
23
24 function check_search () {
25 global $wgRequest , $wgTitle ;
26 $this->mSearch = $wgRequest->getText( 'search' );
27 if( !is_null( $this->mSearch ) && $this->mSearch !== '' ) {
28 // Compatibility with old search URLs which didn't use Special:Search
29 // Do this above the read whitelist check for security...
30 $wgTitle = Title::makeTitle( NS_SPECIAL, 'Search' );
31 }
32 }
33
34 function check_user_read () {
35 global $wgTitle , $wgOut ;
36 # If the user is not logged in, the Namespace:title of the article must be in
37 # the Read array in order for the user to see it. (We have to check here to
38 # catch special pages etc. We check again in Article::view())
39 if ( !is_null( $wgTitle ) && !$wgTitle->userCanRead() ) {
40 $wgOut->loginToUse();
41 $wgOut->output();
42 exit;
43 }
44 }
45
46
47 function main_setup () {
48 global $wgRequest , $wgOut , $wgTitle , $wgContLang ;
49 global $action , $title ;
50 wfProfileIn( 'main-misc-setup' );
51
52 # Query string fields
53 $action = $wgRequest->getVal( 'action', 'view' );
54 $title = $wgRequest->getVal( 'title' );
55
56 if ($wgRequest->getVal( 'printable' ) == 'yes') {
57 $wgOut->setPrintable();
58 }
59
60 if ( '' == $title && 'delete' != $action ) {
61 $wgTitle = Title::newFromText( wfMsgForContent( 'mainpage' ) );
62 } elseif ( $curid = $wgRequest->getInt( 'curid' ) ) {
63 # URLs like this are generated by RC, because rc_title isn't always accurate
64 $wgTitle = Title::newFromID( $curid );
65 } else {
66 $wgTitle = Title::newFromURL( $title );
67 /* check variant links so that interwiki links don't have to worry about
68 the possible different language variants
69 */
70 if( count($wgContLang->getVariants()) > 1 && !is_null($wgTitle) && $wgTitle->getArticleID() == 0 )
71 $wgContLang->findVariantLink( $title, $wgTitle );
72
73 }
74 wfProfileOut( 'main-misc-setup' );
75 }
76
77 function main_updates () {
78 # Deferred updates aren't really deferred anymore. It's important to report errors to the
79 # user, and that means doing this before OutputPage::output(). Note that for page saves,
80 # the client will wait until the script exits anyway before following the redirect.
81 wfProfileIn( 'main-updates' );
82 global $wgDeferredUpdateList ;
83 foreach ( $wgDeferredUpdateList as $up ) {
84 $up->doUpdate();
85 }
86 wfProfileOut( 'main-updates' );
87 }
88
89 function main_cleanup () {
90 global $wgLoadBalancer , $wgOut , $wgPostCommitUpdateList ;
91 wfProfileIn( 'main-cleanup' );
92 $wgLoadBalancer->saveMasterPos();
93
94 # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
95 $wgLoadBalancer->commitAll();
96
97 $wgOut->output();
98
99 foreach ( $wgPostCommitUpdateList as $up ) {
100 $up->doUpdate();
101 }
102
103 wfProfileOut( 'main-cleanup' );
104 }
105
106 function main_action () {
107 global $wgTitle , $wgArticle , $wgRequest , $wgOut , $wgServer ;
108 global $wgDisableInternalSearch , $wgUseCategoryMagic , $wgDisabledActions , $action ;
109 wfProfileIn( 'main-action' );
110
111 if( !$wgDisableInternalSearch && !is_null( $this->mSearch ) && $this->mSearch !== '' ) {
112 require_once( 'includes/SpecialSearch.php' );
113 $wgTitle = Title::makeTitle( NS_SPECIAL, 'Search' );
114 wfSpecialSearch();
115 } else if( !$wgTitle or $wgTitle->getDBkey() == '' ) {
116 $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) );
117 $wgOut->errorpage( 'badtitle', 'badtitletext' );
118 } else if ( $wgTitle->getInterwiki() != '' ) {
119 if( $rdfrom = $wgRequest->getVal( 'rdfrom' ) ) {
120 $url = $wgTitle->getFullURL( 'rdfrom=' . urlencode( $rdfrom ) );
121 } else {
122 $url = $wgTitle->getFullURL();
123 }
124 # Check for a redirect loop
125 if ( !preg_match( '/^' . preg_quote( $wgServer, '/' ) . '/', $url ) && $wgTitle->isLocal() ) {
126 $wgOut->redirect( $url );
127 } else {
128 $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) );
129 $wgOut->errorpage( 'badtitle', 'badtitletext' );
130 }
131 } else if ( ( $action == 'view' ) &&
132 (!isset( $_GET['title'] ) || $wgTitle->getPrefixedDBKey() != $_GET['title'] ) &&
133 !count( array_diff( array_keys( $_GET ), array( 'action', 'title' ) ) ) )
134 {
135 /* redirect to canonical url, make it a 301 to allow caching */
136 $wgOut->setSquidMaxage( 1200 );
137 $wgOut->redirect( $wgTitle->getFullURL(), '301');
138 } else if ( NS_SPECIAL == $wgTitle->getNamespace() ) {
139 # actions that need to be made when we have a special pages
140 SpecialPage::executePath( $wgTitle );
141 } else {
142 if ( NS_MEDIA == $wgTitle->getNamespace() ) {
143 $wgTitle = Title::makeTitle( NS_IMAGE, $wgTitle->getDBkey() );
144 }
145
146 $ns = $wgTitle->getNamespace();
147
148 // Namespace might change when using redirects
149 if($action == 'view' && !$wgRequest->getVal( 'oldid' ) ) {
150 $wgArticle = new Article( $wgTitle );
151 $rTitle = Title::newFromRedirect( $wgArticle->fetchContent() );
152 if($rTitle) {
153 # Reload from the page pointed to later
154 $wgArticle->mContentLoaded = false;
155 $ns = $rTitle->getNamespace();
156 }
157 }
158
159 // Categories and images are handled by a different class
160 if ( $ns == NS_IMAGE ) {
161 unset($wgArticle);
162 require_once( 'includes/ImagePage.php' );
163 $wgArticle = new ImagePage( $wgTitle );
164 } elseif ( $wgUseCategoryMagic && $ns == NS_CATEGORY ) {
165 unset($wgArticle);
166 require_once( 'includes/CategoryPage.php' );
167 $wgArticle = new CategoryPage( $wgTitle );
168 }
169
170 if ( in_array( $action, $wgDisabledActions ) ) {
171 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
172 } else {
173 $act = 'act_' . $action ;
174 if ( method_exists ( $this , $act ) ) {
175 $this->$act ( $action ) ;
176 } else {
177 $this->action_unknown ( $action ) ;
178 }
179 }
180 }
181
182 wfProfileOut( 'main-action' );
183 }
184
185 #____________________________________________________________________________________
186 #Action methods
187
188 function act_view ( $action ) {
189 global $wgOut , $wgSquidMaxage , $wgArticle ;
190 $wgOut->setSquidMaxage( $wgSquidMaxage );
191 $wgArticle->view();
192 }
193
194 function act_print ( $action ) {
195 global $wgArticle ;
196 $wgArticle->view () ;
197 }
198
199 function act_dublincore ( $action ) {
200 global $wgArticle , $wgEnableDublinCoreRdf ;
201 if( !$wgEnableDublinCoreRdf ) {
202 wfHttpError( 403, 'Forbidden', wfMsg( 'nodublincore' ) );
203 } else {
204 require_once( 'includes/Metadata.php' );
205 wfDublinCoreRdf( $wgArticle );
206 }
207 }
208
209 function act_creativecommons ( $action ) {
210 global $wgArticle , $wgEnableCreativeCommonsRdf ;
211 if( !$wgEnableCreativeCommonsRdf ) {
212 wfHttpError( 403, 'Forbidden', wfMsg('nocreativecommons') );
213 } else {
214 require_once( 'includes/Metadata.php' );
215 wfCreativeCommonsRdf( $wgArticle );
216 }
217 }
218
219 function act_credits ( $action ) {
220 global $wgArticle ;
221 require_once( 'includes/Credits.php' );
222 showCreditsPage( $wgArticle );
223 }
224
225 function act_submit ( $action ) {
226 global $wgCommandLineMode , $wgRequest ;
227 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
228 # Send a cookie so anons get talk message notifications
229 User::SetupSession();
230 }
231 $this->act_edit ( $action ) ;
232 }
233
234 function act_edit ( $action ) {
235 global $wgRequest , $wgUseExternalEditor , $wgUser , $wgArticle ;
236 $internal = $wgRequest->getVal( 'internaledit' );
237 $external = $wgRequest->getVal( 'externaledit' );
238 $section = $wgRequest->getVal( 'section' );
239 $oldid = $wgRequest->getVal( 'oldid' );
240 if(!$wgUseExternalEditor || $action=='submit' || $internal ||
241 $section || $oldid || (!$wgUser->getOption('externaleditor') && !$external)) {
242 require_once( 'includes/EditPage.php' );
243 $editor = new EditPage( $wgArticle );
244 $editor->submit();
245 } elseif($wgUseExternalEditor && ($external || $wgUser->getOption('externaleditor'))) {
246 require_once( 'includes/ExternalEdit.php' );
247 $mode = $wgRequest->getVal( 'mode' );
248 $extedit = new ExternalEdit( $wgArticle, $mode );
249 $extedit->edit();
250 }
251 }
252
253 function act_history ( $action ) {
254 global $wgTitle , $wgArticle , $wgSquidMaxage ;
255 if ($_SERVER['REQUEST_URI'] == $wgTitle->getInternalURL('action=history')) {
256 $wgOut->setSquidMaxage( $wgSquidMaxage );
257 }
258 require_once( 'includes/PageHistory.php' );
259 $history = new PageHistory( $wgArticle );
260 $history->history();
261 }
262
263 function act_raw ( $action ) {
264 global $wgArticle ;
265 require_once( 'includes/RawPage.php' );
266 $raw = new RawPage( $wgArticle );
267 $raw->view();
268 }
269
270
271 function action_unknown ( $action ) {
272 global $wgArticle , $wgOut ;
273 if (wfRunHooks('UnknownAction', array($action, $wgArticle))) {
274 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
275 }
276 }
277
278
279 function act_watch ( $action ) { $this->article_action ( $action ) ; }
280 function act_unwatch ( $action ) { $this->article_action ( $action ) ; }
281 function act_delete ( $action ) { $this->article_action ( $action ) ; }
282 function act_revert ( $action ) { $this->article_action ( $action ) ; }
283 function act_rollback ( $action ) { $this->article_action ( $action ) ; }
284 function act_protect ( $action ) { $this->article_action ( $action ) ; }
285 function act_unprotect ( $action ) { $this->article_action ( $action ) ; }
286 function act_info ( $action ) { $this->article_action ( $action ) ; }
287 function act_markpatrolled ( $action ) { $this->article_action ( $action ) ; }
288 function act_render ( $action ) { $this->article_action ( $action ) ; }
289 function act_deletetrackback ( $action ) { $this->article_action ( $action ) ; }
290 function act_purge ( $action ) { $this->article_action ( $action ) ; }
291
292 function article_action ( $action ) {
293 global $wgArticle ;
294 $wgArticle->$action() ;
295 }
296
297
298 } ; # end of class MediaWikiType
299
300 ?>
301