3e591831cf3e697549be5eef76b8ec44c88ff543
3 #__________________________
13 function MediaWikiType () {
14 OutputPage
::setEncodings(); # Not really used yet
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 () ;
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' );
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() ) {
47 function main_setup () {
48 global $wgRequest , $wgOut , $wgTitle , $wgContLang ;
49 global $action , $title ;
50 wfProfileIn( 'main-misc-setup' );
53 $action = $wgRequest->getVal( 'action', 'view' );
54 $title = $wgRequest->getVal( 'title' );
56 if ($wgRequest->getVal( 'printable' ) == 'yes') {
57 $wgOut->setPrintable();
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 );
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
70 if( count($wgContLang->getVariants()) > 1 && !is_null($wgTitle) && $wgTitle->getArticleID() == 0 )
71 $wgContLang->findVariantLink( $title, $wgTitle );
74 wfProfileOut( 'main-misc-setup' );
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 ) {
86 wfProfileOut( 'main-updates' );
89 function main_cleanup () {
90 global $wgLoadBalancer , $wgOut , $wgPostCommitUpdateList ;
91 wfProfileIn( 'main-cleanup' );
92 $wgLoadBalancer->saveMasterPos();
94 # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
95 $wgLoadBalancer->commitAll();
99 foreach ( $wgPostCommitUpdateList as $up ) {
103 wfProfileOut( 'main-cleanup' );
106 function main_action () {
107 global $wgTitle , $wgArticle , $wgRequest , $wgOut , $wgServer ;
108 global $wgDisableInternalSearch , $wgUseCategoryMagic , $wgDisabledActions , $action ;
109 wfProfileIn( 'main-action' );
111 if( !$wgDisableInternalSearch && !is_null( $this->mSearch
) && $this->mSearch
!== '' ) {
112 require_once( 'includes/SpecialSearch.php' );
113 $wgTitle = Title
::makeTitle( NS_SPECIAL
, 'Search' );
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 ) );
122 $url = $wgTitle->getFullURL();
124 # Check for a redirect loop
125 if ( !preg_match( '/^' . preg_quote( $wgServer, '/' ) . '/', $url ) && $wgTitle->isLocal() ) {
126 $wgOut->redirect( $url );
128 $wgTitle = Title
::newFromText( wfMsgForContent( 'badtitle' ) );
129 $wgOut->errorpage( 'badtitle', 'badtitletext' );
131 } else if ( ( $action == 'view' ) &&
132 (!isset( $_GET['title'] ) ||
$wgTitle->getPrefixedDBKey() != $_GET['title'] ) &&
133 !count( array_diff( array_keys( $_GET ), array( 'action', 'title' ) ) ) )
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 );
142 if ( NS_MEDIA
== $wgTitle->getNamespace() ) {
143 $wgTitle = Title
::makeTitle( NS_IMAGE
, $wgTitle->getDBkey() );
146 $ns = $wgTitle->getNamespace();
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() );
153 # Reload from the page pointed to later
154 $wgArticle->mContentLoaded
= false;
155 $ns = $rTitle->getNamespace();
159 // Categories and images are handled by a different class
160 if ( $ns == NS_IMAGE
) {
162 require_once( 'includes/ImagePage.php' );
163 $wgArticle = new ImagePage( $wgTitle );
164 } elseif ( $wgUseCategoryMagic && $ns == NS_CATEGORY
) {
166 require_once( 'includes/CategoryPage.php' );
167 $wgArticle = new CategoryPage( $wgTitle );
170 if ( in_array( $action, $wgDisabledActions ) ) {
171 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
173 $act = 'act_' . $action ;
174 if ( method_exists ( $this , $act ) ) {
175 $this->$act ( $action ) ;
177 $this->action_unknown ( $action ) ;
182 wfProfileOut( 'main-action' );
185 #____________________________________________________________________________________
188 function act_view ( $action ) {
189 global $wgOut , $wgSquidMaxage , $wgArticle ;
190 $wgOut->setSquidMaxage( $wgSquidMaxage );
194 function act_print ( $action ) {
196 $wgArticle->view () ;
199 function act_dublincore ( $action ) {
200 global $wgArticle , $wgEnableDublinCoreRdf ;
201 if( !$wgEnableDublinCoreRdf ) {
202 wfHttpError( 403, 'Forbidden', wfMsg( 'nodublincore' ) );
204 require_once( 'includes/Metadata.php' );
205 wfDublinCoreRdf( $wgArticle );
209 function act_creativecommons ( $action ) {
210 global $wgArticle , $wgEnableCreativeCommonsRdf ;
211 if( !$wgEnableCreativeCommonsRdf ) {
212 wfHttpError( 403, 'Forbidden', wfMsg('nocreativecommons') );
214 require_once( 'includes/Metadata.php' );
215 wfCreativeCommonsRdf( $wgArticle );
219 function act_credits ( $action ) {
221 require_once( 'includes/Credits.php' );
222 showCreditsPage( $wgArticle );
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();
231 $this->act_edit ( $action ) ;
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 );
245 } elseif($wgUseExternalEditor && ($external ||
$wgUser->getOption('externaleditor'))) {
246 require_once( 'includes/ExternalEdit.php' );
247 $mode = $wgRequest->getVal( 'mode' );
248 $extedit = new ExternalEdit( $wgArticle, $mode );
253 function act_history ( $action ) {
254 global $wgTitle , $wgArticle , $wgSquidMaxage ;
255 if ($_SERVER['REQUEST_URI'] == $wgTitle->getInternalURL('action=history')) {
256 $wgOut->setSquidMaxage( $wgSquidMaxage );
258 require_once( 'includes/PageHistory.php' );
259 $history = new PageHistory( $wgArticle );
263 function act_raw ( $action ) {
265 require_once( 'includes/RawPage.php' );
266 $raw = new RawPage( $wgArticle );
271 function action_unknown ( $action ) {
272 global $wgArticle , $wgOut ;
273 if (wfRunHooks('UnknownAction', array($action, $wgArticle))) {
274 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
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_validate ( $action ) { $this->article_action ( $action ) ; }
289 function act_render ( $action ) { $this->article_action ( $action ) ; }
290 function act_deletetrackback ( $action ) { $this->article_action ( $action ) ; }
291 function act_purge ( $action ) { $this->article_action ( $action ) ; }
293 function article_action ( $action ) {
295 $wgArticle->$action() ;
299 } ; # end of class MediaWikiType