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' );
46 if ( !$this->initializeSpecialCases( $title, $output, $request ) ) {
47 $article = $this->initializeArticle( $title, $request );
48 $this->performAction( $output, $article, $title, $user, $request );
50 wfProfileOut( 'MediaWiki::initialize' );
55 * Initialize the object to be known as $wgArticle for special cases
57 function initializeSpecialCases ( &$title, &$output, $request ) {
59 wfProfileIn( 'MediaWiki::initializeSpecialCases' );
61 $search = $this->getVal('Search');
62 $action = $this->getVal('Action');
63 if( !$this->getVal('DisableInternalSearch') && !is_null( $search ) && $search !== '' ) {
64 require_once( 'includes/SpecialSearch.php' );
65 $title = Title
::makeTitle( NS_SPECIAL
, 'Search' );
67 } else if( !$title or $title->getDBkey() == '' ) {
68 $title = Title
::newFromText( wfMsgForContent( 'badtitle' ) );
69 $output->errorpage( 'badtitle', 'badtitletext' );
70 } else if ( $title->getInterwiki() != '' ) {
71 if( $rdfrom = $request->getVal( 'rdfrom' ) ) {
72 $url = $title->getFullURL( 'rdfrom=' . urlencode( $rdfrom ) );
74 $url = $title->getFullURL();
76 /* Check for a redirect loop */
77 if ( !preg_match( '/^' . preg_quote( $this->getVal('Server'), '/' ) . '/', $url ) && $title->isLocal() ) {
78 $output->redirect( $url );
80 $title = Title
::newFromText( wfMsgForContent( 'badtitle' ) );
81 $output->errorpage( 'badtitle', 'badtitletext' );
83 } else if ( ( $action == 'view' ) &&
84 (!isset( $this->GET
['title'] ) ||
$title->getPrefixedDBKey() != $this->GET
['title'] ) &&
85 !count( array_diff( array_keys( $this->GET
), array( 'action', 'title' ) ) ) )
87 /* Redirect to canonical url, make it a 301 to allow caching */
88 $output->setSquidMaxage( 1200 );
89 $output->redirect( $title->getFullURL(), '301');
90 } else if ( NS_SPECIAL
== $title->getNamespace() ) {
91 /* actions that need to be made when we have a special pages */
92 SpecialPage
::executePath( $title );
94 /* No match to special cases */
95 wfProfileOut( 'MediaWiki::initializeSpecialCases' );
98 /* Did match a special case */
99 wfProfileOut( 'MediaWiki::initializeSpecialCases' );
104 * Initialize the object to be known as $wgArticle for "standard" actions
106 function initializeArticle( &$title, $request ) {
108 wfProfileIn( 'MediaWiki::initializeArticle' );
110 $action = $this->getVal('Action');
112 if( NS_MEDIA
== $title->getNamespace() ) {
113 $title = Title
::makeTitle( NS_IMAGE
, $title->getDBkey() );
116 $ns = $title->getNamespace();
118 /* Namespace might change when using redirects */
119 $article = new Article( $title );
120 if( $action == 'view' && !$request->getVal( 'oldid' ) ) {
121 $rTitle = Title
::newFromRedirect( $article->fetchContent() );
123 /* Reload from the page pointed to later */
124 $article->mContentLoaded
= false;
125 $ns = $rTitle->getNamespace();
126 $wasRedirected = true;
130 /* Categories and images are handled by a different class */
131 if( $ns == NS_IMAGE
) {
132 $b4 = $title->getPrefixedText();
134 require_once( 'includes/ImagePage.php' );
135 $article = new ImagePage( $title );
136 if( isset( $wasRedirected ) && $request->getVal( 'redirect' ) != 'no' ) {
137 $article->mTitle
= $rTitle;
138 $article->mRedirectedFrom
= $b4;
140 } elseif( $ns == NS_CATEGORY
) {
142 require_once( 'includes/CategoryPage.php' );
143 $article = new CategoryPage( $title );
145 wfProfileOut( 'MediaWiki::initializeArticle' );
150 * Perform one of the "standard" actions
152 function performAction( &$output, &$article, &$title, &$user, &$request ) {
154 wfProfileIn( 'MediaWiki::performAction' );
156 $action = $this->getVal('Action');
157 if( in_array( $action, $this->getVal('DisabledActions',array()) ) ) {
158 /* No such action; this will switch to the default case */
159 $action = "nosuchaction";
164 $output->setSquidMaxage( $this->getVal( 'SquidMaxage' ) );
175 case 'markpatrolled':
178 case 'deletetrackback':
186 if( !$this->getVal( 'EnableDublinCoreRdf' ) ) {
187 wfHttpError( 403, 'Forbidden', wfMsg( 'nodublincore' ) );
189 require_once( 'includes/Metadata.php' );
190 wfDublinCoreRdf( $article );
193 case 'creativecommons':
194 if( !$this->getVal( 'EnableCreativeCommonsRdf' ) ) {
195 wfHttpError( 403, 'Forbidden', wfMsg( 'nocreativecommons' ) );
197 require_once( 'includes/Metadata.php' );
198 wfCreativeCommonsRdf( $article );
202 require_once( 'includes/Credits.php' );
203 showCreditsPage( $article );
206 if( !$this->getVal( 'CommandLineMode' ) && !$request->checkSessionCookie() ) {
207 /* Send a cookie so anons get talk message notifications */
208 User
::SetupSession();
212 $internal = $request->getVal( 'internaledit' );
213 $external = $request->getVal( 'externaledit' );
214 $section = $request->getVal( 'section' );
215 $oldid = $request->getVal( 'oldid' );
216 if( !$this->getVal( 'UseExternalEditor' ) ||
$action=='submit' ||
$internal ||
217 $section ||
$oldid ||
( !$user->getOption( 'externaleditor' ) && !$external ) ) {
218 require_once( 'includes/EditPage.php' );
219 $editor = new EditPage( $article );
221 } elseif( $this->getVal( 'UseExternalEditor' ) && ( $external ||
$user->getOption( 'externaleditor' ) ) ) {
222 require_once( 'includes/ExternalEdit.php' );
223 $mode = $request->getVal( 'mode' );
224 $extedit = new ExternalEdit( $article, $mode );
229 if( $_SERVER['REQUEST_URI'] == $title->getInternalURL( 'action=history' ) ) {
230 $output->setSquidMaxage( $this->getVal( 'SquidMaxage' ) );
232 require_once( 'includes/PageHistory.php' );
233 $history = new PageHistory( $article );
237 require_once( 'includes/RawPage.php' );
238 $raw = new RawPage( $article );
242 if( wfRunHooks( 'UnknownAction', array( $action, $article ) ) ) {
243 $output->errorpage( 'nosuchaction', 'nosuchactiontext' );
245 wfProfileOut( 'MediaWiki::performAction' );
250 }; /* End of class MediaWiki */