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() );
47 # These links are not in the body, so we can't use the delayed link colouring.
48 # Disable it and enable it again later.
49 $pPLC=$sk->postParseLinkColour();
50 $sk->postParseLinkColour( false );
55 $ul = $sk->makeLinkObj( $nt, htmlspecialchars( $nt->getText() ) );
56 $userCond = "=" . $id;
58 $talk = $nt->getTalkPage();
60 $ul .= " (" . $sk->makeLinkObj( $talk, $wgLang->getNsText(Namespace::getTalk(0)) ) . ")";
63 # Enable delayed link colouring again.
64 $sk->postParseLinkColour( $pPLC );
66 if ( $target == 'newbies' ) {
67 # View the contributions of all recently created accounts
68 $max = $dbr->selectField( 'user', 'max(user_id)', false, $fname );
69 $userCond = ">" . ($max - $max / 100);
70 $ul = wfMsg ( 'newbies' );
74 $wgOut->setSubtitle( wfMsg( "contribsub", $ul ) );
77 $cmq = "AND cur_minor_edit=0";
78 $omq = "AND old_minor_edit=0";
79 $mlink = $sk->makeKnownLink( $wgLang->specialPage( "Contributions" ),
80 WfMsg( "show" ), "target=" . htmlspecialchars( $nt->getPrefixedURL() ) .
81 "&offset={$offset}&limit={$limit}&hideminor=0" );
84 $mlink = $sk->makeKnownLink( $wgLang->specialPage( "Contributions" ),
85 WfMsg( "hide" ), "target=" . htmlspecialchars( $nt->getPrefixedURL() ) .
86 "&offset={$offset}&limit={$limit}&hideminor=1" );
89 extract( $dbr->tableNames( 'old', 'cur' ) );
90 if ( $userCond == "" ) {
91 $sql = "SELECT cur_namespace,cur_title,cur_timestamp,cur_comment,cur_minor_edit,cur_is_new,cur_user_text FROM $cur " .
92 "WHERE cur_user_text='" . $dbr->strencode( $nt->getText() ) . "' {$cmq} " .
93 "ORDER BY inverse_timestamp LIMIT {$querylimit}";
94 $res1 = $dbr->query( $sql, $fname );
96 $sql = "SELECT old_namespace,old_title,old_timestamp,old_comment,old_minor_edit,old_user_text,old_id FROM $old " .
97 "WHERE old_user_text='" . $dbr->strencode( $nt->getText() ) . "' {$omq} " .
98 "ORDER BY inverse_timestamp LIMIT {$querylimit}";
99 $res2 = $dbr->query( $sql, $fname );
101 $sql = "SELECT cur_namespace,cur_title,cur_timestamp,cur_comment,cur_minor_edit,cur_is_new,cur_user_text FROM $cur " .
102 "WHERE cur_user {$userCond} {$cmq} ORDER BY inverse_timestamp LIMIT {$querylimit}";
103 $res1 = $dbr->query( $sql, $fname );
105 $sql = "SELECT old_namespace,old_title,old_timestamp,old_comment,old_minor_edit,old_user_text,old_id FROM $old " .
106 "WHERE old_user {$userCond} {$omq} ORDER BY inverse_timestamp LIMIT {$querylimit}";
107 $res2 = $dbr->query( $sql, $fname );
109 $nCur = $dbr->numRows( $res1 );
110 $nOld = $dbr->numRows( $res2 );
112 $top = wfShowingResults( $offset, $limit );
113 $wgOut->addHTML( "<p>{$top}\n" );
115 $sl = wfViewPrevNext( $offset, $limit,
116 $wgLang->specialpage( "Contributions" ),
117 "hideminor={$hideminor}&target=" . wfUrlEncode( $target ),
118 ($nCur +
$nOld) <= $offlimit);
120 $shm = wfMsg( "showhideminor", $mlink );
121 $wgOut->addHTML( "<br />{$sl} ($shm)</p>\n");
124 if ( 0 == $nCur && 0 == $nOld ) {
125 $wgOut->addHTML( "\n<p>" . wfMsg( "nocontribs" ) . "</p>\n" );
128 if ( 0 != $nCur ) { $obj1 = $dbr->fetchObject( $res1 ); }
129 if ( 0 != $nOld ) { $obj2 = $dbr->fetchObject( $res2 ); }
131 $wgOut->addHTML( "<ul>\n" );
132 for( $n = 0; $n < $offlimit; $n++
) {
133 if ( 0 == $nCur && 0 == $nOld ) { break; }
135 if ( ( 0 == $nOld ) ||
137 ( $obj1->cur_timestamp
>= $obj2->old_timestamp
) ) ) {
138 $ns = $obj1->cur_namespace
;
139 $t = $obj1->cur_title
;
140 $ts = $obj1->cur_timestamp
;
141 $comment =$obj1->cur_comment
;
142 $me = $obj1->cur_minor_edit
;
143 $isnew = $obj1->cur_is_new
;
144 $usertext = $obj1->cur_user_text
;
146 $obj1 = $dbr->fetchObject( $res1 );
151 $ns = $obj2->old_namespace
;
152 $t = $obj2->old_title
;
153 $ts = $obj2->old_timestamp
;
154 $comment =$obj2->old_comment
;
155 $me = $obj2->old_minor_edit
;
156 $usertext = $obj2->old_user_text
;
157 $oldid = $obj2->old_id
;
159 $obj2 = $dbr->fetchObject( $res2 );
165 ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, ( $me > 0), $isnew, $usertext, $oldid );
167 $wgOut->addHTML( "</ul>\n" );
170 global $wgUseValidation;
171 if( $wgUseValidation ) {
172 require_once( 'SpecialValidate.php' );
173 $val = new Validation
;
174 $val = $val->countUserValidations ( $id ) ;
175 $wgOut->addHTML( wfMsg ( 'val_user_validations', $val ) );
181 * Generates each row in the contributions list.
183 * Contributions which are marked "top" are currently on top of the history.
184 * For these contributions, a [rollback] link is shown for users with sysop
185 * privileges. The rollback link restores the most recent version that was not
186 * written by the target user.
188 * If the contributions page is called with the parameter &bot=1, all rollback
189 * links also get that parameter. It causes the edit itself and the rollback
190 * to be marked as "bot" edits. Bot edits are hidden by default from recent
191 * changes, so this allows sysops to combat a busy vandal without bothering
194 * @todo This would probably look a lot nicer in a table.
196 function ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, $isminor, $isnew, $target, $oldid ) {
197 global $wgLang, $wgOut, $wgUser, $wgRequest;
198 $page = Title
::makeName( $ns, $t );
199 $link = $sk->makeKnownLink( $page, "" );
203 $topmarktext .= $sk->makeKnownLink( $page, wfMsg("uctop"), "diff=0" );
205 $topmarktext .= wfMsg("newarticle");
207 $sysop = $wgUser->isSysop();
209 $extraRollback = $wgRequest->getBool( "bot" ) ?
'&bot=1' : '';
210 # $target = $wgRequest->getText( 'target' );
211 $topmarktext .= " [". $sk->makeKnownLink( $page,
212 wfMsg( "rollbacklink" ),
213 "action=rollback&from=" . urlencode( $target ) . $extraRollback ) ."]";
218 $oldtext= $sk->makeKnownLink( $page, '('.wfMsg('diff').')', 'diff=prev&oldid='.$oldid );
219 } else { $oldtext=''; }
220 $histlink="(".$sk->makeKnownLink($page,wfMsg("hist"),"action=history").")";
224 $comment="<em>(". $sk->formatComment($comment, Title
::newFromText($t) ) .")</em> ";
227 $d = $wgLang->timeanddate( $ts, true );
230 $mflag = '<span class="minor">'.wfMsg( "minoreditletter" ).'</span> ';
235 $wgOut->addHTML( "<li>{$d} {$histlink} {$mflag} {$link} {$comment}{$topmarktext}{$oldtext}</li>\n" );
241 function ucCountLink( $lim, $d ) {
242 global $wgUser, $wgLang, $wgRequest;
244 $target = $wgRequest->getText( 'target' );
245 $sk = $wgUser->getSkin();
246 $s = $sk->makeKnownLink( $wgLang->specialPage( "Contributions" ),
247 "{$lim}", "target={$target}&days={$d}&limit={$lim}" );
254 function ucDaysLink( $lim, $d ) {
255 global $wgUser, $wgLang, $wgRequest;
257 $target = $wgRequest->getText( 'target' );
258 $sk = $wgUser->getSkin();
259 $s = $sk->makeKnownLink( $wgLang->specialPage( "Contributions" ),
260 "{$d}", "target={$target}&days={$d}&limit={$lim}" );