1eae5b904cac789a6936dfe3237306224e055a11
4 * @subpackage SpecialPage
7 /** @package MediaWiki */
8 class DeletedContribsFinder
extends ContribsFinder
{
9 var $username, $offset, $limit, $namespace;
12 function getEditLimit( $dir ) {
13 list( $index, $usercond ) = $this->getUserCond();
14 $nscond = $this->getNamespaceCond();
15 $use_index = $this->dbr
->useIndexClause( $index );
16 list( $archive ) = $this->dbr
->tableNamesN( 'archive' );
17 $sql = "SELECT ar_timestamp " .
18 " FROM $archive $use_index " .
19 " WHERE $usercond $nscond" .
20 " ORDER BY ar_timestamp $dir LIMIT 1";
22 $res = $this->dbr
->query( $sql, __METHOD__
);
23 $row = $this->dbr
->fetchObject( $res );
25 return $row->ar_timestamp
;
31 function getUserCond() {
32 $condition = ' ar_user_text=' . $this->dbr
->addQuotes( $this->username
);
33 $index = 'usertext_timestamp';
34 return array( $index, $condition );
37 function getNamespaceCond() {
38 if ( $this->namespace !== false )
39 return ' AND ar_namespace = ' . (int)$this->namespace;
43 # The following functions share a lot of code with each other and with
44 # their counterparts in ContribsFinder. Some refactoring should help.
46 function getPreviousOffsetForPaging() {
47 list( $index, $usercond ) = $this->getUserCond();
48 $nscond = $this->getNamespaceCond();
50 $use_index = $this->dbr
->useIndexClause( $index );
51 list( $archive ) = $this->dbr
->tableNamesN( 'archive' );
53 $sql = "SELECT ar_timestamp FROM $archive $use_index " .
54 "WHERE ar_timestamp > '" . $this->offset
. "' AND " .
56 $sql .= " ORDER BY ar_timestamp ASC";
57 $sql = $this->dbr
->limitResult( $sql, $this->limit
, 0 );
58 $res = $this->dbr
->query( $sql );
60 $numRows = $this->dbr
->numRows( $res );
62 $this->dbr
->dataSeek( $res, $numRows - 1 );
63 $row = $this->dbr
->fetchObject( $res );
64 $offset = $row->ar_timestamp
;
68 $this->dbr
->freeResult( $res );
72 function getFirstOffsetForPaging() {
73 list( $index, $usercond ) = $this->getUserCond();
74 $use_index = $this->dbr
->useIndexClause( $index );
75 list( $archive ) = $this->dbr
->tableNamesN( 'archive' );
76 $nscond = $this->getNamespaceCond();
77 $sql = "SELECT ar_timestamp FROM $archive $use_index " .
80 $sql .= " ORDER BY ar_timestamp ASC";
81 $sql = $this->dbr
->limitResult( $sql, $this->limit
, 0 );
82 $res = $this->dbr
->query( $sql );
84 $numRows = $this->dbr
->numRows( $res );
86 $this->dbr
->dataSeek( $res, $numRows - 1 );
87 $row = $this->dbr
->fetchObject( $res );
88 $offset = $row->ar_timestamp
;
92 $this->dbr
->freeResult( $res );
96 /* private */ function makeSql() {
99 list( $archive ) = $this->dbr
->tableNamesN( 'archive' );
100 list( $index, $userCond ) = $this->getUserCond();
103 $offsetQuery = "AND ar_timestamp <= '{$this->offset}'";
105 $nscond = $this->getNamespaceCond();
106 $use_index = $this->dbr
->useIndexClause( $index );
108 ar_namespace,ar_title,
109 ar_rev_id,ar_text_id,ar_timestamp,ar_comment,ar_minor_edit,ar_user,ar_user_text
110 FROM $archive $use_index
111 WHERE $userCond $nscond $offsetQuery
112 ORDER BY ar_timestamp DESC";
113 $sql = $this->dbr
->limitResult( $sql, $this->limit
, 0 );
119 * Special page "deleted contributions".
120 * Shows a list of the deleted contributions of a user.
122 * XXX This is almost and exact duplicate of the code in
123 * XXX SpecialContributions.php and should be merged with it.
126 * @param $par String: (optional) user name of the user for which to show the contributions
128 function wfSpecialDeletedcontribs( $par = null ) {
129 global $wgUser, $wgOut, $wgLang, $wgRequest;
131 $target = isset( $par ) ?
$par : $wgRequest->getVal( 'target' );
132 if ( !strlen( $target ) ) {
133 $wgOut->showErrorPage( 'notargettitle', 'notargettext' );
137 $nt = Title
::newFromURL( $target );
139 $wgOut->showErrorPage( 'notargettitle', 'notargettext' );
145 list( $options['limit'], $options['offset']) = wfCheckLimits();
146 $options['offset'] = $wgRequest->getVal( 'offset' );
147 /* Offset must be an integral. */
148 if ( !strlen( $options['offset'] ) ||
!preg_match( '/^[0-9]+$/', $options['offset'] ) )
149 $options['offset'] = '';
151 $title = SpecialPage
::getTitleFor( 'Deletedcontribs' );
152 $options['target'] = $target;
154 $nt =& Title
::makeTitle( NS_USER
, $nt->getDBkey() );
155 $finder = new DeletedContribsFinder( $nt->getText() );
156 $finder->setLimit( $options['limit'] );
157 $finder->setOffset( $options['offset'] );
159 if ( ( $ns = $wgRequest->getVal( 'namespace', null ) ) !== null && $ns !== '' ) {
160 $options['namespace'] = intval( $ns );
161 $finder->setNamespace( $options['namespace'] );
163 $options['namespace'] = '';
166 if ( $wgRequest->getText( 'go' ) == 'prev' ) {
167 $offset = $finder->getPreviousOffsetForPaging();
168 if ( $offset !== false ) {
169 $options['offset'] = $offset;
170 $prevurl = $title->getLocalURL( wfArrayToCGI( $options ) );
171 $wgOut->redirect( $prevurl );
176 if ( $wgRequest->getText( 'go' ) == 'first' ) {
177 $offset = $finder->getFirstOffsetForPaging();
178 if ( $offset !== false ) {
179 $options['offset'] = $offset;
180 $prevurl = $title->getLocalURL( wfArrayToCGI( $options ) );
181 $wgOut->redirect( $prevurl );
186 $wgOut->setSubtitle( wfMsgHtml( 'contribsub', contributionsSub( $nt ) ) );
188 $id = User
::idFromName( $nt->getText() );
189 wfRunHooks( 'SpecialDeletedcontribsBeforeMainOutput', $id );
191 $wgOut->addHTML( contributionsForm( $options) );
193 $contribs = $finder->find();
195 if ( count( $contribs ) == 0) {
196 $wgOut->addWikiText( wfMsg( 'nocontribs' ) );
200 list( $early, $late ) = $finder->getEditLimits();
201 $lastts = count( $contribs ) ?
$contribs[count( $contribs ) - 1]->ar_timestamp
: 0;
202 $atstart = ( !count( $contribs ) ||
$late == $contribs[0]->ar_timestamp
);
203 $atend = ( !count( $contribs ) ||
$early == $lastts );
205 // These four are defaults
206 $newestlink = wfMsgHtml( 'sp-contributions-newest' );
207 $oldestlink = wfMsgHtml( 'sp-contributions-oldest' );
208 $newerlink = wfMsgHtml( 'sp-contributions-newer', $options['limit'] );
209 $olderlink = wfMsgHtml( 'sp-contributions-older', $options['limit'] );
212 $stuff = $title->escapeLocalURL( wfArrayToCGI( array( 'offset' => '' ), $options ) );
213 $newestlink = "<a href=\"$stuff\">$newestlink</a>";
214 $stuff = $title->escapeLocalURL( wfArrayToCGI( array( 'go' => 'prev' ), $options ) );
215 $newerlink = "<a href=\"$stuff\">$newerlink</a>";
219 $stuff = $title->escapeLocalURL( wfArrayToCGI( array( 'go' => 'first' ), $options ) );
220 $oldestlink = "<a href=\"$stuff\">$oldestlink</a>";
221 $stuff = $title->escapeLocalURL( wfArrayToCGI( array( 'offset' => $lastts ), $options ) );
222 $olderlink = "<a href=\"$stuff\">$olderlink</a>";
225 $firstlast = "($newestlink | $oldestlink)";
228 foreach ( array( 20, 50, 100, 250, 500 ) as $num ) {
229 $stuff = $title->escapeLocalURL( wfArrayToCGI( array( 'limit' => $num ), $options ) );
230 $urls[] = "<a href=\"$stuff\">".$wgLang->formatNum( $num )."</a>";
232 $bits = implode( $urls, ' | ' );
234 $prevnextbits = $firstlast .' '. wfMsgHtml( 'viewprevnext', $newerlink, $olderlink, $bits );
236 $wgOut->addHTML( "<p>{$prevnextbits}</p>\n" );
238 $wgOut->addHTML( "<ul>\n" );
240 $sk = $wgUser->getSkin();
241 foreach ( $contribs as $contrib )
242 $wgOut->addHTML( dcListEdit( $sk, $contrib ) );
244 $wgOut->addHTML( "</ul>\n" );
245 $wgOut->addHTML( "<p>{$prevnextbits}</p>\n" );
250 * Generates each row in the deleted contributions list.
252 * @todo This would probably look a lot nicer in a table.
254 function dcListEdit( $sk, $row ) {
255 $fname = 'dcListEdit';
256 wfProfileIn( $fname );
258 global $wgLang, $wgUser, $wgRequest;
259 static $messages, $undelete;
260 if( !isset( $messages ) ) {
261 foreach( explode( ' ', 'undel minoreditletter' ) as $msg ) {
262 $messages[$msg] = wfMsgExt( $msg, array( 'escape') );
265 if( !isset( $undelete ) ) {
266 $undelete =& SpecialPage
::getTitleFor( 'Undelete' );
269 $page = Title
::makeTitle( $row->ar_namespace
, $row->ar_title
)->getPrefixedText();
271 $ts = wfTimestamp( TS_MW
, $row->ar_timestamp
);
272 $d = $wgLang->timeanddate( $ts, true );
274 $link = $sk->makeKnownLinkObj( $undelete, $page, "target=$page×tamp=$ts" );
275 $undellink = '(' . $sk->makeKnownLinkObj( $undelete, $messages['undel'], "target=$page" ) . ')';
277 if( $row->ar_minor_edit
) {
278 $mflag = '<span class="minor">' . $messages['minoreditletter'] . '</span> ';
283 $comment = $sk->commentBlock( $row->ar_comment
);
285 $ret = "<li>{$d}{$mflag} {$link} {$undellink} {$comment}</li>";
286 wfProfileOut( $fname );