From c1f9b1f7b1b77776192048005dcc66dcf3df2bfb Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 27 Dec 2014 15:41:37 +0100 Subject: Update to MediaWiki 1.24.1 --- includes/revisiondelete/RevDelFileItem.php | 237 +++++++++++++++++++++++++++++ 1 file changed, 237 insertions(+) create mode 100644 includes/revisiondelete/RevDelFileItem.php (limited to 'includes/revisiondelete/RevDelFileItem.php') diff --git a/includes/revisiondelete/RevDelFileItem.php b/includes/revisiondelete/RevDelFileItem.php new file mode 100644 index 00000000..a6517fe9 --- /dev/null +++ b/includes/revisiondelete/RevDelFileItem.php @@ -0,0 +1,237 @@ +file = RepoGroup::singleton()->getLocalRepo()->newFileFromRow( $row ); + } + + public function getIdField() { + return 'oi_archive_name'; + } + + public function getTimestampField() { + return 'oi_timestamp'; + } + + public function getAuthorIdField() { + return 'oi_user'; + } + + public function getAuthorNameField() { + return 'oi_user_text'; + } + + public function getId() { + $parts = explode( '!', $this->row->oi_archive_name ); + + return $parts[0]; + } + + public function canView() { + return $this->file->userCan( File::DELETED_RESTRICTED, $this->list->getUser() ); + } + + public function canViewContent() { + return $this->file->userCan( File::DELETED_FILE, $this->list->getUser() ); + } + + public function getBits() { + return $this->file->getVisibility(); + } + + public function setBits( $bits ) { + # Queue the file op + # @todo FIXME: Move to LocalFile.php + if ( $this->isDeleted() ) { + if ( $bits & File::DELETED_FILE ) { + # Still deleted + } else { + # Newly undeleted + $key = $this->file->getStorageKey(); + $srcRel = $this->file->repo->getDeletedHashPath( $key ) . $key; + $this->list->storeBatch[] = array( + $this->file->repo->getVirtualUrl( 'deleted' ) . '/' . $srcRel, + 'public', + $this->file->getRel() + ); + $this->list->cleanupBatch[] = $key; + } + } elseif ( $bits & File::DELETED_FILE ) { + # Newly deleted + $key = $this->file->getStorageKey(); + $dstRel = $this->file->repo->getDeletedHashPath( $key ) . $key; + $this->list->deleteBatch[] = array( $this->file->getRel(), $dstRel ); + } + + # Do the database operations + $dbw = wfGetDB( DB_MASTER ); + $dbw->update( 'oldimage', + array( 'oi_deleted' => $bits ), + array( + 'oi_name' => $this->row->oi_name, + 'oi_timestamp' => $this->row->oi_timestamp, + 'oi_deleted' => $this->getBits() + ), + __METHOD__ + ); + + return (bool)$dbw->affectedRows(); + } + + public function isDeleted() { + return $this->file->isDeleted( File::DELETED_FILE ); + } + + /** + * Get the link to the file. + * Overridden by RevDelArchivedFileItem. + * @return string + */ + protected function getLink() { + $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate( + $this->file->getTimestamp(), $this->list->getUser() ) ); + + if ( !$this->isDeleted() ) { + # Regular files... + return Html::rawElement( 'a', array( 'href' => $this->file->getUrl() ), $date ); + } + + # Hidden files... + if ( !$this->canViewContent() ) { + $link = $date; + } else { + $link = Linker::link( + SpecialPage::getTitleFor( 'Revisiondelete' ), + $date, + array(), + array( + 'target' => $this->list->title->getPrefixedText(), + 'file' => $this->file->getArchiveName(), + 'token' => $this->list->getUser()->getEditToken( + $this->file->getArchiveName() ) + ) + ); + } + + return '' . $link . ''; + } + + /** + * Generate a user tool link cluster if the current user is allowed to view it + * @return string HTML + */ + protected function getUserTools() { + if ( $this->file->userCan( Revision::DELETED_USER, $this->list->getUser() ) ) { + $uid = $this->file->getUser( 'id' ); + $name = $this->file->getUser( 'text' ); + $link = Linker::userLink( $uid, $name ) . Linker::userToolLinks( $uid, $name ); + } else { + $link = $this->list->msg( 'rev-deleted-user' )->escaped(); + } + if ( $this->file->isDeleted( Revision::DELETED_USER ) ) { + return '' . $link . ''; + } + + return $link; + } + + /** + * Wrap and format the file's comment block, if the current + * user is allowed to view it. + * + * @return string HTML + */ + protected function getComment() { + if ( $this->file->userCan( File::DELETED_COMMENT, $this->list->getUser() ) ) { + $block = Linker::commentBlock( $this->file->getDescription() ); + } else { + $block = ' ' . $this->list->msg( 'rev-deleted-comment' )->escaped(); + } + if ( $this->file->isDeleted( File::DELETED_COMMENT ) ) { + return "$block"; + } + + return $block; + } + + public function getHTML() { + $data = + $this->list->msg( 'widthheight' )->numParams( + $this->file->getWidth(), $this->file->getHeight() )->text() . + ' (' . $this->list->msg( 'nbytes' )->numParams( $this->file->getSize() )->text() . ')'; + + return '
  • ' . $this->getLink() . ' ' . $this->getUserTools() . ' ' . + $data . ' ' . $this->getComment() . '
  • '; + } + + public function getApiData( ApiResult $result ) { + $file = $this->file; + $user = $this->list->getUser(); + $ret = array( + 'title' => $this->list->title->getPrefixedText(), + 'archivename' => $file->getArchiveName(), + 'timestamp' => wfTimestamp( TS_ISO_8601, $file->getTimestamp() ), + 'width' => $file->getWidth(), + 'height' => $file->getHeight(), + 'size' => $file->getSize(), + ); + $ret += $file->isDeleted( Revision::DELETED_USER ) ? array( 'userhidden' => '' ) : array(); + $ret += $file->isDeleted( Revision::DELETED_COMMENT ) ? array( 'commenthidden' => '' ) : array(); + $ret += $this->isDeleted() ? array( 'contenthidden' => '' ) : array(); + if ( !$this->isDeleted() ) { + $ret += array( + 'url' => $file->getUrl(), + ); + } elseif ( $this->canViewContent() ) { + $ret += array( + 'url' => SpecialPage::getTitleFor( 'Revisiondelete' )->getLinkURL( + array( + 'target' => $this->list->title->getPrefixedText(), + 'file' => $file->getArchiveName(), + 'token' => $user->getEditToken( $file->getArchiveName() ) + ), + false, PROTO_RELATIVE + ), + ); + } + if ( $file->userCan( Revision::DELETED_USER, $user ) ) { + $ret += array( + 'userid' => $file->user, + 'user' => $file->user_text, + ); + } + if ( $file->userCan( Revision::DELETED_COMMENT, $user ) ) { + $ret += array( + 'comment' => $file->description, + ); + } + + return $ret; + } +} -- cgit v1.2.3-54-g00ecf