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