5 * @subpackage SpecialPage
9 * Special page "user contributions".
10 * Shows a list of the contributions of a user.
13 * @param string $par (optional) user name of the user for which to show the contributions
15 function wfSpecialContributions( $par = '' ) {
16 global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest;
17 $fname = "wfSpecialContributions";
22 $target = $wgRequest->getVal( 'target' );
24 if ( "" == $target ) {
25 $wgOut->errorpage( "notargettitle", "notargettext" );
29 # FIXME: Change from numeric offsets to date offsets
30 list( $limit, $offset ) = wfCheckLimits( 50, "" );
31 $offlimit = $limit +
$offset;
32 $querylimit = $offlimit +
1;
33 $hideminor = ($wgRequest->getVal( 'hideminor' ) ?
1 : 0);
34 $sk = $wgUser->getSkin();
35 $dbr =& wfGetDB( DB_SLAVE
);
38 $nt = Title
::newFromURL( $target );
40 $wgOut->errorpage( "notargettitle", "notargettext" );
43 $nt->setNamespace( Namespace::getUser() );
45 $id = User
::idFromName( $nt->getText() );
50 $ul = $sk->makeLinkObj( $nt, htmlspecialchars( $nt->getText() ) );
51 $userCond = "=" . $id;
53 $talk = $nt->getTalkPage();
55 $ul .= " (" . $sk->makeLinkObj( $talk, $wgLang->getNsText(Namespace::getTalk(0)) ) . ")";
59 if ( $target == 'newbies' ) {
60 # View the contributions of all recently created accounts
61 $max = $dbr->selectField( 'user', 'max(user_id)', false, $fname );
62 $userCond = ">" . ($max - $max / 100);
63 $ul = wfMsg ( 'newbies' );
67 $wgOut->setSubtitle( wfMsg( "contribsub", $ul ) );
70 $cmq = "AND cur_minor_edit=0";
71 $omq = "AND old_minor_edit=0";
72 $mlink = $sk->makeKnownLink( $wgContLang->specialPage( "Contributions" ),
73 WfMsg( "show" ), "target=" . htmlspecialchars( $nt->getPrefixedURL() ) .
74 "&offset={$offset}&limit={$limit}&hideminor=0" );
77 $mlink = $sk->makeKnownLink( $wgContLang->specialPage( "Contributions" ),
78 WfMsg( "hide" ), "target=" . htmlspecialchars( $nt->getPrefixedURL() ) .
79 "&offset={$offset}&limit={$limit}&hideminor=1" );
82 extract( $dbr->tableNames( 'old', 'cur' ) );
83 if ( $userCond == "" ) {
84 $sql = "SELECT cur_namespace,cur_title,cur_timestamp,cur_comment,cur_minor_edit,cur_is_new,cur_user_text FROM $cur " .
85 "WHERE cur_user_text='" . $dbr->strencode( $nt->getText() ) . "' {$cmq} " .
86 "ORDER BY inverse_timestamp LIMIT {$querylimit}";
87 $res1 = $dbr->query( $sql, $fname );
89 $sql = "SELECT old_articleid,old_timestamp,old_comment,old_minor_edit,old_user_text,old_id FROM $old " .
90 "WHERE old_user_text='" . $dbr->strencode( $nt->getText() ) . "' {$omq} " .
91 "ORDER BY inverse_timestamp LIMIT {$querylimit}";
92 $res2 = $dbr->query( $sql, $fname );
94 $sql = "SELECT cur_namespace,cur_title,cur_timestamp,cur_comment,cur_minor_edit,cur_is_new,cur_user_text FROM $cur " .
95 "WHERE cur_user {$userCond} {$cmq} ORDER BY inverse_timestamp LIMIT {$querylimit}";
96 $res1 = $dbr->query( $sql, $fname );
98 $sql = "SELECT old_articleid,old_timestamp,old_comment,old_minor_edit,old_user_text,old_id FROM $old " .
99 "WHERE old_user {$userCond} {$omq} ORDER BY inverse_timestamp LIMIT {$querylimit}";
100 $res2 = $dbr->query( $sql, $fname );
102 $nCur = $dbr->numRows( $res1 );
103 $nOld = $dbr->numRows( $res2 );
105 $top = wfShowingResults( $offset, $limit );
106 $wgOut->addHTML( "<p>{$top}\n" );
108 $sl = wfViewPrevNext( $offset, $limit,
109 $wgContLang->specialpage( "Contributions" ),
110 "hideminor={$hideminor}&target=" . wfUrlEncode( $target ),
111 ($nCur +
$nOld) <= $offlimit);
113 $shm = wfMsg( "showhideminor", $mlink );
114 $wgOut->addHTML( "<br />{$sl} ($shm)</p>\n");
117 if ( 0 == $nCur && 0 == $nOld ) {
118 $wgOut->addHTML( "\n<p>" . wfMsg( "nocontribs" ) . "</p>\n" );
121 if ( 0 != $nCur ) { $obj1 = $dbr->fetchObject( $res1 ); }
122 if ( 0 != $nOld ) { $obj2 = $dbr->fetchObject( $res2 ); }
124 $wgOut->addHTML( "<ul>\n" );
125 for( $n = 0; $n < $offlimit; $n++
) {
126 if ( 0 == $nCur && 0 == $nOld ) { break; }
128 if ( ( 0 == $nOld ) ||
130 ( $obj1->cur_timestamp
>= $obj2->old_timestamp
) ) ) {
131 $ns = $obj1->cur_namespace
;
132 $t = $obj1->cur_title
;
133 $ts = $obj1->cur_timestamp
;
134 $comment =$obj1->cur_comment
;
135 $me = $obj1->cur_minor_edit
;
136 $isnew = $obj1->cur_is_new
;
137 $usertext = $obj1->cur_user_text
;
139 $obj1 = $dbr->fetchObject( $res1 );
144 $tt = Title
::newFromID($obj2->old_articleid
);
145 $ns = $tt->getNamespace();
146 $t = $tt->getDBkey();
147 $ts = $obj2->old_timestamp
;
148 $comment =$obj2->old_comment
;
149 $me = $obj2->old_minor_edit
;
150 $usertext = $obj2->old_user_text
;
151 $oldid = $obj2->old_id
;
153 $obj2 = $dbr->fetchObject( $res2 );
159 ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, ( $me > 0), $isnew, $usertext, $oldid );
161 $wgOut->addHTML( "</ul>\n" );
164 global $wgUseValidation;
165 if( $wgUseValidation ) {
166 require_once( 'SpecialValidate.php' );
167 $val = new Validation
;
168 $val = $val->countUserValidations ( $id ) ;
169 $wgOut->addHTML( wfMsg ( 'val_user_validations', $val ) );
175 * Generates each row in the contributions list.
177 * Contributions which are marked "top" are currently on top of the history.
178 * For these contributions, a [rollback] link is shown for users with sysop
179 * privileges. The rollback link restores the most recent version that was not
180 * written by the target user.
182 * If the contributions page is called with the parameter &bot=1, all rollback
183 * links also get that parameter. It causes the edit itself and the rollback
184 * to be marked as "bot" edits. Bot edits are hidden by default from recent
185 * changes, so this allows sysops to combat a busy vandal without bothering
188 * @todo This would probably look a lot nicer in a table.
190 function ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, $isminor, $isnew, $target, $oldid ) {
191 global $wgLang, $wgOut, $wgUser, $wgRequest;
192 $page = Title
::makeName( $ns, $t );
193 $link = $sk->makeKnownLink( $page, '' );
194 $difftext = $topmarktext = '';
196 $topmarktext .= '<strong>' . wfMsg('uctop') . '</strong>';
198 $difftext .= $sk->makeKnownLink( $page, '(' . wfMsg('diff') . ')', 'diff=0' );
200 $difftext .= wfMsg('newarticle');
202 $sysop = $wgUser->isSysop();
204 $extraRollback = $wgRequest->getBool( 'bot' ) ?
'&bot=1' : '';
205 # $target = $wgRequest->getText( 'target' );
206 $topmarktext .= ' ['. $sk->makeKnownLink( $page,
207 wfMsg( 'rollbacklink' ),
208 'action=rollback&from=' . urlencode( $target ) . $extraRollback ) .']';
213 $difftext= $sk->makeKnownLink( $page, '('.wfMsg('diff').')', 'diff=prev&oldid='.$oldid );
215 $histlink='('.$sk->makeKnownLink($page,wfMsg('hist'),'action=history').')';
219 $comment='<em>('. $sk->formatComment($comment, Title
::newFromText($t) ) .')</em> ';
222 $d = $wgLang->timeanddate( $ts, true );
225 $mflag = '<span class="minor">'.wfMsg( 'minoreditletter' ).'</span> ';
230 $wgOut->addHTML( "<li>{$d} {$histlink} {$difftext} {$mflag} {$link} {$comment} {$topmarktext}</li>\n" );
236 function ucCountLink( $lim, $d ) {
237 global $wgUser, $wgContLang, $wgRequest;
239 $target = $wgRequest->getText( 'target' );
240 $sk = $wgUser->getSkin();
241 $s = $sk->makeKnownLink( $wgContLang->specialPage( "Contributions" ),
242 "{$lim}", "target={$target}&days={$d}&limit={$lim}" );
249 function ucDaysLink( $lim, $d ) {
250 global $wgUser, $wgContLang, $wgRequest;
252 $target = $wgRequest->getText( 'target' );
253 $sk = $wgUser->getSkin();
254 $s = $sk->makeKnownLink( $wgContLang->specialPage( "Contributions" ),
255 "{$d}", "target={$target}&days={$d}&limit={$lim}" );