moving some more stuff from index.php to Wiki.php
[lhc/web/wiklou.git] / includes / Wiki.php
1 <?php
2
3 class MediaWiki {
4
5 var $params = array () ;
6
7 function setVal ( $key , &$value ) {
8 $this->param[strtolower($key)] = $value ;
9 }
10
11 function getVal ( $key , $default = "" ) {
12 $key = strtolower ( $key ) ;
13 if ( isset ( $this->params[$key] ) ) {
14 return $this->params[$key] ;
15 }
16 return $default ;
17 }
18
19 function initializeArticle ( &$title , $action ) {
20 global $wgRequest ;
21 if ( NS_MEDIA == $title->getNamespace() ) {
22 $title = Title::makeTitle( NS_IMAGE, $title->getDBkey() );
23 }
24
25 $ns = $title->getNamespace();
26
27 // Namespace might change when using redirects
28 $article = new Article( $title );
29 if($action == 'view' && !$wgRequest->getVal( 'oldid' ) ) {
30 $rTitle = Title::newFromRedirect( $article->fetchContent() );
31 if($rTitle) {
32 # Reload from the page pointed to later
33 $article->mContentLoaded = false;
34 $ns = $rTitle->getNamespace();
35 }
36 }
37
38 // Categories and images are handled by a different class
39 if ( $ns == NS_IMAGE ) {
40 unset($article);
41 require_once( 'includes/ImagePage.php' );
42 return new ImagePage( $title );
43 } elseif ( $ns == NS_CATEGORY ) {
44 unset($article);
45 require_once( 'includes/CategoryPage.php' );
46 return new CategoryPage( $title );
47 }
48 return $article ;
49 }
50
51 function performAction ( $action , &$output , &$article , &$title , &$user , &$request ) {
52 switch( $action ) {
53 case 'view':
54 $output->setSquidMaxage( $this->getVal('SquidMaxage') );
55 $article->view();
56 break;
57 case 'watch':
58 case 'unwatch':
59 case 'delete':
60 case 'revert':
61 case 'rollback':
62 case 'protect':
63 case 'unprotect':
64 case 'info':
65 case 'markpatrolled':
66 case 'validate':
67 case 'render':
68 case 'deletetrackback':
69 case 'purge':
70 $article->$action();
71 break;
72 case 'print':
73 $article->view();
74 break;
75 case 'dublincore':
76 if( !$this->getVal('EnableDublinCoreRdf') ) {
77 wfHttpError( 403, 'Forbidden', wfMsg( 'nodublincore' ) );
78 } else {
79 require_once( 'includes/Metadata.php' );
80 wfDublinCoreRdf( $article );
81 }
82 break;
83 case 'creativecommons':
84 if( !$this->getVal('EnableCreativeCommonsRdf') ) {
85 wfHttpError( 403, 'Forbidden', wfMsg('nocreativecommons') );
86 } else {
87 require_once( 'includes/Metadata.php' );
88 wfCreativeCommonsRdf( $article );
89 }
90 break;
91 case 'credits':
92 require_once( 'includes/Credits.php' );
93 showCreditsPage( $article );
94 break;
95 case 'submit':
96 if( !$this->getVal('CommandLineMode') && !$request->checkSessionCookie() ) {
97 # Send a cookie so anons get talk message notifications
98 User::SetupSession();
99 }
100 # Continue...
101 case 'edit':
102 $internal = $request->getVal( 'internaledit' );
103 $external = $request->getVal( 'externaledit' );
104 $section = $request->getVal( 'section' );
105 $oldid = $request->getVal( 'oldid' );
106 if(!$this->getVal('UseExternalEditor') || $action=='submit' || $internal ||
107 $section || $oldid || (!$user->getOption('externaleditor') && !$external)) {
108 require_once( 'includes/EditPage.php' );
109 $editor = new EditPage( $article );
110 $editor->submit();
111 } elseif($this->getVal('UseExternalEditor') && ($external || $user->getOption('externaleditor'))) {
112 require_once( 'includes/ExternalEdit.php' );
113 $mode = $request->getVal( 'mode' );
114 $extedit = new ExternalEdit( $article, $mode );
115 $extedit->edit();
116 }
117 break;
118 case 'history':
119 if ($_SERVER['REQUEST_URI'] == $title->getInternalURL('action=history')) {
120 $output->setSquidMaxage( $this->getVal('SquidMaxage') );
121 }
122 require_once( 'includes/PageHistory.php' );
123 $history = new PageHistory( $article );
124 $history->history();
125 break;
126 case 'raw':
127 require_once( 'includes/RawPage.php' );
128 $raw = new RawPage( $article );
129 $raw->view();
130 break;
131 default:
132 if (wfRunHooks('UnknownAction', array($action, $article))) {
133 $output->errorpage( 'nosuchaction', 'nosuchactiontext' );
134 }
135 }
136 }
137
138 } ; # End of class MediaWiki
139
140 ?>
141