5 * @subpackage SpecialPage
9 * Special page "user contributions".
10 * Shows a list of the contributions of a user.
13 * @param string $par (optional) user name of the user for which to show the contributions
15 function wfSpecialContributions( $par = '' ) {
16 global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest;
17 $fname = 'wfSpecialContributions';
22 $target = $wgRequest->getVal( 'target' );
24 if ( '' == $target ) {
25 $wgOut->errorpage( 'notargettitle', 'notargettext' );
29 # FIXME: Change from numeric offsets to date offsets
30 list( $limit, $offset ) = wfCheckLimits( 50, '' );
31 $offlimit = $limit +
$offset;
32 $querylimit = $offlimit +
1;
33 $hideminor = ($wgRequest->getVal( 'hideminor' ) ?
1 : 0);
34 $sk = $wgUser->getSkin();
35 $dbr =& wfGetDB( DB_SLAVE
);
37 $namespace = $wgRequest->getVal( 'namespace', '' );
38 if( $namespace != '' ) {
39 $namespace = IntVal( $namespace );
44 $nt = Title
::newFromURL( $target );
46 $wgOut->errorpage( 'notargettitle', 'notargettext' );
49 $nt =& Title
::makeTitle( NS_USER
, $nt->getDBkey() );
51 $id = User
::idFromName( $nt->getText() );
56 $ul = $sk->makeLinkObj( $nt, htmlspecialchars( $nt->getText() ) );
57 $userCond = '=' . $id;
59 $talk = $nt->getTalkPage();
61 $ul .= ' (' . $sk->makeLinkObj( $talk, $wgLang->getNsText( NS_TALK
) ) . ')';
65 if ( $target == 'newbies' ) {
66 # View the contributions of all recently created accounts
67 $max = $dbr->selectField( 'user', 'max(user_id)', false, $fname );
68 $userCond = '>' . ($max - $max / 100);
69 $ul = wfMsg ( 'newbies' );
73 $wgOut->setSubtitle( wfMsg( 'contribsub', $ul ) );
76 $minorQuery = "AND rev_minor_edit=0";
77 $mlink = $sk->makeKnownLink( $wgContLang->specialPage( "Contributions" ),
78 WfMsg( "show" ), "target=" . htmlspecialchars( $nt->getPrefixedURL() ) .
79 "&offset={$offset}&limit={$limit}&hideminor=0&namespace={$namespace}" );
82 $mlink = $sk->makeKnownLink( $wgContLang->specialPage( "Contributions" ),
83 WfMsg( 'hide' ), 'target=' . htmlspecialchars( $nt->getPrefixedURL() ) .
84 "&offset={$offset}&limit={$limit}&hideminor=1&namespace={$namespace}" );
87 if( !is_null($namespace) ) {
88 $minorQuery .= " AND page_namespace = {$namespace}";
91 extract( $dbr->tableNames( 'page', 'revision' ) );
92 if ( $userCond == "" ) {
93 $condition = "rev_user_text=" . $dbr->addQuotes( $nt->getText() );
94 $index = 'usertext_timestamp';
96 $condition = "rev_user {$userCond}";
97 $index = 'user_timestamp';
101 $use_index = $dbr->useIndexClause( $index );
103 page_namespace,page_title,page_is_new,page_latest,
104 rev_id,rev_timestamp,rev_comment,rev_minor_edit,rev_user_text,
106 FROM $page,$revision $use_index
107 WHERE page_id=rev_page AND $condition $minorQuery " .
108 "ORDER BY rev_timestamp DESC LIMIT {$querylimit}";
109 $res = $dbr->query( $sql, $fname );
110 $numRows = $dbr->numRows( $res );
112 $wgOut->addHTML( namespaceForm( $target, $hideminor, $namespace ) );
114 $top = wfShowingResults( $offset, $limit );
115 $wgOut->addHTML( "<p>{$top}\n" );
117 $sl = wfViewPrevNext( $offset, $limit,
118 $wgContLang->specialpage( "Contributions" ),
119 "hideminor={$hideminor}&namespace={$namespace}&target=" . wfUrlEncode( $target ),
120 ($numRows) <= $offlimit);
122 $shm = wfMsg( "showhideminor", $mlink );
123 $wgOut->addHTML( "<br />{$sl} ($shm)</p>\n");
126 if ( 0 == $numRows ) {
127 $wgOut->addHTML( "\n<p>" . wfMsg( "nocontribs" ) . "</p>\n" );
131 $wgOut->addHTML( "<ul>\n" );
132 while( $obj = $dbr->fetchObject( $res ) ) {
133 $wgOut->addHTML( ucListEdit( $sk, $obj ) );
135 $wgOut->addHTML( "</ul>\n" );
137 $wgOut->addHTML( "<br />{$sl} ($shm)\n");
142 * Generates each row in the contributions list.
144 * Contributions which are marked "top" are currently on top of the history.
145 * For these contributions, a [rollback] link is shown for users with sysop
146 * privileges. The rollback link restores the most recent version that was not
147 * written by the target user.
149 * If the contributions page is called with the parameter &bot=1, all rollback
150 * links also get that parameter. It causes the edit itself and the rollback
151 * to be marked as "bot" edits. Bot edits are hidden by default from recent
152 * changes, so this allows sysops to combat a busy vandal without bothering
155 * @todo This would probably look a lot nicer in a table.
157 function ucListEdit( $sk, $row ) {
158 $fname = 'ucListEdit';
159 wfProfileIn( $fname );
161 global $wgLang, $wgOut, $wgUser, $wgRequest;
163 if( !isset( $messages ) ) {
164 foreach( explode( ' ', 'uctop diff newarticle rollbacklink diff hist minoreditletter' ) as $msg ) {
165 $messages[$msg] = wfMsg( $msg );
169 $page =& Title
::makeTitle( $row->page_namespace
, $row->page_title
);
170 $link = $sk->makeKnownLinkObj( $page, '' );
171 $difftext = $topmarktext = '';
172 if( $row->rev_id
== $row->page_latest
) {
173 $topmarktext .= '<strong>' . $messages['uctop'] . '</strong>';
174 if( !$row->page_is_new
) {
175 $difftext .= $sk->makeKnownLinkObj( $page, '(' . $messages['diff'] . ')', 'diff=0' );
177 $difftext .= $messages['newarticle'];
180 if( $wgUser->isAllowed('rollback') ) {
181 $extraRollback = $wgRequest->getBool( 'bot' ) ?
'&bot=1' : '';
182 $extraRollback .= '&token=' . urlencode(
183 $wgUser->editToken( array( $page->getPrefixedText(), $row->rev_user_text
) ) );
184 $topmarktext .= ' ['. $sk->makeKnownLinkObj( $page,
185 $messages['rollbacklink'],
186 'action=rollback&from=' . urlencode( $row->rev_user_text
) . $extraRollback ) .']';
190 if( $row->rev_deleted
&& !$wgUser->isAllowed( 'undelete' ) ) {
191 $difftext = '(' . $messages['diff'] . ')';
193 $difftext = $sk->makeKnownLinkObj( $page, '(' . $messages['diff'].')', 'diff=prev&oldid='.$row->rev_id
);
195 $histlink='('.$sk->makeKnownLinkObj( $page, $messages['hist'], 'action=history' ) . ')';
197 $comment = $sk->commentBlock( $row->rev_comment
, $page );
198 $d = $wgLang->timeanddate( $row->rev_timestamp
, true );
200 if( $row->rev_minor_edit
) {
201 $mflag = '<span class="minor">' . $messages['minoreditletter'] . '</span> ';
206 $ret = "{$d} {$histlink} {$difftext} {$mflag} {$link} {$comment} {$topmarktext}";
207 if( $row->rev_deleted
) {
208 $ret = '<span class="deleted">' . $ret . '</span> ' . htmlspecialchars( wfMsg( 'deletedrev' ) );
210 $ret = "<li>$ret</li>\n";
211 wfProfileOut( $fname );
216 * Generates a form used to restrict display of contributions
217 * to a specific namespace
220 * @param string $target target user to show contributions for
221 * @param string $hideminor whether minor contributions are hidden
222 * @param string $namespace currently selected namespace, NULL for show all
224 function namespaceForm ( $target, $hideminor, $namespace ) {
225 global $wgContLang, $wgScript;
227 $namespaceselect = '<select name="namespace">';
228 $namespaceselect .= '<option value="" '.(is_null($namespace) ?
' selected="selected"' : '').'>'.wfMsg( 'contributionsall' ).'</option>';
229 $arr = $wgContLang->getNamespaces();
230 foreach( array_keys( $arr ) as $i ) {
234 $namespacename = str_replace ( "_", " ", $arr[$i] );
235 $n = ($i == 0) ?
wfMsg ( 'articlenamespace' ) : $namespacename;
236 $sel = ($i === $namespace) ?
' selected="selected"' : '';
237 $namespaceselect .= "<option value='{$i}'{$sel}>{$n}</option>";
239 $namespaceselect .= '</select>';
241 $submitbutton = '<input type="submit" value="' . wfMsg( 'allpagessubmit' ) . '" />';
243 $out = "<div class='namespaceselector'><form method='get' action='{$wgScript}'>";
244 $out .= '<input type="hidden" name="title" value="'.$wgContLang->specialpage( 'Contributions' ).'" />';
245 $out .= '<input type="hidden" name="target" value="'.htmlspecialchars( $target ).'" />';
246 $out .= '<input type="hidden" name="hideminor" value="'.$hideminor.'" />';
247 $out .= wfMsg ( 'allpagesformtext2', $namespaceselect, $submitbutton );
248 $out .= '</form></div>';