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