MediaWiki  master
RevDelArchivedFileItem.php
Go to the documentation of this file.
1 <?php
24 
33  protected $lockFile;
34 
35  public function __construct( RevisionListBase $list, $row ) {
36  parent::__construct( $list, $row );
37  $this->lockFile = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
38  ->newFile( $row->fa_name );
39  }
40 
41  protected static function initFile( $list, $row ) {
43  }
44 
45  public function getIdField() {
46  return 'fa_id';
47  }
48 
49  public function getTimestampField() {
50  return 'fa_timestamp';
51  }
52 
53  public function getAuthorIdField() {
54  return 'fa_user';
55  }
56 
57  public function getAuthorNameField() {
58  return 'fa_user_text';
59  }
60 
61  public function getAuthorActorField() {
62  return 'fa_actor';
63  }
64 
65  public function getId() {
66  return $this->row->fa_id;
67  }
68 
69  public function setBits( $bits ) {
70  $dbw = wfGetDB( DB_PRIMARY );
71  $dbw->newUpdateQueryBuilder()
72  ->update( 'filearchive' )
73  ->set( [ 'fa_deleted' => $bits ] )
74  ->where( [
75  'fa_id' => $this->row->fa_id,
76  'fa_deleted' => $this->getBits(),
77  ] )
78  ->caller( __METHOD__ )->execute();
79 
80  return (bool)$dbw->affectedRows();
81  }
82 
83  protected function getLink() {
84  $date = $this->list->getLanguage()->userTimeAndDate(
85  $this->file->getTimestamp(), $this->list->getUser() );
86 
87  # Hidden files...
88  if ( !$this->canViewContent() ) {
89  $link = htmlspecialchars( $date );
90  } else {
91  $undelete = SpecialPage::getTitleFor( 'Undelete' );
92  $key = $this->file->getKey();
93  $link = $this->getLinkRenderer()->makeLink( $undelete, $date, [],
94  [
95  'target' => $this->list->getPageName(),
96  'file' => $key,
97  'token' => $this->list->getUser()->getEditToken( $key )
98  ]
99  );
100  }
101  if ( $this->isDeleted() ) {
102  $link = '<span class="history-deleted">' . $link . '</span>';
103  }
104 
105  return $link;
106  }
107 
108  public function getApiData( ApiResult $result ) {
109  $file = $this->file;
110  $user = $this->list->getUser();
111  $ret = [
112  'title' => $this->list->getPageName(),
113  'timestamp' => wfTimestamp( TS_ISO_8601, $file->getTimestamp() ),
114  'width' => $file->getWidth(),
115  'height' => $file->getHeight(),
116  'size' => $file->getSize(),
117  'userhidden' => (bool)$file->isDeleted( File::DELETED_USER ),
118  'commenthidden' => (bool)$file->isDeleted( File::DELETED_COMMENT ),
119  'contenthidden' => (bool)$this->isDeleted(),
120  ];
121  if ( $this->canViewContent() ) {
122  $ret += [
123  'url' => SpecialPage::getTitleFor( 'Revisiondelete' )->getLinkURL(
124  [
125  'target' => $this->list->getPageName(),
126  'file' => $file->getKey(),
127  'token' => $user->getEditToken( $file->getKey() )
128  ]
129  ),
130  ];
131  }
132  $uploader = $file->getUploader( ArchivedFile::FOR_THIS_USER, $user );
133  if ( $uploader ) {
134  $ret += [
135  'userid' => $uploader->getId(),
136  'user' => $uploader->getName(),
137  ];
138  }
139  $comment = $file->getDescription( ArchivedFile::FOR_THIS_USER, $user );
140  if ( $comment !== '' ) {
141  $ret += [
142  'comment' => $comment,
143  ];
144  }
145 
146  return $ret;
147  }
148 
149  public function lock() {
150  return $this->lockFile->acquireFileLock();
151  }
152 
153  public function unlock() {
154  return $this->lockFile->releaseFileLock();
155  }
156 }
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
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:35
const FOR_THIS_USER
static newFromRow( $row)
Loads a file object from the filearchive table.
const DELETED_COMMENT
Definition: File.php:75
const DELETED_USER
Definition: File.php:76
getWidth( $page=1)
Return the width of the image @stable to override.
Definition: LocalFile.php:908
getUploader(int $audience=self::FOR_PUBLIC, Authority $performer=null)
Definition: LocalFile.php:2414
getSize()
Returns the size of the image file, in bytes @stable to override.
Definition: LocalFile.php:1197
getDescription( $audience=self::FOR_PUBLIC, Authority $performer=null)
Definition: LocalFile.php:2431
getHeight( $page=1)
Return the height of the image @stable to override.
Definition: LocalFile.php:941
Service locator for MediaWiki core services.
Parent class for all special pages.
Definition: SpecialPage.php:66
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
stdClass $row
The database result row.
getLinkRenderer()
Returns an instance of LinkRenderer.
List for revision table items for a single page.
const DB_PRIMARY
Definition: defines.php:28