<?php
/**
* MediaWiki is the to-be base class for this whole project
+ *
+ * @internal documentation reviewed 15 Mar 2010
*/
class MediaWiki {
* Note that keys are case-insensitive!
*
* @param $key String: key to get
- * @param $default Mixed: default value if if the key doesn't exist
+ * @param $default string default value, defaults to empty string
+ * @return $default Mixed: default value if if the key doesn't exist
*/
function getVal( $key, $default = '' ) {
$key = strtolower( $key );
return true;
}
}
-
- /**
- * Check if the average lag of database slaves is higher that $avgLag, and
- * if it's the case, output an error message
- *
- * @param $avgLag int: maximum lag allowed for the request, as supplied by
- * the client
- * @return bool true if the request can continue
- */
- function checkAvgLag( $avgLag ) {
- list( $host, $lag ) = wfGetLB()->getAvgLag();
- if( $lag > $avgLag ) {
- wfAvglagError( $lag, $avgLag );
- return false;
- } else {
- return true;
- }
- }
/**
* Checks some initial queries
if( $wgRequest->getVal( 'printable' ) === 'yes' ) {
$wgOut->setPrintable();
}
- $ret = NULL;
+ $ret = null;
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 ) {
+ } elseif( $title == '' && $action != 'delete' ) {
$ret = Title::newMainPage();
} else {
$ret = Title::newFromURL( $title );
* @param $title Title
* @param $output OutputPage
* @param $request WebRequest
+ * @return boolean true if successful
*/
function preliminaryChecks( &$title, &$output, $request ) {
if( $request->getCheck( 'search' ) ) {
global $wgContLang, $wgUser;
$action = $this->getVal( 'Action' );
$perferred = $wgContLang->getPreferredVariant( false );
- // Invalid titles
- if( is_null($title) || $title->getDBkey() == '' ) {
+
+ // Invalid titles. Bug 21776: The interwikis must redirect even if the page name is empty.
+ if( is_null($title) || ( ($title->getDBkey() == '') && ($title->getInterwiki() == '') ) ) {
$title = SpecialPage::getTitleFor( 'Badtitle' );
# Die now before we mess up $wgArticle and the skin stops working
throw new ErrorPageError( 'badtitle', 'badtitletext' );
+
// Interwiki redirects
} else if( $title->getInterwiki() != '' ) {
if( $rdfrom = $request->getVal( 'rdfrom' ) ) {
wfProfileOut( __METHOD__ );
throw new ErrorPageError( 'badtitle', 'badtitletext' );
}
- // Redirect loops, no title in URL, $wgUsePathInfo URLs
+ // Redirect loops, no title in URL, $wgUsePathInfo URLs, and URLs with a variant
} else if( $action == 'view' && !$request->wasPosted() &&
( ( !isset($this->GET['title']) || $title->getPrefixedDBKey() != $this->GET['title'] ) ||
- ( !isset($this->GET['variant']) && $perferred != $wgContLang->getCode() &&
- $wgContLang->hasVariants() && !$wgUser->isLoggedIn() ) ) &&
+ // No valid variant in URL (if the main-language has multi-variants), to ensure
+ // anonymous access would always be redirect to a URL with 'variant' parameter
+ ( !isset($this->GET['variant']) && $wgContLang->hasVariants() && !$wgUser->isLoggedIn() ) ) &&
!count( array_diff( array_keys( $this->GET ), array( 'action', 'title' ) ) ) )
{
- $targetUrl = $title->getFullURL();
+ if( !$wgUser->isLoggedIn() ) {
+ $pref = $wgContLang->getPreferredVariant( false, $fromHeader = true );
+ $targetUrl = $title->getFullURL( '', $variant = $pref );
+ }
+ else
+ $targetUrl = $title->getFullURL();
// Redirect to canonical url, make it a 301 to allow caching
if( $targetUrl == $request->getFullRequestURL() ) {
$message = "Redirect loop detected!\n\n" .
$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( 'diff' ) && // ... and not when showing diff
$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() ) )