+ /**
+ * Initialization of ... everything
+ @return Article either the object to become $wgArticle, or NULL
+ */
+ function initialize ( &$title, &$output, &$user, $request) {
+ wfProfileIn( 'MediaWiki::initialize' );
+ $this->preliminaryChecks ( $title, $output, $request ) ;
+ $article = NULL;
+ if ( !$this->initializeSpecialCases( $title, $output, $request ) ) {
+ $article = $this->initializeArticle( $title, $request );
+ if( is_object( $article ) ) {
+ $this->performAction( $output, $article, $title, $user, $request );
+ } elseif( is_string( $article ) ) {
+ $output->redirect( $article );
+ } else {
+ throw new MWException( "Shouldn't happen: MediaWiki::initializeArticle() returned neither an object nor a URL" );
+ }
+ }
+ wfProfileOut( 'MediaWiki::initialize' );
+ return $article;
+ }
+
+ function checkMaxLag( $maxLag ) {
+ global $wgLoadBalancer;
+ list( $host, $lag ) = $wgLoadBalancer->getMaxLag();
+ if ( $lag > $maxLag ) {
+ wfMaxlagError( $host, $lag, $maxLag );
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+
+ /**
+ * Checks some initial queries
+ * Note that $title here is *not* a Title object, but a string!
+ */
+ function checkInitialQueries( $title,$action,&$output,$request, $lang) {
+ if ($request->getVal( 'printable' ) == 'yes') {
+ $output->setPrintable();
+ }
+
+ $ret = NULL ;
+
+
+ if ( '' == $title && 'delete' != $action ) {
+ $ret = Title::newMainPage();
+ } elseif ( $curid = $request->getInt( 'curid' ) ) {
+ # URLs like this are generated by RC, because rc_title isn't always accurate
+ $ret = Title::newFromID( $curid );
+ } else {
+ $ret = Title::newFromURL( $title );
+ /* check variant links so that interwiki links don't have to worry about
+ the possible different language variants
+ */
+ if( count($lang->getVariants()) > 1 && !is_null($ret) && $ret->getArticleID() == 0 )
+ $lang->findVariantLink( $title, $ret );
+
+ }
+ if ( ( $oldid = $request->getInt( 'oldid' ) )
+ && ( is_null( $ret ) || $ret->getNamespace() != NS_SPECIAL ) ) {
+ // Allow oldid to override a changed or missing title.
+ $rev = Revision::newFromId( $oldid );
+ if( $rev ) {
+ $ret = $rev->getTitle();
+ }
+ }
+ return $ret ;
+ }
+
+ /**
+ * Checks for search query and anon-cannot-read case
+ */
+ function preliminaryChecks ( &$title, &$output, $request ) {
+
+ if( $request->getCheck( 'search' ) ) {
+ // Compatibility with old search URLs which didn't use Special:Search
+ // Just check for presence here, so blank requests still
+ // show the search page when using ugly URLs (bug 8054).
+
+ // Do this above the read whitelist check for security...
+ $title = SpecialPage::getTitleFor( 'Search' );
+ }
+
+ # If the user is not logged in, the Namespace:title of the article must be in
+ # the Read array in order for the user to see it. (We have to check here to
+ # catch special pages etc. We check again in Article::view())
+ if ( !is_null( $title ) && !$title->userCanRead() ) {
+ $output->loginToUse();
+ $output->output();
+ exit;
+ }
+
+ }
+
+ /**
+ * Initialize the object to be known as $wgArticle for special cases
+ */
+ function initializeSpecialCases ( &$title, &$output, $request ) {
+ global $wgRequest;
+ wfProfileIn( 'MediaWiki::initializeSpecialCases' );
+
+ $action = $this->getVal('Action');
+ if( !$title or $title->getDBkey() == '' ) {
+ $title = SpecialPage::getTitleFor( 'Badtitle' );
+ # Die now before we mess up $wgArticle and the skin stops working
+ throw new ErrorPageError( 'badtitle', 'badtitletext' );
+ } else if ( $title->getInterwiki() != '' ) {
+ if( $rdfrom = $request->getVal( 'rdfrom' ) ) {
+ $url = $title->getFullURL( 'rdfrom=' . urlencode( $rdfrom ) );
+ } else {
+ $url = $title->getFullURL();
+ }
+ /* Check for a redirect loop */
+ if ( !preg_match( '/^' . preg_quote( $this->getVal('Server'), '/' ) . '/', $url ) && $title->isLocal() ) {
+ $output->redirect( $url );
+ } else {
+ $title = SpecialPage::getTitleFor( 'Badtitle' );
+ throw new ErrorPageError( 'badtitle', 'badtitletext' );
+ }
+ } else if ( ( $action == 'view' ) && !$wgRequest->wasPosted() &&
+ (!isset( $this->GET['title'] ) || $title->getPrefixedDBKey() != $this->GET['title'] ) &&
+ !count( array_diff( array_keys( $this->GET ), array( 'action', 'title' ) ) ) )
+ {
+ $targetUrl = $title->getFullURL();
+ // Redirect to canonical url, make it a 301 to allow caching
+ global $wgUsePathInfo;
+ if( $targetUrl == $wgRequest->getFullRequestURL() ) {
+ $message = "Redirect loop detected!\n\n" .
+ "This means the wiki got confused about what page was " .
+ "requested; this sometimes happens when moving a wiki " .
+ "to a new server or changing the server configuration.\n\n";
+
+ if( $wgUsePathInfo ) {
+ $message .= "The wiki is trying to interpret the page " .
+ "title from the URL path portion (PATH_INFO), which " .
+ "sometimes fails depending on the web server. Try " .
+ "setting \"\$wgUsePathInfo = false;\" in your " .
+ "LocalSettings.php, or check that \$wgArticlePath " .
+ "is correct.";
+ } else {
+ $message .= "Your web server was detected as possibly not " .
+ "supporting URL path components (PATH_INFO) correctly; " .
+ "check your LocalSettings.php for a customized " .
+ "\$wgArticlePath setting and/or toggle \$wgUsePathInfo " .
+ "to true.";
+ }
+ wfHttpError( 500, "Internal error", $message );
+ return false;
+ } else {
+ $output->setSquidMaxage( 1200 );
+ $output->redirect( $targetUrl, '301');
+ }
+ } else if ( NS_SPECIAL == $title->getNamespace() ) {
+ /* actions that need to be made when we have a special pages */
+ SpecialPage::executePath( $title );
+ } else {
+ /* No match to special cases */
+ wfProfileOut( 'MediaWiki::initializeSpecialCases' );
+ return false;
+ }
+ /* Did match a special case */
+ wfProfileOut( 'MediaWiki::initializeSpecialCases' );
+ return true;
+ }
+
+ /**
+ * Create an Article object of the appropriate class for the given page.
+ * @param Title $title
+ * @return Article
+ */
+ static function articleFromTitle( $title ) {
+ $article = null;
+ wfRunHooks('ArticleFromTitle', array( &$title, &$article ) );
+ if ( $article ) {
+ return $article;
+ }
+