}
/**
- * @todo document
+ * Builds the image revision log shown on image pages
+ *
* @addtogroup Media
*/
class ImageHistoryList {
- var $img, $skin;
- function ImageHistoryList( $skin, $img ) {
+
+ protected $img, $skin, $title;
+
+ public function __construct( $skin, $img ) {
$this->skin = $skin;
$this->img = $img;
+ $this->title = $img->getTitle();
}
- function beginImageHistoryList() {
- $s = "\n" .
- Xml::element( 'h2', array( 'id' => 'filehistory' ), wfMsg( 'imghistory' ) ) .
- "\n<p>" . wfMsg( 'imghistlegend' ) . "</p>\n".'<ul class="special">';
- return $s;
+ public function beginImageHistoryList() {
+ global $wgOut, $wgUser;
+ return Xml::element( 'h2', array( 'id' => 'filehistory' ), wfMsg( 'filehist' ) )
+ . $wgOut->parse( wfMsgNoTrans( 'filehist-help' ) )
+ . Xml::openElement( 'table', array( 'class' => 'filehistory' ) ) . "\n"
+ . '<tr><th></th>'
+ . ( $this->img->isLocal() && $wgUser->isAllowed( 'delete' ) ? '<th></th>' : '' )
+ . '<th>' . wfMsgHtml( 'filehist-datetime' ) . '</th>'
+ . '<th>' . wfMsgHtml( 'filehist-user' ) . '</th>'
+ . '<th>' . wfMsgHtml( 'filehist-dimensions' ) . '</th>'
+ . '<th>' . wfMsgHtml( 'filehist-filesize' ) . '</th>'
+ . '<th>' . wfMsgHtml( 'filehist-comment' ) . '</th>'
+ . "</tr>\n";
}
- function endImageHistoryList() {
- $s = "</ul>\n";
- return $s;
+ public function endImageHistoryList() {
+ return "</table>\n";
}
- function imageHistoryLine( $iscur, $timestamp, $img, $user, $usertext, $size, $description, $width, $height ) {
+ public function imageHistoryLine( $iscur, $timestamp, $img, $user, $usertext, $size, $description, $width, $height ) {
global $wgUser, $wgLang, $wgTitle, $wgContLang;
-
- $datetime = $wgLang->timeanddate( $timestamp, true );
- $del = wfMsgHtml( 'deleteimg' );
- $delall = wfMsgHtml( 'deleteimgcompletely' );
- $cur = wfMsgHtml( 'cur' );
$local = $this->img->isLocal();
-
- if ( $iscur ) {
- $url = htmlspecialchars( $this->img->getURL() );
- $rlink = $cur;
- if ( $local && $wgUser->isAllowed('delete') ) {
- $link = $wgTitle->escapeLocalURL( 'image=' . $wgTitle->getPartialURL() .
- '&action=delete' );
- $style = $this->skin->getInternalLinkAttributes( $link, $delall );
-
- $dlink = '<a href="'.$link.'"'.$style.'>'.$delall.'</a>';
- } else {
- $dlink = $del;
- }
- } else {
- $url = htmlspecialchars( $this->img->getArchiveUrl( $img ) );
- if( $local && $wgUser->getID() != 0 && $wgTitle->userCan( 'edit' ) ) {
- $token = urlencode( $wgUser->editToken( $img ) );
- $rlink = $this->skin->makeKnownLinkObj( $wgTitle,
- wfMsgHtml( 'revertimg' ), 'action=revert&oldimage=' .
- urlencode( $img ) . "&wpEditToken=$token" );
- $dlink = $this->skin->makeKnownLinkObj( $wgTitle,
- $del, 'action=delete&oldimage=' . urlencode( $img ) .
- "&wpEditToken=$token" );
- } else {
- # Having live active links for non-logged in users
- # means that bots and spiders crawling our site can
- # inadvertently change content. Baaaad idea.
- $rlink = wfMsgHtml( 'revertimg' );
- $dlink = $del;
- }
+ $row = '';
+
+ // Deletion link
+ if( $local && $wgUser->isAllowed( 'delete' ) ) {
+ $row .= '<td>';
+ $q[] = 'action=delete';
+ $q[] = ( $iscur ? 'image=' . $this->title->getPartialUrl() : 'oldimage=' . urlencode( $img ) );
+ if( !$iscur )
+ $q[] = 'wpEditToken=' . urlencode( $wgUser->editToken( $img ) );
+ $row .= '(' . $this->skin->makeKnownLinkObj(
+ $this->title,
+ wfMsgHtml( $iscur ? 'filehist-deleteall' : 'filehist-deleteone' ),
+ implode( '&', $q )
+ ) . ')';
+ $row .= '</td>';
}
-
- if ( $local ) {
- $userlink = $this->skin->userLink( $user, $usertext ) . $this->skin->userToolLinks( $user, $usertext );
+
+ // Reversion link/current indicator
+ $row .= '<td>';
+ if( $iscur ) {
+ $row .= '(' . wfMsgHtml( 'filehist-current' ) . ')';
+ } elseif( $local && $wgUser->isLoggedIn() && $this->title->userCan( 'edit' ) ) {
+ $q[] = 'action=revert';
+ $q[] = 'oldimage=' . urlencode( $img );
+ $q[] = 'wpEditToken=' . urlencode( $wgUser->editToken( $img ) );
+ $row .= '(' . $this->skin->makeKnownLinkObj(
+ $this->title,
+ wfMsgHtml( 'filehist-revert' ),
+ implode( '&', $q )
+ ) . ')';
+ }
+ $row .= '</td>';
+
+ // Date/time and image link
+ $row .= '<td>';
+ $url = $iscur ? $this->img->getUrl() : $this->img->getArchiveUrl( $img );
+ $row .= Xml::element(
+ 'a',
+ array( 'href' => $url ),
+ $wgLang->timeAndDate( $timestamp, true )
+ );
+ $row .= '</td>';
+
+ // Uploading user
+ $row .= '<td>';
+ if( $local ) {
+ $row .= $this->skin->userLink( $user, $usertext ) . $this->skin->userToolLinks( $user, $usertext );
} else {
- $userlink = htmlspecialchars( $usertext );
+ $row .= htmlspecialchars( $usertext );
}
- $nbytes = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),
- $wgLang->formatNum( $size ) );
- $widthheight = wfMsgHtml( 'widthheight', $width, $height );
- $style = $this->skin->getInternalLinkAttributes( $url, $datetime );
-
- $s = "<li> ({$dlink}) ({$rlink}) <a href=\"{$url}\"{$style}>{$datetime}</a> . . {$userlink} . . {$widthheight} ({$nbytes})";
-
- $s .= $this->skin->commentBlock( $description, $wgTitle );
- $s .= "</li>\n";
- return $s;
+ $row .= '</td>';
+
+ // Image dimensions
+ // FIXME: What about sound files? Should have the duration instead...
+ $row .= '<td>' . wfMsgHtml( 'widthheight', $width, $height ) . '</td>';
+
+ // File size
+ $row .= '<td>' . $this->skin->formatSize( $size ) . '</td>';
+
+ // Comment
+ $row .= '<td>' . $this->skin->formatComment( $description, $this->title ) . '</td>';
+
+ return "<tr>{$row}</tr>\n";
}
-}
-
-
+}
\ No newline at end of file
'imgdelete' => 'del',
'imgdesc' => 'desc',
'imgfile' => 'file',
-'imglegend' => 'Legend: (desc) = show/edit file description.',
-'imghistory' => 'File history',
-'revertimg' => 'rev',
-'deleteimg' => 'del',
-'deleteimgcompletely' => 'Delete all revisions of this file',
-'imghistlegend' => 'Legend: (cur) = this is the current file, (del) = delete
-this old version, (rev) = revert to this old version.
-<br /><i>Click on date to see the file uploaded on that date</i>.',
+'filehist' => 'File history',
+'filehist-help' => 'Click on a date/time to view the file as it appeared at that time.',
+'filehist-deleteall' => 'delete all',
+'filehist-deleteone' => 'delete this',
+'filehist-revert' => 'revert',
+'filehist-current' => 'current',
+'filehist-datetime' => 'Date/Time',
+'filehist-user' => 'User',
+'filehist-dimensions' => 'Dimensions',
+'filehist-filesize' => 'File size',
+'filehist-comment' => 'Comment',
'imagelinks' => 'Links',
'linkstoimage' => 'The following pages link to this file:',
'nolinkstoimage' => 'There are no pages that link to this file.',