74a6a95f1e0fe1a96dd5a2e2785e472e090a963c
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( $this->target
== 'newbies' ) {
143 $userlink = ' . . ' . $sk->userLink( $row->rev_user
, $row->rev_user_text
);
144 $userlink .= ' (' . $sk->userTalkLink( $row->rev_user
, $row->rev_user_text
) . ') ';
149 if( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
150 $d = '<span class="history-deleted">' . $d . '</span>';
153 if( $row->rev_minor_edit
) {
154 $mflag = '<span class="minor">' . $this->messages
['minoreditletter'] . '</span> ';
159 $ret = "{$d} {$histlink} {$difftext} {$mflag} {$link}{$userlink}{$comment} {$topmarktext}";
160 if( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
161 $ret .= ' ' . wfMsgHtml( 'deletedrev' );
163 $ret = "<li>$ret</li>\n";
164 wfProfileOut( __METHOD__
);
169 * Get the Database object in use
173 public function getDatabase() {
180 * Special page "user contributions".
181 * Shows a list of the contributions of a user.
184 * @param $par String: (optional) user name of the user for which to show the contributions
186 function wfSpecialContributions( $par = null ) {
187 global $wgUser, $wgOut, $wgLang, $wgRequest;
191 if ( isset( $par ) && $par == 'newbies' ) {
193 $options['contribs'] = 'newbie';
194 } elseif ( isset( $par ) ) {
197 $target = $wgRequest->getVal( 'target' );
200 // check for radiobox
201 if ( $wgRequest->getVal( 'contribs' ) == 'newbie' ) {
203 $options['contribs'] = 'newbie';
206 if ( !strlen( $target ) ) {
207 $wgOut->addHTML( contributionsForm( '' ) );
211 $options['limit'] = $wgRequest->getInt( 'limit', 50 );
212 $options['target'] = $target;
214 $nt = Title
::makeTitleSafe( NS_USER
, $target );
216 $wgOut->addHTML( contributionsForm( '' ) );
219 $id = User
::idFromName( $nt->getText() );
221 if ( $target != 'newbies' ) {
222 $target = $nt->getText();
223 $wgOut->setSubtitle( contributionsSub( $nt, $id ) );
225 $wgOut->setSubtitle( wfMsgHtml( 'sp-contributions-newbies-sub') );
228 if ( ( $ns = $wgRequest->getVal( 'namespace', null ) ) !== null && $ns !== '' ) {
229 $options['namespace'] = intval( $ns );
231 $options['namespace'] = '';
233 if ( $wgUser->isAllowed( 'rollback' ) && $wgRequest->getBool( 'bot' ) ) {
234 $options['bot'] = '1';
237 wfRunHooks( 'SpecialContributionsBeforeMainOutput', $id );
239 $wgOut->addHTML( contributionsForm( $options ) );
241 $pager = new ContribsPager( $target, $options['namespace'] );
242 if ( !$pager->getNumRows() ) {
243 $wgOut->addWikiText( wfMsg( 'nocontribs' ) );
247 # Show a message about slave lag, if applicable
248 if( ( $lag = $pager->getDatabase()->getLag() ) > 0 )
249 $wgOut->showLagWarning( $lag );
252 '<p>' . $pager->getNavigationBar() . '</p>' .
254 '<p>' . $pager->getNavigationBar() . '</p>' );
256 # If there were contributions, and it was a valid user or IP, show
257 # the appropriate "footer" message - WHOIS tools, etc.
258 if( $target != 'newbies' ) {
259 $message = IP
::isIPAddress( $target )
260 ?
'sp-contributions-footer-anon'
261 : 'sp-contributions-footer';
264 $text = wfMsg( $message, $target );
265 if( !wfEmptyMsg( $message, $text ) && $text != '-' ) {
266 $wgOut->addHtml( '<div class="mw-contributions-footer">' );
267 $wgOut->addWikiText( $text );
268 $wgOut->addHtml( '</div>' );
274 * Generates the subheading with links
275 * @param Title $nt Title object for the target
276 * @param integer $id User ID for the target
277 * @return String: appropriately-escaped HTML to be output literally
279 function contributionsSub( $nt, $id ) {
280 global $wgSysopUserBans, $wgLang, $wgUser;
282 $sk = $wgUser->getSkin();
285 $user = $nt->getText();
287 $user = $sk->makeLinkObj( $nt, htmlspecialchars( $nt->getText() ) );
289 $talk = $nt->getTalkPage();
292 $tools[] = $sk->makeLinkObj( $talk, wfMsgHtml( 'talkpagelinktext' ) );
293 if( ( $id != 0 && $wgSysopUserBans ) ||
( $id == 0 && User
::isIP( $nt->getText() ) ) ) {
295 if( $wgUser->isAllowed( 'block' ) )
296 $tools[] = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Blockip', $nt->getDBkey() ), wfMsgHtml( 'blocklink' ) );
298 $tools[] = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Log' ), wfMsgHtml( 'sp-contributions-blocklog' ), 'type=block&page=' . $nt->getPrefixedUrl() );
301 $tools[] = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Log' ), wfMsgHtml( 'log' ), 'user=' . $nt->getPartialUrl() );
302 $links = implode( ' | ', $tools );
305 // Old message 'contribsub' had one parameter, but that doesn't work for
306 // languages that want to put the "for" bit right after $user but before
307 // $links. If 'contribsub' is around, use it for reverse compatibility,
308 // otherwise use 'contribsub2'.
309 if( wfEmptyMsg( 'contribsub', wfMsg( 'contribsub' ) ) ) {
310 return wfMsgHtml( 'contribsub2', $user, $links );
312 return wfMsgHtml( 'contribsub', "$user ($links)" );
317 * Generates the namespace selector form with hidden attributes.
318 * @param $options Array: the options to be included.
320 function contributionsForm( $options ) {
321 global $wgScript, $wgTitle, $wgRequest;
323 $options['title'] = $wgTitle->getPrefixedText();
324 if ( !isset( $options['target'] ) ) {
325 $options['target'] = '';
327 $options['target'] = str_replace( '_' , ' ' , $options['target'] );
330 if ( !isset( $options['namespace'] ) ) {
331 $options['namespace'] = '';
334 if ( !isset( $options['contribs'] ) ) {
335 $options['contribs'] = 'user';
338 if ( $options['contribs'] == 'newbie' ) {
339 $options['target'] = '';
342 $f = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
344 foreach ( $options as $name => $value ) {
345 if ( in_array( $name, array( 'namespace', 'target', 'contribs' ) ) ) {
348 $f .= "\t" . Xml
::hidden( $name, $value ) . "\n";
352 Xml
::element( 'legend', array(), wfMsg( 'sp-contributions-search' ) ) .
353 Xml
::radioLabel( wfMsgExt( 'sp-contributions-newbies', array( 'parseinline' ) ), 'contribs' , 'newbie' , 'newbie', $options['contribs'] == 'newbie' ?
true : false ) . '<br />' .
354 Xml
::radioLabel( wfMsgExt( 'sp-contributions-username', array( 'parseinline' ) ), 'contribs' , 'user', 'user', $options['contribs'] == 'user' ?
true : false ) . ' ' .
355 Xml
::input( 'target', 20, $options['target']) . ' '.
356 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) .
357 Xml
::namespaceSelector( $options['namespace'], '' ) .
358 Xml
::submitButton( wfMsg( 'sp-contributions-submit' ) ) .
360 Xml
::closeElement( 'form' );