<?php
-/**
- */
-/**
- *
- */
if( !defined( 'MEDIAWIKI' ) )
die( 1 );
/**
* Special handling for image description pages
*
- * @addtogroup Media
+ * @ingroup Media
*/
class ImagePage extends Article {
- /* private */ var $img; // Image object this page is shown for
+ /* private */ var $img; // Image object
+ /* private */ var $displayImg;
/* private */ var $repo;
+ /* private */ var $fileLoaded;
var $mExtraDescription = false;
var $dupes;
- function __construct( $title, $time = false ) {
+ function __construct( $title ) {
parent::__construct( $title );
- $this->img = wfFindFile( $this->mTitle, $time );
+ $this->dupes = null;
+ $this->repo = null;
+ }
+
+ protected function loadFile() {
+ if ( $this->fileLoaded ) {
+ return true;
+ }
+ $this->fileLoaded = true;
+
+ $this->displayImg = $this->img = false;
+ wfRunHooks( 'ImagePageFindFile', array( $this, &$this->img, &$this->displayImg ) );
if ( !$this->img ) {
- $this->img = wfLocalFile( $this->mTitle );
- $this->current = $this->img;
- } else {
- $this->current = $time ? wfLocalFile( $this->mTitle ) : $this->img;
+ $this->img = wfFindFile( $this->mTitle );
+ if ( !$this->img ) {
+ $this->img = wfLocalFile( $this->mTitle );
+ }
+ }
+ if ( !$this->displayImg ) {
+ $this->displayImg = $this->img;
}
$this->repo = $this->img->getRepo();
- $this->dupes = null;
}
/**
function view() {
global $wgOut, $wgShowEXIF, $wgRequest, $wgUser;
+ $this->loadFile();
if ( $this->mTitle->getNamespace() == NS_IMAGE && $this->img->getRedirected() ) {
if ( $this->mTitle->getDBkey() == $this->img->getName() ) {
if ( $this->mTitle->getNamespace() != NS_IMAGE || ( isset( $diff ) && $diffOnly ) )
return Article::view();
- if ($wgShowEXIF && $this->img->exists()) {
+ if ( $wgShowEXIF && $this->displayImg->exists() ) {
// FIXME: bad interface, see note on MediaHandler::formatMetadata().
- $formattedMetadata = $this->img->formatMetadata();
+ $formattedMetadata = $this->displayImg->formatMetadata();
$showmeta = $formattedMetadata !== false;
} else {
$showmeta = false;
}
- if ($this->img->exists())
- $wgOut->addHTML($this->showTOC($showmeta));
+ if ( $this->displayImg->exists() )
+ $wgOut->addHTML( $this->showTOC($showmeta) );
$this->openShowImage();
$this->imageDupes();
// TODO: We may want to find local images redirecting to a foreign
// file: "The following local files redirect to this file"
- if ( $this->img->isLocal() ) $this->imageRedirects();
+ if ( $this->img->isLocal() ) {
+ $this->imageRedirects();
+ }
$this->imageLinks();
if ( $showmeta ) {
}
public function getRedirectTarget() {
- if ( $this->img->isLocal() )
+ $this->loadFile();
+ if ( $this->img->isLocal() ) {
return parent::getRedirectTarget();
-
+ }
// Foreign image page
$from = $this->img->getRedirected();
$to = $this->img->getName();
- if ($from == $to) return null;
+ if ( $from == $to ) {
+ return null;
+ }
return $this->mRedirectTarget = Title::makeTitle( NS_IMAGE, $to );
}
public function followRedirect() {
- if ( $this->img->isLocal() )
+ $this->loadFile();
+ if ( $this->img->isLocal() ) {
return parent::followRedirect();
-
+ }
$from = $this->img->getRedirected();
$to = $this->img->getName();
- if ($from == $to) return false;
+ if ( $from == $to ) {
+ return false;
+ }
return Title::makeTitle( NS_IMAGE, $to );
}
public function isRedirect( $text = false ) {
+ $this->loadFile();
if ( $this->img->isLocal() )
return parent::isRedirect( $text );
}
public function isLocal() {
+ $this->loadFile();
return $this->img->isLocal();
}
public function getFile() {
+ $this->loadFile();
return $this->img;
}
+ public function getDisplayedFile() {
+ $this->loadFile();
+ return $this->displayImg;
+ }
+
public function getDuplicates() {
- if ( !is_null($this->dupes) ) return $this->dupes;
-
- if ( !( $hash = $this->img->getSha1() ) )
+ $this->loadFile();
+ if ( !is_null($this->dupes) ) {
+ return $this->dupes;
+ }
+ if ( !( $hash = $this->img->getSha1() ) ) {
return $this->dupes = array();
+ }
$dupes = RepoGroup::singleton()->findBySha1( $hash );
-
// Remove duplicates with self and non matching file sizes
$self = $this->img->getRepoName().':'.$this->img->getName();
$size = $this->img->getSize();
* shared upload server if possible.
*/
function getContent() {
+ $this->loadFile();
if( $this->img && !$this->img->isLocal() && 0 == $this->getID() ) {
return '';
}
function openShowImage() {
global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgLang, $wgContLang;
- $full_url = $this->img->getURL();
+ $this->loadFile();
+
+ $full_url = $this->displayImg->getURL();
$linkAttribs = false;
$sizeSel = intval( $wgUser->getOption( 'imagesize') );
if( !isset( $wgImageLimits[$sizeSel] ) ) {
$sk = $wgUser->getSkin();
$dirmark = $wgContLang->getDirMark();
- if ( $this->img->exists() ) {
+ if ( $this->displayImg->exists() ) {
# image
$page = $wgRequest->getIntOrNull( 'page' );
if ( is_null( $page ) ) {
} else {
$params = array( 'page' => $page );
}
- $width_orig = $this->img->getWidth();
+ $width_orig = $this->displayImg->getWidth();
$width = $width_orig;
- $height_orig = $this->img->getHeight();
+ $height_orig = $this->displayImg->getHeight();
$height = $height_orig;
- $mime = $this->img->getMimeType();
+ $mime = $this->displayImg->getMimeType();
$showLink = false;
$linkAttribs = array( 'href' => $full_url );
- $longDesc = $this->img->getLongDesc();
+ $longDesc = $this->displayImg->getLongDesc();
wfRunHooks( 'ImageOpenShowImageInlineBefore', array( &$this , &$wgOut ) ) ;
- if ( $this->img->allowInlineDisplay() ) {
+ if ( $this->displayImg->allowInlineDisplay() ) {
# image
# "Download high res version" link below the image
- #$msgsize = wfMsgHtml('file-info-size', $width_orig, $height_orig, $sk->formatSize( $this->img->getSize() ), $mime );
+ #$msgsize = wfMsgHtml('file-info-size', $width_orig, $height_orig, $sk->formatSize( $this->displayImg->getSize() ), $mime );
# We'll show a thumbnail of this image
if ( $width > $maxWidth || $height > $maxHeight ) {
# Calculate the thumbnail size.
array( 'parseinline' ), $wgLang->formatNum( $width ), $wgLang->formatNum( $height ) );
} else {
# Image is small enough to show full size on image page
- $msgbig = htmlspecialchars( $this->img->getName() );
+ $msgbig = htmlspecialchars( $this->displayImg->getName() );
$msgsmall = wfMsgExt( 'file-nohires', array( 'parseinline' ) );
}
$params['width'] = $width;
- $thumbnail = $this->img->transform( $params );
+ $thumbnail = $this->displayImg->transform( $params );
$anchorclose = "<br />";
- if( $this->img->mustRender() ) {
+ if( $this->displayImg->mustRender() ) {
$showLink = true;
} else {
$anchorclose .=
'<br />' . Xml::tags( 'a', $linkAttribs, $msgbig ) . "$dirmark " . $longDesc;
}
- if ( $this->img->isMultipage() ) {
+ if ( $this->displayImg->isMultipage() ) {
$wgOut->addHTML( '<table class="multipageimage"><tr><td>' );
}
if ( $thumbnail ) {
$options = array(
- 'alt' => $this->img->getTitle()->getPrefixedText(),
+ 'alt' => $this->displayImg->getTitle()->getPrefixedText(),
'file-link' => true,
);
$wgOut->addHTML( '<div class="fullImageLink" id="file">' .
$anchorclose . '</div>' );
}
- if ( $this->img->isMultipage() ) {
- $count = $this->img->pageCount();
+ if ( $this->displayImg->isMultipage() ) {
+ $count = $this->displayImg->pageCount();
if ( $page > 1 ) {
$label = $wgOut->parse( wfMsg( 'imgmultipageprev' ), false );
$link = $sk->makeKnownLinkObj( $this->mTitle, $label, 'page='. ($page-1) );
- $thumb1 = $sk->makeThumbLinkObj( $this->mTitle, $this->img, $link, $label, 'none',
+ $thumb1 = $sk->makeThumbLinkObj( $this->mTitle, $this->displayImg, $link, $label, 'none',
array( 'page' => $page - 1 ) );
} else {
$thumb1 = '';
if ( $page < $count ) {
$label = wfMsg( 'imgmultipagenext' );
$link = $sk->makeKnownLinkObj( $this->mTitle, $label, 'page='. ($page+1) );
- $thumb2 = $sk->makeThumbLinkObj( $this->mTitle, $this->img, $link, $label, 'none',
+ $thumb2 = $sk->makeThumbLinkObj( $this->mTitle, $this->displayImg, $link, $label, 'none',
array( 'page' => $page + 1 ) );
} else {
$thumb2 = '';
}
} else {
#if direct link is allowed but it's not a renderable image, show an icon.
- if ($this->img->isSafeFile()) {
- $icon= $this->img->iconThumb();
+ if ( $this->displayImg->isSafeFile() ) {
+ $icon= $this->displayImg->iconThumb();
$wgOut->addHTML( '<div class="fullImageLink" id="file">' .
$icon->toHtml( array( 'desc-link' => true ) ) .
if ($showLink) {
- $filename = wfEscapeWikiText( $this->img->getName() );
+ $filename = wfEscapeWikiText( $this->displayImg->getName() );
- if (!$this->img->isSafeFile()) {
+ if ( !$this->displayImg->isSafeFile() ) {
$warning = wfMsgNoTrans( 'mediawarning' );
$wgOut->addWikiText( <<<EOT
<div class="fullMedia">
}
}
- if(!$this->img->isLocal()) {
+ if( !$this->displayImg->isLocal() ) {
$this->printSharedImageText();
}
} else {
$title = SpecialPage::getTitleFor( 'Upload' );
$link = $sk->makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'),
- 'wpDestFile=' . urlencode( $this->img->getName() ) );
+ 'wpDestFile=' . urlencode( $this->displayImg->getName() ) );
$wgOut->addHTML( wfMsgWikiHtml( 'noimage', $link ) );
}
}
function printSharedImageText() {
global $wgOut, $wgUser;
+ $this->loadFile();
+
$descUrl = $this->img->getDescriptionUrl();
$descText = $this->img->getDescriptionText();
$s = "<div class='sharedUploadNotice'>" . wfMsgWikiHtml( 'sharedupload' );
*/
function checkSharedConflict() {
global $wgOut, $wgUser;
+
$repoGroup = RepoGroup::singleton();
if( !$repoGroup->hasForeignRepos() ) {
return;
}
+
+ $this->loadFile();
if( !$this->img->isLocal() ) {
return;
}
}
function checkSharedConflictCallback( $repo ) {
+ $this->loadFile();
$dupfile = $repo->newFile( $this->img->getTitle() );
- if( $dupfile->exists() )
+ if( $dupfile && $dupfile->exists() ) {
$this->dupFile = $dupfile;
- return $dupfile->exists();
+ return $dupfile->exists();
+ }
+ return false;
}
function getUploadUrl() {
+ $this->loadFile();
$uploadTitle = SpecialPage::getTitleFor( 'Upload' );
return $uploadTitle->getFullUrl( 'wpDestFile=' . urlencode( $this->img->getName() ) );
}
function uploadLinksBox() {
global $wgUser, $wgOut;
+ $this->loadFile();
if( !$this->img->isLocal() )
return;
*/
function imageHistory()
{
- global $wgUser, $wgOut, $wgUseExternalEditor;
-
- $sk = $wgUser->getSkin();
+ global $wgOut, $wgUseExternalEditor;
+ $this->loadFile();
if ( $this->img->exists() ) {
- $list = new ImageHistoryList( $sk, $this->current );
- $file = $this->current;
+ $list = new ImageHistoryList( $this );
+ $file = $this->img;
$dims = $file->getDimensionsString();
$s = $list->beginImageHistoryList();
$s .= $list->imageHistoryLine( true, $file );
function imageLinks()
{
global $wgUser, $wgOut;
-
+
$limit = 100;
$dbr = wfGetDB( DB_SLAVE );
__METHOD__,
array( 'LIMIT' => $limit + 1)
);
-
- if ( 0 == $dbr->numRows( $res ) ) {
+ $count = $dbr->numRows( $res );
+ if ( $count == 0 ) {
+ $wgOut->addHTML( "<div id='mw-imagepage-nolinkstoimage'>\n" );
$wgOut->addWikiMsg( 'nolinkstoimage' );
+ $wgOut->addHTML( "</div>\n" );
return;
}
- $wgOut->addWikiMsg( 'linkstoimage' );
+ $wgOut->addHTML( "<div id='mw-imagepage-section-linkstoimage'>\n" );
+ $wgOut->addWikiMsg( 'linkstoimage', $count );
$wgOut->addHTML( "<ul class='mw-imagepage-linktoimage'>\n" );
$sk = $wgUser->getSkin();
$wgOut->addHTML( "<li>{$link}</li>\n" );
}
}
- $wgOut->addHTML( "</ul>\n" );
+ $wgOut->addHTML( "</ul></div>\n" );
$res->free();
-
+
// Add a links to [[Special:Whatlinkshere]]
if ( $count > $limit )
$wgOut->addWikiMsg( 'morelinkstoimage', $this->mTitle->getPrefixedDBkey() );
}
- function imageRedirects()
+ function imageRedirects()
{
global $wgUser, $wgOut;
-
+
$redirects = $this->getTitle()->getRedirectsHere( NS_IMAGE );
if ( count( $redirects ) == 0 ) return;
-
- $wgOut->addWikiMsg( 'redirectstofile' );
+ $wgOut->addHTML( "<div id='mw-imagepage-section-redirectstofile'>\n" );
+ $wgOut->addWikiMsg( 'redirectstofile', count( $redirects ) );
$wgOut->addHTML( "<ul class='mw-imagepage-redirectstofile'>\n" );
$sk = $wgUser->getSkin();
foreach ( $redirects as $title ) {
- $link = $sk->makeKnownLinkObj( $title, "" );
+ $link = $sk->makeKnownLinkObj( $title, "", "redirect=no" );
$wgOut->addHTML( "<li>{$link}</li>\n" );
}
- $wgOut->addHTML( "</ul>\n" );
+ $wgOut->addHTML( "</ul></div>\n" );
}
-
+
function imageDupes() {
- global $wgOut, $wgUser;
-
+ global $wgOut, $wgUser;
+
+ $this->loadFile();
+
$dupes = $this->getDuplicates();
if ( count( $dupes ) == 0 ) return;
- $wgOut->addWikiMsg( 'duplicatesoffile' );
+ $wgOut->addHTML( "<div id='mw-imagepage-section-duplicates'>\n" );
+ $wgOut->addWikiMsg( 'duplicatesoffile', count( $dupes ) );
$wgOut->addHTML( "<ul class='mw-imagepage-duplicates'>\n" );
$sk = $wgUser->getSkin();
$file->getTitle()->getPrefixedText() );
$wgOut->addHTML( "<li>{$link}</li>\n" );
}
- $wgOut->addHTML( "</ul>\n" );
+ $wgOut->addHTML( "</ul></div>\n" );
}
/**
* Delete the file, or an earlier version of it
*/
public function delete() {
- if( !$this->img->exists() || !$this->img->isLocal() ) {
+ $this->loadFile();
+ if( !$this->img->exists() || !$this->img->isLocal() || $this->img->getRedirected() ) {
// Standard article deletion
Article::delete();
return;
* Revert the file to an earlier version
*/
public function revert() {
+ $this->loadFile();
$reverter = new FileRevertForm( $this->img );
$reverter->execute();
}
* Override handling of action=purge
*/
function doPurge() {
+ $this->loadFile();
if( $this->img->exists() ) {
wfDebug( "ImagePage::doPurge purging " . $this->img->getName() . "\n" );
$update = new HTMLCacheUpdate( $this->mTitle, 'imagelinks' );
/**
* Builds the image revision log shown on image pages
*
- * @addtogroup Media
+ * @ingroup Media
*/
class ImageHistoryList {
- protected $img, $skin, $title, $repo;
+ protected $imagePage, $img, $skin, $title, $repo;
+
+ public function __construct( $imagePage ) {
+ global $wgUser;
+ $this->skin = $wgUser->getSkin();
+ $this->current = $imagePage->getFile();
+ $this->img = $imagePage->getDisplayedFile();
+ $this->title = $imagePage->getTitle();
+ $this->imagePage = $imagePage;
+ }
- public function __construct( $skin, $img ) {
- $this->skin = $skin;
- $this->img = $img;
- $this->title = $img->getTitle();
+ function getImagePage() {
+ return $this->imagePage;
+ }
+
+ function getSkin() {
+ return $this->skin;
+ }
+
+ function getFile() {
+ return $this->img;
}
public function beginImageHistoryList() {
. $wgOut->parse( wfMsgNoTrans( 'filehist-help' ) )
. Xml::openElement( 'table', array( 'class' => 'filehistory' ) ) . "\n"
. '<tr><td></td>'
- . ( $this->img->isLocal() && ($wgUser->isAllowed('delete') || $wgUser->isAllowed('deleterevision') ) ? '<td></td>' : '' )
+ . ( $this->current->isLocal() && ($wgUser->isAllowed('delete') || $wgUser->isAllowed('deleterevision') ) ? '<td></td>' : '' )
. '<th>' . wfMsgHtml( 'filehist-datetime' ) . '</th>'
. '<th>' . wfMsgHtml( 'filehist-dimensions' ) . '</th>'
. '<th>' . wfMsgHtml( 'filehist-user' ) . '</th>'
$dims = $file->getDimensionsString();
$sha1 = $file->getSha1();
- $local = $this->img->isLocal();
- $row = $css = '';
+ $local = $this->current->isLocal();
+ $row = $css = $selected = '';
// Deletion link
if( $local && ($wgUser->isAllowed('delete') || $wgUser->isAllowed('deleterevision') ) ) {
$row .= '</td>';
// Date/time and image link
- $row .= "<td style='white-space: nowrap;'>";
+ if( $file->getTimestamp() === $this->img->getTimestamp() ) {
+ $selected = "class='filehistory-selected'";
+ }
+ $row .= "<td $selected style='white-space: nowrap;'>";
if( !$file->userCan(File::DELETED_FILE) ) {
# Don't link to unviewable files
$row .= '<span class="history-deleted">' . $wgLang->timeAndDate( $timestamp, true ) . '</span>';
$revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
# Make a link to review the image
$url = $this->skin->makeKnownLinkObj( $revdel, $wgLang->timeAndDate( $timestamp, true ),
- "target=".$wgTitle->getPrefixedText()."&file=$sha1.".$this->img->getExtension() );
+ "target=".$wgTitle->getPrefixedText()."&file=$sha1.".$this->current->getExtension() );
$row .= '<span class="history-deleted">'.$url.'</span>';
} else {
- $url = $iscur ? $this->img->getUrl() : $this->img->getArchiveUrl( $img );
+ $url = $iscur ? $this->current->getUrl() : $this->current->getArchiveUrl( $img );
$row .= Xml::element( 'a', array( 'href' => $url ), $wgLang->timeAndDate( $timestamp, true ) );
}
}
$row .= '</td>';
- wfRunHooks( 'ImagePageFileHistoryLine', array( &$file, &$row, &$css ) );
- $tagCSS = $css ? " class='$css'" : "";
-
- return "<tr{$tagCSS}>{$row}</tr>\n";
+ wfRunHooks( 'ImagePageFileHistoryLine', array( $this, $file, &$row, &$rowClass ) );
+ $classAttr = $rowClass ? " class='$rowClass'" : "";
+
+ return "<tr{$classAttr}>{$row}</tr>\n";
}
}