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' );
55 function preliminaryChecks ( &$title , &$output , $request ) {
57 # Debug statement for user levels
60 $search = $request->getText( 'search' );
61 if( !is_null( $search ) && $search !== '' ) {
62 // Compatibility with old search URLs which didn't use Special:Search
63 // Do this above the read whitelist check for security...
64 $title = Title
::makeTitle( NS_SPECIAL
, 'Search' );
66 $this->setVal( "Search", $search );
68 # If the user is not logged in, the Namespace:title of the article must be in
69 # the Read array in order for the user to see it. (We have to check here to
70 # catch special pages etc. We check again in Article::view())
71 if ( !is_null( $title ) && !$title->userCanRead() ) {
72 $output->loginToUse();
80 * Initialize the object to be known as $wgArticle for special cases
82 function initializeSpecialCases ( &$title, &$output, $request ) {
84 wfProfileIn( 'MediaWiki::initializeSpecialCases' );
86 $search = $this->getVal('Search');
87 $action = $this->getVal('Action');
88 if( !$this->getVal('DisableInternalSearch') && !is_null( $search ) && $search !== '' ) {
89 require_once( 'includes/SpecialSearch.php' );
90 $title = Title
::makeTitle( NS_SPECIAL
, 'Search' );
92 } else if( !$title or $title->getDBkey() == '' ) {
93 $title = Title
::newFromText( wfMsgForContent( 'badtitle' ) );
94 $output->errorpage( 'badtitle', 'badtitletext' );
95 } else if ( $title->getInterwiki() != '' ) {
96 if( $rdfrom = $request->getVal( 'rdfrom' ) ) {
97 $url = $title->getFullURL( 'rdfrom=' . urlencode( $rdfrom ) );
99 $url = $title->getFullURL();
101 /* Check for a redirect loop */
102 if ( !preg_match( '/^' . preg_quote( $this->getVal('Server'), '/' ) . '/', $url ) && $title->isLocal() ) {
103 $output->redirect( $url );
105 $title = Title
::newFromText( wfMsgForContent( 'badtitle' ) );
106 $output->errorpage( 'badtitle', 'badtitletext' );
108 } else if ( ( $action == 'view' ) &&
109 (!isset( $this->GET
['title'] ) ||
$title->getPrefixedDBKey() != $this->GET
['title'] ) &&
110 !count( array_diff( array_keys( $this->GET
), array( 'action', 'title' ) ) ) )
112 /* Redirect to canonical url, make it a 301 to allow caching */
113 $output->setSquidMaxage( 1200 );
114 $output->redirect( $title->getFullURL(), '301');
115 } else if ( NS_SPECIAL
== $title->getNamespace() ) {
116 /* actions that need to be made when we have a special pages */
117 SpecialPage
::executePath( $title );
119 /* No match to special cases */
120 wfProfileOut( 'MediaWiki::initializeSpecialCases' );
123 /* Did match a special case */
124 wfProfileOut( 'MediaWiki::initializeSpecialCases' );
129 * Initialize the object to be known as $wgArticle for "standard" actions
131 function initializeArticle( &$title, $request ) {
133 wfProfileIn( 'MediaWiki::initializeArticle' );
135 $action = $this->getVal('Action');
137 if( NS_MEDIA
== $title->getNamespace() ) {
138 $title = Title
::makeTitle( NS_IMAGE
, $title->getDBkey() );
141 $ns = $title->getNamespace();
143 /* Namespace might change when using redirects */
144 $article = new Article( $title );
145 if( $action == 'view' && !$request->getVal( 'oldid' ) ) {
146 $rTitle = Title
::newFromRedirect( $article->fetchContent() );
148 /* Reload from the page pointed to later */
149 $article->mContentLoaded
= false;
150 $ns = $rTitle->getNamespace();
151 $wasRedirected = true;
155 /* Categories and images are handled by a different class */
156 if( $ns == NS_IMAGE
) {
157 $b4 = $title->getPrefixedText();
159 require_once( 'includes/ImagePage.php' );
160 $article = new ImagePage( $title );
161 if( isset( $wasRedirected ) && $request->getVal( 'redirect' ) != 'no' ) {
162 $article->mTitle
= $rTitle;
163 $article->mRedirectedFrom
= $b4;
165 } elseif( $ns == NS_CATEGORY
) {
167 require_once( 'includes/CategoryPage.php' );
168 $article = new CategoryPage( $title );
170 wfProfileOut( 'MediaWiki::initializeArticle' );
175 * Cleaning up by doing deferred updates, calling loadbalancer and doing the output
177 function finalCleanup ( &$deferredUpdates , &$loadBalancer , &$output ) {
178 wfProfileIn( 'MediaWiki::finalCleanup' );
179 $this->doUpdates( $deferredUpdates );
180 $loadBalancer->saveMasterPos();
181 # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
182 $loadBalancer->commitAll();
184 wfProfileOut( 'MediaWiki::finalCleanup' );
188 * Deferred updates aren't really deferred anymore. It's important to report errors to the
189 * user, and that means doing this before OutputPage::output(). Note that for page saves,
190 * the client will wait until the script exits anyway before following the redirect.
192 function doUpdates ( &$updates ) {
193 wfProfileIn( 'MediaWiki::doUpdates' );
194 foreach( $updates as $up ) {
197 wfProfileOut( 'MediaWiki::doUpdates' );
201 * Ends this task peacefully
203 function restInPeace ( &$loadBalancer ) {
206 $loadBalancer->closeAll();
207 wfDebug( "Request ended normally\n" );
211 * Perform one of the "standard" actions
213 function performAction( &$output, &$article, &$title, &$user, &$request ) {
215 wfProfileIn( 'MediaWiki::performAction' );
217 $action = $this->getVal('Action');
218 if( in_array( $action, $this->getVal('DisabledActions',array()) ) ) {
219 /* No such action; this will switch to the default case */
220 $action = "nosuchaction";
225 $output->setSquidMaxage( $this->getVal( 'SquidMaxage' ) );
236 case 'markpatrolled':
239 case 'deletetrackback':
247 if( !$this->getVal( 'EnableDublinCoreRdf' ) ) {
248 wfHttpError( 403, 'Forbidden', wfMsg( 'nodublincore' ) );
250 require_once( 'includes/Metadata.php' );
251 wfDublinCoreRdf( $article );
254 case 'creativecommons':
255 if( !$this->getVal( 'EnableCreativeCommonsRdf' ) ) {
256 wfHttpError( 403, 'Forbidden', wfMsg( 'nocreativecommons' ) );
258 require_once( 'includes/Metadata.php' );
259 wfCreativeCommonsRdf( $article );
263 require_once( 'includes/Credits.php' );
264 showCreditsPage( $article );
267 if( !$this->getVal( 'CommandLineMode' ) && !$request->checkSessionCookie() ) {
268 /* Send a cookie so anons get talk message notifications */
269 User
::SetupSession();
273 $internal = $request->getVal( 'internaledit' );
274 $external = $request->getVal( 'externaledit' );
275 $section = $request->getVal( 'section' );
276 $oldid = $request->getVal( 'oldid' );
277 if( !$this->getVal( 'UseExternalEditor' ) ||
$action=='submit' ||
$internal ||
278 $section ||
$oldid ||
( !$user->getOption( 'externaleditor' ) && !$external ) ) {
279 require_once( 'includes/EditPage.php' );
280 $editor = new EditPage( $article );
282 } elseif( $this->getVal( 'UseExternalEditor' ) && ( $external ||
$user->getOption( 'externaleditor' ) ) ) {
283 require_once( 'includes/ExternalEdit.php' );
284 $mode = $request->getVal( 'mode' );
285 $extedit = new ExternalEdit( $article, $mode );
290 if( $_SERVER['REQUEST_URI'] == $title->getInternalURL( 'action=history' ) ) {
291 $output->setSquidMaxage( $this->getVal( 'SquidMaxage' ) );
293 require_once( 'includes/PageHistory.php' );
294 $history = new PageHistory( $article );
298 require_once( 'includes/RawPage.php' );
299 $raw = new RawPage( $article );
303 if( wfRunHooks( 'UnknownAction', array( $action, $article ) ) ) {
304 $output->errorpage( 'nosuchaction', 'nosuchactiontext' );
306 wfProfileOut( 'MediaWiki::performAction' );
312 }; /* End of class MediaWiki */