* 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
This commit is contained in:
parent
1c5386916e
commit
581554c080
4 changed files with 21 additions and 10 deletions
|
|
@ -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 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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 ) );
|
||||
|
|
|
|||
|
|
@ -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 ) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue