1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
|
<?php
/**
* Holders of revision list for a single page
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
*/
namespace MediaWiki\RevisionList;
use MediaWiki\Context\RequestContext;
use MediaWiki\Linker\Linker;
use MediaWiki\MediaWikiServices;
use MediaWiki\Revision\RevisionRecord;
/**
* Item class for a live revision table row
*/
class RevisionItem extends RevisionItemBase {
/** @var RevisionRecord */
protected $revisionRecord;
/** @var RequestContext */
protected $context;
/** @inheritDoc */
public function __construct( RevisionListBase $list, $row ) {
parent::__construct( $list, $row );
$this->revisionRecord = MediaWikiServices::getInstance()
->getRevisionFactory()
->newRevisionFromRow( $row );
$this->context = $list->getContext();
}
/**
* Get the RevisionRecord for the item
*
* @return RevisionRecord
*/
protected function getRevisionRecord(): RevisionRecord {
return $this->revisionRecord;
}
/** @inheritDoc */
public function getIdField() {
return 'rev_id';
}
/** @inheritDoc */
public function getTimestampField() {
return 'rev_timestamp';
}
/** @inheritDoc */
public function getAuthorIdField() {
return 'rev_user';
}
/** @inheritDoc */
public function getAuthorNameField() {
return 'rev_user_text';
}
/** @inheritDoc */
public function canView() {
return $this->getRevisionRecord()->userCan(
RevisionRecord::DELETED_RESTRICTED,
$this->context->getAuthority()
);
}
/** @inheritDoc */
public function canViewContent() {
return $this->getRevisionRecord()->userCan(
RevisionRecord::DELETED_TEXT,
$this->context->getAuthority()
);
}
/**
* @return bool
*/
public function isDeleted() {
return $this->getRevisionRecord()->isDeleted( RevisionRecord::DELETED_TEXT );
}
/**
* Get the HTML link to the revision text.
* @todo Essentially a copy of RevDelRevisionItem::getRevisionLink. That class
* should inherit from this one, and implement an appropriate interface instead
* of extending RevDelItem
* @return string HTML
*/
protected function getRevisionLink() {
$revRecord = $this->getRevisionRecord();
$date = $this->list->getLanguage()->userTimeAndDate(
$revRecord->getTimestamp(), $this->list->getUser() );
if ( $this->isDeleted() && !$this->canViewContent() ) {
return htmlspecialchars( $date );
}
$linkRenderer = $this->getLinkRenderer();
return $linkRenderer->makeKnownLink(
$this->list->getPage(),
$date,
[],
[
'oldid' => $revRecord->getId(),
'unhide' => 1
]
);
}
/**
* Get the HTML link to the diff.
* @todo Essentially a copy of RevDelRevisionItem::getDiffLink. That class
* should inherit from this one, and implement an appropriate interface instead
* of extending RevDelItem
* @return string HTML
*/
protected function getDiffLink() {
if ( $this->isDeleted() && !$this->canViewContent() ) {
return $this->context->msg( 'diff' )->escaped();
} else {
$linkRenderer = $this->getLinkRenderer();
return $linkRenderer->makeKnownLink(
$this->list->getPage(),
$this->list->msg( 'diff' )->text(),
[],
[
'diff' => $this->getRevisionRecord()->getId(),
'oldid' => 'prev',
'unhide' => 1
]
);
}
}
/**
* @todo Essentially a copy of RevDelRevisionItem::getHTML. That class
* should inherit from this one, and implement an appropriate interface instead
* of extending RevDelItem
* @return string HTML
*/
public function getHTML() {
$difflink = $this->context->msg( 'parentheses' )
->rawParams( $this->getDiffLink() )->escaped();
$revlink = $this->getRevisionLink();
$userlink = Linker::revUserLink( $this->getRevisionRecord() );
$comment = MediaWikiServices::getInstance()->getCommentFormatter()
->formatRevision( $this->getRevisionRecord(), $this->context->getAuthority() );
if ( $this->isDeleted() ) {
$class = Linker::getRevisionDeletedClass( $this->getRevisionRecord() );
$revlink = "<span class=\"$class\">$revlink</span>";
}
return "<li>$difflink $revlink $userlink $comment</li>";
}
}
/** @deprecated class alias since 1.43 */
class_alias( RevisionItem::class, 'RevisionItem' );
|