| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
namespace MediaWiki\RevisionList; |
| 24 |
|
| 25 |
use MediaWiki\Context\RequestContext; |
| 26 |
use MediaWiki\Linker\Linker; |
| 27 |
use MediaWiki\MediaWikiServices; |
| 28 |
use MediaWiki\Revision\RevisionRecord; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
class RevisionItem extends RevisionItemBase { |
| 34 |
|
| 35 |
protected $revisionRecord; |
| 36 |
|
| 37 |
|
| 38 |
protected $context; |
| 39 |
|
| 40 |
|
| 41 |
public function __construct( RevisionListBase $list, $row ) { |
| 42 |
parent::__construct( $list, $row ); |
| 43 |
$this->revisionRecord = MediaWikiServices::getInstance() |
| 44 |
->getRevisionFactory() |
| 45 |
->newRevisionFromRow( $row ); |
| 46 |
$this->context = $list->getContext(); |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
protected function getRevisionRecord(): RevisionRecord { |
| 55 |
return $this->revisionRecord; |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
public function getIdField() { |
| 60 |
return 'rev_id'; |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
public function getTimestampField() { |
| 65 |
return 'rev_timestamp'; |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
public function getAuthorIdField() { |
| 70 |
return 'rev_user'; |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
public function getAuthorNameField() { |
| 75 |
return 'rev_user_text'; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
public function canView() { |
| 80 |
return $this->getRevisionRecord()->userCan( |
| 81 |
RevisionRecord::DELETED_RESTRICTED, |
| 82 |
$this->context->getAuthority() |
| 83 |
); |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
public function canViewContent() { |
| 88 |
return $this->getRevisionRecord()->userCan( |
| 89 |
RevisionRecord::DELETED_TEXT, |
| 90 |
$this->context->getAuthority() |
| 91 |
); |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
public function isDeleted() { |
| 98 |
return $this->getRevisionRecord()->isDeleted( RevisionRecord::DELETED_TEXT ); |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
protected function getRevisionLink() { |
| 109 |
$revRecord = $this->getRevisionRecord(); |
| 110 |
$date = $this->list->getLanguage()->userTimeAndDate( |
| 111 |
$revRecord->getTimestamp(), $this->list->getUser() ); |
| 112 |
|
| 113 |
if ( $this->isDeleted() && !$this->canViewContent() ) { |
| 114 |
return htmlspecialchars( $date ); |
| 115 |
} |
| 116 |
$linkRenderer = $this->getLinkRenderer(); |
| 117 |
return $linkRenderer->makeKnownLink( |
| 118 |
$this->list->getPage(), |
| 119 |
$date, |
| 120 |
[], |
| 121 |
[ |
| 122 |
'oldid' => $revRecord->getId(), |
| 123 |
'unhide' => 1 |
| 124 |
] |
| 125 |
); |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
protected function getDiffLink() { |
| 136 |
if ( $this->isDeleted() && !$this->canViewContent() ) { |
| 137 |
return $this->context->msg( 'diff' )->escaped(); |
| 138 |
} else { |
| 139 |
$linkRenderer = $this->getLinkRenderer(); |
| 140 |
return $linkRenderer->makeKnownLink( |
| 141 |
$this->list->getPage(), |
| 142 |
$this->list->msg( 'diff' )->text(), |
| 143 |
[], |
| 144 |
[ |
| 145 |
'diff' => $this->getRevisionRecord()->getId(), |
| 146 |
'oldid' => 'prev', |
| 147 |
'unhide' => 1 |
| 148 |
] |
| 149 |
); |
| 150 |
} |
| 151 |
} |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
public function getHTML() { |
| 160 |
$difflink = $this->context->msg( 'parentheses' ) |
| 161 |
->rawParams( $this->getDiffLink() )->escaped(); |
| 162 |
$revlink = $this->getRevisionLink(); |
| 163 |
$userlink = Linker::revUserLink( $this->getRevisionRecord() ); |
| 164 |
$comment = MediaWikiServices::getInstance()->getCommentFormatter() |
| 165 |
->formatRevision( $this->getRevisionRecord(), $this->context->getAuthority() ); |
| 166 |
if ( $this->isDeleted() ) { |
| 167 |
$class = Linker::getRevisionDeletedClass( $this->getRevisionRecord() ); |
| 168 |
$revlink = "<span class=\"$class\">$revlink</span>"; |
| 169 |
} |
| 170 |
return "<li>$difflink $revlink $userlink $comment</li>"; |
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
class_alias( RevisionItem::class, 'RevisionItem' ); |