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
22 use MediaWiki\MediaWikiServices
;
23 use MediaWiki\RevisionList\RevisionListBase
;
24 use MediaWiki\SpecialPage\SpecialPage
;
27 * Item class for a filearchive table row
29 * @property ArchivedFile $file
30 * @property RevDelArchivedFileList $list
32 class RevDelArchivedFileItem
extends RevDelFileItem
{
36 public function __construct( RevisionListBase
$list, $row ) {
37 parent
::__construct( $list, $row );
38 $this->lockFile
= MediaWikiServices
::getInstance()->getRepoGroup()->getLocalRepo()
39 ->newFile( $row->fa_name
);
42 protected static function initFile( $list, $row ) {
43 return ArchivedFile
::newFromRow( $row );
46 public function getIdField() {
50 public function getTimestampField() {
51 return 'fa_timestamp';
54 public function getAuthorIdField() {
58 public function getAuthorNameField() {
59 return 'fa_user_text';
62 public function getAuthorActorField() {
66 public function getId() {
67 return $this->row
->fa_id
;
70 public function setBits( $bits ) {
71 $dbw = $this->dbProvider
->getPrimaryDatabase();
72 $dbw->newUpdateQueryBuilder()
73 ->update( 'filearchive' )
74 ->set( [ 'fa_deleted' => $bits ] )
76 'fa_id' => $this->row
->fa_id
,
77 'fa_deleted' => $this->getBits(),
79 ->caller( __METHOD__
)->execute();
81 return (bool)$dbw->affectedRows();
84 protected function getLink() {
85 $date = $this->list->getLanguage()->userTimeAndDate(
86 $this->file
->getTimestamp(), $this->list->getUser() );
89 if ( !$this->canViewContent() ) {
90 $link = htmlspecialchars( $date );
92 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
93 $key = $this->file
->getKey();
94 $link = $this->getLinkRenderer()->makeLink( $undelete, $date, [],
96 'target' => $this->list->getPageName(),
98 'token' => $this->list->getUser()->getEditToken( $key )
102 if ( $this->isDeleted() ) {
103 $link = '<span class="history-deleted">' . $link . '</span>';
109 public function getApiData( ApiResult
$result ) {
111 $user = $this->list->getUser();
113 'title' => $this->list->getPageName(),
114 'timestamp' => wfTimestamp( TS_ISO_8601
, $file->getTimestamp() ),
115 'width' => $file->getWidth(),
116 'height' => $file->getHeight(),
117 'size' => $file->getSize(),
118 'userhidden' => (bool)$file->isDeleted( File
::DELETED_USER
),
119 'commenthidden' => (bool)$file->isDeleted( File
::DELETED_COMMENT
),
120 'contenthidden' => (bool)$this->isDeleted(),
122 if ( $this->canViewContent() ) {
124 'url' => SpecialPage
::getTitleFor( 'Revisiondelete' )->getLinkURL(
126 'target' => $this->list->getPageName(),
127 'file' => $file->getKey(),
128 'token' => $user->getEditToken( $file->getKey() )
133 $uploader = $file->getUploader( ArchivedFile
::FOR_THIS_USER
, $user );
136 'userid' => $uploader->getId(),
137 'user' => $uploader->getName(),
140 $comment = $file->getDescription( ArchivedFile
::FOR_THIS_USER
, $user );
141 if ( $comment !== '' ) {
143 'comment' => $comment,
150 public function lock() {
151 return $this->lockFile
->acquireFileLock();
154 public function unlock() {
155 return $this->lockFile
->releaseFileLock();