Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
33.33% covered (danger)
33.33%
19 / 57
75.00% covered (warning)
75.00%
9 / 12
CRAP
0.00% covered (danger)
0.00%
0 / 1
RevisionItem
33.33% covered (danger)
33.33%
19 / 57
75.00% covered (warning)
75.00%
9 / 12
102.63
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 getRevisionRecord
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getIdField
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getTimestampField
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getAuthorIdField
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getAuthorNameField
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 canView
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 canViewContent
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 isDeleted
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getRevisionLink
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
12
 getDiffLink
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
12
 getHTML
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
6
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
23use MediaWiki\Context\RequestContext;
24use MediaWiki\Linker\Linker;
25use MediaWiki\MediaWikiServices;
26use MediaWiki\Revision\RevisionRecord;
27
28/**
29 * Item class for a live revision table row
30 */
31class RevisionItem extends RevisionItemBase {
32    /** @var RevisionRecord */
33    protected $revisionRecord;
34
35    /** @var RequestContext */
36    protected $context;
37
38    /** @inheritDoc */
39    public function __construct( RevisionListBase $list, $row ) {
40        parent::__construct( $list, $row );
41        $this->revisionRecord = MediaWikiServices::getInstance()
42            ->getRevisionFactory()
43            ->newRevisionFromRow( $row );
44        $this->context = $list->getContext();
45    }
46
47    /**
48     * Get the RevisionRecord for the item
49     *
50     * @return RevisionRecord
51     */
52    protected function getRevisionRecord(): RevisionRecord {
53        return $this->revisionRecord;
54    }
55
56    /** @inheritDoc */
57    public function getIdField() {
58        return 'rev_id';
59    }
60
61    /** @inheritDoc */
62    public function getTimestampField() {
63        return 'rev_timestamp';
64    }
65
66    /** @inheritDoc */
67    public function getAuthorIdField() {
68        return 'rev_user';
69    }
70
71    /** @inheritDoc */
72    public function getAuthorNameField() {
73        return 'rev_user_text';
74    }
75
76    /** @inheritDoc */
77    public function canView() {
78        return $this->getRevisionRecord()->userCan(
79            RevisionRecord::DELETED_RESTRICTED,
80            $this->context->getAuthority()
81        );
82    }
83
84    /** @inheritDoc */
85    public function canViewContent() {
86        return $this->getRevisionRecord()->userCan(
87            RevisionRecord::DELETED_TEXT,
88            $this->context->getAuthority()
89        );
90    }
91
92    /**
93     * @return bool
94     */
95    public function isDeleted() {
96        return $this->getRevisionRecord()->isDeleted( RevisionRecord::DELETED_TEXT );
97    }
98
99    /**
100     * Get the HTML link to the revision text.
101     * @todo Essentially a copy of RevDelRevisionItem::getRevisionLink. That class
102     * should inherit from this one, and implement an appropriate interface instead
103     * of extending RevDelItem
104     * @return string HTML
105     */
106    protected function getRevisionLink() {
107        $revRecord = $this->getRevisionRecord();
108        $date = $this->list->getLanguage()->userTimeAndDate(
109            $revRecord->getTimestamp(), $this->list->getUser() );
110
111        if ( $this->isDeleted() && !$this->canViewContent() ) {
112            return htmlspecialchars( $date );
113        }
114        $linkRenderer = $this->getLinkRenderer();
115        return $linkRenderer->makeKnownLink(
116            $this->list->getPage(),
117            $date,
118            [],
119            [
120                'oldid' => $revRecord->getId(),
121                'unhide' => 1
122            ]
123        );
124    }
125
126    /**
127     * Get the HTML link to the diff.
128     * @todo Essentially a copy of RevDelRevisionItem::getDiffLink. That class
129     * should inherit from this one, and implement an appropriate interface instead
130     * of extending RevDelItem
131     * @return string HTML
132     */
133    protected function getDiffLink() {
134        if ( $this->isDeleted() && !$this->canViewContent() ) {
135            return $this->context->msg( 'diff' )->escaped();
136        } else {
137            $linkRenderer = $this->getLinkRenderer();
138            return $linkRenderer->makeKnownLink(
139                $this->list->getPage(),
140                $this->list->msg( 'diff' )->text(),
141                [],
142                [
143                    'diff' => $this->getRevisionRecord()->getId(),
144                    'oldid' => 'prev',
145                    'unhide' => 1
146                ]
147            );
148        }
149    }
150
151    /**
152     * @todo Essentially a copy of RevDelRevisionItem::getHTML. That class
153     * should inherit from this one, and implement an appropriate interface instead
154     * of extending RevDelItem
155     * @return string HTML
156     */
157    public function getHTML() {
158        $difflink = $this->context->msg( 'parentheses' )
159            ->rawParams( $this->getDiffLink() )->escaped();
160        $revlink = $this->getRevisionLink();
161        $userlink = Linker::revUserLink( $this->getRevisionRecord() );
162        $comment = MediaWikiServices::getInstance()->getCommentFormatter()
163            ->formatRevision( $this->getRevisionRecord(), $this->context->getAuthority() );
164        if ( $this->isDeleted() ) {
165            $class = Linker::getRevisionDeletedClass( $this->getRevisionRecord() );
166            $revlink = "<span class=\"$class\">$revlink</span>";
167        }
168        return "<li>$difflink $revlink $userlink $comment</li>";
169    }
170}