Merge "Improve docs for Title::getInternalURL/getCanonicalURL"
[lhc/web/wiklou.git] / includes / revisionlist / RevisionItem.php
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 /**
24 * Item class for a live revision table row
25 */
26 class RevisionItem extends RevisionItemBase {
27 /** @var Revision */
28 protected $revision;
29
30 /** @var RequestContext */
31 protected $context;
32
33 public function __construct( $list, $row ) {
34 parent::__construct( $list, $row );
35 $this->revision = new Revision( $row );
36 $this->context = $list->getContext();
37 }
38
39 public function getIdField() {
40 return 'rev_id';
41 }
42
43 public function getTimestampField() {
44 return 'rev_timestamp';
45 }
46
47 public function getAuthorIdField() {
48 return 'rev_user';
49 }
50
51 public function getAuthorNameField() {
52 return 'rev_user_text';
53 }
54
55 public function canView() {
56 return $this->revision->userCan( Revision::DELETED_RESTRICTED, $this->context->getUser() );
57 }
58
59 public function canViewContent() {
60 return $this->revision->userCan( Revision::DELETED_TEXT, $this->context->getUser() );
61 }
62
63 public function isDeleted() {
64 return $this->revision->isDeleted( Revision::DELETED_TEXT );
65 }
66
67 /**
68 * Get the HTML link to the revision text.
69 * @todo Essentially a copy of RevDelRevisionItem::getRevisionLink. That class
70 * should inherit from this one, and implement an appropriate interface instead
71 * of extending RevDelItem
72 * @return string
73 */
74 protected function getRevisionLink() {
75 $date = $this->list->getLanguage()->userTimeAndDate(
76 $this->revision->getTimestamp(), $this->list->getUser() );
77
78 if ( $this->isDeleted() && !$this->canViewContent() ) {
79 return htmlspecialchars( $date );
80 }
81 $linkRenderer = $this->getLinkRenderer();
82 return $linkRenderer->makeKnownLink(
83 $this->list->title,
84 $date,
85 [],
86 [
87 'oldid' => $this->revision->getId(),
88 'unhide' => 1
89 ]
90 );
91 }
92
93 /**
94 * Get the HTML link to the diff.
95 * @todo Essentially a copy of RevDelRevisionItem::getDiffLink. That class
96 * should inherit from this one, and implement an appropriate interface instead
97 * of extending RevDelItem
98 * @return string
99 */
100 protected function getDiffLink() {
101 if ( $this->isDeleted() && !$this->canViewContent() ) {
102 return $this->context->msg( 'diff' )->escaped();
103 } else {
104 $linkRenderer = $this->getLinkRenderer();
105 return $linkRenderer->makeKnownLink(
106 $this->list->title,
107 $this->list->msg( 'diff' )->text(),
108 [],
109 [
110 'diff' => $this->revision->getId(),
111 'oldid' => 'prev',
112 'unhide' => 1
113 ]
114 );
115 }
116 }
117
118 /**
119 * @todo Essentially a copy of RevDelRevisionItem::getHTML. That class
120 * should inherit from this one, and implement an appropriate interface instead
121 * of extending RevDelItem
122 * @return string
123 */
124 public function getHTML() {
125 $difflink = $this->context->msg( 'parentheses' )
126 ->rawParams( $this->getDiffLink() )->escaped();
127 $revlink = $this->getRevisionLink();
128 $userlink = Linker::revUserLink( $this->revision );
129 $comment = Linker::revComment( $this->revision );
130 if ( $this->isDeleted() ) {
131 $revlink = "<span class=\"history-deleted\">$revlink</span>";
132 }
133 return "<li>$difflink $revlink $userlink $comment</li>";
134 }
135 }