contributions list:
[lhc/web/wiklou.git] / includes / SpecialContributions.php
1 <?php
2
3 function wfSpecialContributions( $par = "" )
4 {
5 global $wgUser, $wgOut, $wgLang, $wgRequest;
6 $fname = "wfSpecialContributions";
7 $sysop = $wgUser->isSysop();
8
9 if( $par )
10 $target = $par;
11 else
12 $target = $wgRequest->getVal( 'target' );
13
14 if ( "" == $target ) {
15 $wgOut->errorpage( "notargettitle", "notargettext" );
16 return;
17 }
18
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
25 $nt = Title::newFromURL( $target );
26 $nt->setNamespace( Namespace::getUser() );
27
28 $sk = $wgUser->getSkin();
29 $id = User::idFromName( $nt->getText() );
30
31 if ( 0 == $id ) {
32 $ul = $nt->getText();
33 } else {
34 $ul = $sk->makeLinkObj( $nt, $nt->getText() );
35 }
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 ) );
42
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" );
54 }
55
56 if ( 0 == $id ) {
57 $sql = "SELECT cur_namespace,cur_title,cur_timestamp,cur_comment,cur_minor_edit 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 );
61
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 FROM cur " .
68 "WHERE cur_user={$id} {$cmq} ORDER BY inverse_timestamp LIMIT {$querylimit}";
69 $res1 = wfQuery( $sql, DB_READ, $fname );
70
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 );
74 }
75 $nCur = wfNumRows( $res1 );
76 $nOld = wfNumRows( $res2 );
77
78 $top = wfShowingResults( $offset, $limit );
79 $wgOut->addHTML( "<p>{$top}\n" );
80
81 $sl = wfViewPrevNext( $offset, $limit,
82 $wgLang->specialpage( "Contributions" ),
83 "hideminor={$hideminor}&target=" . wfUrlEncode( $target ),
84 ($nCur + $nOld) <= $offlimit);
85
86 $shm = wfMsg( "showhideminor", $mlink );
87 $wgOut->addHTML( "<br>{$sl} ($shm) \n");
88
89
90 if ( 0 == $nCur && 0 == $nOld ) {
91 $wgOut->addHTML( "\n<p>" . wfMsg( "nocontribs" ) . "</p>\n" );
92 return;
93 }
94 if ( 0 != $nCur ) { $obj1 = wfFetchObject( $res1 ); }
95 if ( 0 != $nOld ) { $obj2 = wfFetchObject( $res2 ); }
96
97 $wgOut->addHTML( "<ul>\n" );
98 for( $n = 0; $n < $offlimit; $n++ ) {
99 if ( 0 == $nCur && 0 == $nOld ) { break; }
100
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
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;
119
120 $obj2 = wfFetchObject( $res2 );
121 $topmark = false;
122 --$nOld;
123 }
124 if( $n >= $offset )
125 ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, ( $me > 0) );
126 }
127 $wgOut->addHTML( "</ul>\n" );
128 }
129
130
131 /*
132
133 Generates each row in the contributions list.
134
135 Contributions which are marked "top" are currently on top of the history.
136 For these contributions, a [rollback] link is shown for users with sysop
137 privileges. The rollback link restores the most recent version that was not
138 written by the target user.
139
140 If the contributions page is called with the parameter &bot=1, all rollback
141 links also get that parameter. It causes the edit itself and the rollback
142 to be marked as "bot" edits. Bot edits are hidden by default from recent
143 changes, so this allows sysops to combat a busy vandal without bothering
144 other users.
145
146 TODO: This would probably look a lot nicer in a table.
147
148 */
149 function ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, $isminor )
150 {
151 global $wgLang, $wgOut, $wgUser, $wgRequest, $target;
152 $page = Title::makeName( $ns, $t );
153 $link = $sk->makeKnownLink( $page, "" );
154 $topmarktext="";
155 if($topmark) {
156 $topmarktext .= $sk->makeKnownLink( $page, wfMsg("uctop"), "diff=0" );
157 $sysop = $wgUser->isSysop();
158 if($sysop ) {
159 $extraRollback = $wgRequest->getBool( "bot" ) ? '&bot=1' : '';
160 $topmarktext .= " [". $sk->makeKnownLink( $page,
161 wfMsg( "rollbacklink" ),
162 "action=rollback&from=" . urlencode( $target ) . $extraRollback ) ."]";
163 }
164
165 }
166 $histlink="(".$sk->makeKnownLink($page,wfMsg("hist"),"action=history").")";
167
168 if($comment) {
169
170 $comment="<em>(". htmlspecialchars( $comment ) .")</em> ";
171
172 }
173 $d = $wgLang->timeanddate( $ts, true );
174
175 if ($isminor) {
176 $mflag = "<strong>" . wfMsg( "minoreditletter" ) . "</strong> ";
177 } else {
178 $mflag = "";
179 }
180
181 $wgOut->addHTML( "<li>{$d} {$histlink} {$mflag} {$link} {$comment}{$topmarktext}</li>\n" );
182 }
183
184 function ucCountLink( $lim, $d )
185 {
186 global $wgUser, $wgLang, $target;
187
188 $sk = $wgUser->getSkin();
189 $s = $sk->makeKnownLink( $wgLang->specialPage( "Contributions" ),
190 "{$lim}", "target={$target}&days={$d}&limit={$lim}" );
191 return $s;
192 }
193
194 function ucDaysLink( $lim, $d )
195 {
196 global $wgUser, $wgLang, $target;
197
198 $sk = $wgUser->getSkin();
199 $s = $sk->makeKnownLink( $wgLang->specialPage( "Contributions" ),
200 "{$d}", "target={$target}&days={$d}&limit={$lim}" );
201 return $s;
202 }
203 ?>