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, $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( $wgLang->specialPage( "Contributions" ),
73 WfMsg( "show" ), "target=" . htmlspecialchars( $nt->getPrefixedURL() ) .
74 "&offset={$offset}&limit={$limit}&hideminor=0" );
77 $mlink = $sk->makeKnownLink( $wgLang->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_namespace,old_title,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_namespace,old_title,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 $wgLang->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 $ns = $obj2->old_namespace
;
145 $t = $obj2->old_title
;
146 $ts = $obj2->old_timestamp
;
147 $comment =$obj2->old_comment
;
148 $me = $obj2->old_minor_edit
;
149 $usertext = $obj2->old_user_text
;
150 $oldid = $obj2->old_id
;
152 $obj2 = $dbr->fetchObject( $res2 );
158 ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, ( $me > 0), $isnew, $usertext, $oldid );
160 $wgOut->addHTML( "</ul>\n" );
163 global $wgUseValidation;
164 if( $wgUseValidation ) {
165 require_once( 'SpecialValidate.php' );
166 $val = new Validation
;
167 $val = $val->countUserValidations ( $id ) ;
168 $wgOut->addHTML( wfMsg ( 'val_user_validations', $val ) );
174 * Generates each row in the contributions list.
176 * Contributions which are marked "top" are currently on top of the history.
177 * For these contributions, a [rollback] link is shown for users with sysop
178 * privileges. The rollback link restores the most recent version that was not
179 * written by the target user.
181 * If the contributions page is called with the parameter &bot=1, all rollback
182 * links also get that parameter. It causes the edit itself and the rollback
183 * to be marked as "bot" edits. Bot edits are hidden by default from recent
184 * changes, so this allows sysops to combat a busy vandal without bothering
187 * @todo This would probably look a lot nicer in a table.
189 function ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, $isminor, $isnew, $target, $oldid ) {
190 global $wgLang, $wgOut, $wgUser, $wgRequest;
191 $page = Title
::makeName( $ns, $t );
192 $link = $sk->makeKnownLink( $page, "" );
196 $topmarktext .= $sk->makeKnownLink( $page, wfMsg("uctop"), "diff=0" );
198 $topmarktext .= wfMsg("newarticle");
200 $sysop = $wgUser->isSysop();
202 $extraRollback = $wgRequest->getBool( "bot" ) ?
'&bot=1' : '';
203 # $target = $wgRequest->getText( 'target' );
204 $topmarktext .= " [". $sk->makeKnownLink( $page,
205 wfMsg( "rollbacklink" ),
206 "action=rollback&from=" . urlencode( $target ) . $extraRollback ) ."]";
211 $oldtext= $sk->makeKnownLink( $page, '('.wfMsg('diff').')', 'diff=prev&oldid='.$oldid );
212 } else { $oldtext=''; }
213 $histlink="(".$sk->makeKnownLink($page,wfMsg("hist"),"action=history").")";
217 $comment="<em>(". $sk->formatComment($comment, Title
::newFromText($t) ) .")</em> ";
220 $d = $wgLang->timeanddate( $ts, true );
223 $mflag = '<span class="minor">'.wfMsg( "minoreditletter" ).'</span> ';
228 $wgOut->addHTML( "<li>{$d} {$histlink} {$mflag} {$link} {$comment}{$topmarktext}{$oldtext}</li>\n" );
234 function ucCountLink( $lim, $d ) {
235 global $wgUser, $wgLang, $wgRequest;
237 $target = $wgRequest->getText( 'target' );
238 $sk = $wgUser->getSkin();
239 $s = $sk->makeKnownLink( $wgLang->specialPage( "Contributions" ),
240 "{$lim}", "target={$target}&days={$d}&limit={$lim}" );
247 function ucDaysLink( $lim, $d ) {
248 global $wgUser, $wgLang, $wgRequest;
250 $target = $wgRequest->getText( 'target' );
251 $sk = $wgUser->getSkin();
252 $s = $sk->makeKnownLink( $wgLang->specialPage( "Contributions" ),
253 "{$d}", "target={$target}&days={$d}&limit={$lim}" );