| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
use MediaWiki\Api\ApiResult; |
| 23 |
use MediaWiki\MediaWikiServices; |
| 24 |
use MediaWiki\RevisionList\RevisionListBase; |
| 25 |
use MediaWiki\SpecialPage\SpecialPage; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
class RevDelArchivedFileItem extends RevDelFileItem { |
| 34 |
|
| 35 |
protected $lockFile; |
| 36 |
|
| 37 |
public function __construct( RevisionListBase $list, $row ) { |
| 38 |
parent::__construct( $list, $row ); |
| 39 |
$this->lockFile = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo() |
| 40 |
->newFile( $row->fa_name ); |
| 41 |
} |
| 42 |
|
| 43 |
protected static function initFile( $list, $row ) { |
| 44 |
return ArchivedFile::newFromRow( $row ); |
| 45 |
} |
| 46 |
|
| 47 |
public function getIdField() { |
| 48 |
return 'fa_id'; |
| 49 |
} |
| 50 |
|
| 51 |
public function getTimestampField() { |
| 52 |
return 'fa_timestamp'; |
| 53 |
} |
| 54 |
|
| 55 |
public function getAuthorIdField() { |
| 56 |
return 'fa_user'; |
| 57 |
} |
| 58 |
|
| 59 |
public function getAuthorNameField() { |
| 60 |
return 'fa_user_text'; |
| 61 |
} |
| 62 |
|
| 63 |
public function getAuthorActorField() { |
| 64 |
return 'fa_actor'; |
| 65 |
} |
| 66 |
|
| 67 |
public function getId() { |
| 68 |
return $this->row->fa_id; |
| 69 |
} |
| 70 |
|
| 71 |
public function setBits( $bits ) { |
| 72 |
$dbw = $this->dbProvider->getPrimaryDatabase(); |
| 73 |
$dbw->newUpdateQueryBuilder() |
| 74 |
->update( 'filearchive' ) |
| 75 |
->set( [ 'fa_deleted' => $bits ] ) |
| 76 |
->where( [ |
| 77 |
'fa_id' => $this->row->fa_id, |
| 78 |
'fa_deleted' => $this->getBits(), |
| 79 |
] ) |
| 80 |
->caller( __METHOD__ )->execute(); |
| 81 |
|
| 82 |
return (bool)$dbw->affectedRows(); |
| 83 |
} |
| 84 |
|
| 85 |
protected function getLink() { |
| 86 |
$date = $this->list->getLanguage()->userTimeAndDate( |
| 87 |
$this->file->getTimestamp(), $this->list->getUser() ); |
| 88 |
|
| 89 |
|
| 90 |
if ( !$this->canViewContent() ) { |
| 91 |
$link = htmlspecialchars( $date ); |
| 92 |
} else { |
| 93 |
$undelete = SpecialPage::getTitleFor( 'Undelete' ); |
| 94 |
$key = $this->file->getKey(); |
| 95 |
$link = $this->getLinkRenderer()->makeLink( $undelete, $date, [], |
| 96 |
[ |
| 97 |
'target' => $this->list->getPageName(), |
| 98 |
'file' => $key, |
| 99 |
'token' => $this->list->getUser()->getEditToken( $key ) |
| 100 |
] |
| 101 |
); |
| 102 |
} |
| 103 |
if ( $this->isDeleted() ) { |
| 104 |
$link = '<span class="history-deleted">' . $link . '</span>'; |
| 105 |
} |
| 106 |
|
| 107 |
return $link; |
| 108 |
} |
| 109 |
|
| 110 |
public function getApiData( ApiResult $result ) { |
| 111 |
$file = $this->file; |
| 112 |
$user = $this->list->getUser(); |
| 113 |
$ret = [ |
| 114 |
'title' => $this->list->getPageName(), |
| 115 |
'timestamp' => wfTimestamp( TS_ISO_8601, $file->getTimestamp() ), |
| 116 |
'width' => $file->getWidth(), |
| 117 |
'height' => $file->getHeight(), |
| 118 |
'size' => $file->getSize(), |
| 119 |
'userhidden' => (bool)$file->isDeleted( File::DELETED_USER ), |
| 120 |
'commenthidden' => (bool)$file->isDeleted( File::DELETED_COMMENT ), |
| 121 |
'contenthidden' => (bool)$this->isDeleted(), |
| 122 |
]; |
| 123 |
if ( $this->canViewContent() ) { |
| 124 |
$ret += [ |
| 125 |
'url' => SpecialPage::getTitleFor( 'Revisiondelete' )->getLinkURL( |
| 126 |
[ |
| 127 |
'target' => $this->list->getPageName(), |
| 128 |
'file' => $file->getKey(), |
| 129 |
'token' => $user->getEditToken( $file->getKey() ) |
| 130 |
] |
| 131 |
), |
| 132 |
]; |
| 133 |
} |
| 134 |
$uploader = $file->getUploader( ArchivedFile::FOR_THIS_USER, $user ); |
| 135 |
if ( $uploader ) { |
| 136 |
$ret += [ |
| 137 |
'userid' => $uploader->getId(), |
| 138 |
'user' => $uploader->getName(), |
| 139 |
]; |
| 140 |
} |
| 141 |
$comment = $file->getDescription( ArchivedFile::FOR_THIS_USER, $user ); |
| 142 |
if ( $comment !== '' ) { |
| 143 |
$ret += [ |
| 144 |
'comment' => $comment, |
| 145 |
]; |
| 146 |
} |
| 147 |
|
| 148 |
return $ret; |
| 149 |
} |
| 150 |
|
| 151 |
public function lock() { |
| 152 |
return $this->lockFile->acquireFileLock(); |
| 153 |
} |
| 154 |
|
| 155 |
public function unlock() { |
| 156 |
return $this->lockFile->releaseFileLock(); |
| 157 |
} |
| 158 |
} |