3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
25 class DeletedContribsPager
extends IndexPager
{
27 public $mDefaultDirection = IndexPager
::DIR_DESCENDING
;
30 public $namespace = '';
34 * @var string Navigation bar with paging links.
36 protected $mNavigationBar;
38 function __construct( IContextSource
$context, $target, $namespace = false ) {
39 parent
::__construct( $context );
40 $msgs = [ 'deletionlog', 'undeleteviewlink', 'diff' ];
41 foreach ( $msgs as $msg ) {
42 $this->messages
[$msg] = $this->msg( $msg )->escaped();
44 $this->target
= $target;
45 $this->namespace = $namespace;
46 $this->mDb
= wfGetDB( DB_SLAVE
, 'contributions' );
49 function getDefaultQuery() {
50 $query = parent
::getDefaultQuery();
51 $query['target'] = $this->target
;
56 function getQueryInfo() {
57 list( $index, $userCond ) = $this->getUserCond();
58 $conds = array_merge( $userCond, $this->getNamespaceCond() );
59 $user = $this->getUser();
60 // Paranoia: avoid brute force searches (bug 17792)
61 if ( !$user->isAllowed( 'deletedhistory' ) ) {
62 $conds[] = $this->mDb
->bitAnd( 'ar_deleted', Revision
::DELETED_USER
) . ' = 0';
63 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
64 $conds[] = $this->mDb
->bitAnd( 'ar_deleted', Revision
::SUPPRESSED_USER
) .
65 ' != ' . Revision
::SUPPRESSED_USER
;
69 'tables' => [ 'archive' ],
71 'ar_rev_id', 'ar_namespace', 'ar_title', 'ar_timestamp', 'ar_comment',
72 'ar_minor_edit', 'ar_user', 'ar_user_text', 'ar_deleted'
75 'options' => [ 'USE INDEX' => $index ]
80 * This method basically executes the exact same code as the parent class, though with
81 * a hook added, to allow extensions to add additional queries.
83 * @param string $offset Index offset, inclusive
84 * @param int $limit Exact query limit
85 * @param bool $descending Query direction, false for ascending, true for descending
86 * @return ResultWrapper
88 function reallyDoQuery( $offset, $limit, $descending ) {
89 $data = [ parent
::reallyDoQuery( $offset, $limit, $descending ) ];
91 // This hook will allow extensions to add in additional queries, nearly
92 // identical to ContribsPager::reallyDoQuery.
94 'DeletedContribsPager::reallyDoQuery',
95 [ &$data, $this, $offset, $limit, $descending ]
100 // loop all results and collect them in an array
101 foreach ( $data as $query ) {
102 foreach ( $query as $i => $row ) {
103 // use index column as key, allowing us to easily sort in PHP
104 $result[$row->{$this->getIndexField()} . "-$i"] = $row;
116 $result = array_slice( $result, 0, $limit );
118 // get rid of array keys
119 $result = array_values( $result );
121 return new FakeResultWrapper( $result );
124 function getUserCond() {
127 $condition['ar_user_text'] = $this->target
;
128 $index = 'usertext_timestamp';
130 return [ $index, $condition ];
133 function getIndexField() {
134 return 'ar_timestamp';
137 function getStartBody() {
141 function getEndBody() {
145 function getNavigationBar() {
146 if ( isset( $this->mNavigationBar
) ) {
147 return $this->mNavigationBar
;
151 'prev' => $this->msg( 'pager-newer-n' )->numParams( $this->mLimit
)->escaped(),
152 'next' => $this->msg( 'pager-older-n' )->numParams( $this->mLimit
)->escaped(),
153 'first' => $this->msg( 'histlast' )->escaped(),
154 'last' => $this->msg( 'histfirst' )->escaped()
157 $pagingLinks = $this->getPagingLinks( $linkTexts );
158 $limitLinks = $this->getLimitLinks();
159 $lang = $this->getLanguage();
160 $limits = $lang->pipeList( $limitLinks );
162 $firstLast = $lang->pipeList( [ $pagingLinks['first'], $pagingLinks['last'] ] );
163 $firstLast = $this->msg( 'parentheses' )->rawParams( $firstLast )->escaped();
164 $prevNext = $this->msg( 'viewprevnext' )
166 $pagingLinks['prev'],
167 $pagingLinks['next'],
170 $separator = $this->msg( 'word-separator' )->escaped();
171 $this->mNavigationBar
= $firstLast . $separator . $prevNext;
173 return $this->mNavigationBar
;
176 function getNamespaceCond() {
177 if ( $this->namespace !== '' ) {
178 return [ 'ar_namespace' => (int)$this->namespace ];
185 * Generates each row in the contributions list.
187 * @todo This would probably look a lot nicer in a table.
188 * @param stdClass $row
191 function formatRow( $row ) {
196 * There may be more than just revision rows. To make sure that we'll only be processing
197 * revisions here, let's _try_ to build a revision out of our row (without displaying
198 * notices though) and then trying to grab data from the built object. If we succeed,
199 * we're definitely dealing with revision data and we may proceed, if not, we'll leave it
200 * to extensions to subscribe to the hook to parse the row.
202 MediaWiki\
suppressWarnings();
204 $rev = Revision
::newFromArchiveRow( $row );
205 $validRevision = (bool)$rev->getId();
206 } catch ( Exception
$e ) {
207 $validRevision = false;
209 MediaWiki\restoreWarnings
();
211 if ( $validRevision ) {
212 $ret = $this->formatRevisionRow( $row );
215 // Let extensions add data
216 Hooks
::run( 'DeletedContributionsLineEnding', [ $this, &$ret, $row, &$classes ] );
218 if ( $classes === [] && $ret === '' ) {
219 wfDebug( "Dropping Special:DeletedContribution row that could not be formatted\n" );
220 $ret = "<!-- Could not format Special:DeletedContribution row. -->\n";
222 $ret = Html
::rawElement( 'li', [ 'class' => $classes ], $ret ) . "\n";
229 * Generates each row in the contributions list for archive entries.
231 * Contributions which are marked "top" are currently on top of the history.
232 * For these contributions, a [rollback] link is shown for users with sysop
233 * privileges. The rollback link restores the most recent version that was not
234 * written by the target user.
236 * @todo This would probably look a lot nicer in a table.
237 * @param stdClass $row
240 function formatRevisionRow( $row ) {
241 $page = Title
::makeTitle( $row->ar_namespace
, $row->ar_title
);
243 $rev = new Revision( [
245 'id' => $row->ar_rev_id
,
246 'comment' => $row->ar_comment
,
247 'user' => $row->ar_user
,
248 'user_text' => $row->ar_user_text
,
249 'timestamp' => $row->ar_timestamp
,
250 'minor_edit' => $row->ar_minor_edit
,
251 'deleted' => $row->ar_deleted
,
254 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
256 $logs = SpecialPage
::getTitleFor( 'Log' );
257 $dellog = Linker
::linkKnown(
259 $this->messages
['deletionlog'],
263 'page' => $page->getPrefixedText()
267 $reviewlink = Linker
::linkKnown(
268 SpecialPage
::getTitleFor( 'Undelete', $page->getPrefixedDBkey() ),
269 $this->messages
['undeleteviewlink']
272 $user = $this->getUser();
274 if ( $user->isAllowed( 'deletedtext' ) ) {
275 $last = Linker
::linkKnown(
277 $this->messages
['diff'],
280 'target' => $page->getPrefixedText(),
281 'timestamp' => $rev->getTimestamp(),
286 $last = $this->messages
['diff'];
289 $comment = Linker
::revComment( $rev );
290 $date = $this->getLanguage()->userTimeAndDate( $rev->getTimestamp(), $user );
291 $date = htmlspecialchars( $date );
293 if ( !$user->isAllowed( 'undelete' ) ||
!$rev->userCan( Revision
::DELETED_TEXT
, $user ) ) {
294 $link = $date; // unusable link
296 $link = Linker
::linkKnown(
299 [ 'class' => 'mw-changeslist-date' ],
301 'target' => $page->getPrefixedText(),
302 'timestamp' => $rev->getTimestamp()
306 // Style deleted items
307 if ( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
308 $link = '<span class="history-deleted">' . $link . '</span>';
311 $pagelink = Linker
::link(
314 [ 'class' => 'mw-changeslist-title' ]
317 if ( $rev->isMinor() ) {
318 $mflag = ChangesList
::flag( 'minor' );
323 // Revision delete link
324 $del = Linker
::getRevDeleteLink( $user, $rev, $page );
329 $tools = Html
::rawElement(
331 [ 'class' => 'mw-deletedcontribs-tools' ],
332 $this->msg( 'parentheses' )->rawParams( $this->getLanguage()->pipeList(
333 [ $last, $dellog, $reviewlink ] ) )->escaped()
336 $separator = '<span class="mw-changeslist-separator">. .</span>';
337 $ret = "{$del}{$link} {$tools} {$separator} {$mflag} {$pagelink} {$comment}";
339 # Denote if username is redacted for this edit
340 if ( $rev->isDeleted( Revision
::DELETED_USER
) ) {
341 $ret .= " <strong>" . $this->msg( 'rev-deleted-user-contribs' )->escaped() . "</strong>";
348 * Get the Database object in use
352 public function getDatabase() {