]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/specials/SpecialDeletedContributions.php
MediaWiki 1.15.0
[autoinstallsdev/mediawiki.git] / includes / specials / SpecialDeletedContributions.php
1 <?php
2 /**
3  * Implements Special:DeletedContributions to display archived revisions
4  * @ingroup SpecialPage
5  */
6
7 class DeletedContribsPager extends IndexPager {
8         public $mDefaultDirection = true;
9         var $messages, $target;
10         var $namespace = '', $mDb;
11
12         function __construct( $target, $namespace = false ) {
13                 parent::__construct();
14                 foreach( explode( ' ', 'deletionlog undeletebtn minoreditletter diff' ) as $msg ) {
15                         $this->messages[$msg] = wfMsgExt( $msg, array( 'escape') );
16                 }
17                 $this->target = $target;
18                 $this->namespace = $namespace;
19                 $this->mDb = wfGetDB( DB_SLAVE, 'contributions' );
20         }
21
22         function getDefaultQuery() {
23                 $query = parent::getDefaultQuery();
24                 $query['target'] = $this->target;
25                 return $query;
26         }
27
28         function getQueryInfo() {
29                 global $wgUser;
30                 list( $index, $userCond ) = $this->getUserCond();
31                 $conds = array_merge( $userCond, $this->getNamespaceCond() );
32                 // Paranoia: avoid brute force searches (bug 17792)
33                 if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
34                         $conds[] = 'ar_deleted & ' . Revision::DELETED_USER . ' = 0';
35                 }
36                 return array(
37                         'tables' => array( 'archive' ),
38                         'fields' => array(
39                                 'ar_rev_id', 'ar_namespace', 'ar_title', 'ar_timestamp', 'ar_comment', 'ar_minor_edit',
40                                 'ar_user', 'ar_user_text', 'ar_deleted'
41                         ),
42                         'conds' => $conds,
43                         'options' => array( 'USE INDEX' => $index )
44                 );
45         }
46
47         function getUserCond() {
48                 $condition = array();
49
50                 $condition['ar_user_text'] = $this->target;
51                 $index = 'usertext_timestamp';
52
53                 return array( $index, $condition );
54         }
55
56         function getIndexField() {
57                 return 'ar_timestamp';
58         }
59
60         function getStartBody() {
61                 return "<ul>\n";
62         }
63
64         function getEndBody() {
65                 return "</ul>\n";
66         }
67
68         function getNavigationBar() {
69                 global $wgLang;
70
71                 if ( isset( $this->mNavigationBar ) ) {
72                         return $this->mNavigationBar;
73                 }
74                 $linkTexts = array(
75                         'prev' => wfMsgHtml( 'pager-newer-n', $this->mLimit ),
76                         'next' => wfMsgHtml( 'pager-older-n', $this->mLimit ),
77                         'first' => wfMsgHtml( 'histlast' ),
78                         'last' => wfMsgHtml( 'histfirst' )
79                 );
80
81                 $pagingLinks = $this->getPagingLinks( $linkTexts );
82                 $limitLinks = $this->getLimitLinks();
83                 $limits = $wgLang->pipeList( $limitLinks );
84
85                 $this->mNavigationBar = "(" . $wgLang->pipeList( array( $pagingLinks['first'], $pagingLinks['last'] ) ) . ") " .
86                         wfMsgExt( 'viewprevnext', array( 'parsemag' ), $pagingLinks['prev'], $pagingLinks['next'], $limits );
87                 return $this->mNavigationBar;
88         }
89
90         function getNamespaceCond() {
91                 if ( $this->namespace !== '' ) {
92                         return array( 'ar_namespace' => (int)$this->namespace );
93                 } else {
94                         return array();
95                 }
96         }
97
98         /**
99          * Generates each row in the contributions list.
100          *
101          * Contributions which are marked "top" are currently on top of the history.
102          * For these contributions, a [rollback] link is shown for users with sysop
103          * privileges. The rollback link restores the most recent version that was not
104          * written by the target user.
105          *
106          * @todo This would probably look a lot nicer in a table.
107          */
108         function formatRow( $row ) {
109                 wfProfileIn( __METHOD__ );
110
111                 global $wgLang, $wgUser;
112
113                 $sk = $this->getSkin();
114
115                 $rev = new Revision( array(
116                                 'id'         => $row->ar_rev_id,
117                                 'comment'    => $row->ar_comment,
118                                 'user'       => $row->ar_user,
119                                 'user_text'  => $row->ar_user_text,
120                                 'timestamp'  => $row->ar_timestamp,
121                                 'minor_edit' => $row->ar_minor_edit,
122                                 'deleted' => $row->ar_deleted,
123                                 ) );
124
125                 $page = Title::makeTitle( $row->ar_namespace, $row->ar_title );
126
127                 $undelete = SpecialPage::getTitleFor( 'Undelete' );
128
129                 $logs = SpecialPage::getTitleFor( 'Log' );
130                 $dellog = $sk->makeKnownLinkObj( $logs,
131                         $this->messages['deletionlog'],
132                         'type=delete&page=' . $page->getPrefixedUrl() );
133
134                 $reviewlink = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Undelete', $page->getPrefixedDBkey() ),
135                         $this->messages['undeletebtn'] );
136
137                 $link = $sk->makeKnownLinkObj( $undelete,
138                         htmlspecialchars( $page->getPrefixedText() ),
139                         'target=' . $page->getPrefixedUrl() .
140                         '&timestamp=' . $rev->getTimestamp() );
141
142                 $last = $sk->makeKnownLinkObj( $undelete,
143                         $this->messages['diff'],
144                         "target=" . $page->getPrefixedUrl() .
145                         "&timestamp=" . $rev->getTimestamp() .
146                         "&diff=prev" );
147
148                 $comment = $sk->revComment( $rev );
149                 $d = $wgLang->timeanddate( $rev->getTimestamp(), true );
150
151                 if( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
152                         $d = '<span class="history-deleted">' . $d . '</span>';
153                 } else {
154                         $link = $sk->makeKnownLinkObj( $undelete, $d,
155                                 'target=' . $page->getPrefixedUrl() .
156                                 '&timestamp=' . $rev->getTimestamp() );
157                 }
158
159                 $pagelink = $sk->makeLinkObj( $page );
160
161                 if( $rev->isMinor() ) {
162                         $mflag = '<span class="minor">' . $this->messages['minoreditletter'] . '</span> ';
163                 } else {
164                         $mflag = '';
165                 }
166
167
168                 $ret = "{$link} ($last) ({$dellog}) ({$reviewlink}) . . {$mflag} {$pagelink} {$comment}";
169                 if( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
170                         $ret .= ' ' . wfMsgHtml( 'deletedrev' );
171                 }
172
173                 $ret = "<li>$ret</li>\n";
174
175                 wfProfileOut( __METHOD__ );
176                 return $ret;
177         }
178
179         /**
180          * Get the Database object in use
181          *
182          * @return Database
183          */
184         public function getDatabase() {
185                 return $this->mDb;
186         }
187 }
188
189 class DeletedContributionsPage extends SpecialPage {
190         function __construct() {
191                 parent::__construct( 'DeletedContributions', 'deletedhistory',
192                 /*listed*/ true, /*function*/ false, /*file*/ false );
193         }
194
195         /**
196          * Special page "deleted user contributions".
197          * Shows a list of the deleted contributions of a user.
198          *
199          * @return      none
200          * @param       $par    String: (optional) user name of the user for which to show the contributions
201          */
202         function execute( $par ) {
203                 global $wgUser;
204                 $this->setHeaders();
205
206                 if ( !$this->userCanExecute( $wgUser ) ) {
207                         $this->displayRestrictionError();
208                         return;
209                 }
210
211                 global $wgUser, $wgOut, $wgLang, $wgRequest;
212
213                 $wgOut->setPageTitle( wfMsgExt( 'deletedcontributions-title', array( 'parsemag' ) ) );
214
215                 $options = array();
216
217                 if ( isset( $par ) ) {
218                         $target = $par;
219                 } else {
220                         $target = $wgRequest->getVal( 'target' );
221                 }
222
223                 if ( !strlen( $target ) ) {
224                         $wgOut->addHTML( $this->getForm( '' ) );
225                         return;
226                 }
227
228                 $options['limit'] = $wgRequest->getInt( 'limit', 50 );
229                 $options['target'] = $target;
230
231                 $nt = Title::makeTitleSafe( NS_USER, $target );
232                 if ( !$nt ) {
233                         $wgOut->addHTML( $this->getForm( '' ) );
234                         return;
235                 }
236                 $id = User::idFromName( $nt->getText() );
237
238                 $target = $nt->getText();
239                 $wgOut->setSubtitle( $this->getSubTitle( $nt, $id ) );
240
241                 if ( ( $ns = $wgRequest->getVal( 'namespace', null ) ) !== null && $ns !== '' ) {
242                         $options['namespace'] = intval( $ns );
243                 } else {
244                         $options['namespace'] = '';
245                 }
246
247                 $wgOut->addHTML( $this->getForm( $options ) );
248
249                 $pager = new DeletedContribsPager( $target, $options['namespace'] );
250                 if ( !$pager->getNumRows() ) {
251                         $wgOut->addWikiText( wfMsg( 'nocontribs' ) );
252                         return;
253                 }
254
255                 # Show a message about slave lag, if applicable
256                 if( ( $lag = $pager->getDatabase()->getLag() ) > 0 )
257                         $wgOut->showLagWarning( $lag );
258
259                 $wgOut->addHTML(
260                         '<p>' . $pager->getNavigationBar() . '</p>' .
261                         $pager->getBody() .
262                         '<p>' . $pager->getNavigationBar() . '</p>' );
263
264                 # If there were contributions, and it was a valid user or IP, show
265                 # the appropriate "footer" message - WHOIS tools, etc.
266                 if( $target != 'newbies' ) {
267                         $message = IP::isIPAddress( $target )
268                                 ? 'sp-contributions-footer-anon'
269                                 : 'sp-contributions-footer';
270
271
272                         $text = wfMsgNoTrans( $message, $target );
273                         if( !wfEmptyMsg( $message, $text ) && $text != '-' ) {
274                                 $wgOut->addHTML( '<div class="mw-contributions-footer">' );
275                                 $wgOut->addWikiText( $text );
276                                 $wgOut->addHTML( '</div>' );
277                         }
278                 }
279         }
280
281         /**
282          * Generates the subheading with links
283          * @param $nt @see Title object for the target
284          */
285         function getSubTitle( $nt, $id ) {
286                 global $wgSysopUserBans, $wgLang, $wgUser;
287
288                 $sk = $wgUser->getSkin();
289
290                 if ( 0 == $id ) {
291                         $user = $nt->getText();
292                 } else {
293                         $user = $sk->makeLinkObj( $nt, htmlspecialchars( $nt->getText() ) );
294                 }
295                 $talk = $nt->getTalkPage();
296                 if( $talk ) {
297                         # Talk page link
298                         $tools[] = $sk->makeLinkObj( $talk, wfMsgHtml( 'talkpagelinktext' ) );
299                         if( ( $id != 0 && $wgSysopUserBans ) || ( $id == 0 && User::isIP( $nt->getText() ) ) ) {
300                                 # Block link
301                                 if( $wgUser->isAllowed( 'block' ) )
302                                         $tools[] = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Blockip', $nt->getDBkey() ),
303                                                 wfMsgHtml( 'blocklink' ) );
304                                 # Block log link
305                                 $tools[] = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Log' ),
306                                         wfMsgHtml( 'sp-contributions-blocklog' ), 'type=block&page=' . $nt->getPrefixedUrl() );
307                         }
308                         # Other logs link
309                         $tools[] = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Log' ),
310                                 wfMsgHtml( 'log' ), 'user=' . $nt->getPartialUrl() );
311                         # Link to undeleted contributions
312                         $tools[] = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Contributions', $nt->getDBkey() ),
313                                 wfMsgHtml( 'contributions' ) );
314                                 
315                         wfRunHooks( 'ContributionsToolLinks', array( $id, $nt, &$tools ) );
316
317                         $links = $wgLang->pipeList( $tools );
318                 }
319
320                 // Old message 'contribsub' had one parameter, but that doesn't work for
321                 // languages that want to put the "for" bit right after $user but before
322                 // $links.  If 'contribsub' is around, use it for reverse compatibility,
323                 // otherwise use 'contribsub2'.
324                 if( wfEmptyMsg( 'contribsub', wfMsg( 'contribsub' ) ) ) {
325                         return wfMsgHtml( 'contribsub2', $user, $links );
326                 } else {
327                         return wfMsgHtml( 'contribsub', "$user ($links)" );
328                 }
329         }
330
331         /**
332          * Generates the namespace selector form with hidden attributes.
333          * @param $options Array: the options to be included.
334          */
335         function getForm( $options ) {
336                 global $wgScript, $wgTitle, $wgRequest;
337
338                 $options['title'] = $wgTitle->getPrefixedText();
339                 if ( !isset( $options['target'] ) ) {
340                         $options['target'] = '';
341                 } else {
342                         $options['target'] = str_replace( '_' , ' ' , $options['target'] );
343                 }
344
345                 if ( !isset( $options['namespace'] ) ) {
346                         $options['namespace'] = '';
347                 }
348
349                 if ( !isset( $options['contribs'] ) ) {
350                         $options['contribs'] = 'user';
351                 }
352
353                 if ( $options['contribs'] == 'newbie' ) {
354                         $options['target'] = '';
355                 }
356
357                 $f = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
358
359                 foreach ( $options as $name => $value ) {
360                         if ( in_array( $name, array( 'namespace', 'target', 'contribs' ) ) ) {
361                                 continue;
362                         }
363                         $f .= "\t" . Xml::hidden( $name, $value ) . "\n";
364                 }
365
366                 $f .=  Xml::openElement( 'fieldset' ) .
367                         Xml::element( 'legend', array(), wfMsg( 'sp-contributions-search' ) ) .
368                         Xml::tags( 'label', array( 'for' => 'target' ), wfMsgExt( 'sp-contributions-username', 'parseinline' ) ) . ' ' .
369                         Xml::input( 'target', 20, $options['target']) . ' '.
370                         Xml::label( wfMsg( 'namespace' ), 'namespace' ) . ' ' .
371                         Xml::namespaceSelector( $options['namespace'], '' ) . ' ' .
372                         Xml::submitButton( wfMsg( 'sp-contributions-submit' ) ) .
373                         Xml::closeElement( 'fieldset' ) .
374                         Xml::closeElement( 'form' );
375                 return $f;
376         }
377 }