- if( $action == 'view' && !$request->getVal( 'oldid' ) &&
- $request->getVal( 'redirect' ) != 'no' ) {
-
- $dbr =& wfGetDB(DB_SLAVE);
- $article->loadPageData($article->pageDataFromTitle($dbr, $title));
-
- /* Follow redirects only for... redirects */
- if ($article->mIsRedirect) {
- $target = $article->followRedirect();
+ // Check for redirects ...
+ $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() ) )
+ {
+ # Give extensions a change to ignore/handle redirects as needed
+ $ignoreRedirect = $target = false;
+
+ $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?
+ $target = $target ? $target : $article->followRedirect();