MediaWiki  master
RevDelFileItem.php
Go to the documentation of this file.
1 <?php
24 
28 class RevDelFileItem extends RevDelItem {
30  protected $list;
32  protected $file;
33 
34  public function __construct( RevisionListBase $list, $row ) {
35  parent::__construct( $list, $row );
36  $this->file = static::initFile( $list, $row );
37  }
38 
46  protected static function initFile( $list, $row ) {
47  return MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
48  ->newFileFromRow( $row );
49  }
50 
51  public function getIdField() {
52  return 'oi_archive_name';
53  }
54 
55  public function getTimestampField() {
56  return 'oi_timestamp';
57  }
58 
59  public function getAuthorIdField() {
60  return 'oi_user';
61  }
62 
63  public function getAuthorNameField() {
64  return 'oi_user_text';
65  }
66 
67  public function getAuthorActorField() {
68  return 'oi_actor';
69  }
70 
71  public function getId() {
72  $parts = explode( '!', $this->row->oi_archive_name );
73 
74  return $parts[0];
75  }
76 
77  public function canView() {
78  return $this->file->userCan( File::DELETED_RESTRICTED, $this->list->getUser() );
79  }
80 
81  public function canViewContent() {
82  return $this->file->userCan( File::DELETED_FILE, $this->list->getUser() );
83  }
84 
85  public function getBits() {
86  return $this->file->getVisibility();
87  }
88 
89  public function setBits( $bits ) {
90  # Queue the file op
91  # @todo FIXME: Move to LocalFile.php
92  if ( $this->isDeleted() ) {
93  if ( $bits & File::DELETED_FILE ) {
94  # Still deleted
95  } else {
96  # Newly undeleted
97  $key = $this->file->getStorageKey();
98  $srcRel = $this->file->repo->getDeletedHashPath( $key ) . $key;
99  $this->list->storeBatch[] = [
100  $this->file->repo->getVirtualUrl( 'deleted' ) . '/' . $srcRel,
101  'public',
102  $this->file->getRel()
103  ];
104  $this->list->cleanupBatch[] = $key;
105  }
106  } elseif ( $bits & File::DELETED_FILE ) {
107  # Newly deleted
108  $key = $this->file->getStorageKey();
109  $dstRel = $this->file->repo->getDeletedHashPath( $key ) . $key;
110  $this->list->deleteBatch[] = [ $this->file->getRel(), $dstRel ];
111  }
112 
113  # Do the database operations
114  $dbw = wfGetDB( DB_PRIMARY );
115  $dbw->update( 'oldimage',
116  [ 'oi_deleted' => $bits ],
117  [
118  'oi_name' => $this->row->oi_name,
119  'oi_timestamp' => $this->row->oi_timestamp,
120  'oi_deleted' => $this->getBits()
121  ],
122  __METHOD__
123  );
124 
125  return (bool)$dbw->affectedRows();
126  }
127 
128  public function isDeleted() {
129  return $this->file->isDeleted( File::DELETED_FILE );
130  }
131 
137  protected function getLink() {
138  $date = $this->list->getLanguage()->userTimeAndDate(
139  $this->file->getTimestamp(), $this->list->getUser() );
140 
141  if ( !$this->isDeleted() ) {
142  # Regular files...
143  return Html::element( 'a', [ 'href' => $this->file->getUrl() ], $date );
144  }
145 
146  # Hidden files...
147  if ( !$this->canViewContent() ) {
148  $link = htmlspecialchars( $date );
149  } else {
150  $link = $this->getLinkRenderer()->makeLink(
151  SpecialPage::getTitleFor( 'Revisiondelete' ),
152  $date,
153  [],
154  [
155  'target' => $this->list->getPageName(),
156  'file' => $this->file->getArchiveName(),
157  'token' => $this->list->getCsrfTokenSet()
158  ->getToken( $this->file->getArchiveName() )
159  ->toString(),
160  ]
161  );
162  }
163 
164  return '<span class="history-deleted">' . $link . '</span>';
165  }
166 
171  protected function getUserTools() {
172  $uploader = $this->file->getUploader( File::FOR_THIS_USER, $this->list->getAuthority() );
173  if ( $uploader ) {
174  $link = Linker::userLink( $uploader->getId(), $uploader->getName() ) .
175  Linker::userToolLinks( $uploader->getId(), $uploader->getName() );
176  return $link;
177  } else {
178  $link = $this->list->msg( 'rev-deleted-user' )->escaped();
179  }
180  if ( $this->file->isDeleted( File::DELETED_USER ) ) {
181  return '<span class="history-deleted">' . $link . '</span>';
182  }
183  return $link;
184  }
185 
192  protected function getComment() {
193  if ( $this->file->userCan( File::DELETED_COMMENT, $this->list->getUser() ) ) {
194  $block = Linker::commentBlock( $this->file->getDescription() );
195  } else {
196  $block = ' ' . $this->list->msg( 'rev-deleted-comment' )->escaped();
197  }
198  if ( $this->file->isDeleted( File::DELETED_COMMENT ) ) {
199  return "<span class=\"history-deleted\">$block</span>";
200  }
201 
202  return $block;
203  }
204 
205  public function getHTML() {
206  $data =
207  $this->list->msg( 'widthheight' )->numParams(
208  $this->file->getWidth(), $this->file->getHeight() )->text() .
209  ' (' . $this->list->msg( 'nbytes' )->numParams( $this->file->getSize() )->text() . ')';
210 
211  return '<li>' . $this->getLink() . ' ' . $this->getUserTools() . ' ' .
212  $data . ' ' . $this->getComment() . '</li>';
213  }
214 
215  public function getApiData( ApiResult $result ) {
216  $file = $this->file;
217  $user = $this->list->getUser();
218  $ret = [
219  'title' => $this->list->getPageName(),
220  'archivename' => $file->getArchiveName(),
221  'timestamp' => wfTimestamp( TS_ISO_8601, $file->getTimestamp() ),
222  'width' => $file->getWidth(),
223  'height' => $file->getHeight(),
224  'size' => $file->getSize(),
225  'userhidden' => (bool)$file->isDeleted( RevisionRecord::DELETED_USER ),
226  'commenthidden' => (bool)$file->isDeleted( RevisionRecord::DELETED_COMMENT ),
227  'contenthidden' => (bool)$this->isDeleted(),
228  ];
229  if ( !$this->isDeleted() ) {
230  $ret += [
231  'url' => $file->getUrl(),
232  ];
233  } elseif ( $this->canViewContent() ) {
234  $ret += [
235  'url' => SpecialPage::getTitleFor( 'Revisiondelete' )->getLinkURL(
236  [
237  'target' => $this->list->getPageName(),
238  'file' => $file->getArchiveName(),
239  'token' => $this->list->getCsrfTokenSet()
240  ->getToken( $file->getArchiveName() )
241  ->toString(),
242  ]
243  ),
244  ];
245  }
246  $uploader = $file->getUploader( File::FOR_THIS_USER, $user );
247  if ( $uploader ) {
248  $ret += [
249  'userid' => $uploader->getId(),
250  'user' => $uploader->getName(),
251  ];
252  }
253  $comment = $file->getDescription( File::FOR_THIS_USER, $user );
254  if ( $comment ) {
255  $ret += [
256  'comment' => $comment,
257  ];
258  }
259 
260  return $ret;
261  }
262 
263  public function lock() {
264  return $this->file->acquireFileLock();
265  }
266 
267  public function unlock() {
268  return $this->file->releaseFileLock();
269  }
270 }
RevDelFileItem\$file
OldLocalFile $file
Definition: RevDelFileItem.php:32
MediaWiki\Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:47
File\DELETED_USER
const DELETED_USER
Definition: File.php:72
RevDelFileItem\getApiData
getApiData(ApiResult $result)
Get the return information about the revision for the API.
Definition: RevDelFileItem.php:215
LocalFile\getTimestamp
getTimestamp()
Definition: LocalFile.php:2603
RevDelFileItem\getAuthorIdField
getAuthorIdField()
Get the DB field name storing user ids.
Definition: RevDelFileItem.php:59
Linker\userLink
static userLink( $userId, $userName, $altUserName=false)
Make user link (or user contributions for unregistered users)
Definition: Linker.php:1068
RevisionListBase
List for revision table items for a single page.
Definition: RevisionListBase.php:30
File\DELETED_RESTRICTED
const DELETED_RESTRICTED
Definition: File.php:73
OldLocalFile\isDeleted
isDeleted( $field)
Definition: OldLocalFile.php:391
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:186
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1692
Linker\userToolLinks
static userToolLinks( $userId, $userText, $redContribsWhenNoEdits=false, $flags=0, $edits=null, $useParentheses=true)
Generate standard user tool links (talk, contributions, block link, etc.)
Definition: Linker.php:1113
RevDelFileItem\lock
lock()
Lock the item against changes outside of the DB.
Definition: RevDelFileItem.php:263
File\getUser
getUser( $type='text')
Returns ID or name of user who uploaded the file STUB.
Definition: File.php:614
File\getUrl
getUrl()
Return the URL of the file.
Definition: File.php:383
RevDelFileItem\getIdField
getIdField()
Get the DB field name associated with the ID list.
Definition: RevDelFileItem.php:51
RevDelFileItem\getTimestampField
getTimestampField()
Get the DB field name storing timestamps.
Definition: RevDelFileItem.php:55
LocalFile\getSize
getSize()
Returns the size of the image file, in bytes.
Definition: LocalFile.php:1340
SpecialPage\getTitleFor
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
Definition: SpecialPage.php:107
RevDelFileItem\__construct
__construct(RevisionListBase $list, $row)
Definition: RevDelFileItem.php:34
RevDelFileItem\initFile
static initFile( $list, $row)
Create file object from $row sourced from $list.
Definition: RevDelFileItem.php:46
RevDelFileItem\setBits
setBits( $bits)
Set the visibility of the item.
Definition: RevDelFileItem.php:89
RevDelFileItem\getAuthorActorField
getAuthorActorField()
Get the DB field name storing actor ids.
Definition: RevDelFileItem.php:67
RevDelFileItem\getAuthorNameField
getAuthorNameField()
Get the DB field name storing user names.
Definition: RevDelFileItem.php:63
File\DELETED_COMMENT
const DELETED_COMMENT
Definition: File.php:71
ApiResult
This class represents the result of the API operations.
Definition: ApiResult.php:35
RevDelFileItem\unlock
unlock()
Unlock the item against changes outside of the DB.
Definition: RevDelFileItem.php:267
RevisionItemBase\getLinkRenderer
getLinkRenderer()
Returns an instance of LinkRenderer.
Definition: RevisionItemBase.php:178
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2226
RevDelFileItem\isDeleted
isDeleted()
Definition: RevDelFileItem.php:128
File\FOR_THIS_USER
const FOR_THIS_USER
Definition: File.php:87
RevDelFileItem\getComment
getComment()
Wrap and format the file's comment block, if the current user is allowed to view it.
Definition: RevDelFileItem.php:192
RevDelFileItem\getHTML
getHTML()
Get the HTML of the list item.
Definition: RevDelFileItem.php:205
RevDelFileItem\getUserTools
getUserTools()
Generate a user tool link cluster if the current user is allowed to view it.
Definition: RevDelFileItem.php:171
RevDelFileItem\canViewContent
canViewContent()
Returns true if the current user can view the item text/file.
Definition: RevDelFileItem.php:81
RevDelFileItem\getBits
getBits()
Get the current deletion bitfield value.
Definition: RevDelFileItem.php:85
Linker\commentBlock
static commentBlock( $comment, $title=null, $local=false, $wikiId=null, $useParentheses=true)
Wrap a comment in standard punctuation and formatting if it's non-empty, otherwise return empty strin...
Definition: Linker.php:1751
DB_PRIMARY
const DB_PRIMARY
Definition: defines.php:27
RevDelFileItem
Item class for an oldimage table row.
Definition: RevDelFileItem.php:28
RevDelFileItem\getLink
getLink()
Get the link to the file.
Definition: RevDelFileItem.php:137
RevDelFileItem\canView
canView()
Returns true if the current user can view the item.
Definition: RevDelFileItem.php:77
LocalFile\getDescription
getDescription( $audience=self::FOR_PUBLIC, Authority $performer=null)
Definition: LocalFile.php:2588
RevDelFileItem\getId
getId()
Get the ID, as it would appear in the ids URL parameter.
Definition: RevDelFileItem.php:71
LocalFile\getUploader
getUploader(int $audience=self::FOR_PUBLIC, Authority $performer=null)
Definition: LocalFile.php:2571
RevDelFileItem\$list
RevDelFileList $list
Definition: RevDelFileItem.php:30
RevDelFileList
List for oldimage table items.
Definition: RevDelFileList.php:29
File\DELETED_FILE
const DELETED_FILE
Definition: File.php:70
LocalFile\getWidth
getWidth( $page=1)
Return the width of the image @stable to override.
Definition: LocalFile.php:968
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:232
RevisionItemBase\$row
stdClass $row
The database result row.
Definition: RevisionItemBase.php:34
LocalFile\getHeight
getHeight( $page=1)
Return the height of the image @stable to override.
Definition: LocalFile.php:1001
OldLocalFile\getArchiveName
getArchiveName()
Definition: OldLocalFile.php:217
OldLocalFile
Class to represent a file in the oldimage table.
Definition: OldLocalFile.php:35
RevDelItem
Abstract base class for deletable items.
Definition: RevDelItem.php:25