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 $this->performAction( $output, $article, $title, $user, $request );
51 wfProfileOut( 'MediaWiki::initialize' );
56 * Checks some initial queries
57 * Note that $title here is *not* a Title object, but a string!
59 function checkInitialQueries( $title,$action,&$output,$request, $lang) {
60 if ($request->getVal( 'printable' ) == 'yes') {
61 $output->setPrintable();
67 if ( '' == $title && 'delete' != $action ) {
68 $ret = Title
::newFromText( wfMsgForContent( 'mainpage' ) );
69 } elseif ( $curid = $request->getInt( 'curid' ) ) {
70 # URLs like this are generated by RC, because rc_title isn't always accurate
71 $ret = Title
::newFromID( $curid );
73 $ret = Title
::newFromURL( $title );
74 /* check variant links so that interwiki links don't have to worry about
75 the possible different language variants
77 if( count($lang->getVariants()) > 1 && !is_null($ret) && $ret->getArticleID() == 0 )
78 $lang->findVariantLink( $title, $ret );
85 * Checks for search query and anon-cannot-read case
87 function preliminaryChecks ( &$title, &$output, $request ) {
89 # Debug statement for user levels
92 $search = $request->getText( 'search' );
93 if( !is_null( $search ) && $search !== '' ) {
94 // Compatibility with old search URLs which didn't use Special:Search
95 // Do this above the read whitelist check for security...
96 $title = Title
::makeTitle( NS_SPECIAL
, 'Search' );
98 $this->setVal( "Search", $search );
100 # If the user is not logged in, the Namespace:title of the article must be in
101 # the Read array in order for the user to see it. (We have to check here to
102 # catch special pages etc. We check again in Article::view())
103 if ( !is_null( $title ) && !$title->userCanRead() ) {
104 $output->loginToUse();
112 * Initialize the object to be known as $wgArticle for special cases
114 function initializeSpecialCases ( &$title, &$output, $request ) {
116 wfProfileIn( 'MediaWiki::initializeSpecialCases' );
118 $search = $this->getVal('Search');
119 $action = $this->getVal('Action');
120 if( !$this->getVal('DisableInternalSearch') && !is_null( $search ) && $search !== '' ) {
121 require_once( 'includes/SpecialSearch.php' );
122 $title = Title
::makeTitle( NS_SPECIAL
, 'Search' );
124 } else if( !$title or $title->getDBkey() == '' ) {
125 $title = Title
::newFromText( wfMsgForContent( 'badtitle' ) );
126 $output->errorpage( 'badtitle', 'badtitletext' );
127 } else if ( $title->getInterwiki() != '' ) {
128 if( $rdfrom = $request->getVal( 'rdfrom' ) ) {
129 $url = $title->getFullURL( 'rdfrom=' . urlencode( $rdfrom ) );
131 $url = $title->getFullURL();
133 /* Check for a redirect loop */
134 if ( !preg_match( '/^' . preg_quote( $this->getVal('Server'), '/' ) . '/', $url ) && $title->isLocal() ) {
135 $output->redirect( $url );
137 $title = Title
::newFromText( wfMsgForContent( 'badtitle' ) );
138 $output->errorpage( 'badtitle', 'badtitletext' );
140 } else if ( ( $action == 'view' ) &&
141 (!isset( $this->GET
['title'] ) ||
$title->getPrefixedDBKey() != $this->GET
['title'] ) &&
142 !count( array_diff( array_keys( $this->GET
), array( 'action', 'title' ) ) ) )
144 /* Redirect to canonical url, make it a 301 to allow caching */
145 $output->setSquidMaxage( 1200 );
146 $output->redirect( $title->getFullURL(), '301');
147 } else if ( NS_SPECIAL
== $title->getNamespace() ) {
148 /* actions that need to be made when we have a special pages */
149 SpecialPage
::executePath( $title );
151 /* No match to special cases */
152 wfProfileOut( 'MediaWiki::initializeSpecialCases' );
155 /* Did match a special case */
156 wfProfileOut( 'MediaWiki::initializeSpecialCases' );
161 * Initialize the object to be known as $wgArticle for "standard" actions
163 function initializeArticle( &$title, $request ) {
165 wfProfileIn( 'MediaWiki::initializeArticle' );
167 $action = $this->getVal('Action');
169 if( NS_MEDIA
== $title->getNamespace() ) {
170 $title = Title
::makeTitle( NS_IMAGE
, $title->getDBkey() );
173 $ns = $title->getNamespace();
175 /* Namespace might change when using redirects */
176 $article = new Article( $title );
177 if( $action == 'view' && !$request->getVal( 'oldid' ) ) {
178 $rTitle = Title
::newFromRedirect( $article->fetchContent() );
180 /* Reload from the page pointed to later */
181 $article->mContentLoaded
= false;
182 $ns = $rTitle->getNamespace();
183 $wasRedirected = true;
187 /* Categories and images are handled by a different class */
188 if( $ns == NS_IMAGE
) {
189 $b4 = $title->getPrefixedText();
191 require_once( 'includes/ImagePage.php' );
192 $article = new ImagePage( $title );
193 if( isset( $wasRedirected ) && $request->getVal( 'redirect' ) != 'no' ) {
194 $article->mTitle
= $rTitle;
195 $article->mRedirectedFrom
= $b4;
197 } elseif( $ns == NS_CATEGORY
) {
199 require_once( 'includes/CategoryPage.php' );
200 $article = new CategoryPage( $title );
202 wfProfileOut( 'MediaWiki::initializeArticle' );
207 * Cleaning up by doing deferred updates, calling loadbalancer and doing the output
209 function finalCleanup ( &$deferredUpdates, &$loadBalancer, &$output ) {
210 wfProfileIn( 'MediaWiki::finalCleanup' );
211 $this->doUpdates( $deferredUpdates );
212 $loadBalancer->saveMasterPos();
213 # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
214 $loadBalancer->commitAll();
216 wfProfileOut( 'MediaWiki::finalCleanup' );
220 * Deferred updates aren't really deferred anymore. It's important to report errors to the
221 * user, and that means doing this before OutputPage::output(). Note that for page saves,
222 * the client will wait until the script exits anyway before following the redirect.
224 function doUpdates ( &$updates ) {
225 wfProfileIn( 'MediaWiki::doUpdates' );
226 foreach( $updates as $up ) {
229 wfProfileOut( 'MediaWiki::doUpdates' );
233 * Ends this task peacefully
235 function restInPeace ( &$loadBalancer ) {
238 $loadBalancer->closeAll();
239 wfDebug( "Request ended normally\n" );
243 * Perform one of the "standard" actions
245 function performAction( &$output, &$article, &$title, &$user, &$request ) {
247 wfProfileIn( 'MediaWiki::performAction' );
249 $action = $this->getVal('Action');
250 if( in_array( $action, $this->getVal('DisabledActions',array()) ) ) {
251 /* No such action; this will switch to the default case */
252 $action = "nosuchaction";
257 $output->setSquidMaxage( $this->getVal( 'SquidMaxage' ) );
268 case 'markpatrolled':
271 case 'deletetrackback':
279 if( !$this->getVal( 'EnableDublinCoreRdf' ) ) {
280 wfHttpError( 403, 'Forbidden', wfMsg( 'nodublincore' ) );
282 require_once( 'includes/Metadata.php' );
283 wfDublinCoreRdf( $article );
286 case 'creativecommons':
287 if( !$this->getVal( 'EnableCreativeCommonsRdf' ) ) {
288 wfHttpError( 403, 'Forbidden', wfMsg( 'nocreativecommons' ) );
290 require_once( 'includes/Metadata.php' );
291 wfCreativeCommonsRdf( $article );
295 require_once( 'includes/Credits.php' );
296 showCreditsPage( $article );
299 if( !$this->getVal( 'CommandLineMode' ) && !$request->checkSessionCookie() ) {
300 /* Send a cookie so anons get talk message notifications */
301 User
::SetupSession();
305 $internal = $request->getVal( 'internaledit' );
306 $external = $request->getVal( 'externaledit' );
307 $section = $request->getVal( 'section' );
308 $oldid = $request->getVal( 'oldid' );
309 if( !$this->getVal( 'UseExternalEditor' ) ||
$action=='submit' ||
$internal ||
310 $section ||
$oldid ||
( !$user->getOption( 'externaleditor' ) && !$external ) ) {
311 require_once( 'includes/EditPage.php' );
312 $editor = new EditPage( $article );
314 } elseif( $this->getVal( 'UseExternalEditor' ) && ( $external ||
$user->getOption( 'externaleditor' ) ) ) {
315 require_once( 'includes/ExternalEdit.php' );
316 $mode = $request->getVal( 'mode' );
317 $extedit = new ExternalEdit( $article, $mode );
322 if( $_SERVER['REQUEST_URI'] == $title->getInternalURL( 'action=history' ) ) {
323 $output->setSquidMaxage( $this->getVal( 'SquidMaxage' ) );
325 require_once( 'includes/PageHistory.php' );
326 $history = new PageHistory( $article );
330 require_once( 'includes/RawPage.php' );
331 $raw = new RawPage( $article );
335 if( wfRunHooks( 'UnknownAction', array( $action, $article ) ) ) {
336 $output->errorpage( 'nosuchaction', 'nosuchactiontext' );
338 wfProfileOut( 'MediaWiki::performAction' );
344 }; /* End of class MediaWiki */