/* private */ var $img; // Image object this page is shown for
/* private */ var $repo;
var $mExtraDescription = false;
+ var $dupes;
function __construct( $title, $time = false ) {
parent::__construct( $title );
} else {
$this->current = $time ? wfLocalFile( $this->mTitle ) : $this->img;
}
- $this->repo = $this->img->repo;
+ $this->repo = $this->img->getRepo();
+ $this->dupes = null;
}
/**
$this->closeShowImage();
$this->imageHistory();
+ // TODO: Cleanup the following
+
+ $wgOut->addHTML( Xml::element( 'h2',
+ array( 'id' => 'filelinks' ),
+ wfMsg( 'imagelinks' ) ) . "\n" );
+ $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();
$this->imageLinks();
- if ( $this->img->isLocal() ) $this->imageRedirects();
if ( $showmeta ) {
global $wgStylePath, $wgStyleVersion;
public function getFile() {
return $this->img;
}
+
+ public function getDuplicates() {
+ 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();
+ foreach ( $dupes as $index => $file ) {
+ $key = $file->getRepoName().':'.$file->getName();
+ if ( $key == $self )
+ unset( $dupes[$index] );
+ if ( $file->getSize() != $size )
+ unset( $dupes[$index] );
+ }
+ return $this->dupes = $dupes;
+
+ }
+
/**
* Create the TOC
}
}
+ /*
+ * Check for files with the same name on the foreign repos.
+ */
function checkSharedConflict() {
global $wgOut, $wgUser;
$repoGroup = RepoGroup::singleton();
$list = new ImageHistoryList( $sk, $this->current );
$file = $this->current;
$dims = $file->getDimensionsString();
- $s = $list->beginImageHistoryList() .
- $list->imageHistoryLine( true, $file );
+ $s = $list->beginImageHistoryList();
+ $s .= $list->imageHistoryLine( true, $file );
// old image versions
$hist = $this->img->getHistory();
foreach( $hist as $file ) {
$limit = 100;
- $wgOut->addHTML( Xml::element( 'h2', array( 'id' => 'filelinks' ), wfMsg( 'imagelinks' ) ) . "\n" );
-
$dbr = wfGetDB( DB_SLAVE );
$res = $dbr->select(
return;
}
$wgOut->addWikiMsg( 'linkstoimage' );
- $wgOut->addHTML( "<ul>\n" );
+ $wgOut->addHTML( "<ul class='mw-imagepage-linktoimage'>\n" );
$sk = $wgUser->getSkin();
$count = 0;
{
global $wgUser, $wgOut;
- $dbr = wfGetDB( DB_SLAVE );
- $res = $dbr->select(
- array( 'redirect', 'page' ),
- array( 'page_title' ),
- array(
- 'rd_namespace' => NS_IMAGE,
- 'rd_title' => $this->mTitle->getDBkey(),
- 'page_namespace' => NS_IMAGE,
- 'rd_from = page_id'
- ),
- __METHOD__
- );
+ $redirects = $this->getTitle()->getRedirectsHere( NS_IMAGE );
+ if ( count( $redirects ) == 0 ) return;
- if ( 0 == $dbr->numRows( $res ) )
- return;
-
$wgOut->addWikiMsg( 'redirectstofile' );
- $wgOut->addHTML( "<ul>\n" );
+ $wgOut->addHTML( "<ul class='mw-imagepage-redirectstofile'>\n" );
$sk = $wgUser->getSkin();
- while ( $row = $dbr->fetchObject( $res ) ) {
- $name = Title::makeTitle( NS_IMAGE, $row->page_title );
- $link = $sk->makeKnownLinkObj( $name, "" );
- wfDebug("Image redirect: {$row->page_title}\n");
+ foreach ( $redirects as $title ) {
+ $link = $sk->makeKnownLinkObj( $title, "" );
+ $wgOut->addHTML( "<li>{$link}</li>\n" );
+ }
+ $wgOut->addHTML( "</ul>\n" );
+
+ }
+
+ function imageDupes() {
+ global $wgOut, $wgUser;
+
+ $dupes = $this->getDuplicates();
+ if ( count( $dupes ) == 0 ) return;
+
+ $wgOut->addWikiMsg( 'duplicatesoffile' );
+ $wgOut->addHTML( "<ul class='mw-imagepage-duplicates'>\n" );
+
+ $sk = $wgUser->getSkin();
+ foreach ( $dupes as $file ) {
+ if ( $file->isLocal() )
+ $link = $sk->makeKnownLinkObj( $file->getTitle(), "" );
+ else
+ $link = $sk->makeExternalLink( $file->getDescriptionUrl(),
+ $file->getTitle()->getPrefixedText() );
$wgOut->addHTML( "<li>{$link}</li>\n" );
}
$wgOut->addHTML( "</ul>\n" );
-
- $res->free();
}
/**
public function beginImageHistoryList() {
global $wgOut, $wgUser;
- $deleteColumn = $wgUser->isAllowed( 'delete' ) || $wgUser->isAllowed( 'deleterevision' );
return Xml::element( 'h2', array( 'id' => 'filehistory' ), wfMsg( 'filehist' ) )
. $wgOut->parse( wfMsgNoTrans( 'filehist-help' ) )
- . Xml::openElement( 'table', array( 'class' => 'filehistory' ) ) . "\n"
- . '<tr><td></td>'
- . ( $this->img->isLocal() && $deleteColumn ? '<td></td>' : '' )
- . '<th>' . wfMsgHtml( 'filehist-datetime' ) . '</th>'
- . '<th>' . wfMsgHtml( 'filehist-user' ) . '</th>'
- . '<th>' . wfMsgHtml( 'filehist-dimensions' ) . '</th>'
- . '<th class="mw-imagepage-filesize">' . wfMsgHtml( 'filehist-filesize' ) . '</th>'
- . '<th>' . wfMsgHtml( 'filehist-comment' ) . '</th>'
- . "</tr>\n";
+ . Xml::openElement( 'table', array( 'class' => 'filehistory' ) ) . "\n";
}
public function endImageHistoryList() {
$sha1 = $file->getSha1();
$local = $this->img->isLocal();
- $row = '';
+ $row = $css = '';
// Deletion link
if( $local && ($wgUser->isAllowed('delete') || $wgUser->isAllowed('deleterevision') ) ) {
- $row .= '<td>';
# Link to remove from history
if( $wgUser->isAllowed( 'delete' ) ) {
$q = array();
$q[] = 'action=delete';
if( !$iscur )
$q[] = 'oldimage=' . urlencode( $img );
- $row .= $this->skin->makeKnownLinkObj(
+ $row .= '<td>' . $this->skin->makeKnownLinkObj(
$this->title,
wfMsgHtml( $iscur ? 'filehist-deleteall' : 'filehist-deleteone' ),
implode( '&', $q )
);
- $row .= '<br/>';
+ $row .= '</td>';
}
# Link to hide content
if( $wgUser->isAllowed( 'deleterevision' ) ) {
if( $file->isDeleted(File::DELETED_RESTRICTED) )
$del = "<strong>$del</strong>";
}
- $row .= "<tt><small>$del</small></tt>";
+ $row .= "<td style='white-space: nowrap;'><tt><small>$del</small></tt></td>";
}
- $row .= '</td>';
}
// Reversion link/current indicator
$row .= '</td>';
// Date/time and image link
- $row .= '<td>';
+ $row .= "<td 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>';
$row .= '<span class="history-deleted">'.$url.'</span>';
} else {
$url = $iscur ? $this->img->getUrl() : $this->img->getArchiveUrl( $img );
- $row .= Xml::element( 'a',
- array( 'href' => $url ),
- $wgLang->timeAndDate( $timestamp, true ) );
+ $row .= Xml::element( 'a', array( 'href' => $url ), $wgLang->timeAndDate( $timestamp, true ) );
}
- $row .= '</td>';
+ $row .= "</td><td>";
+
+ // Image dimensions
+ $row .= ' ' . htmlspecialchars( $dims );
+
+ // File size
+ $row .= " <span style='white-space: nowrap;'>(" . $this->skin->formatSize( $size ) . ')</span>';
// Uploading user
- $row .= '<td>';
+ $row .= '</td><td>';
if( $local ) {
// Hide deleted usernames
if( $file->isDeleted(File::DELETED_USER) )
} else {
$row .= htmlspecialchars( $usertext );
}
- $row .= '</td>';
-
- // Image dimensions
- $row .= '<td>' . htmlspecialchars( $dims ) . '</td>';
-
- // File size
- $row .= '<td class="mw-imagepage-filesize">' . $this->skin->formatSize( $size ) . '</td>';
// Don't show deleted descriptions
- if ( $file->isDeleted(File::DELETED_COMMENT) )
- $row .= '<td><span class="history-deleted">' . wfMsgHtml('rev-deleted-comment') . '</span></td>';
- else
- $row .= '<td>' . $this->skin->commentBlock( $description, $this->title ) . '</td>';
+ if ( $file->isDeleted(File::DELETED_COMMENT) ) {
+ $row .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-comment') . '</span>';
+ } else {
+ $row .= ' ' . $this->skin->commentBlock( $description, $this->title );
+ }
+ $row .= '</td>';
- return "<tr>{$row}</tr>\n";
+ wfRunHooks( 'ImagePageFileHistoryLine', array( &$file, &$row, &$css ) );
+ $tagCSS = $css ? " class='$css'" : "";
+
+ return "<tr{$tagCSS}>{$row}</tr>\n";
}
}