3 * Special:Contributions, show user contributions in a paged list
4 * @addtogroup SpecialPage
7 class ContribsPager
extends IndexPager
{
8 public $mDefaultDirection = true;
9 var $messages, $target;
10 var $namespace = '', $mDb;
12 function __construct( $target, $namespace = false ) {
13 parent
::__construct();
14 foreach( explode( ' ', 'uctop diff newarticle rollbacklink diff hist minoreditletter' ) as $msg ) {
15 $this->messages
[$msg] = wfMsgExt( $msg, array( 'escape') );
17 $this->target
= $target;
18 $this->namespace = $namespace;
19 $this->mDb
= wfGetDB( DB_SLAVE
, 'contributions' );
22 function getDefaultQuery() {
23 $query = parent
::getDefaultQuery();
24 $query['target'] = $this->target
;
28 function getQueryInfo() {
29 list( $index, $userCond ) = $this->getUserCond();
30 $conds = array_merge( array( 'page_id=rev_page' ), $userCond, $this->getNamespaceCond() );
33 'tables' => array( 'page', 'revision' ),
35 'page_namespace', 'page_title', 'page_is_new', 'page_latest', 'rev_id', 'rev_page',
36 'rev_text_id', 'rev_timestamp', 'rev_comment', 'rev_minor_edit', 'rev_user',
37 'rev_user_text', 'rev_deleted'
40 'options' => array( 'FORCE INDEX' => $index )
44 function getUserCond() {
47 if ( $this->target
== 'newbies' ) {
48 $max = $this->mDb
->selectField( 'user', 'max(user_id)', false, __METHOD__
);
49 $condition[] = 'rev_user >' . (int)($max - $max / 100);
50 $index = 'user_timestamp';
52 $condition['rev_user_text'] = $this->target
;
53 $index = 'usertext_timestamp';
55 return array( $index, $condition );
58 function getNamespaceCond() {
59 if ( $this->namespace !== '' ) {
60 return array( 'page_namespace' => (int)$this->namespace );
66 function getIndexField() {
67 return 'rev_timestamp';
70 function getStartBody() {
74 function getEndBody() {
78 function getNavigationBar() {
79 if ( isset( $this->mNavigationBar
) ) {
80 return $this->mNavigationBar
;
83 'prev' => wfMsgHtml( "sp-contributions-newer", $this->mLimit
),
84 'next' => wfMsgHtml( 'sp-contributions-older', $this->mLimit
),
85 'first' => wfMsgHtml('sp-contributions-newest'),
86 'last' => wfMsgHtml( 'sp-contributions-oldest' )
89 $pagingLinks = $this->getPagingLinks( $linkTexts );
90 $limitLinks = $this->getLimitLinks();
91 $limits = implode( ' | ', $limitLinks );
93 $this->mNavigationBar
= "({$pagingLinks['first']} | {$pagingLinks['last']}) " .
94 wfMsgHtml("viewprevnext", $pagingLinks['prev'], $pagingLinks['next'], $limits);
95 return $this->mNavigationBar
;
99 * Generates each row in the contributions list.
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.
106 * @todo This would probably look a lot nicer in a table.
108 function formatRow( $row ) {
109 wfProfileIn( __METHOD__
);
111 global $wgLang, $wgUser;
113 $sk = $this->getSkin();
114 $rev = new Revision( $row );
116 $page = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
117 $link = $sk->makeKnownLinkObj( $page );
118 $difftext = $topmarktext = '';
119 if( $row->rev_id
== $row->page_latest
) {
120 $topmarktext .= '<strong>' . $this->messages
['uctop'] . '</strong>';
121 if( !$row->page_is_new
) {
122 $difftext .= '(' . $sk->makeKnownLinkObj( $page, $this->messages
['diff'], 'diff=0' ) . ')';
124 $difftext .= $this->messages
['newarticle'];
127 if( $wgUser->isAllowed( 'rollback' ) ) {
128 $topmarktext .= ' '.$sk->generateRollback( $rev );
132 if( $rev->userCan( Revision
::DELETED_TEXT
) ) {
133 $difftext = '(' . $sk->makeKnownLinkObj( $page, $this->messages
['diff'], 'diff=prev&oldid='.$row->rev_id
) . ')';
135 $difftext = '(' . $this->messages
['diff'] . ')';
137 $histlink='('.$sk->makeKnownLinkObj( $page, $this->messages
['hist'], 'action=history' ) . ')';
139 $comment = $sk->revComment( $rev );
140 $d = $wgLang->timeanddate( wfTimestamp( TS_MW
, $row->rev_timestamp
), true );
142 if( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
143 $d = '<span class="history-deleted">' . $d . '</span>';
146 if( $row->rev_minor_edit
) {
147 $mflag = '<span class="minor">' . $this->messages
['minoreditletter'] . '</span> ';
152 $ret = "{$d} {$histlink} {$difftext} {$mflag} {$link} {$comment} {$topmarktext}";
153 if( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
154 $ret .= ' ' . wfMsgHtml( 'deletedrev' );
156 $ret = "<li>$ret</li>\n";
157 wfProfileOut( __METHOD__
);
163 * Special page "user contributions".
164 * Shows a list of the contributions of a user.
167 * @param $par String: (optional) user name of the user for which to show the contributions
169 function wfSpecialContributions( $par = null ) {
170 global $wgUser, $wgOut, $wgLang, $wgRequest;
174 if ( isset( $par ) && $par == 'newbies' ) {
176 $options['contribs'] = 'newbie';
177 } elseif ( isset( $par ) ) {
180 $target = $wgRequest->getVal( 'target' );
183 // check for radiobox
184 if ( $wgRequest->getVal( 'contribs' ) == 'newbie' ) {
186 $options['contribs'] = 'newbie';
189 if ( !strlen( $target ) ) {
190 $wgOut->addHTML( contributionsForm( '' ) );
194 $options['limit'] = $wgRequest->getInt( 'limit', 50 );
195 $options['target'] = $target;
197 $nt = Title
::makeTitleSafe( NS_USER
, $target );
199 $wgOut->addHTML( contributionsForm( '' ) );
202 $id = User
::idFromName( $nt->getText() );
204 if ( $target != 'newbies' ) {
205 $target = $nt->getText();
206 $wgOut->setSubtitle( contributionsSub( $nt, $id ) );
208 $wgOut->setSubtitle( wfMsgHtml( 'sp-contributions-newbies-sub') );
211 if ( ( $ns = $wgRequest->getVal( 'namespace', null ) ) !== null && $ns !== '' ) {
212 $options['namespace'] = intval( $ns );
214 $options['namespace'] = '';
216 if ( $wgUser->isAllowed( 'rollback' ) && $wgRequest->getBool( 'bot' ) ) {
217 $options['bot'] = '1';
220 wfRunHooks( 'SpecialContributionsBeforeMainOutput', $id );
222 $wgOut->addHTML( contributionsForm( $options ) );
224 $pager = new ContribsPager( $target, $options['namespace'] );
225 if ( !$pager->getNumRows() ) {
226 $wgOut->addWikiText( wfMsg( 'nocontribs' ) );
230 '<p>' . $pager->getNavigationBar() . '</p>' .
232 '<p>' . $pager->getNavigationBar() . '</p>' );
234 # If there were contributions, and it was a valid user or IP, show
235 # the appropriate "footer" message - WHOIS tools, etc.
236 if( $target != 'newbies' ) {
237 $message = IP
::isIPAddress( $target )
238 ?
'sp-contributions-footer-anon'
239 : 'sp-contributions-footer';
242 $text = wfMsg( $message, $target );
243 if( !wfEmptyMsg( $message, $text ) && $text != '-' ) {
244 $wgOut->addHtml( '<div class="mw-contributions-footer">' );
245 $wgOut->addWikiText( $text );
246 $wgOut->addHtml( '</div>' );
252 * Generates the subheading with links
253 * @param Title $nt Title object for the target
254 * @param integer $id User ID for the target
255 * @return String: appropriately-escaped HTML to be output literally
257 function contributionsSub( $nt, $id ) {
258 global $wgSysopUserBans, $wgLang, $wgUser;
260 $sk = $wgUser->getSkin();
263 $user = $nt->getText();
265 $user = $sk->makeLinkObj( $nt, htmlspecialchars( $nt->getText() ) );
267 $talk = $nt->getTalkPage();
270 $tools[] = $sk->makeLinkObj( $talk, wfMsgHtml( 'talkpagelinktext' ) );
271 if( ( $id != 0 && $wgSysopUserBans ) ||
( $id == 0 && User
::isIP( $nt->getText() ) ) ) {
273 if( $wgUser->isAllowed( 'block' ) )
274 $tools[] = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Blockip', $nt->getDBkey() ), wfMsgHtml( 'blocklink' ) );
276 $tools[] = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Log' ), wfMsgHtml( 'sp-contributions-blocklog' ), 'type=block&page=' . $nt->getPrefixedUrl() );
279 $tools[] = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Log' ), wfMsgHtml( 'log' ), 'user=' . $nt->getPartialUrl() );
280 $links = implode( ' | ', $tools );
283 // Old message 'contribsub' had one parameter, but that doesn't work for
284 // languages that want to put the "for" bit right after $user but before
285 // $links. If 'contribsub' is around, use it for reverse compatibility,
286 // otherwise use 'contribsub2'.
287 if( wfEmptyMsg( 'contribsub', wfMsg( 'contribsub' ) ) ) {
288 return wfMsgHtml( 'contribsub2', $user, $links );
290 return wfMsgHtml( 'contribsub', "$user ($links)" );
295 * Generates the namespace selector form with hidden attributes.
296 * @param $options Array: the options to be included.
298 function contributionsForm( $options ) {
299 global $wgScript, $wgTitle, $wgRequest;
301 $options['title'] = $wgTitle->getPrefixedText();
302 if ( !isset( $options['target'] ) ) {
303 $options['target'] = '';
305 $options['target'] = str_replace( '_' , ' ' , $options['target'] );
308 if ( !isset( $options['namespace'] ) ) {
309 $options['namespace'] = '';
312 if ( !isset( $options['contribs'] ) ) {
313 $options['contribs'] = 'user';
316 if ( $options['contribs'] == 'newbie' ) {
317 $options['target'] = '';
320 $f = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
322 foreach ( $options as $name => $value ) {
323 if ( in_array( $name, array( 'namespace', 'target', 'contribs' ) ) ) {
326 $f .= "\t" . Xml
::hidden( $name, $value ) . "\n";
330 Xml
::element( 'legend', array(), wfMsg( 'sp-contributions-search' ) ) .
331 Xml
::radioLabel( wfMsgExt( 'sp-contributions-newbies', array( 'parseinline' ) ), 'contribs' , 'newbie' , 'newbie', $options['contribs'] == 'newbie' ?
true : false ) . '<br />' .
332 Xml
::radioLabel( wfMsgExt( 'sp-contributions-username', array( 'parseinline' ) ), 'contribs' , 'user', 'user', $options['contribs'] == 'user' ?
true : false ) . ' ' .
333 Xml
::input( 'target', 20, $options['target']) . ' '.
334 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) .
335 Xml
::namespaceSelector( $options['namespace'], '' ) .
336 Xml
::submitButton( wfMsg( 'sp-contributions-submit' ) ) .
338 Xml
::closeElement( 'form' );