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_MASTER );
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->title->getPrefixedText(),
156  'file' => $this->file->getArchiveName(),
157  'token' => $this->list->getUser()->getEditToken(
158  $this->file->getArchiveName() )
159  ]
160  );
161  }
162 
163  return '<span class="history-deleted">' . $link . '</span>';
164  }
165 
170  protected function getUserTools() {
171  if ( $this->file->userCan( RevisionRecord::DELETED_USER, $this->list->getUser() ) ) {
172  $uid = $this->file->getUser( 'id' );
173  $name = $this->file->getUser( 'text' );
174  $link = Linker::userLink( $uid, $name ) . Linker::userToolLinks( $uid, $name );
175  } else {
176  $link = $this->list->msg( 'rev-deleted-user' )->escaped();
177  }
178  if ( $this->file->isDeleted( RevisionRecord::DELETED_USER ) ) {
179  return '<span class="history-deleted">' . $link . '</span>';
180  }
181 
182  return $link;
183  }
184 
191  protected function getComment() {
192  if ( $this->file->userCan( File::DELETED_COMMENT, $this->list->getUser() ) ) {
193  $block = Linker::commentBlock( $this->file->getDescription() );
194  } else {
195  $block = ' ' . $this->list->msg( 'rev-deleted-comment' )->escaped();
196  }
197  if ( $this->file->isDeleted( File::DELETED_COMMENT ) ) {
198  return "<span class=\"history-deleted\">$block</span>";
199  }
200 
201  return $block;
202  }
203 
204  public function getHTML() {
205  $data =
206  $this->list->msg( 'widthheight' )->numParams(
207  $this->file->getWidth(), $this->file->getHeight() )->text() .
208  ' (' . $this->list->msg( 'nbytes' )->numParams( $this->file->getSize() )->text() . ')';
209 
210  return '<li>' . $this->getLink() . ' ' . $this->getUserTools() . ' ' .
211  $data . ' ' . $this->getComment() . '</li>';
212  }
213 
214  public function getApiData( ApiResult $result ) {
215  $file = $this->file;
216  $user = $this->list->getUser();
217  $ret = [
218  'title' => $this->list->title->getPrefixedText(),
219  'archivename' => $file->getArchiveName(),
220  'timestamp' => wfTimestamp( TS_ISO_8601, $file->getTimestamp() ),
221  'width' => $file->getWidth(),
222  'height' => $file->getHeight(),
223  'size' => $file->getSize(),
224  'userhidden' => (bool)$file->isDeleted( RevisionRecord::DELETED_USER ),
225  'commenthidden' => (bool)$file->isDeleted( RevisionRecord::DELETED_COMMENT ),
226  'contenthidden' => (bool)$this->isDeleted(),
227  ];
228  if ( !$this->isDeleted() ) {
229  $ret += [
230  'url' => $file->getUrl(),
231  ];
232  } elseif ( $this->canViewContent() ) {
233  $ret += [
234  'url' => SpecialPage::getTitleFor( 'Revisiondelete' )->getLinkURL(
235  [
236  'target' => $this->list->title->getPrefixedText(),
237  'file' => $file->getArchiveName(),
238  'token' => $user->getEditToken( $file->getArchiveName() )
239  ]
240  ),
241  ];
242  }
243  if ( $file->userCan( RevisionRecord::DELETED_USER, $user ) ) {
244  $ret += [
245  'userid' => $file->getUser( 'id' ),
246  'user' => $file->getUser( 'text' ),
247  ];
248  }
249  if ( $file->userCan( RevisionRecord::DELETED_COMMENT, $user ) ) {
250  $ret += [
251  'comment' => $file->getDescription( LocalFile::RAW ),
252  ];
253  }
254 
255  return $ret;
256  }
257 
258  public function lock() {
259  return $this->file->acquireFileLock();
260  }
261 
262  public function unlock() {
263  return $this->file->releaseFileLock();
264  }
265 }
RevDelFileItem\$file
OldLocalFile $file
Definition: RevDelFileItem.php:32
Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:46
RevDelFileItem\getApiData
getApiData(ApiResult $result)
Get the return information about the revision for the API.
Definition: RevDelFileItem.php:214
LocalFile\getTimestamp
getTimestamp()
Stable to override.
Definition: LocalFile.php:2227
RevDelFileItem\getAuthorIdField
getAuthorIdField()
Get the DB field name storing user ids.
Definition: RevDelFileItem.php:59
LocalFile\getUser
getUser( $type='text')
Returns user who uploaded the file @stable to override.
Definition: LocalFile.php:893
Linker\userLink
static userLink( $userId, $userName, $altUserName=false)
Make user link (or user contributions for unregistered users)
Definition: Linker.php:896
RevisionListBase
List for revision table items for a single page.
Definition: RevisionListBase.php:29
File\DELETED_RESTRICTED
const DELETED_RESTRICTED
Definition: File.php:70
File\RAW
const RAW
Definition: File.php:85
OldLocalFile\isDeleted
isDeleted( $field)
Definition: OldLocalFile.php:362
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:160
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1815
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:941
RevDelFileItem\lock
lock()
Lock the item against changes outside of the DB.
Definition: RevDelFileItem.php:258
File\getUrl
getUrl()
Return the URL of the file Stable to override.
Definition: File.php:368
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 @stable to override.
Definition: LocalFile.php:967
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:92
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:68
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:262
RevisionItemBase\getLinkRenderer
getLinkRenderer()
Returns an instance of LinkRenderer.
Definition: RevisionItemBase.php:174
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2475
RevDelFileItem\isDeleted
isDeleted()
Definition: RevDelFileItem.php:128
DB_MASTER
const DB_MASTER
Definition: defines.php:26
RevDelFileItem\getComment
getComment()
Wrap and format the file's comment block, if the current user is allowed to view it.
Definition: RevDelFileItem.php:191
RevDelFileItem\getHTML
getHTML()
Get the HTML of the list item.
Definition: RevDelFileItem.php:204
LocalFile\getDescription
getDescription( $audience=self::FOR_PUBLIC, User $user=null)
Stable to override.
Definition: LocalFile.php:2210
RevDelFileItem\getUserTools
getUserTools()
Generate a user tool link cluster if the current user is allowed to view it.
Definition: RevDelFileItem.php:170
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:1574
RevisionItemBase\$row
$row
The database result row.
Definition: RevisionItemBase.php:33
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
OldLocalFile\userCan
userCan( $field, User $user=null)
Determine if the current user is allowed to view a particular field of this image file,...
Definition: OldLocalFile.php:386
RevDelFileItem\getId
getId()
Get the ID, as it would appear in the ids URL parameter.
Definition: RevDelFileItem.php:71
RevDelFileItem\$list
RevDelFileList $list
Definition: RevDelFileItem.php:30
RevDelFileList
List for oldimage table items.
Definition: RevDelFileList.php:28
File\DELETED_FILE
const DELETED_FILE
Definition: File.php:67
LocalFile\getWidth
getWidth( $page=1)
Return the width of the image @stable to override.
Definition: LocalFile.php:826
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:231
LocalFile\getHeight
getHeight( $page=1)
Return the height of the image @stable to override.
Definition: LocalFile.php:859
OldLocalFile\getArchiveName
getArchiveName()
Stable to override.
Definition: OldLocalFile.php:194
OldLocalFile
Class to represent a file in the oldimage table.
Definition: OldLocalFile.php:33
RevDelItem
Abstract base class for deletable items.
Definition: RevDelItem.php:25