Fix hook situation for Skin::doEditSectionLink
[mediawiki.git] / includes / revisiondelete / RevDelFileItem.php
bloba6517fe9c7b603cf789aeef3a6465382a287e3b4
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
18 * @file
19 * @ingroup RevisionDelete
22 /**
23 * Item class for an oldimage table row
25 class RevDelFileItem extends RevDelItem {
26 /** @var File */
27 public $file;
29 public function __construct( $list, $row ) {
30 parent::__construct( $list, $row );
31 $this->file = RepoGroup::singleton()->getLocalRepo()->newFileFromRow( $row );
34 public function getIdField() {
35 return 'oi_archive_name';
38 public function getTimestampField() {
39 return 'oi_timestamp';
42 public function getAuthorIdField() {
43 return 'oi_user';
46 public function getAuthorNameField() {
47 return 'oi_user_text';
50 public function getId() {
51 $parts = explode( '!', $this->row->oi_archive_name );
53 return $parts[0];
56 public function canView() {
57 return $this->file->userCan( File::DELETED_RESTRICTED, $this->list->getUser() );
60 public function canViewContent() {
61 return $this->file->userCan( File::DELETED_FILE, $this->list->getUser() );
64 public function getBits() {
65 return $this->file->getVisibility();
68 public function setBits( $bits ) {
69 # Queue the file op
70 # @todo FIXME: Move to LocalFile.php
71 if ( $this->isDeleted() ) {
72 if ( $bits & File::DELETED_FILE ) {
73 # Still deleted
74 } else {
75 # Newly undeleted
76 $key = $this->file->getStorageKey();
77 $srcRel = $this->file->repo->getDeletedHashPath( $key ) . $key;
78 $this->list->storeBatch[] = array(
79 $this->file->repo->getVirtualUrl( 'deleted' ) . '/' . $srcRel,
80 'public',
81 $this->file->getRel()
83 $this->list->cleanupBatch[] = $key;
85 } elseif ( $bits & File::DELETED_FILE ) {
86 # Newly deleted
87 $key = $this->file->getStorageKey();
88 $dstRel = $this->file->repo->getDeletedHashPath( $key ) . $key;
89 $this->list->deleteBatch[] = array( $this->file->getRel(), $dstRel );
92 # Do the database operations
93 $dbw = wfGetDB( DB_MASTER );
94 $dbw->update( 'oldimage',
95 array( 'oi_deleted' => $bits ),
96 array(
97 'oi_name' => $this->row->oi_name,
98 'oi_timestamp' => $this->row->oi_timestamp,
99 'oi_deleted' => $this->getBits()
101 __METHOD__
104 return (bool)$dbw->affectedRows();
107 public function isDeleted() {
108 return $this->file->isDeleted( File::DELETED_FILE );
112 * Get the link to the file.
113 * Overridden by RevDelArchivedFileItem.
114 * @return string
116 protected function getLink() {
117 $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate(
118 $this->file->getTimestamp(), $this->list->getUser() ) );
120 if ( !$this->isDeleted() ) {
121 # Regular files...
122 return Html::rawElement( 'a', array( 'href' => $this->file->getUrl() ), $date );
125 # Hidden files...
126 if ( !$this->canViewContent() ) {
127 $link = $date;
128 } else {
129 $link = Linker::link(
130 SpecialPage::getTitleFor( 'Revisiondelete' ),
131 $date,
132 array(),
133 array(
134 'target' => $this->list->title->getPrefixedText(),
135 'file' => $this->file->getArchiveName(),
136 'token' => $this->list->getUser()->getEditToken(
137 $this->file->getArchiveName() )
142 return '<span class="history-deleted">' . $link . '</span>';
146 * Generate a user tool link cluster if the current user is allowed to view it
147 * @return string HTML
149 protected function getUserTools() {
150 if ( $this->file->userCan( Revision::DELETED_USER, $this->list->getUser() ) ) {
151 $uid = $this->file->getUser( 'id' );
152 $name = $this->file->getUser( 'text' );
153 $link = Linker::userLink( $uid, $name ) . Linker::userToolLinks( $uid, $name );
154 } else {
155 $link = $this->list->msg( 'rev-deleted-user' )->escaped();
157 if ( $this->file->isDeleted( Revision::DELETED_USER ) ) {
158 return '<span class="history-deleted">' . $link . '</span>';
161 return $link;
165 * Wrap and format the file's comment block, if the current
166 * user is allowed to view it.
168 * @return string HTML
170 protected function getComment() {
171 if ( $this->file->userCan( File::DELETED_COMMENT, $this->list->getUser() ) ) {
172 $block = Linker::commentBlock( $this->file->getDescription() );
173 } else {
174 $block = ' ' . $this->list->msg( 'rev-deleted-comment' )->escaped();
176 if ( $this->file->isDeleted( File::DELETED_COMMENT ) ) {
177 return "<span class=\"history-deleted\">$block</span>";
180 return $block;
183 public function getHTML() {
184 $data =
185 $this->list->msg( 'widthheight' )->numParams(
186 $this->file->getWidth(), $this->file->getHeight() )->text() .
187 ' (' . $this->list->msg( 'nbytes' )->numParams( $this->file->getSize() )->text() . ')';
189 return '<li>' . $this->getLink() . ' ' . $this->getUserTools() . ' ' .
190 $data . ' ' . $this->getComment() . '</li>';
193 public function getApiData( ApiResult $result ) {
194 $file = $this->file;
195 $user = $this->list->getUser();
196 $ret = array(
197 'title' => $this->list->title->getPrefixedText(),
198 'archivename' => $file->getArchiveName(),
199 'timestamp' => wfTimestamp( TS_ISO_8601, $file->getTimestamp() ),
200 'width' => $file->getWidth(),
201 'height' => $file->getHeight(),
202 'size' => $file->getSize(),
204 $ret += $file->isDeleted( Revision::DELETED_USER ) ? array( 'userhidden' => '' ) : array();
205 $ret += $file->isDeleted( Revision::DELETED_COMMENT ) ? array( 'commenthidden' => '' ) : array();
206 $ret += $this->isDeleted() ? array( 'contenthidden' => '' ) : array();
207 if ( !$this->isDeleted() ) {
208 $ret += array(
209 'url' => $file->getUrl(),
211 } elseif ( $this->canViewContent() ) {
212 $ret += array(
213 'url' => SpecialPage::getTitleFor( 'Revisiondelete' )->getLinkURL(
214 array(
215 'target' => $this->list->title->getPrefixedText(),
216 'file' => $file->getArchiveName(),
217 'token' => $user->getEditToken( $file->getArchiveName() )
219 false, PROTO_RELATIVE
223 if ( $file->userCan( Revision::DELETED_USER, $user ) ) {
224 $ret += array(
225 'userid' => $file->user,
226 'user' => $file->user_text,
229 if ( $file->userCan( Revision::DELETED_COMMENT, $user ) ) {
230 $ret += array(
231 'comment' => $file->description,
235 return $ret;