Debian Codegraph @

includes/revisionlist/RevisionItem.php

raw symbols SCIP
1 <?php
2 /**
3 * Holders of revision list for a single page
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
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 * Item class for a live revision table row
32 */
33 class RevisionItem extends RevisionItemBase {
34 /** @var RevisionRecord */
35 protected $revisionRecord;
36
37 /** @var RequestContext */
38 protected $context;
39
40 /** @inheritDoc */
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 * Get the RevisionRecord for the item
51 *
52 * @return RevisionRecord
53 */
54 protected function getRevisionRecord(): RevisionRecord {
55 return $this->revisionRecord;
56 }
57
58 /** @inheritDoc */
59 public function getIdField() {
60 return 'rev_id';
61 }
62
63 /** @inheritDoc */
64 public function getTimestampField() {
65 return 'rev_timestamp';
66 }
67
68 /** @inheritDoc */
69 public function getAuthorIdField() {
70 return 'rev_user';
71 }
72
73 /** @inheritDoc */
74 public function getAuthorNameField() {
75 return 'rev_user_text';
76 }
77
78 /** @inheritDoc */
79 public function canView() {
80 return $this->getRevisionRecord()->userCan(
81 RevisionRecord::DELETED_RESTRICTED,
82 $this->context->getAuthority()
83 );
84 }
85
86 /** @inheritDoc */
87 public function canViewContent() {
88 return $this->getRevisionRecord()->userCan(
89 RevisionRecord::DELETED_TEXT,
90 $this->context->getAuthority()
91 );
92 }
93
94 /**
95 * @return bool
96 */
97 public function isDeleted() {
98 return $this->getRevisionRecord()->isDeleted( RevisionRecord::DELETED_TEXT );
99 }
100
101 /**
102 * Get the HTML link to the revision text.
103 * @todo Essentially a copy of RevDelRevisionItem::getRevisionLink. That class
104 * should inherit from this one, and implement an appropriate interface instead
105 * of extending RevDelItem
106 * @return string HTML
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 * Get the HTML link to the diff.
130 * @todo Essentially a copy of RevDelRevisionItem::getDiffLink. That class
131 * should inherit from this one, and implement an appropriate interface instead
132 * of extending RevDelItem
133 * @return string HTML
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 * @todo Essentially a copy of RevDelRevisionItem::getHTML. That class
155 * should inherit from this one, and implement an appropriate interface instead
156 * of extending RevDelItem
157 * @return string HTML
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 /** @deprecated class alias since 1.43 */
174 class_alias( RevisionItem::class, 'RevisionItem' );