From: Bryan Tong Minh Date: Thu, 8 May 2008 20:15:09 +0000 (+0000) Subject: * Add new flag FIND_IGNORE_REDIRECT to wfFindFile and functions it depends on X-Git-Tag: 1.31.0-rc.0~47806 X-Git-Url: http://git.cyclocoop.org//%27%40script%40/%27?a=commitdiff_plain;h=581554c080cb6dbd5fda5bc53ab2a656bda87dcf;p=lhc%2Fweb%2Fwiklou.git * Add new flag FIND_IGNORE_REDIRECT to wfFindFile and functions it depends on * Follow redirects on image pages if the redirect is actually an image redirect * Add comments to the check for redirect code in MediaWiki::initializeArticle so that I actually understand what it does --- diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 07cfdf6cc6..e84e82cbf0 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -2425,10 +2425,11 @@ function &wfGetLBFactory() { * @param mixed $time Requested time for an archived image, or false for the * current version. An image object will be returned which * was created at the specified time. + * @param mixed $flags FileRepo::FIND_ flags * @return File, or false if the file does not exist */ -function wfFindFile( $title, $time = false ) { - return RepoGroup::singleton()->findFile( $title, $time ); +function wfFindFile( $title, $time = false, $flags = 0 ) { + return RepoGroup::singleton()->findFile( $title, $time, $flags ); } /** diff --git a/includes/Wiki.php b/includes/Wiki.php index 8930902ff8..8f9368a017 100644 --- a/includes/Wiki.php +++ b/includes/Wiki.php @@ -277,11 +277,17 @@ class MediaWiki { $action = $this->getVal( 'action' ); $article = self::articleFromTitle( $title ); - + + wfDebug("Article: ".$title->getPrefixedText()."\n"); + // Namespace might change when using redirects - if( ( $action == 'view' || $action == 'render' ) && !$request->getVal( 'oldid' ) && - $request->getVal( 'redirect' ) != 'no' && - !( $title->getNamespace() == NS_IMAGE && wfFindFile( $title->getText() ) ) ) { + // Check for redirects ... + 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 an image page with associated file + !( $title->getNamespace() == NS_IMAGE && wfFindFile( $title->getText(), false, + FileRepo::FIND_IGNORE_REDIRECT ) ) ) { // ... unless it is really an image redirect $dbr = wfGetDB( DB_SLAVE ); $article->loadPageData( $article->pageDataFromTitle( $dbr, $title ) ); diff --git a/includes/filerepo/FileRepo.php b/includes/filerepo/FileRepo.php index 2fd17497f6..b7559e8633 100644 --- a/includes/filerepo/FileRepo.php +++ b/includes/filerepo/FileRepo.php @@ -7,6 +7,7 @@ abstract class FileRepo { const DELETE_SOURCE = 1; const FIND_PRIVATE = 1; + const FIND_IGNORE_REDIRECT = 2; const OVERWRITE = 2; const OVERWRITE_SAME = 4; @@ -104,8 +105,10 @@ abstract class FileRepo { } } } + # Now try redirects - $redir = $this->checkRedirect( $title ); + if ( $flags & FileRepo::FIND_IGNORE_REDIRECT ) return false; + $redir = $this->checkRedirect( $title ); if( $redir && $redir->getNamespace() == NS_IMAGE) { $img = $this->newFile( $redir ); if( !$img ) { diff --git a/includes/filerepo/RepoGroup.php b/includes/filerepo/RepoGroup.php index 39e56883f3..477265e242 100644 --- a/includes/filerepo/RepoGroup.php +++ b/includes/filerepo/RepoGroup.php @@ -56,19 +56,20 @@ class RepoGroup { * @param mixed $title Title object or string * @param mixed $time The 14-char timestamp the file should have * been uploaded, or false for the current version + * @param mixed $flags FileRepo::FIND_ flags * @return File object or false if it is not found */ - function findFile( $title, $time = false ) { + function findFile( $title, $time = false, $flags = 0 ) { if ( !$this->reposInitialised ) { $this->initialiseRepos(); } - $image = $this->localRepo->findFile( $title, $time ); + $image = $this->localRepo->findFile( $title, $time, $flags ); if ( $image ) { return $image; } foreach ( $this->foreignRepos as $repo ) { - $image = $repo->findFile( $title, $time ); + $image = $repo->findFile( $title, $time, $flags ); if ( $image ) { return $image; }