a0effc6d3cd8ae5e887acf2d824914e05ec402ed
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 ) {
15 parent
::__construct();
16 foreach( explode( ' ', 'uctop diff newarticle rollbacklink diff hist minoreditletter' ) as $msg ) {
17 $this->messages
[$msg] = wfMsgExt( $msg, array( 'escape') );
19 $this->target
= $target;
20 $this->namespace = $namespace;
21 $this->mDb
= wfGetDB( DB_SLAVE
, 'contributions' );
24 function getDefaultQuery() {
25 $query = parent
::getDefaultQuery();
26 $query['target'] = $this->target
;
30 function getQueryInfo() {
31 list( $index, $userCond ) = $this->getUserCond();
32 $conds = array_merge( array( 'page_id=rev_page' ), $userCond, $this->getNamespaceCond() );
35 'tables' => array( 'page', 'revision' ),
37 'page_namespace', 'page_title', 'page_is_new', 'page_latest', 'rev_id', 'rev_page',
38 'rev_text_id', 'rev_timestamp', 'rev_comment', 'rev_minor_edit', 'rev_user',
39 'rev_user_text', 'rev_deleted'
42 'options' => array( 'FORCE INDEX' => $index )
46 function getUserCond() {
49 if ( $this->target
== 'newbies' ) {
50 $max = $this->mDb
->selectField( 'user', 'max(user_id)', false, __METHOD__
);
51 $condition[] = 'rev_user >' . (int)($max - $max / 2/*100*/);
52 $index = 'user_timestamp';
54 $condition['rev_user_text'] = $this->target
;
55 $index = 'usertext_timestamp';
57 return array( $index, $condition );
60 function getNamespaceCond() {
61 if ( $this->namespace !== '' ) {
62 return array( 'page_namespace' => (int)$this->namespace );
68 function getIndexField() {
69 return 'rev_timestamp';
72 function getStartBody() {
76 function getEndBody() {
80 function getNavigationBar() {
81 if ( isset( $this->mNavigationBar
) ) {
82 return $this->mNavigationBar
;
85 'prev' => wfMsgHtml( "sp-contributions-newer", $this->mLimit
),
86 'next' => wfMsgHtml( 'sp-contributions-older', $this->mLimit
),
87 'first' => wfMsgHtml('sp-contributions-newest'),
88 'last' => wfMsgHtml( 'sp-contributions-oldest' )
91 $pagingLinks = $this->getPagingLinks( $linkTexts );
92 $limitLinks = $this->getLimitLinks();
93 $limits = implode( ' | ', $limitLinks );
95 $this->mNavigationBar
= "({$pagingLinks['first']} | {$pagingLinks['last']}) " .
96 wfMsgHtml("viewprevnext", $pagingLinks['prev'], $pagingLinks['next'], $limits);
97 return $this->mNavigationBar
;
101 * Generates each row in the contributions list.
103 * Contributions which are marked "top" are currently on top of the history.
104 * For these contributions, a [rollback] link is shown for users with sysop
105 * privileges. The rollback link restores the most recent version that was not
106 * written by the target user.
108 * @todo This would probably look a lot nicer in a table.
110 function formatRow( $row ) {
111 wfProfileIn( __METHOD__
);
113 global $wgLang, $wgUser;
115 $sk = $this->getSkin();
116 $rev = new Revision( $row );
118 $page = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
119 $link = $sk->makeKnownLinkObj( $page );
120 $difftext = $topmarktext = '';
121 if( $row->rev_id
== $row->page_latest
) {
122 $topmarktext .= '<strong>' . $this->messages
['uctop'] . '</strong>';
123 if( !$row->page_is_new
) {
124 $difftext .= '(' . $sk->makeKnownLinkObj( $page, $this->messages
['diff'], 'diff=0' ) . ')';
126 $difftext .= $this->messages
['newarticle'];
129 if( $wgUser->isAllowed( 'rollback' ) ) {
130 $topmarktext .= ' '.$sk->generateRollback( $rev );
134 if( $rev->userCan( Revision
::DELETED_TEXT
) ) {
135 $difftext = '(' . $sk->makeKnownLinkObj( $page, $this->messages
['diff'], 'diff=prev&oldid='.$row->rev_id
) . ')';
137 $difftext = '(' . $this->messages
['diff'] . ')';
139 $histlink='('.$sk->makeKnownLinkObj( $page, $this->messages
['hist'], 'action=history' ) . ')';
141 $comment = $sk->revComment( $rev );
142 $d = $wgLang->timeanddate( wfTimestamp( TS_MW
, $row->rev_timestamp
), true );
144 if( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
145 $d = '<span class="history-deleted">' . $d . '</span>';
148 if( $row->rev_minor_edit
) {
149 $mflag = '<span class="minor">' . $this->messages
['minoreditletter'] . '</span> ';
154 $ret = "{$d} {$histlink} {$difftext} {$mflag} {$link} {$comment} {$topmarktext}";
155 if( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
156 $ret .= ' ' . wfMsgHtml( 'deletedrev' );
158 $ret = "<li>$ret</li>\n";
159 wfProfileOut( __METHOD__
);
165 * Special page "user contributions".
166 * Shows a list of the contributions of a user.
169 * @param $par String: (optional) user name of the user for which to show the contributions
171 function wfSpecialContributions( $par = null ) {
172 global $wgUser, $wgOut, $wgLang, $wgRequest;
176 if ( isset( $par ) && $par == 'newbies' ) {
178 $options['contribs'] = 'newbie';
179 } elseif ( isset( $par ) ) {
182 $target = $wgRequest->getVal( 'target' );
185 // check for radiobox
186 if ( $wgRequest->getVal( 'contribs' ) == 'newbie' ) {
188 $options['contribs'] = 'newbie';
191 if ( !strlen( $target ) ) {
192 $wgOut->addHTML( contributionsForm( '' ) );
196 $options['limit'] = $wgRequest->getInt( 'limit', 50 );
197 $options['target'] = $target;
199 $nt = Title
::makeTitleSafe( NS_USER
, $target );
201 $wgOut->addHTML( contributionsForm( '' ) );
204 $id = User
::idFromName( $nt->getText() );
206 if ( $target != 'newbies' ) {
207 $target = $nt->getText();
208 $wgOut->setSubtitle( contributionsSub( $nt, $id ) );
210 $wgOut->setSubtitle( wfMsgHtml( 'sp-contributions-newbies-sub') );
213 if ( ( $ns = $wgRequest->getVal( 'namespace', null ) ) !== null && $ns !== '' ) {
214 $options['namespace'] = intval( $ns );
216 $options['namespace'] = '';
218 if ( $wgUser->isAllowed( 'rollback' ) && $wgRequest->getBool( 'bot' ) ) {
219 $options['bot'] = '1';
222 wfRunHooks( 'SpecialContributionsBeforeMainOutput', $id );
224 $wgOut->addHTML( contributionsForm( $options ) );
226 $pager = new ContribsPager( $target, $options['namespace'] );
227 if ( !$pager->getNumRows() ) {
228 $wgOut->addWikiText( wfMsg( 'nocontribs' ) );
232 '<p>' . $pager->getNavigationBar() . '</p>' .
234 '<p>' . $pager->getNavigationBar() . '</p>' );
236 # If there were contributions, and it was a valid user or IP, show
237 # the appropriate "footer" message - WHOIS tools, etc.
238 if( $target != 'newbies' ) {
239 $message = IP
::isIPAddress( $target )
240 ?
'sp-contributions-footer-anon'
241 : 'sp-contributions-footer';
244 $text = wfMsg( $message, $target );
245 if( !wfEmptyMsg( $message, $text ) && $text != '-' ) {
246 $wgOut->addHtml( '<div class="mw-contributions-footer">' );
247 $wgOut->addWikiText( $text );
248 $wgOut->addHtml( '</div>' );
254 * Generates the subheading with links
255 * @param Title $nt Title object for the target
256 * @param integer $id User ID for the target
257 * @return String: appropriately-escaped HTML to be output literally
259 function contributionsSub( $nt, $id ) {
260 global $wgSysopUserBans, $wgLang, $wgUser;
262 $sk = $wgUser->getSkin();
265 $user = $nt->getText();
267 $user = $sk->makeLinkObj( $nt, htmlspecialchars( $nt->getText() ) );
269 $talk = $nt->getTalkPage();
272 $tools[] = $sk->makeLinkObj( $talk, $wgLang->getNsText( NS_TALK
) );
273 if( ( $id != 0 && $wgSysopUserBans ) ||
( $id == 0 && User
::isIP( $nt->getText() ) ) ) {
275 if( $wgUser->isAllowed( 'block' ) )
276 $tools[] = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Blockip', $nt->getDBkey() ), wfMsgHtml( 'blocklink' ) );
278 $tools[] = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Log' ), wfMsgHtml( 'sp-contributions-blocklog' ), 'type=block&page=' . $nt->getPrefixedUrl() );
281 $tools[] = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Log' ), wfMsgHtml( 'log' ), 'user=' . $nt->getPartialUrl() );
282 $links = implode( ' | ', $tools );
285 // Old message 'contribsub' had one parameter, but that doesn't work for
286 // languages that want to put the "for" bit right after $user but before
287 // $links. If 'contribsub' is around, use it for reverse compatibility,
288 // otherwise use 'contribsub2'.
289 if( wfEmptyMsg( 'contribsub', wfMsg( 'contribsub' ) ) ) {
290 return wfMsgHtml( 'contribsub2', $user, $links );
292 return wfMsgHtml( 'contribsub', "$user ($links)" );
297 * Generates the namespace selector form with hidden attributes.
298 * @param $options Array: the options to be included.
300 function contributionsForm( $options ) {
301 global $wgScript, $wgTitle, $wgRequest;
303 $options['title'] = $wgTitle->getPrefixedText();
304 if ( !isset( $options['target'] ) ) {
305 $options['target'] = '';
307 $options['target'] = str_replace( '_' , ' ' , $options['target'] );
310 if ( !isset( $options['namespace'] ) ) {
311 $options['namespace'] = '';
314 if ( !isset( $options['contribs'] ) ) {
315 $options['contribs'] = 'user';
318 if ( $options['contribs'] == 'newbie' ) {
319 $options['target'] = '';
322 $f = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
324 foreach ( $options as $name => $value ) {
325 if ( in_array( $name, array( 'namespace', 'target', 'contribs' ) ) ) {
328 $f .= "\t" . Xml
::hidden( $name, $value ) . "\n";
332 Xml
::element( 'legend', array(), wfMsg( 'sp-contributions-search' ) ) .
333 Xml
::radioLabel( wfMsgExt( 'sp-contributions-newbies', array( 'parseinline' ) ), 'contribs' , 'newbie' , 'newbie', $options['contribs'] == 'newbie' ?
true : false ) . '<br />' .
334 Xml
::radioLabel( wfMsgExt( 'sp-contributions-username', array( 'parseinline' ) ), 'contribs' , 'user', 'user', $options['contribs'] == 'user' ?
true : false ) . ' ' .
335 Xml
::input( 'target', 20, $options['target']) . ' '.
336 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) .
337 Xml
::namespaceSelector( $options['namespace'], '' ) .
338 Xml
::submitButton( wfMsg( 'sp-contributions-submit' ) ) .
340 Xml
::closeElement( 'form' );