summaryrefslogtreecommitdiff
path: root/includes/Wiki.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2009-02-22 13:37:51 +0100
committerPierre Schmitz <pierre@archlinux.de>2009-02-22 13:37:51 +0100
commitb9b85843572bf283f48285001e276ba7e61b63f6 (patch)
tree4c6f4571552ada9ccfb4030481dcf77308f8b254 /includes/Wiki.php
parentd9a20acc4e789cca747ad360d87ee3f3e7aa58c1 (diff)
updated to MediaWiki 1.14.0
Diffstat (limited to 'includes/Wiki.php')
-rw-r--r--includes/Wiki.php139
1 files changed, 74 insertions, 65 deletions
diff --git a/includes/Wiki.php b/includes/Wiki.php
index fa49290a..ce4ce67e 100644
--- a/includes/Wiki.php
+++ b/includes/Wiki.php
@@ -42,6 +42,7 @@ class MediaWiki {
/**
* Initialization of ... everything
* Performs the request too
+ * FIXME: why is this crap called "initialize" when it performs everything?
*
* @param $title Title ($wgTitle)
* @param $article Article
@@ -51,8 +52,11 @@ class MediaWiki {
*/
function initialize( &$title, &$article, &$output, &$user, $request ) {
wfProfileIn( __METHOD__ );
- $this->preliminaryChecks( $title, $output, $request ) ;
- if ( !$this->initializeSpecialCases( $title, $output, $request ) ) {
+ if( !$this->preliminaryChecks( $title, $output, $request ) ) {
+ wfProfileOut( __METHOD__ );
+ return;
+ }
+ if( !$this->initializeSpecialCases( $title, $output, $request ) ) {
$new_article = $this->initializeArticle( $title, $request );
if( is_object( $new_article ) ) {
$article = $new_article;
@@ -60,6 +64,7 @@ class MediaWiki {
} elseif( is_string( $new_article ) ) {
$output->redirect( $new_article );
} else {
+ wfProfileOut( __METHOD__ );
throw new MWException( "Shouldn't happen: MediaWiki::initializeArticle() returned neither an object nor a URL" );
}
}
@@ -76,7 +81,7 @@ class MediaWiki {
*/
function checkMaxLag( $maxLag ) {
list( $host, $lag ) = wfGetLB()->getMaxLag();
- if ( $lag > $maxLag ) {
+ if( $lag > $maxLag ) {
wfMaxlagError( $host, $lag, $maxLag );
return false;
} else {
@@ -84,7 +89,6 @@ class MediaWiki {
}
}
-
/**
* Checks some initial queries
* Note that $title here is *not* a Title object, but a string!
@@ -95,26 +99,23 @@ class MediaWiki {
*/
function checkInitialQueries( $title, $action ) {
global $wgOut, $wgRequest, $wgContLang;
- if( $wgRequest->getVal( 'printable' ) == 'yes' ){
+ if( $wgRequest->getVal( 'printable' ) === 'yes' ) {
$wgOut->setPrintable();
}
-
$ret = NULL;
-
- if ( '' == $title && 'delete' != $action ) {
- $ret = Title::newMainPage();
- } elseif ( $curid = $wgRequest->getInt( 'curid' ) ) {
+ if( $curid = $wgRequest->getInt( 'curid' ) ) {
# URLs like this are generated by RC, because rc_title isn't always accurate
$ret = Title::newFromID( $curid );
+ } elseif( '' == $title && 'delete' != $action ) {
+ $ret = Title::newMainPage();
} 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( $wgContLang->getVariants() ) > 1 && !is_null( $ret ) && $ret->getArticleID() == 0 )
$wgContLang->findVariantLink( $title, $ret );
-
}
- if ( ( $oldid = $wgRequest->getInt( 'oldid' ) )
+ if( ( $oldid = $wgRequest->getInt( 'oldid' ) )
&& ( is_null( $ret ) || $ret->getNamespace() != NS_SPECIAL ) ) {
// Allow oldid to override a changed or missing title.
$rev = Revision::newFromId( $oldid );
@@ -133,7 +134,6 @@ class MediaWiki {
* @param $request WebRequest
*/
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
@@ -142,16 +142,16 @@ class MediaWiki {
// 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() ) {
+ if( !is_null( $title ) && !$title->userCanRead() ) {
$output->loginToUse();
$output->output();
- exit;
+ $output->disable();
+ return false;
}
-
+ return true;
}
/**
@@ -161,6 +161,8 @@ class MediaWiki {
* - redirect loop
* - special pages
*
+ * FIXME: why is this crap called "initialize" when it performs everything?
+ *
* @param $title Title
* @param $output OutputPage
* @param $request WebRequest
@@ -170,25 +172,25 @@ class MediaWiki {
wfProfileIn( __METHOD__ );
$action = $this->getVal( 'Action' );
- if( !$title || $title->getDBkey() == '' ) {
+ if( is_null($title) || $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() != '' ) {
+ } 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() ) {
+ 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' ) && !$request->wasPosted() &&
- (!isset( $this->GET['title'] ) || $title->getPrefixedDBKey() != $this->GET['title'] ) &&
+ } else if( $action == 'view' && !$request->wasPosted() &&
+ ( !isset($this->GET['title']) || $title->getPrefixedDBKey() != $this->GET['title'] ) &&
!count( array_diff( array_keys( $this->GET ), array( 'action', 'title' ) ) ) )
{
$targetUrl = $title->getFullURL();
@@ -219,7 +221,7 @@ class MediaWiki {
$output->setSquidMaxage( 1200 );
$output->redirect( $targetUrl, '301' );
}
- } else if ( NS_SPECIAL == $title->getNamespace() ) {
+ } else if( NS_SPECIAL == $title->getNamespace() ) {
/* actions that need to be made when we have a special pages */
SpecialPage::executePath( $title );
} else {
@@ -241,7 +243,7 @@ class MediaWiki {
static function articleFromTitle( &$title ) {
if( NS_MEDIA == $title->getNamespace() ) {
// FIXME: where should this go?
- $title = Title::makeTitle( NS_IMAGE, $title->getDBkey() );
+ $title = Title::makeTitle( NS_FILE, $title->getDBkey() );
}
$article = null;
@@ -251,12 +253,12 @@ class MediaWiki {
}
switch( $title->getNamespace() ) {
- case NS_IMAGE:
- return new ImagePage( $title );
- case NS_CATEGORY:
- return new CategoryPage( $title );
- default:
- return new Article( $title );
+ case NS_FILE:
+ return new ImagePage( $title );
+ case NS_CATEGORY:
+ return new CategoryPage( $title );
+ default:
+ return new Article( $title );
}
}
@@ -271,27 +273,32 @@ class MediaWiki {
function initializeArticle( &$title, $request ) {
wfProfileIn( __METHOD__ );
- $action = $this->getVal( 'action' );
+ $action = $this->getVal( 'action', 'view' );
$article = self::articleFromTitle( $title );
-
- wfDebug("Article: ".$title->getPrefixedText()."\n");
-
+ # NS_MEDIAWIKI has no redirects.
+ # It is also used for CSS/JS, so performance matters here...
+ if( $title->getNamespace() == NS_MEDIAWIKI ) {
+ wfProfileOut( __METHOD__ );
+ return $article;
+ }
// Namespace might change when using redirects
// Check for redirects ...
- $file = $title->getNamespace() == NS_IMAGE ? $article->getFile() : null;
+ $file = ($title->getNamespace() == NS_FILE) ? $article->getFile() : null;
if( ( $action == 'view' || $action == 'render' ) // ... for actions that show content
- && !$request->getVal( 'oldid' ) && // ... and are not old revisions
- $request->getVal( 'redirect' ) != 'no' && // ... unless explicitly told not to
- // ... and the article is not a non-redirect image page with associated file
- !( is_object( $file ) && $file->exists() && !$file->getRedirected() ) ) {
-
+ && !$request->getVal( 'oldid' ) && // ... and are not old revisions
+ $request->getVal( 'redirect' ) != 'no' && // ... unless explicitly told not to
+ // ... and the article is not a non-redirect image page with associated file
+ !( is_object( $file ) && $file->exists() && !$file->getRedirected() ) )
+ {
# Give extensions a change to ignore/handle redirects as needed
$ignoreRedirect = $target = false;
- wfRunHooks( 'InitializeArticleMaybeRedirect', array( &$title, &$request, &$ignoreRedirect, &$target ) );
-
+
$dbr = wfGetDB( DB_SLAVE );
$article->loadPageData( $article->pageDataFromTitle( $dbr, $title ) );
+ wfRunHooks( 'InitializeArticleMaybeRedirect',
+ array(&$title,&$request,&$ignoreRedirect,&$target,&$article) );
+
// Follow redirects only for... redirects
if( !$ignoreRedirect && $article->isRedirect() ) {
# Is the target already set by an extension?
@@ -302,12 +309,11 @@ class MediaWiki {
return $target;
}
}
-
- if( is_object( $target ) ) {
+ if( is_object($target) ) {
// Rewrite environment to redirected article
$rarticle = self::articleFromTitle( $target );
$rarticle->loadPageData( $rarticle->pageDataFromTitle( $dbr, $target ) );
- if ( $rarticle->exists() || ( is_object( $file ) && !$file->isLocal() ) ) {
+ if( $rarticle->exists() || ( is_object( $file ) && !$file->isLocal() ) ) {
$rarticle->setRedirectedFrom( $title );
$article = $rarticle;
$title = $target;
@@ -327,14 +333,18 @@ class MediaWiki {
* @param $deferredUpdates array of updates to do
* @param $output OutputPage
*/
- function finalCleanup ( &$deferredUpdates, &$output ) {
+ function finalCleanup( &$deferredUpdates, &$output ) {
wfProfileIn( __METHOD__ );
- $this->doUpdates( $deferredUpdates );
- $this->doJobs();
# Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
$factory = wfGetLBFactory();
- $factory->shutdown();
+ $factory->commitMasterChanges();
+ # Output everything!
$output->output();
+ # Do any deferred jobs
+ $this->doUpdates( $deferredUpdates );
+ $this->doJobs();
+ # Commit and close up!
+ $factory->shutdown();
wfProfileOut( __METHOD__ );
}
@@ -359,7 +369,7 @@ class MediaWiki {
$up->doUpdate();
# Commit after every update to prevent lock contention
- if ( $dbw->trxLevel() ) {
+ if( $dbw->trxLevel() ) {
$dbw->commit();
}
}
@@ -372,12 +382,12 @@ class MediaWiki {
function doJobs() {
$jobRunRate = $this->getVal( 'JobRunRate' );
- if ( $jobRunRate <= 0 || wfReadOnly() ) {
+ if( $jobRunRate <= 0 || wfReadOnly() ) {
return;
}
- if ( $jobRunRate < 1 ) {
+ if( $jobRunRate < 1 ) {
$max = mt_getrandmax();
- if ( mt_rand( 0, $max ) > $max * $jobRunRate ) {
+ if( mt_rand( 0, $max ) > $max * $jobRunRate ) {
return;
}
$n = 1;
@@ -391,7 +401,7 @@ class MediaWiki {
$success = $job->run();
$t += wfTime();
$t = round( $t*1000 );
- if ( !$success ) {
+ if( !$success ) {
$output .= "Error: " . $job->getLastError() . ", Time: $t ms\n";
} else {
$output .= "Success, Time: $t ms\n";
@@ -420,7 +430,7 @@ class MediaWiki {
function performAction( &$output, &$article, &$title, &$user, &$request ) {
wfProfileIn( __METHOD__ );
- if ( !wfRunHooks( 'MediaWikiPerformAction', array( $output, $article, $title, $user, $request, $this ) ) ) {
+ if( !wfRunHooks( 'MediaWikiPerformAction', array( $output, $article, $title, $user, $request, $this ) ) ) {
wfProfileOut( __METHOD__ );
return;
}
@@ -436,6 +446,10 @@ class MediaWiki {
$output->setSquidMaxage( $this->getVal( 'SquidMaxage' ) );
$article->view();
break;
+ case 'raw': // includes JS/CSS
+ $raw = new RawPage( $article );
+ $raw->view();
+ break;
case 'watch':
case 'unwatch':
case 'delete':
@@ -457,21 +471,20 @@ class MediaWiki {
if( !$this->getVal( 'EnableDublinCoreRdf' ) ) {
wfHttpError( 403, 'Forbidden', wfMsg( 'nodublincore' ) );
} else {
- require_once( 'includes/Metadata.php' );
- wfDublinCoreRdf( $article );
+ $rdf = new DublinCoreRdf( $article );
+ $rdf->show();
}
break;
case 'creativecommons':
if( !$this->getVal( 'EnableCreativeCommonsRdf' ) ) {
wfHttpError( 403, 'Forbidden', wfMsg( 'nocreativecommons' ) );
} else {
- require_once( 'includes/Metadata.php' );
- wfCreativeCommonsRdf( $article );
+ $rdf = new CreativeCommonsRdf( $article );
+ $rdf->show();
}
break;
case 'credits':
- require_once( 'includes/Credits.php' );
- showCreditsPage( $article );
+ Credits::showPage( $article );
break;
case 'submit':
if( session_id() == '' ) {
@@ -504,10 +517,6 @@ class MediaWiki {
$history = new PageHistory( $article );
$history->history();
break;
- case 'raw':
- $raw = new RawPage( $article );
- $raw->view();
- break;
default:
if( wfRunHooks( 'UnknownAction', array( $action, $article ) ) ) {
$output->showErrorPage( 'nosuchaction', 'nosuchactiontext' );