MediaWiki master
RevDelArchivedFileItem.php
Go to the documentation of this file.
1<?php
25
34 protected $lockFile;
35
36 public function __construct( RevisionListBase $list, $row ) {
37 parent::__construct( $list, $row );
38 $this->lockFile = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
39 ->newFile( $row->fa_name );
40 }
41
42 protected static function initFile( $list, $row ) {
43 return ArchivedFile::newFromRow( $row );
44 }
45
46 public function getIdField() {
47 return 'fa_id';
48 }
49
50 public function getTimestampField() {
51 return 'fa_timestamp';
52 }
53
54 public function getAuthorIdField() {
55 return 'fa_user';
56 }
57
58 public function getAuthorNameField() {
59 return 'fa_user_text';
60 }
61
62 public function getAuthorActorField() {
63 return 'fa_actor';
64 }
65
66 public function getId() {
67 return $this->row->fa_id;
68 }
69
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();
80
81 return (bool)$dbw->affectedRows();
82 }
83
84 protected function getLink() {
85 $date = $this->list->getLanguage()->userTimeAndDate(
86 $this->file->getTimestamp(), $this->list->getUser() );
87
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, [],
95 [
96 'target' => $this->list->getPageName(),
97 'file' => $key,
98 'token' => $this->list->getUser()->getEditToken( $key )
99 ]
100 );
101 }
102 if ( $this->isDeleted() ) {
103 $link = '<span class="history-deleted">' . $link . '</span>';
104 }
105
106 return $link;
107 }
108
109 public function getApiData( ApiResult $result ) {
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(),
121 ];
122 if ( $this->canViewContent() ) {
123 $ret += [
124 'url' => SpecialPage::getTitleFor( 'Revisiondelete' )->getLinkURL(
125 [
126 'target' => $this->list->getPageName(),
127 'file' => $file->getKey(),
128 'token' => $user->getEditToken( $file->getKey() )
129 ]
130 ),
131 ];
132 }
133 $uploader = $file->getUploader( ArchivedFile::FOR_THIS_USER, $user );
134 if ( $uploader ) {
135 $ret += [
136 'userid' => $uploader->getId(),
137 'user' => $uploader->getName(),
138 ];
139 }
140 $comment = $file->getDescription( ArchivedFile::FOR_THIS_USER, $user );
141 if ( $comment !== '' ) {
142 $ret += [
143 'comment' => $comment,
144 ];
145 }
146
147 return $ret;
148 }
149
150 public function lock() {
151 return $this->lockFile->acquireFileLock();
152 }
153
154 public function unlock() {
155 return $this->lockFile->releaseFileLock();
156 }
157}
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
This class represents the result of the API operations.
Definition ApiResult.php:36
Local file in the wiki's own database.
Definition LocalFile.php:69
getWidth( $page=1)
Return the width of the image.
getUploader(int $audience=self::FOR_PUBLIC, Authority $performer=null)
getSize()
Returns the size of the image file, in bytes.
getDescription( $audience=self::FOR_PUBLIC, Authority $performer=null)
getHeight( $page=1)
Return the height of the image.
Service locator for MediaWiki core services.
getLinkRenderer()
Returns an instance of LinkRenderer.
stdClass $row
The database result row.
List for revision table items for a single page.
Parent class for all special pages.
isDeleted( $field)
static initFile( $list, $row)
Create file object from $row sourced from $list.
getIdField()
Get the DB field name associated with the ID list.
getAuthorNameField()
Get the DB field name storing user names.
getApiData(ApiResult $result)
Get the return information about the revision for the API.
unlock()
Unlock the item against changes outside of the DB.
getTimestampField()
Get the DB field name storing timestamps.
setBits( $bits)
Set the visibility of the item.
__construct(RevisionListBase $list, $row)
getLink()
Get the link to the file.
lock()
Lock the item against changes outside of the DB.
getId()
Get the ID, as it would appear in the ids URL parameter.
getAuthorActorField()
Get the DB field name storing actor ids.
getAuthorIdField()
Get the DB field name storing user ids.
Item class for an oldimage table row.
RevDelFileList $list
canViewContent()
Returns true if the current user can view the item text/file.
OldLocalFile $file