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