Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
65.22% covered (warning)
65.22%
15 / 23
71.43% covered (warning)
71.43%
10 / 14
CRAP
0.00% covered (danger)
0.00%
0 / 1
RevisionItemBase
68.18% covered (warning)
68.18%
15 / 22
71.43% covered (warning)
71.43%
10 / 14
20.31
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
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
 getAuthorActorField
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getId
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 formatDate
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 formatTime
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getTimestamp
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getAuthorId
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getAuthorName
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getAuthorActor
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 canView
n/a
0 / 0
n/a
0 / 0
0
 canViewContent
n/a
0 / 0
n/a
0 / 0
0
 getHTML
n/a
0 / 0
n/a
0 / 0
0
 getLinkRenderer
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
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
23namespace MediaWiki\RevisionList;
24
25use MediaWiki\Linker\LinkRenderer;
26use MediaWiki\MediaWikiServices;
27use stdClass;
28
29/**
30 * Abstract base class for revision items
31 */
32abstract class RevisionItemBase {
33    /** @var RevisionListBase The parent */
34    protected $list;
35
36    /** @var stdClass The database result row */
37    protected $row;
38
39    /**
40     * @param RevisionListBase $list
41     * @param stdClass $row DB result row
42     */
43    public function __construct( RevisionListBase $list, $row ) {
44        $this->list = $list;
45        $this->row = $row;
46    }
47
48    /**
49     * Get the DB field name associated with the ID list.
50     * Override this function.
51     * @return string|null
52     */
53    public function getIdField() {
54        return null;
55    }
56
57    /**
58     * Get the DB field name storing timestamps.
59     * Override this function.
60     * @return string|false
61     */
62    public function getTimestampField() {
63        return false;
64    }
65
66    /**
67     * Get the DB field name storing user ids.
68     * Override this function.
69     * @return string|false
70     */
71    public function getAuthorIdField() {
72        return false;
73    }
74
75    /**
76     * Get the DB field name storing user names.
77     * Override this function.
78     * @return string|false
79     */
80    public function getAuthorNameField() {
81        return false;
82    }
83
84    /**
85     * Get the DB field name storing actor ids.
86     * Override this function.
87     * @since 1.31
88     * @return string|false
89     */
90    public function getAuthorActorField() {
91        return false;
92    }
93
94    /**
95     * Get the ID, as it would appear in the ids URL parameter
96     * @return int|string
97     */
98    public function getId() {
99        $field = $this->getIdField();
100        return intval( $this->row->$field );
101    }
102
103    /**
104     * Get the date, formatted in user's language
105     * @return string
106     */
107    public function formatDate() {
108        return $this->list->getLanguage()->userDate( $this->getTimestamp(),
109            $this->list->getUser() );
110    }
111
112    /**
113     * Get the time, formatted in user's language
114     * @return string
115     */
116    public function formatTime() {
117        return $this->list->getLanguage()->userTime( $this->getTimestamp(),
118            $this->list->getUser() );
119    }
120
121    /**
122     * Get the timestamp in MW 14-char form
123     * @return string|false
124     */
125    public function getTimestamp() {
126        $field = $this->getTimestampField();
127        return wfTimestamp( TS_MW, $this->row->$field );
128    }
129
130    /**
131     * Get the author user ID
132     * @return int
133     */
134    public function getAuthorId() {
135        $field = $this->getAuthorIdField();
136        return intval( $this->row->$field );
137    }
138
139    /**
140     * Get the author user name
141     * @return string
142     */
143    public function getAuthorName() {
144        $field = $this->getAuthorNameField();
145        return strval( $this->row->$field );
146    }
147
148    /**
149     * Get the author actor ID
150     * @since 1.31
151     * @return string
152     */
153    public function getAuthorActor() {
154        $field = $this->getAuthorActorField();
155        return strval( $this->row->$field );
156    }
157
158    /**
159     * Returns true if the current user can view the item
160     * @return bool
161     */
162    abstract public function canView();
163
164    /**
165     * Returns true if the current user can view the item text/file
166     * @return bool
167     */
168    abstract public function canViewContent();
169
170    /**
171     * Get the HTML of the list item. Should be include "<li></li>" tags.
172     * This is used to show the list in HTML form, by the special page.
173     * @return string HTML
174     */
175    abstract public function getHTML();
176
177    /**
178     * Returns an instance of LinkRenderer
179     * @return LinkRenderer
180     */
181    protected function getLinkRenderer() {
182        return MediaWikiServices::getInstance()->getLinkRenderer();
183    }
184}
185/** @deprecated class alias since 1.43 */
186class_alias( RevisionItemBase::class, 'RevisionItemBase' );