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