profiling correction
[mediawiki.git] / includes / SpecialContributions.php
blobad9b5acb5e06014fbec882dc36b73218b0763129
1 <?php
3 function wfSpecialContributions( $par = "" )
5 global $wgUser, $wgOut, $wgLang, $wgRequest;
6 $fname = "wfSpecialContributions";
7 $sysop = $wgUser->isSysop();
9 if( $par )
10 $target = $par;
11 else
12 $target = $wgRequest->getVal( 'target' );
14 if ( "" == $target ) {
15 $wgOut->errorpage( "notargettitle", "notargettext" );
16 return;
19 # FIXME: Change from numeric offsets to date offsets
20 list( $limit, $offset ) = wfCheckLimits( 50, "" );
21 $offlimit = $limit + $offset;
22 $querylimit = $offlimit + 1;
23 $hideminor = ($wgRequest->getVal( 'hideminor' ) ? 1 : 0);
25 $nt = Title::newFromURL( $target );
26 $nt->setNamespace( Namespace::getUser() );
28 $sk = $wgUser->getSkin();
29 $id = User::idFromName( $nt->getText() );
31 if ( 0 == $id ) {
32 $ul = $nt->getText();
33 } else {
34 $ul = $sk->makeLinkObj( $nt, $nt->getText() );
36 $talk = $nt->getTalkPage();
37 if( $talk )
38 $ul .= " (" . $sk->makeLinkObj( $talk, $wgLang->getNsText(Namespace::getTalk(0)) ) . ")";
39 else
40 $ul .= "brrrp";
41 $wgOut->setSubtitle( wfMsg( "contribsub", $ul ) );
43 if ( $hideminor ) {
44 $cmq = "AND cur_minor_edit=0";
45 $omq = "AND old_minor_edit=0";
46 $mlink = $sk->makeKnownLink( $wgLang->specialPage( "Contributions" ),
47 WfMsg( "show" ), "target=" . wfEscapeHTML( $nt->getPrefixedURL() ) .
48 "&offset={$offset}&limit={$limit}&hideminor=0" );
49 } else {
50 $cmq = $omq = "";
51 $mlink = $sk->makeKnownLink( $wgLang->specialPage( "Contributions" ),
52 WfMsg( "hide" ), "target=" . wfEscapeHTML( $nt->getPrefixedURL() ) .
53 "&offset={$offset}&limit={$limit}&hideminor=1" );
56 if ( 0 == $id ) {
57 $sql = "SELECT cur_namespace,cur_title,cur_timestamp,cur_comment,cur_minor_edit,cur_is_new FROM cur " .
58 "WHERE cur_user_text='" . wfStrencode( $nt->getText() ) . "' {$cmq} " .
59 "ORDER BY inverse_timestamp LIMIT {$querylimit}";
60 $res1 = wfQuery( $sql, DB_READ, $fname );
62 $sql = "SELECT old_namespace,old_title,old_timestamp,old_comment,old_minor_edit FROM old " .
63 "WHERE old_user_text='" . wfStrencode( $nt->getText() ) . "' {$omq} " .
64 "ORDER BY inverse_timestamp LIMIT {$querylimit}";
65 $res2 = wfQuery( $sql, DB_READ, $fname );
66 } else {
67 $sql = "SELECT cur_namespace,cur_title,cur_timestamp,cur_comment,cur_minor_edit,cur_is_new FROM cur " .
68 "WHERE cur_user={$id} {$cmq} ORDER BY inverse_timestamp LIMIT {$querylimit}";
69 $res1 = wfQuery( $sql, DB_READ, $fname );
71 $sql = "SELECT old_namespace,old_title,old_timestamp,old_comment,old_minor_edit FROM old " .
72 "WHERE old_user={$id} {$omq} ORDER BY inverse_timestamp LIMIT {$querylimit}";
73 $res2 = wfQuery( $sql, DB_READ, $fname );
75 $nCur = wfNumRows( $res1 );
76 $nOld = wfNumRows( $res2 );
78 $top = wfShowingResults( $offset, $limit );
79 $wgOut->addHTML( "<p>{$top}\n" );
81 $sl = wfViewPrevNext( $offset, $limit,
82 $wgLang->specialpage( "Contributions" ),
83 "hideminor={$hideminor}&target=" . wfUrlEncode( $target ),
84 ($nCur + $nOld) <= $offlimit);
86 $shm = wfMsg( "showhideminor", $mlink );
87 $wgOut->addHTML( "<br />{$sl} ($shm)</p>\n");
90 if ( 0 == $nCur && 0 == $nOld ) {
91 $wgOut->addHTML( "\n<p>" . wfMsg( "nocontribs" ) . "</p>\n" );
92 return;
94 if ( 0 != $nCur ) { $obj1 = wfFetchObject( $res1 ); }
95 if ( 0 != $nOld ) { $obj2 = wfFetchObject( $res2 ); }
97 $wgOut->addHTML( "<ul>\n" );
98 for( $n = 0; $n < $offlimit; $n++ ) {
99 if ( 0 == $nCur && 0 == $nOld ) { break; }
101 if ( ( 0 == $nOld ) ||
102 ( ( 0 != $nCur ) &&
103 ( $obj1->cur_timestamp >= $obj2->old_timestamp ) ) ) {
104 $ns = $obj1->cur_namespace;
105 $t = $obj1->cur_title;
106 $ts = $obj1->cur_timestamp;
107 $comment =$obj1->cur_comment;
108 $me = $obj1->cur_minor_edit;
109 $isnew = $obj1->cur_is_new;
110 $obj1 = wfFetchObject( $res1 );
111 $topmark = true;
112 --$nCur;
113 } else {
114 $ns = $obj2->old_namespace;
115 $t = $obj2->old_title;
116 $ts = $obj2->old_timestamp;
117 $comment =$obj2->old_comment;
118 $me = $obj2->old_minor_edit;
120 $obj2 = wfFetchObject( $res2 );
121 $topmark = false;
122 $isnew = false;
123 --$nOld;
125 if( $n >= $offset )
126 ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, ( $me > 0), $isnew );
128 $wgOut->addHTML( "</ul>\n" );
134 Generates each row in the contributions list.
136 Contributions which are marked "top" are currently on top of the history.
137 For these contributions, a [rollback] link is shown for users with sysop
138 privileges. The rollback link restores the most recent version that was not
139 written by the target user.
141 If the contributions page is called with the parameter &bot=1, all rollback
142 links also get that parameter. It causes the edit itself and the rollback
143 to be marked as "bot" edits. Bot edits are hidden by default from recent
144 changes, so this allows sysops to combat a busy vandal without bothering
145 other users.
147 TODO: This would probably look a lot nicer in a table.
150 function ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, $isminor, $isnew )
152 global $wgLang, $wgOut, $wgUser, $wgRequest;
153 $page = Title::makeName( $ns, $t );
154 $link = $sk->makeKnownLink( $page, "" );
155 $topmarktext="";
156 if($topmark) {
157 if(!$isnew) {
158 $topmarktext .= $sk->makeKnownLink( $page, wfMsg("uctop"), "diff=0" );
159 } else {
160 $topmarktext .= wfMsg("newarticle");
162 $sysop = $wgUser->isSysop();
163 if($sysop ) {
164 $extraRollback = $wgRequest->getBool( "bot" ) ? '&bot=1' : '';
165 $target = $wgRequest->getText( 'target' );
166 $topmarktext .= " [". $sk->makeKnownLink( $page,
167 wfMsg( "rollbacklink" ),
168 "action=rollback&from=" . urlencode( $target ) . $extraRollback ) ."]";
172 $histlink="(".$sk->makeKnownLink($page,wfMsg("hist"),"action=history").")";
174 if($comment) {
176 $comment="<em>(". $sk->formatComment($comment ) .")</em> ";
179 $d = $wgLang->timeanddate( $ts, true );
181 if ($isminor) {
182 $mflag = "<strong>" . wfMsg( "minoreditletter" ) . "</strong> ";
183 } else {
184 $mflag = "";
187 $wgOut->addHTML( "<li>{$d} {$histlink} {$mflag} {$link} {$comment}{$topmarktext}</li>\n" );
190 function ucCountLink( $lim, $d )
192 global $wgUser, $wgLang, $wgRequest;
194 $target = $wgRequest->getText( 'target' );
195 $sk = $wgUser->getSkin();
196 $s = $sk->makeKnownLink( $wgLang->specialPage( "Contributions" ),
197 "{$lim}", "target={$target}&days={$d}&limit={$lim}" );
198 return $s;
201 function ucDaysLink( $lim, $d )
203 global $wgUser, $wgLang, $wgRequest;
205 $target = $wgRequest->getText( 'target' );
206 $sk = $wgUser->getSkin();
207 $s = $sk->makeKnownLink( $wgLang->specialPage( "Contributions" ),
208 "{$d}", "target={$target}&days={$d}&limit={$lim}" );
209 return $s;