Fix rollback to avoid race conditions with multiple people trying to revert after...
[lhc/web/wiklou.git] / includes / SpecialContributions.php
1 <?
2
3 function wfSpecialContributions()
4 {
5 global $wgUser, $wgOut, $wgLang, $target, $offset, $limit, $hideminor;
6 $fname = "wfSpecialContributions";
7 $sysop = $wgUser->isSysop();
8
9 if ( "" == $target ) {
10 $wgOut->errorpage( "notargettitle", "notargettext" );
11 return;
12 }
13 $offset = (int)$offset;
14 $limit = (int)$limit;
15 if( $offset < 0 ) { $offset = 0; }
16 if( $limit < 1 ) { $limit = 50; }
17
18 $target = wfCleanQueryVar( $target );
19 $nt = Title::newFromURL( $target );
20 $nt->setNamespace( Namespace::getUser() );
21
22 $sk = $wgUser->getSkin();
23 $id = User::idFromName( $nt->getText() );
24
25 if ( 0 == $id ) { $ul = $nt->getText(); }
26 else {
27 $ul = $sk->makeKnownLink( $nt->getPrefixedText(), $nt->getText() );
28 }
29 $sub = str_replace( "$1", $ul, wfMsg( "contribsub" ) );
30 $wgOut->setSubtitle( $sub );
31
32 if ( ! isset( $hideminor ) ) {
33 $hideminor = $wgUser->getOption( "hideminor" );
34 }
35 if ( $hideminor ) {
36 $cmq = "AND cur_minor_edit=0";
37 $omq = "AND old_minor_edit=0";
38 } else { $cmq = $omq = ""; }
39
40 $top = wfShowingResults( $offset, $limit );
41 $wgOut->addHTML( "<p>{$top}\n" );
42
43 $sl = wfViewPrevNext( $offset, $limit,
44 $wgLang->specialpage( "Contributions" ), "target=" . wfUrlEncode( $target ) );
45 $wgOut->addHTML( "<br>{$sl}\n" );
46
47 # Sorting slowness on cur and especially old
48 # forces us to check RC table first
49 if ( 0 == $id ) {
50 $sql = "SELECT cur_namespace,cur_title,cur_timestamp,cur_comment FROM cur " .
51 "WHERE cur_user_text='" . wfStrencode( $nt->getText() ) . "' {$cmq} " .
52 "ORDER BY inverse_timestamp LIMIT {$offset}, {$limit}";
53 $res1 = wfQuery( $sql, $fname );
54
55 $sql = "SELECT old_namespace,old_title,old_timestamp,old_comment FROM old " .
56 "WHERE old_user_text='" . wfStrencode( $nt->getText() ) . "' {$omq} " .
57 "ORDER BY inverse_timestamp LIMIT {$offset}, {$limit}";
58 $res2 = wfQuery( $sql, $fname );
59 } else {
60 $sql = "SELECT cur_namespace,cur_title,cur_timestamp,cur_comment FROM cur " .
61 "WHERE cur_user={$id} {$cmq} ORDER BY inverse_timestamp LIMIT {$offset}, {$limit}";
62 $res1 = wfQuery( $sql, $fname );
63
64 $sql = "SELECT old_namespace,old_title,old_timestamp,old_comment FROM old " .
65 "WHERE old_user={$id} {$omq} ORDER BY inverse_timestamp LIMIT {$offset}, {$limit}";
66 $res2 = wfQuery( $sql, $fname );
67 }
68 $nCur = wfNumRows( $res1 );
69 $nOld = wfNumRows( $res2 );
70
71
72 if ( 0 == $nCur && 0 == $nOld && 0 == $rcrows ) {
73 $wgOut->addHTML( "\n<p>" . wfMsg( "nocontribs" ) . "</p>\n" );
74 return;
75 }
76 if ( 0 != $nCur ) { $obj1 = wfFetchObject( $res1 ); }
77 if ( 0 != $nOld ) { $obj2 = wfFetchObject( $res2 ); }
78
79 $wgOut->addHTML( "<ul>\n" );
80 while ( $limit ) {
81 if ( 0 == $nCur && 0 == $nOld ) { break; }
82
83 if ( ( 0 == $nOld ) ||
84 ( ( 0 != $nCur ) &&
85 ( $obj1->cur_timestamp >= $obj2->old_timestamp ) ) ) {
86 $ns = $obj1->cur_namespace;
87 $t = $obj1->cur_title;
88 $ts = $obj1->cur_timestamp;
89 $comment =$obj1->cur_comment;
90
91 $obj1 = wfFetchObject( $res1 );
92 $topmark = true;
93 --$nCur;
94 } else {
95 $ns = $obj2->old_namespace;
96 $t = $obj2->old_title;
97 $ts = $obj2->old_timestamp;
98 $comment =$obj2->old_comment;
99
100 $obj2 = wfFetchObject( $res2 );
101 $topmark = false;
102 --$nOld;
103 }
104 ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment );
105
106 --$limit;
107 }
108 $wgOut->addHTML( "</ul>\n" );
109 }
110
111 function ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment )
112 {
113 global $wgLang, $wgOut, $wgUser, $target;
114 $page = Title::makeName( $ns, $t );
115 $link = $sk->makeKnownLink( $page, "" );
116 $topmarktext = $topmark ? wfMsg ( "uctop" ) : "";
117 $sysop = $wgUser->isSysop();
118 if($sysop && $topmark ) {
119 $topmarktext .= " [". $sk->makeKnownLink( $page,
120 wfMsg( "rollbacklink" ), "action=rollback&from=" . urlencode( $target ) ) ."]";
121 }
122 if($comment) {
123
124 $comment="<em>(". htmlspecialchars( $comment ) .")</em> ";
125
126 }
127 $d = $wgLang->timeanddate( $ts, true );
128
129 $wgOut->addHTML( "<li>{$d} {$link} {$comment}{$topmarktext}</li>\n" );
130 }
131
132 function ucCountLink( $lim, $d )
133 {
134 global $wgUser, $wgLang, $target;
135
136 $sk = $wgUser->getSkin();
137 $s = $sk->makeKnownLink( $wgLang->specialPage( "Contributions" ),
138 "{$lim}", "target={$target}&days={$d}&limit={$lim}" );
139 return $s;
140 }
141
142 function ucDaysLink( $lim, $d )
143 {
144 global $wgUser, $wgLang, $target;
145
146 $sk = $wgUser->getSkin();
147 $s = $sk->makeKnownLink( $wgLang->specialPage( "Contributions" ),
148 "{$d}", "target={$target}&days={$d}&limit={$lim}" );
149 return $s;
150 }
151 ?>