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