Merging latest features from stable
[lhc/web/wiklou.git] / includes / SpecialContributions.php
1 <?
2
3 function wfSpecialContributions( $par = "" )
4 {
5 global $wgUser, $wgOut, $wgLang, $target, $hideminor;
6 $fname = "wfSpecialContributions";
7 $sysop = $wgUser->isSysop();
8
9 if( $par )
10 $target = $par;
11 else
12 $target = wfCleanQueryVar( $target );
13
14 if ( "" == $target ) {
15 $wgOut->errorpage( "notargettitle", "notargettext" );
16 return;
17 }
18 list( $limit, $offset ) = wfCheckLimits( 50, "" );
19 $offlimit = $limit + $offset;
20
21 $nt = Title::newFromURL( $target );
22 $nt->setNamespace( Namespace::getUser() );
23
24 $sk = $wgUser->getSkin();
25 $id = User::idFromName( $nt->getText() );
26
27 if ( 0 == $id ) { $ul = $nt->getText(); }
28 else {
29 $ul = $sk->makeKnownLink( $nt->getPrefixedText(), $nt->getText() );
30 }
31 $sub = str_replace( "$1", $ul, wfMsg( "contribsub" ) );
32 $wgOut->setSubtitle( $sub );
33
34 if ( ! isset( $hideminor ) ) {
35 $hideminor = $wgUser->getOption( "hideminor" );
36 }
37 if ( $hideminor ) {
38 $cmq = "AND cur_minor_edit=0";
39 $omq = "AND old_minor_edit=0";
40 } else { $cmq = $omq = ""; }
41
42 $top = wfShowingResults( $offset, $limit );
43 $wgOut->addHTML( "<p>{$top}\n" );
44
45 $sl = wfViewPrevNext( $offset, $limit,
46 $wgLang->specialpage( "Contributions" ), "target=" . wfUrlEncode( $target ) );
47 $wgOut->addHTML( "<br>{$sl}\n" );
48
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 {$offlimit}";
53 $res1 = wfQuery( $sql, DB_READ, $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 {$offlimit}";
58 $res2 = wfQuery( $sql, DB_READ, $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 {$offlimit}";
62 $res1 = wfQuery( $sql, DB_READ, $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 {$offlimit}";
66 $res2 = wfQuery( $sql, DB_READ, $fname );
67 }
68 $nCur = wfNumRows( $res1 );
69 $nOld = wfNumRows( $res2 );
70
71
72 if ( 0 == $nCur && 0 == $nOld ) {
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 for( $n = 0; $n < $offlimit; $n++ ) {
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 if( $n >= $offset )
105 ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment );
106 }
107 $wgOut->addHTML( "</ul>\n" );
108 }
109
110 function ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment )
111 {
112 global $wgLang, $wgOut, $wgUser, $target;
113 $page = Title::makeName( $ns, $t );
114 $link = $sk->makeKnownLink( $page, "" );
115 $topmarktext = $topmark ? wfMsg ( "uctop" ) : "";
116 $sysop = $wgUser->isSysop();
117 if($sysop && $topmark ) {
118 $topmarktext .= " [". $sk->makeKnownLink( $page,
119 wfMsg( "rollbacklink" ), "action=rollback&from=" . urlencode( $target ) ) ."]";
120 }
121 if($comment) {
122
123 $comment="<em>(". htmlspecialchars( $comment ) .")</em> ";
124
125 }
126 $d = $wgLang->timeanddate( $ts, true );
127
128 $wgOut->addHTML( "<li>{$d} {$link} {$comment}{$topmarktext}</li>\n" );
129 }
130
131 function ucCountLink( $lim, $d )
132 {
133 global $wgUser, $wgLang, $target;
134
135 $sk = $wgUser->getSkin();
136 $s = $sk->makeKnownLink( $wgLang->specialPage( "Contributions" ),
137 "{$lim}", "target={$target}&days={$d}&limit={$lim}" );
138 return $s;
139 }
140
141 function ucDaysLink( $lim, $d )
142 {
143 global $wgUser, $wgLang, $target;
144
145 $sk = $wgUser->getSkin();
146 $s = $sk->makeKnownLink( $wgLang->specialPage( "Contributions" ),
147 "{$d}", "target={$target}&days={$d}&limit={$lim}" );
148 return $s;
149 }
150 ?>