X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/includes/page/ImageHistoryList.php diff --git a/includes/page/ImageHistoryList.php b/includes/page/ImageHistoryList.php new file mode 100644 index 00000000..bb8ed242 --- /dev/null +++ b/includes/page/ImageHistoryList.php @@ -0,0 +1,326 @@ +current = $imagePage->getPage()->getFile(); + $this->img = $imagePage->getDisplayedFile(); + $this->title = $imagePage->getTitle(); + $this->imagePage = $imagePage; + $this->showThumb = $wgShowArchiveThumbnails && $this->img->canRender(); + $this->setContext( $imagePage->getContext() ); + } + + /** + * @return ImagePage + */ + public function getImagePage() { + return $this->imagePage; + } + + /** + * @return File + */ + public function getFile() { + return $this->img; + } + + /** + * @param string $navLinks + * @return string + */ + public function beginImageHistoryList( $navLinks = '' ) { + return Xml::element( 'h2', [ 'id' => 'filehistory' ], $this->msg( 'filehist' )->text() ) + . "\n" + . "
\n" + . $this->msg( 'filehist-help' )->parseAsBlock() + . $navLinks . "\n" + . Xml::openElement( 'table', [ 'class' => 'wikitable filehistory' ] ) . "\n" + . '' + . ( $this->current->isLocal() + && ( $this->getUser()->isAllowedAny( 'delete', 'deletedhistory' ) ) ? '' : '' ) + . '' . $this->msg( 'filehist-datetime' )->escaped() . '' + . ( $this->showThumb ? '' . $this->msg( 'filehist-thumb' )->escaped() . '' : '' ) + . '' . $this->msg( 'filehist-dimensions' )->escaped() . '' + . '' . $this->msg( 'filehist-user' )->escaped() . '' + . '' . $this->msg( 'filehist-comment' )->escaped() . '' + . "\n"; + } + + /** + * @param string $navLinks + * @return string + */ + public function endImageHistoryList( $navLinks = '' ) { + return "\n$navLinks\n
\n"; + } + + /** + * @param bool $iscur + * @param File $file + * @return string + */ + public function imageHistoryLine( $iscur, $file ) { + global $wgContLang; + + $user = $this->getUser(); + $lang = $this->getLanguage(); + $timestamp = wfTimestamp( TS_MW, $file->getTimestamp() ); + $img = $iscur ? $file->getName() : $file->getArchiveName(); + $userId = $file->getUser( 'id' ); + $userText = $file->getUser( 'text' ); + $description = $file->getDescription( File::FOR_THIS_USER, $user ); + + $local = $this->current->isLocal(); + $row = $selected = ''; + + // Deletion link + if ( $local && ( $user->isAllowedAny( 'delete', 'deletedhistory' ) ) ) { + $row .= ''; + # Link to remove from history + if ( $user->isAllowed( 'delete' ) ) { + $q = [ 'action' => 'delete' ]; + if ( !$iscur ) { + $q['oldimage'] = $img; + } + $row .= Linker::linkKnown( + $this->title, + $this->msg( $iscur ? 'filehist-deleteall' : 'filehist-deleteone' )->escaped(), + [], $q + ); + } + # Link to hide content. Don't show useless link to people who cannot hide revisions. + $canHide = $user->isAllowed( 'deleterevision' ); + if ( $canHide || ( $user->isAllowed( 'deletedhistory' ) && $file->getVisibility() ) ) { + if ( $user->isAllowed( 'delete' ) ) { + $row .= '
'; + } + // If file is top revision or locked from this user, don't link + if ( $iscur || !$file->userCan( File::DELETED_RESTRICTED, $user ) ) { + $del = Linker::revDeleteLinkDisabled( $canHide ); + } else { + list( $ts, ) = explode( '!', $img, 2 ); + $query = [ + 'type' => 'oldimage', + 'target' => $this->title->getPrefixedText(), + 'ids' => $ts, + ]; + $del = Linker::revDeleteLink( $query, + $file->isDeleted( File::DELETED_RESTRICTED ), $canHide ); + } + $row .= $del; + } + $row .= ''; + } + + // Reversion link/current indicator + $row .= ''; + if ( $iscur ) { + $row .= $this->msg( 'filehist-current' )->escaped(); + } elseif ( $local && $this->title->quickUserCan( 'edit', $user ) + && $this->title->quickUserCan( 'upload', $user ) + ) { + if ( $file->isDeleted( File::DELETED_FILE ) ) { + $row .= $this->msg( 'filehist-revert' )->escaped(); + } else { + $row .= Linker::linkKnown( + $this->title, + $this->msg( 'filehist-revert' )->escaped(), + [], + [ + 'action' => 'revert', + 'oldimage' => $img, + ] + ); + } + } + $row .= ''; + + // Date/time and image link + if ( $file->getTimestamp() === $this->img->getTimestamp() ) { + $selected = "class='filehistory-selected'"; + } + $row .= ""; + if ( !$file->userCan( File::DELETED_FILE, $user ) ) { + # Don't link to unviewable files + $row .= '' + . $lang->userTimeAndDate( $timestamp, $user ) . ''; + } elseif ( $file->isDeleted( File::DELETED_FILE ) ) { + if ( $local ) { + $this->preventClickjacking(); + $revdel = SpecialPage::getTitleFor( 'Revisiondelete' ); + # Make a link to review the image + $url = Linker::linkKnown( + $revdel, + $lang->userTimeAndDate( $timestamp, $user ), + [], + [ + 'target' => $this->title->getPrefixedText(), + 'file' => $img, + 'token' => $user->getEditToken( $img ) + ] + ); + } else { + $url = $lang->userTimeAndDate( $timestamp, $user ); + } + $row .= '' . $url . ''; + } elseif ( !$file->exists() ) { + $row .= '' + . $lang->userTimeAndDate( $timestamp, $user ) . ''; + } else { + $url = $iscur ? $this->current->getUrl() : $this->current->getArchiveUrl( $img ); + $row .= Xml::element( + 'a', + [ 'href' => $url ], + $lang->userTimeAndDate( $timestamp, $user ) + ); + } + $row .= ""; + + // Thumbnail + if ( $this->showThumb ) { + $row .= '' . $this->getThumbForLine( $file ) . ''; + } + + // Image dimensions + size + $row .= ''; + $row .= htmlspecialchars( $file->getDimensionsString() ); + $row .= $this->msg( 'word-separator' )->escaped(); + $row .= ''; + $row .= $this->msg( 'parentheses' )->sizeParams( $file->getSize() )->escaped(); + $row .= ''; + $row .= ''; + + // Uploading user + $row .= ''; + // Hide deleted usernames + if ( $file->isDeleted( File::DELETED_USER ) ) { + $row .= '' + . $this->msg( 'rev-deleted-user' )->escaped() . ''; + } else { + if ( $local ) { + $row .= Linker::userLink( $userId, $userText ); + $row .= ''; + $row .= Linker::userToolLinks( $userId, $userText ); + $row .= ''; + } else { + $row .= htmlspecialchars( $userText ); + } + } + $row .= ''; + + // Don't show deleted descriptions + if ( $file->isDeleted( File::DELETED_COMMENT ) ) { + $row .= '' . + $this->msg( 'rev-deleted-comment' )->escaped() . ''; + } else { + $row .= '' . + Linker::formatComment( $description, $this->title ) . ''; + } + + $rowClass = null; + Hooks::run( 'ImagePageFileHistoryLine', [ $this, $file, &$row, &$rowClass ] ); + $classAttr = $rowClass ? " class='$rowClass'" : ''; + + return "{$row}\n"; + } + + /** + * @param File $file + * @return string + */ + protected function getThumbForLine( $file ) { + $lang = $this->getLanguage(); + $user = $this->getUser(); + if ( $file->allowInlineDisplay() && $file->userCan( File::DELETED_FILE, $user ) + && !$file->isDeleted( File::DELETED_FILE ) + ) { + $params = [ + 'width' => '120', + 'height' => '120', + ]; + $timestamp = wfTimestamp( TS_MW, $file->getTimestamp() ); + + $thumbnail = $file->transform( $params ); + $options = [ + 'alt' => $this->msg( 'filehist-thumbtext', + $lang->userTimeAndDate( $timestamp, $user ), + $lang->userDate( $timestamp, $user ), + $lang->userTime( $timestamp, $user ) )->text(), + 'file-link' => true, + ]; + + if ( !$thumbnail ) { + return $this->msg( 'filehist-nothumb' )->escaped(); + } + + return $thumbnail->toHtml( $options ); + } else { + return $this->msg( 'filehist-nothumb' )->escaped(); + } + } + + /** + * @param bool $enable + */ + protected function preventClickjacking( $enable = true ) { + $this->preventClickjacking = $enable; + } + + /** + * @return bool + */ + public function getPreventClickjacking() { + return $this->preventClickjacking; + } +}