old->"old"
[lhc/web/wiklou.git] / includes / SpecialContributions.php
1 <?php
2
3 function wfSpecialContributions( $par = "" )
4 {
5 global $wgUser, $wgOut, $wgLang, $wgRequest, $wgIsPg;
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 $oldtable=$wgIsPg?'"old"':'old';
57 if ( 0 == $id ) {
58 $sql = "SELECT cur_namespace,cur_title,cur_timestamp,cur_comment,cur_minor_edit,cur_is_new FROM cur " .
59 "WHERE cur_user_text='" . wfStrencode( $nt->getText() ) . "' {$cmq} " .
60 "ORDER BY inverse_timestamp LIMIT {$querylimit}";
61 $res1 = wfQuery( $sql, DB_READ, $fname );
62
63 $sql = "SELECT old_namespace,old_title,old_timestamp,old_comment,old_minor_edit FROM $oldtable " .
64 "WHERE old_user_text='" . wfStrencode( $nt->getText() ) . "' {$omq} " .
65 "ORDER BY inverse_timestamp LIMIT {$querylimit}";
66 $res2 = wfQuery( $sql, DB_READ, $fname );
67 } else {
68 $sql = "SELECT cur_namespace,cur_title,cur_timestamp,cur_comment,cur_minor_edit,cur_is_new FROM cur " .
69 "WHERE cur_user={$id} {$cmq} ORDER BY inverse_timestamp LIMIT {$querylimit}";
70 $res1 = wfQuery( $sql, DB_READ, $fname );
71
72 $sql = "SELECT old_namespace,old_title,old_timestamp,old_comment,old_minor_edit FROM $oldtable " .
73 "WHERE old_user={$id} {$omq} ORDER BY inverse_timestamp LIMIT {$querylimit}";
74 $res2 = wfQuery( $sql, DB_READ, $fname );
75 }
76 $nCur = wfNumRows( $res1 );
77 $nOld = wfNumRows( $res2 );
78
79 $top = wfShowingResults( $offset, $limit );
80 $wgOut->addHTML( "<p>{$top}\n" );
81
82 $sl = wfViewPrevNext( $offset, $limit,
83 $wgLang->specialpage( "Contributions" ),
84 "hideminor={$hideminor}&target=" . wfUrlEncode( $target ),
85 ($nCur + $nOld) <= $offlimit);
86
87 $shm = wfMsg( "showhideminor", $mlink );
88 $wgOut->addHTML( "<br />{$sl} ($shm)</p>\n");
89
90
91 if ( 0 == $nCur && 0 == $nOld ) {
92 $wgOut->addHTML( "\n<p>" . wfMsg( "nocontribs" ) . "</p>\n" );
93 return;
94 }
95 if ( 0 != $nCur ) { $obj1 = wfFetchObject( $res1 ); }
96 if ( 0 != $nOld ) { $obj2 = wfFetchObject( $res2 ); }
97
98 $wgOut->addHTML( "<ul>\n" );
99 for( $n = 0; $n < $offlimit; $n++ ) {
100 if ( 0 == $nCur && 0 == $nOld ) { break; }
101
102 if ( ( 0 == $nOld ) ||
103 ( ( 0 != $nCur ) &&
104 ( $obj1->cur_timestamp >= $obj2->old_timestamp ) ) ) {
105 $ns = $obj1->cur_namespace;
106 $t = $obj1->cur_title;
107 $ts = $obj1->cur_timestamp;
108 $comment =$obj1->cur_comment;
109 $me = $obj1->cur_minor_edit;
110 $isnew = $obj1->cur_is_new;
111 $obj1 = wfFetchObject( $res1 );
112 $topmark = true;
113 --$nCur;
114 } else {
115 $ns = $obj2->old_namespace;
116 $t = $obj2->old_title;
117 $ts = $obj2->old_timestamp;
118 $comment =$obj2->old_comment;
119 $me = $obj2->old_minor_edit;
120
121 $obj2 = wfFetchObject( $res2 );
122 $topmark = false;
123 $isnew = false;
124 --$nOld;
125 }
126 if( $n >= $offset )
127 ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, ( $me > 0), $isnew );
128 }
129 $wgOut->addHTML( "</ul>\n" );
130 }
131
132
133 /*
134
135 Generates each row in the contributions list.
136
137 Contributions which are marked "top" are currently on top of the history.
138 For these contributions, a [rollback] link is shown for users with sysop
139 privileges. The rollback link restores the most recent version that was not
140 written by the target user.
141
142 If the contributions page is called with the parameter &bot=1, all rollback
143 links also get that parameter. It causes the edit itself and the rollback
144 to be marked as "bot" edits. Bot edits are hidden by default from recent
145 changes, so this allows sysops to combat a busy vandal without bothering
146 other users.
147
148 TODO: This would probably look a lot nicer in a table.
149
150 */
151 function ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, $isminor, $isnew )
152 {
153 global $wgLang, $wgOut, $wgUser, $wgRequest;
154 $page = Title::makeName( $ns, $t );
155 $link = $sk->makeKnownLink( $page, "" );
156 $topmarktext="";
157 if($topmark) {
158 if(!$isnew) {
159 $topmarktext .= $sk->makeKnownLink( $page, wfMsg("uctop"), "diff=0" );
160 } else {
161 $topmarktext .= wfMsg("newarticle");
162 }
163 $sysop = $wgUser->isSysop();
164 if($sysop ) {
165 $extraRollback = $wgRequest->getBool( "bot" ) ? '&bot=1' : '';
166 $target = $wgRequest->getText( 'target' );
167 $topmarktext .= " [". $sk->makeKnownLink( $page,
168 wfMsg( "rollbacklink" ),
169 "action=rollback&from=" . urlencode( $target ) . $extraRollback ) ."]";
170 }
171
172 }
173 $histlink="(".$sk->makeKnownLink($page,wfMsg("hist"),"action=history").")";
174
175 if($comment) {
176
177 $comment="<em>(". $sk->formatComment($comment ) .")</em> ";
178
179 }
180 $d = $wgLang->timeanddate( $ts, true );
181
182 if ($isminor) {
183 $mflag = "<strong>" . wfMsg( "minoreditletter" ) . "</strong> ";
184 } else {
185 $mflag = "";
186 }
187
188 $wgOut->addHTML( "<li>{$d} {$histlink} {$mflag} {$link} {$comment}{$topmarktext}</li>\n" );
189 }
190
191 function ucCountLink( $lim, $d )
192 {
193 global $wgUser, $wgLang, $wgRequest;
194
195 $target = $wgRequest->getText( 'target' );
196 $sk = $wgUser->getSkin();
197 $s = $sk->makeKnownLink( $wgLang->specialPage( "Contributions" ),
198 "{$lim}", "target={$target}&days={$d}&limit={$lim}" );
199 return $s;
200 }
201
202 function ucDaysLink( $lim, $d )
203 {
204 global $wgUser, $wgLang, $wgRequest;
205
206 $target = $wgRequest->getText( 'target' );
207 $sk = $wgUser->getSkin();
208 $s = $sk->makeKnownLink( $wgLang->specialPage( "Contributions" ),
209 "{$d}", "target={$target}&days={$d}&limit={$lim}" );
210 return $s;
211 }
212 ?>