3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
19 * @ingroup RevisionDelete
23 * Item class for an oldimage table row
25 class RevDelFileItem
extends RevDelItem
{
29 public function __construct( $list, $row ) {
30 parent
::__construct( $list, $row );
31 $this->file
= RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
34 public function getIdField() {
35 return 'oi_archive_name';
38 public function getTimestampField() {
39 return 'oi_timestamp';
42 public function getAuthorIdField() {
46 public function getAuthorNameField() {
47 return 'oi_user_text';
50 public function getId() {
51 $parts = explode( '!', $this->row
->oi_archive_name
);
56 public function canView() {
57 return $this->file
->userCan( File
::DELETED_RESTRICTED
, $this->list->getUser() );
60 public function canViewContent() {
61 return $this->file
->userCan( File
::DELETED_FILE
, $this->list->getUser() );
64 public function getBits() {
65 return $this->file
->getVisibility();
68 public function setBits( $bits ) {
70 # @todo FIXME: Move to LocalFile.php
71 if ( $this->isDeleted() ) {
72 if ( $bits & File
::DELETED_FILE
) {
76 $key = $this->file
->getStorageKey();
77 $srcRel = $this->file
->repo
->getDeletedHashPath( $key ) . $key;
78 $this->list->storeBatch
[] = array( $this->file
->repo
->getVirtualUrl( 'deleted' ) . '/' . $srcRel, 'public', $this->file
->getRel() );
79 $this->list->cleanupBatch
[] = $key;
81 } elseif ( $bits & File
::DELETED_FILE
) {
83 $key = $this->file
->getStorageKey();
84 $dstRel = $this->file
->repo
->getDeletedHashPath( $key ) . $key;
85 $this->list->deleteBatch
[] = array( $this->file
->getRel(), $dstRel );
88 # Do the database operations
89 $dbw = wfGetDB( DB_MASTER
);
90 $dbw->update( 'oldimage', array( 'oi_deleted' => $bits ), array( 'oi_name' => $this->row
->oi_name
, 'oi_timestamp' => $this->row
->oi_timestamp
, 'oi_deleted' => $this->getBits() ), __METHOD__
);
92 return (bool) $dbw->affectedRows();
95 public function isDeleted() {
96 return $this->file
->isDeleted( File
::DELETED_FILE
);
100 * Get the link to the file.
101 * Overridden by RevDelArchivedFileItem.
104 protected function getLink() {
105 $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate( $this->file
->getTimestamp(), $this->list->getUser() ) );
107 if ( !$this->isDeleted() ) {
109 return Html
::rawElement( 'a', array( 'href' => $this->file
->getUrl() ), $date );
113 if ( !$this->canViewContent() ) {
116 $link = Linker
::link( SpecialPage
::getTitleFor( 'Revisiondelete' ), $date, array(), array( 'target' => $this->list->title
->getPrefixedText(), 'file' => $this->file
->getArchiveName(), 'token' => $this->list->getUser()->getEditToken( $this->file
->getArchiveName() ) ) );
119 return '<span class="history-deleted">' . $link . '</span>';
123 * Generate a user tool link cluster if the current user is allowed to view it
124 * @return string HTML
126 protected function getUserTools() {
127 if ( $this->file
->userCan( Revision
::DELETED_USER
, $this->list->getUser() ) ) {
128 $uid = $this->file
->getUser( 'id' );
129 $name = $this->file
->getUser( 'text' );
130 $link = Linker
::userLink( $uid, $name ) . Linker
::userToolLinks( $uid, $name );
132 $link = $this->list->msg( 'rev-deleted-user' )->escaped();
134 if ( $this->file
->isDeleted( Revision
::DELETED_USER
) ) {
135 return '<span class="history-deleted">' . $link . '</span>';
142 * Wrap and format the file's comment block, if the current
143 * user is allowed to view it.
145 * @return string HTML
147 protected function getComment() {
148 if ( $this->file
->userCan( File
::DELETED_COMMENT
, $this->list->getUser() ) ) {
149 $block = Linker
::commentBlock( $this->file
->getDescription() );
151 $block = ' ' . $this->list->msg( 'rev-deleted-comment' )->escaped();
153 if ( $this->file
->isDeleted( File
::DELETED_COMMENT
) ) {
154 return "<span class=\"history-deleted\">$block</span>";
160 public function getHTML() {
161 $data = $this->list->msg( 'widthheight' )->numParams( $this->file
->getWidth(), $this->file
->getHeight() )->text() . ' (' . $this->list->msg( 'nbytes' )->numParams( $this->file
->getSize() )->text() . ')';
163 return '<li>' . $this->getLink() . ' ' . $this->getUserTools() . ' ' . $data . ' ' . $this->getComment() . '</li>';
166 public function getApiData( ApiResult
$result ) {
168 $user = $this->list->getUser();
169 $ret = array( 'title' => $this->list->title
->getPrefixedText(), 'archivename' => $file->getArchiveName(), 'timestamp' => wfTimestamp( TS_ISO_8601
, $file->getTimestamp() ), 'width' => $file->getWidth(), 'height' => $file->getHeight(), 'size' => $file->getSize(), );
170 $ret +
= $file->isDeleted( Revision
::DELETED_USER
) ?
array( 'userhidden' => '' ) : array();
171 $ret +
= $file->isDeleted( Revision
::DELETED_COMMENT
) ?
array( 'commenthidden' => '' ) : array();
172 $ret +
= $this->isDeleted() ?
array( 'contenthidden' => '' ) : array();
173 if ( !$this->isDeleted() ) {
174 $ret +
= array( 'url' => $file->getUrl(), );
175 } elseif ( $this->canViewContent() ) {
176 $ret +
= array( 'url' => SpecialPage
::getTitleFor( 'Revisiondelete' )->getLinkURL( array( 'target' => $this->list->title
->getPrefixedText(), 'file' => $file->getArchiveName(), 'token' => $user->getEditToken( $file->getArchiveName() ) ), false, PROTO_RELATIVE
), );
178 if ( $file->userCan( Revision
::DELETED_USER
, $user ) ) {
179 $ret +
= array( 'userid' => $file->user
, 'user' => $file->user_text
, );
181 if ( $file->userCan( Revision
::DELETED_COMMENT
, $user ) ) {
182 $ret +
= array( 'comment' => $file->description
, );