moving stuff from index.php to includes/Wiki.php
[lhc/web/wiklou.git] / includes / Wiki.php
1 <?
2
3 #__________________________
4 #wiki class
5
6 class MediaWikiType {
7
8 function main_action () {
9 global $wgTitle , $wgArticle , $wgRequest , $wgOut , $wgServer ;
10 global $wgDisableInternalSearch , $wgUseCategoryMagic , $wgDisabledActions , $action ;
11 wfProfileIn( 'main-action' );
12
13 if( !$wgDisableInternalSearch && !is_null( $this->mSearch ) && $this->mSearch !== '' ) {
14 require_once( 'includes/SpecialSearch.php' );
15 $wgTitle = Title::makeTitle( NS_SPECIAL, 'Search' );
16 wfSpecialSearch();
17 } else if( !$wgTitle or $wgTitle->getDBkey() == '' ) {
18 $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) );
19 $wgOut->errorpage( 'badtitle', 'badtitletext' );
20 } else if ( $wgTitle->getInterwiki() != '' ) {
21 if( $rdfrom = $wgRequest->getVal( 'rdfrom' ) ) {
22 $url = $wgTitle->getFullURL( 'rdfrom=' . urlencode( $rdfrom ) );
23 } else {
24 $url = $wgTitle->getFullURL();
25 }
26 # Check for a redirect loop
27 if ( !preg_match( '/^' . preg_quote( $wgServer, '/' ) . '/', $url ) && $wgTitle->isLocal() ) {
28 $wgOut->redirect( $url );
29 } else {
30 $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) );
31 $wgOut->errorpage( 'badtitle', 'badtitletext' );
32 }
33 } else if ( ( $action == 'view' ) &&
34 (!isset( $_GET['title'] ) || $wgTitle->getPrefixedDBKey() != $_GET['title'] ) &&
35 !count( array_diff( array_keys( $_GET ), array( 'action', 'title' ) ) ) )
36 {
37 /* redirect to canonical url, make it a 301 to allow caching */
38 $wgOut->setSquidMaxage( 1200 );
39 $wgOut->redirect( $wgTitle->getFullURL(), '301');
40 } else if ( NS_SPECIAL == $wgTitle->getNamespace() ) {
41 # actions that need to be made when we have a special pages
42 SpecialPage::executePath( $wgTitle );
43 } else {
44 if ( NS_MEDIA == $wgTitle->getNamespace() ) {
45 $wgTitle = Title::makeTitle( NS_IMAGE, $wgTitle->getDBkey() );
46 }
47
48 $ns = $wgTitle->getNamespace();
49
50 // Namespace might change when using redirects
51 if($action == 'view' && !$wgRequest->getVal( 'oldid' ) ) {
52 $wgArticle = new Article( $wgTitle );
53 $rTitle = Title::newFromRedirect( $wgArticle->fetchContent() );
54 if($rTitle) {
55 # Reload from the page pointed to later
56 $wgArticle->mContentLoaded = false;
57 $ns = $rTitle->getNamespace();
58 }
59 }
60
61 // Categories and images are handled by a different class
62 if ( $ns == NS_IMAGE ) {
63 unset($wgArticle);
64 require_once( 'includes/ImagePage.php' );
65 $wgArticle = new ImagePage( $wgTitle );
66 } elseif ( $wgUseCategoryMagic && $ns == NS_CATEGORY ) {
67 unset($wgArticle);
68 require_once( 'includes/CategoryPage.php' );
69 $wgArticle = new CategoryPage( $wgTitle );
70 }
71
72 if ( in_array( $action, $wgDisabledActions ) ) {
73 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
74 } else {
75 $act = 'act_' . $action ;
76 if ( method_exists ( $this , $act ) ) {
77 $this->$act ( $action ) ;
78 } else {
79 $this->action_unknown ( $action ) ;
80 }
81 }
82 }
83
84 wfProfileOut( 'main-action' );
85 }
86
87 #____________________________________________________________________________________
88 #Action methods
89
90 function act_view ( $action ) {
91 global $wgOut , $wgSquidMaxage , $wgArticle ;
92 $wgOut->setSquidMaxage( $wgSquidMaxage );
93 $wgArticle->view();
94 }
95
96 function act_print ( $action ) {
97 global $wgArticle ;
98 $wgArticle->view () ;
99 }
100
101 function act_dublincore ( $action ) {
102 global $wgArticle , $wgEnableDublinCoreRdf ;
103 if( !$wgEnableDublinCoreRdf ) {
104 wfHttpError( 403, 'Forbidden', wfMsg( 'nodublincore' ) );
105 } else {
106 require_once( 'includes/Metadata.php' );
107 wfDublinCoreRdf( $wgArticle );
108 }
109 }
110
111 function act_creativecommons ( $action ) {
112 global $wgArticle , $wgEnableCreativeCommonsRdf ;
113 if( !$wgEnableCreativeCommonsRdf ) {
114 wfHttpError( 403, 'Forbidden', wfMsg('nocreativecommons') );
115 } else {
116 require_once( 'includes/Metadata.php' );
117 wfCreativeCommonsRdf( $wgArticle );
118 }
119 }
120
121 function act_credits ( $action ) {
122 global $wgArticle ;
123 require_once( 'includes/Credits.php' );
124 showCreditsPage( $wgArticle );
125 }
126
127 function act_submit ( $action ) {
128 global $wgCommandLineMode , $wgRequest ;
129 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
130 # Send a cookie so anons get talk message notifications
131 User::SetupSession();
132 }
133 $this->act_edit ( $action ) ;
134 }
135
136 function act_edit ( $action ) {
137 global $wgRequest , $wgUseExternalEditor , $wgUser , $wgArticle ;
138 $internal = $wgRequest->getVal( 'internaledit' );
139 $external = $wgRequest->getVal( 'externaledit' );
140 $section = $wgRequest->getVal( 'section' );
141 $oldid = $wgRequest->getVal( 'oldid' );
142 if(!$wgUseExternalEditor || $action=='submit' || $internal ||
143 $section || $oldid || (!$wgUser->getOption('externaleditor') && !$external)) {
144 require_once( 'includes/EditPage.php' );
145 $editor = new EditPage( $wgArticle );
146 $editor->submit();
147 } elseif($wgUseExternalEditor && ($external || $wgUser->getOption('externaleditor'))) {
148 require_once( 'includes/ExternalEdit.php' );
149 $mode = $wgRequest->getVal( 'mode' );
150 $extedit = new ExternalEdit( $wgArticle, $mode );
151 $extedit->edit();
152 }
153 }
154
155 function act_history ( $action ) {
156 global $wgTitle , $wgArticle , $wgSquidMaxage ;
157 if ($_SERVER['REQUEST_URI'] == $wgTitle->getInternalURL('action=history')) {
158 $wgOut->setSquidMaxage( $wgSquidMaxage );
159 }
160 require_once( 'includes/PageHistory.php' );
161 $history = new PageHistory( $wgArticle );
162 $history->history();
163 }
164
165 function act_raw ( $action ) {
166 global $wgArticle ;
167 require_once( 'includes/RawPage.php' );
168 $raw = new RawPage( $wgArticle );
169 $raw->view();
170 }
171
172
173 function action_unknown ( $action ) {
174 global $wgArticle , $wgOut ;
175 if (wfRunHooks('UnknownAction', array($action, $wgArticle))) {
176 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
177 }
178 }
179
180
181 function act_watch ( $action ) { $this->article_action ( $action ) ; }
182 function act_unwatch ( $action ) { $this->article_action ( $action ) ; }
183 function act_delete ( $action ) { $this->article_action ( $action ) ; }
184 function act_revert ( $action ) { $this->article_action ( $action ) ; }
185 function act_rollback ( $action ) { $this->article_action ( $action ) ; }
186 function act_protect ( $action ) { $this->article_action ( $action ) ; }
187 function act_unprotect ( $action ) { $this->article_action ( $action ) ; }
188 function act_info ( $action ) { $this->article_action ( $action ) ; }
189 function act_markpatrolled ( $action ) { $this->article_action ( $action ) ; }
190 function act_validate ( $action ) { $this->article_action ( $action ) ; }
191 function act_render ( $action ) { $this->article_action ( $action ) ; }
192 function act_deletetrackback ( $action ) { $this->article_action ( $action ) ; }
193 function act_purge ( $action ) { $this->article_action ( $action ) ; }
194
195 function article_action ( $action ) {
196 global $wgArticle ;
197 $wgArticle->$action() ;
198 }
199
200
201 } ; # end of class MediaWikiType
202
203 ?>
204