Conducting a conversation by means of comments
[mediawiki.git] / includes / SpecialContributions.php
blob0dcd5ebfc3ae5141d0ec66d908255d3297976317
1 <?php
3 function wfSpecialContributions( $par = "" )
5 global $wgUser, $wgOut, $wgLang, $wgRequest, $wgIsPg;
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);
24 $sk = $wgUser->getSkin();
26 $userCond = "";
28 $nt = Title::newFromURL( $target );
29 $nt->setNamespace( Namespace::getUser() );
31 $id = User::idFromName( $nt->getText() );
33 if ( 0 == $id ) {
34 $ul = $nt->getText();
35 } else {
36 $ul = $sk->makeLinkObj( $nt, htmlspecialchars( $nt->getText() ) );
37 $userCond = "=" . $id;
39 $talk = $nt->getTalkPage();
40 if( $talk )
41 $ul .= " (" . $sk->makeLinkObj( $talk, $wgLang->getNsText(Namespace::getTalk(0)) ) . ")";
42 else
43 $ul .= "brrrp";
45 if ( $target == 'newbies' ) {
46 # View the contributions of all recently created accounts
47 $row = wfGetArray("user",array("max(user_id) as m"),false);
48 $userCond = ">" . ($row->m - $row->m / 100);
49 $ul = "";
50 $id = 0;
53 $wgOut->setSubtitle( wfMsg( "contribsub", $ul ) );
55 if ( $hideminor ) {
56 $cmq = "AND cur_minor_edit=0";
57 $omq = "AND old_minor_edit=0";
58 $mlink = $sk->makeKnownLink( $wgLang->specialPage( "Contributions" ),
59 WfMsg( "show" ), "target=" . wfEscapeHTML( $nt->getPrefixedURL() ) .
60 "&offset={$offset}&limit={$limit}&hideminor=0" );
61 } else {
62 $cmq = $omq = "";
63 $mlink = $sk->makeKnownLink( $wgLang->specialPage( "Contributions" ),
64 WfMsg( "hide" ), "target=" . wfEscapeHTML( $nt->getPrefixedURL() ) .
65 "&offset={$offset}&limit={$limit}&hideminor=1" );
68 $oldtable=$wgIsPg?'"old"':'old';
69 if ( $userCond == "" ) {
70 $sql = "SELECT cur_namespace,cur_title,cur_timestamp,cur_comment,cur_minor_edit,cur_is_new,cur_user_text FROM cur " .
71 "WHERE cur_user_text='" . wfStrencode( $nt->getText() ) . "' {$cmq} " .
72 "ORDER BY inverse_timestamp LIMIT {$querylimit}";
73 $res1 = wfQuery( $sql, DB_READ, $fname );
75 $sql = "SELECT old_namespace,old_title,old_timestamp,old_comment,old_minor_edit,old_user_text FROM $oldtable " .
76 "WHERE old_user_text='" . wfStrencode( $nt->getText() ) . "' {$omq} " .
77 "ORDER BY inverse_timestamp LIMIT {$querylimit}";
78 $res2 = wfQuery( $sql, DB_READ, $fname );
79 } else {
80 $sql = "SELECT cur_namespace,cur_title,cur_timestamp,cur_comment,cur_minor_edit,cur_is_new,cur_user_text FROM cur " .
81 "WHERE cur_user {$userCond} {$cmq} ORDER BY inverse_timestamp LIMIT {$querylimit}";
82 $res1 = wfQuery( $sql, DB_READ, $fname );
84 $sql = "SELECT old_namespace,old_title,old_timestamp,old_comment,old_minor_edit,old_user_text FROM $oldtable " .
85 "WHERE old_user {$userCond} {$omq} ORDER BY inverse_timestamp LIMIT {$querylimit}";
86 $res2 = wfQuery( $sql, DB_READ, $fname );
88 $nCur = wfNumRows( $res1 );
89 $nOld = wfNumRows( $res2 );
91 $top = wfShowingResults( $offset, $limit );
92 $wgOut->addHTML( "<p>{$top}\n" );
94 $sl = wfViewPrevNext( $offset, $limit,
95 $wgLang->specialpage( "Contributions" ),
96 "hideminor={$hideminor}&target=" . wfUrlEncode( $target ),
97 ($nCur + $nOld) <= $offlimit);
99 $shm = wfMsg( "showhideminor", $mlink );
100 $wgOut->addHTML( "<br />{$sl} ($shm)</p>\n");
103 if ( 0 == $nCur && 0 == $nOld ) {
104 $wgOut->addHTML( "\n<p>" . wfMsg( "nocontribs" ) . "</p>\n" );
105 return;
107 if ( 0 != $nCur ) { $obj1 = wfFetchObject( $res1 ); }
108 if ( 0 != $nOld ) { $obj2 = wfFetchObject( $res2 ); }
110 $wgOut->addHTML( "<ul>\n" );
111 for( $n = 0; $n < $offlimit; $n++ ) {
112 if ( 0 == $nCur && 0 == $nOld ) { break; }
114 if ( ( 0 == $nOld ) ||
115 ( ( 0 != $nCur ) &&
116 ( $obj1->cur_timestamp >= $obj2->old_timestamp ) ) ) {
117 $ns = $obj1->cur_namespace;
118 $t = $obj1->cur_title;
119 $ts = $obj1->cur_timestamp;
120 $comment =$obj1->cur_comment;
121 $me = $obj1->cur_minor_edit;
122 $isnew = $obj1->cur_is_new;
123 $usertext = $obj1->cur_user_text;
125 $obj1 = wfFetchObject( $res1 );
126 $topmark = true;
127 --$nCur;
128 } else {
129 $ns = $obj2->old_namespace;
130 $t = $obj2->old_title;
131 $ts = $obj2->old_timestamp;
132 $comment =$obj2->old_comment;
133 $me = $obj2->old_minor_edit;
134 $usertext = $obj2->old_user_text;
136 $obj2 = wfFetchObject( $res2 );
137 $topmark = false;
138 $isnew = false;
139 --$nOld;
141 if( $n >= $offset )
142 ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, ( $me > 0), $isnew, $usertext );
144 $wgOut->addHTML( "</ul>\n" );
150 Generates each row in the contributions list.
152 Contributions which are marked "top" are currently on top of the history.
153 For these contributions, a [rollback] link is shown for users with sysop
154 privileges. The rollback link restores the most recent version that was not
155 written by the target user.
157 If the contributions page is called with the parameter &bot=1, all rollback
158 links also get that parameter. It causes the edit itself and the rollback
159 to be marked as "bot" edits. Bot edits are hidden by default from recent
160 changes, so this allows sysops to combat a busy vandal without bothering
161 other users.
163 TODO: This would probably look a lot nicer in a table.
166 function ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, $isminor, $isnew, $target )
168 global $wgLang, $wgOut, $wgUser, $wgRequest;
169 $page = Title::makeName( $ns, $t );
170 $link = $sk->makeKnownLink( $page, "" );
171 $topmarktext="";
172 if($topmark) {
173 if(!$isnew) {
174 $topmarktext .= $sk->makeKnownLink( $page, wfMsg("uctop"), "diff=0" );
175 } else {
176 $topmarktext .= wfMsg("newarticle");
178 $sysop = $wgUser->isSysop();
179 if($sysop ) {
180 $extraRollback = $wgRequest->getBool( "bot" ) ? '&bot=1' : '';
181 # $target = $wgRequest->getText( 'target' );
182 $topmarktext .= " [". $sk->makeKnownLink( $page,
183 wfMsg( "rollbacklink" ),
184 "action=rollback&from=" . urlencode( $target ) . $extraRollback ) ."]";
188 $histlink="(".$sk->makeKnownLink($page,wfMsg("hist"),"action=history").")";
190 if($comment) {
192 $comment="<em>(". $sk->formatComment($comment ) .")</em> ";
195 $d = $wgLang->timeanddate( $ts, true );
197 if ($isminor) {
198 $mflag = "<strong>" . wfMsg( "minoreditletter" ) . "</strong> ";
199 } else {
200 $mflag = "";
203 $wgOut->addHTML( "<li>{$d} {$histlink} {$mflag} {$link} {$comment}{$topmarktext}</li>\n" );
206 function ucCountLink( $lim, $d )
208 global $wgUser, $wgLang, $wgRequest;
210 $target = $wgRequest->getText( 'target' );
211 $sk = $wgUser->getSkin();
212 $s = $sk->makeKnownLink( $wgLang->specialPage( "Contributions" ),
213 "{$lim}", "target={$target}&days={$d}&limit={$lim}" );
214 return $s;
217 function ucDaysLink( $lim, $d )
219 global $wgUser, $wgLang, $wgRequest;
221 $target = $wgRequest->getText( 'target' );
222 $sk = $wgUser->getSkin();
223 $s = $sk->makeKnownLink( $wgLang->specialPage( "Contributions" ),
224 "{$d}", "target={$target}&days={$d}&limit={$lim}" );
225 return $s;