7c359b0eef67a98d5da99794f21943bc8b2b451c
3 * MediaWiki is the to-be base class for this whole project
8 var $GET; /* Stores the $_GET variables at time of creation, can be changed */
14 function MediaWiki () {
19 * Stores key/value pairs to circumvent global variables
20 * Note that keys are case-insensitive!
22 function setVal( $key, &$value ) {
23 $key = strtolower( $key );
24 $this->params
[$key] =& $value;
28 * Retieves key/value pairs to circumvent global variables
29 * Note that keys are case-insensitive!
31 function getVal( $key, $default = "" ) {
32 $key = strtolower( $key );
33 if( isset( $this->params
[$key] ) ) {
34 return $this->params
[$key];
40 * Initialization of ... everything
41 @return Article either the object to become $wgArticle, or NULL
43 function initialize ( &$title, &$output, &$user, $request) {
44 wfProfileIn( 'MediaWiki::initialize' );
45 $this->preliminaryChecks ( $title, $output, $request ) ;
47 if ( !$this->initializeSpecialCases( $title, $output, $request ) ) {
48 $article = $this->initializeArticle( $title, $request );
49 if( is_object( $article ) ) {
50 $this->performAction( $output, $article, $title, $user, $request );
51 } elseif( is_string( $article ) ) {
52 $output->redirect( $article );
54 wfDebugDieBacktrace( "Shouldn't happen: MediaWiki::initializeArticle() returned neither an object nor a URL" );
57 wfProfileOut( 'MediaWiki::initialize' );
62 * Checks some initial queries
63 * Note that $title here is *not* a Title object, but a string!
65 function checkInitialQueries( $title,$action,&$output,$request, $lang) {
66 if ($request->getVal( 'printable' ) == 'yes') {
67 $output->setPrintable();
73 if ( '' == $title && 'delete' != $action ) {
74 $ret = Title
::newFromText( wfMsgForContent( 'mainpage' ) );
75 } elseif ( $curid = $request->getInt( 'curid' ) ) {
76 # URLs like this are generated by RC, because rc_title isn't always accurate
77 $ret = Title
::newFromID( $curid );
79 $ret = Title
::newFromURL( $title );
80 /* check variant links so that interwiki links don't have to worry about
81 the possible different language variants
83 if( count($lang->getVariants()) > 1 && !is_null($ret) && $ret->getArticleID() == 0 )
84 $lang->findVariantLink( $title, $ret );
91 * Checks for search query and anon-cannot-read case
93 function preliminaryChecks ( &$title, &$output, $request ) {
95 # Debug statement for user levels
98 $search = $request->getText( 'search' );
99 if( !is_null( $search ) && $search !== '' ) {
100 // Compatibility with old search URLs which didn't use Special:Search
101 // Do this above the read whitelist check for security...
102 $title = Title
::makeTitle( NS_SPECIAL
, 'Search' );
104 $this->setVal( "Search", $search );
106 # If the user is not logged in, the Namespace:title of the article must be in
107 # the Read array in order for the user to see it. (We have to check here to
108 # catch special pages etc. We check again in Article::view())
109 if ( !is_null( $title ) && !$title->userCanRead() ) {
110 $output->loginToUse();
118 * Initialize the object to be known as $wgArticle for special cases
120 function initializeSpecialCases ( &$title, &$output, $request ) {
122 wfProfileIn( 'MediaWiki::initializeSpecialCases' );
124 $search = $this->getVal('Search');
125 $action = $this->getVal('Action');
126 if( !$this->getVal('DisableInternalSearch') && !is_null( $search ) && $search !== '' ) {
127 require_once( 'includes/SpecialSearch.php' );
128 $title = Title
::makeTitle( NS_SPECIAL
, 'Search' );
130 } else if( !$title or $title->getDBkey() == '' ) {
131 $title = Title
::newFromText( wfMsgForContent( 'badtitle' ) );
132 $output->errorpage( 'badtitle', 'badtitletext' );
133 } else if ( $title->getInterwiki() != '' ) {
134 if( $rdfrom = $request->getVal( 'rdfrom' ) ) {
135 $url = $title->getFullURL( 'rdfrom=' . urlencode( $rdfrom ) );
137 $url = $title->getFullURL();
139 /* Check for a redirect loop */
140 if ( !preg_match( '/^' . preg_quote( $this->getVal('Server'), '/' ) . '/', $url ) && $title->isLocal() ) {
141 $output->redirect( $url );
143 $title = Title
::newFromText( wfMsgForContent( 'badtitle' ) );
144 $output->errorpage( 'badtitle', 'badtitletext' );
146 } else if ( ( $action == 'view' ) &&
147 (!isset( $this->GET
['title'] ) ||
$title->getPrefixedDBKey() != $this->GET
['title'] ) &&
148 !count( array_diff( array_keys( $this->GET
), array( 'action', 'title' ) ) ) )
150 /* Redirect to canonical url, make it a 301 to allow caching */
151 $output->setSquidMaxage( 1200 );
152 $output->redirect( $title->getFullURL(), '301');
153 } else if ( NS_SPECIAL
== $title->getNamespace() ) {
154 /* actions that need to be made when we have a special pages */
155 SpecialPage
::executePath( $title );
157 /* No match to special cases */
158 wfProfileOut( 'MediaWiki::initializeSpecialCases' );
161 /* Did match a special case */
162 wfProfileOut( 'MediaWiki::initializeSpecialCases' );
167 * Create an Article object of the appropriate class for the given page.
168 * @param Title $title
171 function articleFromTitle( $title ) {
172 if( NS_MEDIA
== $title->getNamespace() ) {
173 // FIXME: where should this go?
174 $title = Title
::makeTitle( NS_IMAGE
, $title->getDBkey() );
177 switch( $title->getNamespace() ) {
179 require_once( 'includes/ImagePage.php' );
180 return new ImagePage( $title );
182 require_once( 'includes/CategoryPage.php' );
183 return new CategoryPage( $title );
185 return new Article( $title );
190 * Initialize the object to be known as $wgArticle for "standard" actions
191 * Create an Article object for the page, following redirects if needed.
192 * @param Title $title
193 * @param Request $request
194 * @param string $action
195 * @return mixed an Article, or a string to redirect to another URL
197 function initializeArticle( $title, $request ) {
199 wfProfileIn( 'MediaWiki::initializeArticle' );
201 $action = $this->getVal('Action');
202 $article = $this->articleFromTitle( $title );
204 // Namespace might change when using redirects
205 if( $action == 'view' && !$request->getVal( 'oldid' ) && $request->getVal( 'redirect' ) != 'no' ) {
206 $dbr=&wfGetDB(DB_SLAVE
);
207 $article->loadPageData($article->pageDataFromTitle($dbr,$title));
208 /* Follow redirects only for... redirects */
209 if ($article->mIsRedirect
) {
210 $target = $article->followRedirect();
211 if( is_string( $target ) ) {
212 global $wgDisableHardRedirects;
213 if( !$wgDisableHardRedirects ) {
214 // we'll need to redirect
218 if( is_object( $target ) ) {
219 // evil globals hack!
220 /* Rewrite environment to redirected article */
221 $rarticle =& new Article($target);
222 $rarticle->loadPageData($rarticle->pageDataFromTitle($dbr,$target));
223 if ($rarticle->mTitle
->mArticleID
) {
224 $article =& $rarticle;
226 $article->setRedirectedFrom( $title );
232 $wgTitle = $article->mTitle
;
235 wfProfileOut( 'MediaWiki::initializeArticle' );
240 * Cleaning up by doing deferred updates, calling loadbalancer and doing the output
242 function finalCleanup ( &$deferredUpdates, &$loadBalancer, &$output ) {
243 wfProfileIn( 'MediaWiki::finalCleanup' );
244 $this->doUpdates( $deferredUpdates );
245 $loadBalancer->saveMasterPos();
246 # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
247 $loadBalancer->commitAll();
249 wfProfileOut( 'MediaWiki::finalCleanup' );
253 * Deferred updates aren't really deferred anymore. It's important to report errors to the
254 * user, and that means doing this before OutputPage::output(). Note that for page saves,
255 * the client will wait until the script exits anyway before following the redirect.
257 function doUpdates ( &$updates ) {
258 wfProfileIn( 'MediaWiki::doUpdates' );
259 foreach( $updates as $up ) {
262 wfProfileOut( 'MediaWiki::doUpdates' );
266 * Ends this task peacefully
268 function restInPeace ( &$loadBalancer ) {
271 $loadBalancer->closeAll();
272 wfDebug( "Request ended normally\n" );
276 * Perform one of the "standard" actions
278 function performAction( &$output, &$article, &$title, &$user, &$request ) {
280 wfProfileIn( 'MediaWiki::performAction' );
282 $action = $this->getVal('Action');
283 if( in_array( $action, $this->getVal('DisabledActions',array()) ) ) {
284 /* No such action; this will switch to the default case */
285 $action = "nosuchaction";
290 $output->setSquidMaxage( $this->getVal( 'SquidMaxage' ) );
301 case 'markpatrolled':
304 case 'deletetrackback':
312 if( !$this->getVal( 'EnableDublinCoreRdf' ) ) {
313 wfHttpError( 403, 'Forbidden', wfMsg( 'nodublincore' ) );
315 require_once( 'includes/Metadata.php' );
316 wfDublinCoreRdf( $article );
319 case 'creativecommons':
320 if( !$this->getVal( 'EnableCreativeCommonsRdf' ) ) {
321 wfHttpError( 403, 'Forbidden', wfMsg( 'nocreativecommons' ) );
323 require_once( 'includes/Metadata.php' );
324 wfCreativeCommonsRdf( $article );
328 require_once( 'includes/Credits.php' );
329 showCreditsPage( $article );
332 if( !$this->getVal( 'CommandLineMode' ) && !$request->checkSessionCookie() ) {
333 /* Send a cookie so anons get talk message notifications */
334 User
::SetupSession();
338 $internal = $request->getVal( 'internaledit' );
339 $external = $request->getVal( 'externaledit' );
340 $section = $request->getVal( 'section' );
341 $oldid = $request->getVal( 'oldid' );
342 if( !$this->getVal( 'UseExternalEditor' ) ||
$action=='submit' ||
$internal ||
343 $section ||
$oldid ||
( !$user->getOption( 'externaleditor' ) && !$external ) ) {
344 require_once( 'includes/EditPage.php' );
345 $editor = new EditPage( $article );
347 } elseif( $this->getVal( 'UseExternalEditor' ) && ( $external ||
$user->getOption( 'externaleditor' ) ) ) {
348 require_once( 'includes/ExternalEdit.php' );
349 $mode = $request->getVal( 'mode' );
350 $extedit = new ExternalEdit( $article, $mode );
355 if( $_SERVER['REQUEST_URI'] == $title->getInternalURL( 'action=history' ) ) {
356 $output->setSquidMaxage( $this->getVal( 'SquidMaxage' ) );
358 require_once( 'includes/PageHistory.php' );
359 $history = new PageHistory( $article );
363 require_once( 'includes/RawPage.php' );
364 $raw = new RawPage( $article );
368 if( wfRunHooks( 'UnknownAction', array( $action, $article ) ) ) {
369 $output->errorpage( 'nosuchaction', 'nosuchactiontext' );
371 wfProfileOut( 'MediaWiki::performAction' );
377 }; /* End of class MediaWiki */