Merge "Simplify code to avoid interpreting "$" characters in string replacement"
[mediawiki.git] / includes / revisiondelete / RevDelArchivedFileItem.php
blobe5e72085bb0d969d7ba00ff515f35d56c6aaef0e
1 <?php
2 /**
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
18 * @file
19 * @ingroup RevisionDelete
22 use MediaWiki\MediaWikiServices;
23 use MediaWiki\RevisionList\RevisionListBase;
24 use MediaWiki\SpecialPage\SpecialPage;
26 /**
27 * Item class for a filearchive table row
29 * @property ArchivedFile $file
30 * @property RevDelArchivedFileList $list
32 class RevDelArchivedFileItem extends RevDelFileItem {
33 /** @var LocalFile */
34 protected $lockFile;
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() {
47 return 'fa_id';
50 public function getTimestampField() {
51 return 'fa_timestamp';
54 public function getAuthorIdField() {
55 return 'fa_user';
58 public function getAuthorNameField() {
59 return 'fa_user_text';
62 public function getAuthorActorField() {
63 return 'fa_actor';
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 ] )
75 ->where( [
76 'fa_id' => $this->row->fa_id,
77 'fa_deleted' => $this->getBits(),
78 ] )
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() );
88 # Hidden files...
89 if ( !$this->canViewContent() ) {
90 $link = htmlspecialchars( $date );
91 } else {
92 $undelete = SpecialPage::getTitleFor( 'Undelete' );
93 $key = $this->file->getKey();
94 $link = $this->getLinkRenderer()->makeLink( $undelete, $date, [],
96 'target' => $this->list->getPageName(),
97 'file' => $key,
98 'token' => $this->list->getUser()->getEditToken( $key )
102 if ( $this->isDeleted() ) {
103 $link = '<span class="history-deleted">' . $link . '</span>';
106 return $link;
109 public function getApiData( ApiResult $result ) {
110 $file = $this->file;
111 $user = $this->list->getUser();
112 $ret = [
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() ) {
123 $ret += [
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 );
134 if ( $uploader ) {
135 $ret += [
136 'userid' => $uploader->getId(),
137 'user' => $uploader->getName(),
140 $comment = $file->getDescription( ArchivedFile::FOR_THIS_USER, $user );
141 if ( $comment !== '' ) {
142 $ret += [
143 'comment' => $comment,
147 return $ret;
150 public function lock() {
151 return $this->lockFile->acquireFileLock();
154 public function unlock() {
155 return $this->lockFile->releaseFileLock();