]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blobdiff - includes/SpecialContributions.php
MediaWiki 1.11.0
[autoinstalls/mediawiki.git] / includes / SpecialContributions.php
index ffbfe91c733ceb0d25edc05fbd6577d705481f68..cc1b2e6f64d4cbbc9daad18be933ed4d93cd0261 100644 (file)
 <?php
 /**
- * @package MediaWiki
- * @subpackage SpecialPage
+ * Special:Contributions, show user contributions in a paged list
+ * @addtogroup SpecialPage
  */
 
-/** @package MediaWiki */
-class contribs_finder {
-       var $username, $offset, $limit, $namespace;
-       var $dbr;
+class ContribsPager extends IndexPager {
+       public $mDefaultDirection = true;
+       var $messages, $target;
+       var $namespace = '', $mDb;
 
-       function contribs_finder($username) {
-               $this->username = $username;
-               $this->namespace = false;
-               $this->dbr =& wfGetDB(DB_SLAVE);
+       function __construct( $target, $namespace = false, $year = false, $month = false ) {
+               parent::__construct();
+               foreach( explode( ' ', 'uctop diff newarticle rollbacklink diff hist minoreditletter' ) as $msg ) {
+                       $this->messages[$msg] = wfMsgExt( $msg, array( 'escape') );
+               }
+               $this->target = $target;
+               $this->namespace = $namespace;
+               
+               $year = intval($year);
+               $month = intval($month);
+               
+               $this->year = ($year > 0 && $year < 10000) ? $year : false;
+               $this->month = ($month > 0 && $month < 13) ? $month : false;
+               $this->getDateCond();
+               
+               $this->mDb = wfGetDB( DB_SLAVE, 'contributions' );
        }
 
-       function set_namespace($ns) {
-               $this->namespace = $ns;
+       function getDefaultQuery() {
+               $query = parent::getDefaultQuery();
+               $query['target'] = $this->target;
+               return $query;
        }
 
-       function set_limit($limit) {
-               $this->limit = $limit;
+       function getQueryInfo() {
+               list( $index, $userCond ) = $this->getUserCond();
+               $conds = array_merge( array('page_id=rev_page'), $userCond, $this->getNamespaceCond() );
+
+               return array(
+                       'tables' => array( 'page', 'revision' ),
+                       'fields' => array( 
+                               'page_namespace', 'page_title', 'page_is_new', 'page_latest', 'rev_id', 'rev_page', 
+                               'rev_text_id', 'rev_timestamp', 'rev_comment', 'rev_minor_edit', 'rev_user', 
+                               'rev_user_text', 'rev_deleted'
+                       ),
+                       'conds' => $conds,
+                       'options' => array( 'USE INDEX' => $index )
+               );
        }
 
-       function set_offset($offset) {
-               $this->offset = $offset;
+       function getUserCond() {
+               $condition = array();
+
+               if ( $this->target == 'newbies' ) {
+                       $max = $this->mDb->selectField( 'user', 'max(user_id)', false, __METHOD__ );
+                       $condition[] = 'rev_user >' . (int)($max - $max / 100);
+                       $index = 'user_timestamp';
+               } else {
+                       $condition['rev_user_text'] = $this->target;
+                       $index = 'usertext_timestamp';
+               }
+               return array( $index, $condition );
        }
 
-       function get_edit_limit($dir) {
-               list($index, $usercond) = $this->get_user_cond();
-               $nscond = $this->get_namespace_cond();
-               $use_index = $this->dbr->useIndexClause($index);
-               extract($this->dbr->tableNames('revision', 'page'));
-               $sql =  "SELECT rev_timestamp " .
-                       " FROM $page,$revision $use_index " .
-                       " WHERE rev_page=page_id AND $usercond $nscond" .
-                       " ORDER BY rev_timestamp $dir LIMIT 1";
+       function getNamespaceCond() {
+               if ( $this->namespace !== '' ) {
+                       return array( 'page_namespace' => (int)$this->namespace );
+               } else {
+                       return array();
+               }
+       }
+       
+       function getDateCond() {
+               if ( $this->year || $this->month ) {
+                       // Assume this year if only a month is given
+                       if ( $this->year ) {
+                               $year_start = $this->year;
+                       } else {
+                               $year_start = substr( wfTimestampNow(), 0, 4 );
+                               $thisMonth = gmdate( 'n' );
+                               if( $this->month > $thisMonth ) {
+                                       // Future contributions aren't supposed to happen. :)
+                                       $year_start--;
+                               }
+                       }
+                       
+                       if ( $this->month ) {
+                               $month_end = str_pad($this->month + 1, 2, '0', STR_PAD_LEFT);
+                               $year_end = $year_start;
+                       } else {
+                               $month_end = 0;
+                               $year_end = $year_start + 1;
+                       }
+                       $ts_end = str_pad($year_end . $month_end, 14, '0' );
+
+                       $this->mOffset = $ts_end;
+               }
+       }
 
-               $res = $this->dbr->query($sql, "contribs_finder::get_edit_limit");
-               while ($o = $this->dbr->fetchObject($res))
-                       $row = $o;
-               return $row->rev_timestamp;
+       function getIndexField() {
+               return 'rev_timestamp';
        }
 
-       function get_edit_limits() {
-               return array(
-                       $this->get_edit_limit("ASC"),
-                       $this->get_edit_limit("DESC")
+       function getStartBody() {
+               return "<ul>\n";
+       }
+
+       function getEndBody() {
+               return "</ul>\n";
+       }
+
+       function getNavigationBar() {
+               if ( isset( $this->mNavigationBar ) ) {
+                       return $this->mNavigationBar;
+               }
+               $linkTexts = array(
+                       'prev' => wfMsgHtml( "sp-contributions-newer", $this->mLimit ),
+                       'next' => wfMsgHtml( 'sp-contributions-older', $this->mLimit ),
+                       'first' => wfMsgHtml('sp-contributions-newest'),
+                       'last' => wfMsgHtml( 'sp-contributions-oldest' )
                );
+
+               $pagingLinks = $this->getPagingLinks( $linkTexts );
+               $limitLinks = $this->getLimitLinks();
+               $limits = implode( ' | ', $limitLinks );
+               
+               $this->mNavigationBar = "({$pagingLinks['first']} | {$pagingLinks['last']}) " . 
+                       wfMsgHtml("viewprevnext", $pagingLinks['prev'], $pagingLinks['next'], $limits);
+               return $this->mNavigationBar;
        }
 
-       function get_user_cond() {
-               $condition = "";
+       /**
+        * Generates each row in the contributions list.
+        *
+        * Contributions which are marked "top" are currently on top of the history.
+        * For these contributions, a [rollback] link is shown for users with sysop
+        * privileges. The rollback link restores the most recent version that was not
+        * written by the target user.
+        *
+        * @todo This would probably look a lot nicer in a table.
+        */
+       function formatRow( $row ) {
+               wfProfileIn( __METHOD__ );
+
+               global $wgLang, $wgUser, $wgContLang;
+
+               $sk = $this->getSkin();
+               $rev = new Revision( $row );
+
+               $page = Title::makeTitle( $row->page_namespace, $row->page_title );
+               $link = $sk->makeKnownLinkObj( $page );
+               $difftext = $topmarktext = '';
+               if( $row->rev_id == $row->page_latest ) {
+                       $topmarktext .= '<strong>' . $this->messages['uctop'] . '</strong>';
+                       if( !$row->page_is_new ) {
+                               $difftext .= '(' . $sk->makeKnownLinkObj( $page, $this->messages['diff'], 'diff=0' ) . ')';
+                       } else {
+                               $difftext .= $this->messages['newarticle'];
+                       }
+
+                       if( $wgUser->isAllowed( 'rollback' ) ) {
+                               $topmarktext .= ' '.$sk->generateRollback( $rev );
+                       }
+
+               }
+               if( $rev->userCan( Revision::DELETED_TEXT ) ) {
+                       $difftext = '(' . $sk->makeKnownLinkObj( $page, $this->messages['diff'], 'diff=prev&oldid='.$row->rev_id ) . ')';
+               } else {
+                       $difftext = '(' . $this->messages['diff'] . ')';
+               }
+               $histlink='('.$sk->makeKnownLinkObj( $page, $this->messages['hist'], 'action=history' ) . ')';
+
+               $comment = $wgContLang->getDirMark() . $sk->revComment( $rev );
+               $d = $wgLang->timeanddate( wfTimestamp( TS_MW, $row->rev_timestamp ), true );
+               
+               if( $this->target == 'newbies' ) {
+                       $userlink = ' . . ' . $sk->userLink( $row->rev_user, $row->rev_user_text );
+                       $userlink .= ' (' . $sk->userTalkLink( $row->rev_user, $row->rev_user_text ) . ') ';
+               } else {
+                       $userlink = '';
+               }
 
-               if ($this->username == 'newbies') {
-                       $max = $this->dbr->selectField('user', 'max(user_id)', false, "make_sql");
-                       $condition = '>' . (int)($max - $max / 100);
+               if( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
+                       $d = '<span class="history-deleted">' . $d . '</span>';
                }
 
-               if ($condition == "") {
-                       $condition = " rev_user_text=" . $this->dbr->addQuotes($this->username);
-                       $index = 'usertext_timestamp';
+               if( $row->rev_minor_edit ) {
+                       $mflag = '<span class="minor">' . $this->messages['minoreditletter'] . '</span> ';
                } else {
-                       $condition = " rev_user {$condition}";
-                       $index = 'user_timestamp';
+                       $mflag = '';
                }
-               return array($index, $condition);
-       }
-
-       function get_namespace_cond() {
-               if ($this->namespace !== false)
-                       return " AND page_namespace = " . (int)$this->namespace;
-               return "";
-       }
-
-       function get_previous_offset_for_paging() {
-               list($index, $usercond) = $this->get_user_cond();
-               $nscond = $this->get_namespace_cond();
-
-               $use_index = $this->dbr->useIndexClause($index);
-               extract($this->dbr->tableNames('page', 'revision'));
-
-               $sql =  "SELECT rev_timestamp FROM $page, $revision $use_index " .
-                       "WHERE page_id = rev_page AND rev_timestamp > '" . $this->offset . "' AND " .
-                       "rev_user_text = " . $this->dbr->addQuotes($this->username) .
-                       $nscond;
-               $sql .= " ORDER BY rev_timestamp ASC LIMIT " . ($this->limit+1);
-               $res = $this->dbr->query($sql);
-               $rows = array();
-               while ($obj = $this->dbr->fetchObject($res))
-                       $rows[] = $obj;
-               $this->dbr->freeResult($res);
-               return $rows[count($rows) - 1]->rev_timestamp;
-       }
-
-       function get_first_offset_for_paging() {
-               list($index, $usercond) = $this->get_user_cond();
-               $use_index = $this->dbr->useIndexClause($index);
-               extract($this->dbr->tableNames('page', 'revision'));
-               $nscond = $this->get_namespace_cond();
-               $sql =  "SELECT rev_timestamp FROM $page, $revision $use_index " .
-                       "WHERE page_id = rev_page AND " .
-                       "rev_user_text = " . $this->dbr->addQuotes($this->username) .
-                       $nscond;
-               $sql .= " ORDER BY rev_timestamp ASC LIMIT " . $this->limit;
-               $res = $this->dbr->query($sql);
-               $rows = array();
-               while ($obj = $this->dbr->fetchObject($res))
-                       $rows[] = $obj;
-               $this->dbr->freeResult($res);
-               return $rows[count($rows) - 1]->rev_timestamp;
-       }
-
-       /* private */ function make_sql() {
-               $userCond = $condition = $index = $offsetQuery = $limitQuery = "";
-
-               extract($this->dbr->tableNames('page', 'revision'));
-               list($index, $userCond) = $this->get_user_cond();
-
-               $limitQuery = "LIMIT {$this->limit}";
-               if ($this->offset)
-                       $offsetQuery = "AND rev_timestamp <= '{$this->offset}'";
-
-               $nscond = $this->get_namespace_cond();
-               $use_index = $this->dbr->useIndexClause($index);
-               $sql = "SELECT
-                       page_namespace,page_title,page_is_new,page_latest,
-                       rev_id,rev_timestamp,rev_comment,rev_minor_edit,rev_user_text,
-                       rev_deleted
-                       FROM $page,$revision $use_index
-                       WHERE page_id=rev_page AND $userCond $nscond $offsetQuery
-                       ORDER BY rev_timestamp DESC $limitQuery";
-               return $sql;
-       }
-
-       function find() {
-               $contribs = array();
-               $res = $this->dbr->query($this->make_sql(), "contribs_finder::find");
-               while ($c = $this->dbr->fetchObject($res))
-                       $contribs[] = $c;
-               $this->dbr->freeResult($res);
-               return $contribs;
-       }
-};
+
+               $ret = "{$d} {$histlink} {$difftext} {$mflag} {$link}{$userlink}{$comment} {$topmarktext}";
+               if( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
+                       $ret .= ' ' . wfMsgHtml( 'deletedrev' );
+               }
+               $ret = "<li>$ret</li>\n";
+               wfProfileOut( __METHOD__ );
+               return $ret;
+       }
+       
+       /**
+        * Get the Database object in use
+        *
+        * @return Database
+        */
+       public function getDatabase() {
+               return $this->mDb;
+       }
+       
+}
 
 /**
  * Special page "user contributions".
  * Shows a list of the contributions of a user.
  *
  * @return     none
- * @param      string  $par    (optional) user name of the user for which to show the contributions
+ * @param      $par    String: (optional) user name of the user for which to show the contributions
  */
 function wfSpecialContributions( $par = null ) {
-       global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest, $wgTitle,
-              $wgScript;
-       $fname = 'wfSpecialContributions';
+       global $wgUser, $wgOut, $wgLang, $wgRequest;
+
+       $options = array();
+       
+       if ( isset( $par ) && $par == 'newbies' ) {
+               $target = 'newbies';
+               $options['contribs'] = 'newbie';
+       } elseif ( isset( $par ) ) {
+               $target = $par;
+       } else {
+               $target = $wgRequest->getVal( 'target' );
+       }
 
-       $target = isset($par) ? $par : $wgRequest->getVal( 'target' );
-       if (!strlen($target)) {
-               $wgOut->errorpage('notargettitle', 'notargettext');
-               return;
+       // check for radiobox
+       if ( $wgRequest->getVal( 'contribs' ) == 'newbie' ) {
+               $target = 'newbies';
+               $options['contribs'] = 'newbie';
        }
 
-       $nt = Title::newFromURL( $target );
-       if (!$nt) {
-               $wgOut->errorpage( 'notargettitle', 'notargettext' );
+       if ( !strlen( $target ) ) {
+               $wgOut->addHTML( contributionsForm( '' ) );
                return;
        }
-       $nt =& Title::makeTitle(NS_USER, $nt->getDBkey());
 
-       list( $limit, $offset) = wfCheckLimits();
-       $offset = $wgRequest->getVal('offset');
-       /* Offset must be an integral. */
-       if (!strlen($offset) || !preg_match("/^[0-9]+$/", $offset))
-               $offset = 0;
+       $options['limit'] = $wgRequest->getInt( 'limit', 50 );
+       $options['target'] = $target;
 
-       $title = Title::makeTitle(NS_SPECIAL, "Contributions");
-       $urlbits = "target=" . wfUrlEncode($target);
-       $myurl = $title->escapeLocalURL($urlbits);
+       $nt = Title::makeTitleSafe( NS_USER, $target );
+       if ( !$nt ) {
+               $wgOut->addHTML( contributionsForm( '' ) );
+               return;
+       }
+       $id = User::idFromName( $nt->getText() );
 
-       $finder = new contribs_finder(($target == 'newbies') ? 'newbies' : $nt->getText());
+       if ( $target != 'newbies' ) {
+               $target = $nt->getText();
+               $wgOut->setSubtitle( contributionsSub( $nt, $id ) );
+       } else {
+               $wgOut->setSubtitle( wfMsgHtml( 'sp-contributions-newbies-sub') );
+       }
+       
+       if ( ( $ns = $wgRequest->getVal( 'namespace', null ) ) !== null && $ns !== '' ) {
+               $options['namespace'] = intval( $ns );
+       } else {
+               $options['namespace'] = '';
+       }
+       if ( $wgUser->isAllowed( 'rollback' ) && $wgRequest->getBool( 'bot' ) ) {
+               $options['bot'] = '1';
+       }
+       
+       $skip = $wgRequest->getText( 'offset' ) || $wgRequest->getText( 'dir' ) == 'prev';
+       # Offset overrides year/month selection
+       if ( ( $month = $wgRequest->getIntOrNull( 'month' ) ) !== null && $month !== -1 ) {
+               $options['month'] = intval( $month );
+       } else {
+               $options['month'] = '';
+       }
+       if ( ( $year = $wgRequest->getIntOrNull( 'year' ) ) !== null ) {
+               $options['year'] = intval( $year );
+       } else if( $options['month'] ) {
+               $thisMonth = intval( gmdate( 'n' ) );
+               $thisYear = intval( gmdate( 'Y' ) );
+               if( intval( $options['month'] ) > $thisMonth ) {
+                       $thisYear--;
+               }
+               $options['year'] = $thisYear;
+       } else {
+               $options['year'] = '';
+       }
 
-       $finder->set_limit($limit);
-       $finder->set_offset($offset);
+       wfRunHooks( 'SpecialContributionsBeforeMainOutput', $id );
 
-       $nsurl = $xnsurl = "";
-       if (($ns = $wgRequest->getVal('namespace', null)) !== null) {
-               $nsurl = "&namespace=$ns";
-               $xnsurl = htmlspecialchars($nsurl);
-               $finder->set_namespace($ns);
+       $wgOut->addHTML( contributionsForm( $options ) );
+       # Show original selected options, don't apply them so as to allow paging
+       $_GET['year'] = ''; // hack for Pager
+       $_GET['month'] = ''; // hack for Pager
+       if( $skip ) {
+               $options['year'] = '';
+               $options['month'] = '';
        }
 
-       if ($wgRequest->getText('go') == "prev") {
-               $prevts = $finder->get_previous_offset_for_paging();
-               $prevurl = $title->getLocalURL($urlbits . "&offset=$prevts&limit=$limit$nsurl");
-               $wgOut->redirect($prevurl);
+       $pager = new ContribsPager( $target, $options['namespace'], $options['year'], $options['month'] );
+       if ( !$pager->getNumRows() ) {
+               $wgOut->addWikiText( wfMsg( 'nocontribs' ) );
                return;
        }
 
-       if ($wgRequest->getText('go') == "first") {
-               $prevts = $finder->get_first_offset_for_paging();
-               $prevurl = $title->getLocalURL($urlbits . "&offset=$prevts&limit=$limit$nsurl");
-               $wgOut->redirect($prevurl);
-               return;
+       # Show a message about slave lag, if applicable
+       if( ( $lag = $pager->getDatabase()->getLag() ) > 0 )
+               $wgOut->showLagWarning( $lag );
+
+       $wgOut->addHTML( 
+               '<p>' . $pager->getNavigationBar() . '</p>' .
+               $pager->getBody() .
+               '<p>' . $pager->getNavigationBar() . '</p>' );
+       
+       # If there were contributions, and it was a valid user or IP, show
+       # the appropriate "footer" message - WHOIS tools, etc.
+       if( $target != 'newbies' ) {
+               $message = IP::isIPAddress( $target )      
+                       ? 'sp-contributions-footer-anon'
+                       : 'sp-contributions-footer';
+
+
+               $text = wfMsg( $message, $target );
+               if( !wfEmptyMsg( $message, $text ) && $text != '-' ) {
+                       $wgOut->addHtml( '<div class="mw-contributions-footer">' );
+                       $wgOut->addWikiText( $text );
+                       $wgOut->addHtml( '</div>' );
+               }
        }
+}
 
-       $sk = $wgUser->getSkin();
+/**
+ * Generates the subheading with links
+ * @param Title $nt Title object for the target
+ * @param integer $id User ID for the target
+ * @return String: appropriately-escaped HTML to be output literally
+ */
+function contributionsSub( $nt, $id ) {
+       global $wgSysopUserBans, $wgLang, $wgUser;
 
-       $id = User::idFromName($nt->getText());
+       $sk = $wgUser->getSkin();
 
        if ( 0 == $id ) {
-               $ul = $nt->getText();
+               $user = $nt->getText();
        } else {
-               $ul = $sk->makeLinkObj( $nt, htmlspecialchars( $nt->getText() ) );
-               $userCond = '=' . $id;
+               $user = $sk->makeLinkObj( $nt, htmlspecialchars( $nt->getText() ) );
        }
        $talk = $nt->getTalkPage();
        if( $talk ) {
-               $ul .= ' (' . $sk->makeLinkObj( $talk, $wgLang->getNsText( NS_TALK ) ) . ')';
-       }
-
-       if ($target == 'newbies') {
-               $ul = wfMsg ('newbies');
-       }
-
-       $wgOut->setSubtitle( wfMsgHtml( 'contribsub', $ul ) );
-
-       wfRunHooks('SpecialContributionsBeforeMainOutput', $id );
-
-       $arr =  $wgContLang->getFormattedNamespaces();
-       $nsform = "<form method='get' action=\"$wgScript\">\n";
-       $nsform .= wfElement("input", array(
-                       "name" => "title",
-                       "type" => "hidden",
-                       "value" => $wgTitle->getPrefixedText()));
-       $nsform .= wfElement("input", array(
-                       "name" => "offset",
-                       "type" => "hidden",
-                       "value" => $offset));
-       $nsform .= wfElement("input", array(
-                       "name" => "limit",
-                       "type" => "hidden",
-                       "value" => $limit));
-       $nsform .= wfElement("input", array(
-                       "name" => "target",
-                       "type" => "hidden",
-                       "value" => $target));
-       $nsform .= "<p>";
-       $nsform .= wfMsgHtml('namespace');
-
-       $nsform .= HTMLnamespaceselector($ns, '');
-
-       $nsform .= wfElement("input", array(
-                       "type" => "submit",
-                       "value" => wfMsg('allpagessubmit')));
-       $nsform .= "</p></form>\n";
-
-       $wgOut->addHTML($nsform);
-
-       $contribsPage = Title::makeTitle( NS_SPECIAL, 'Contributions' );
-       $contribs = $finder->find();
-
-       if (count($contribs) == 0) {
-               $wgOut->addWikiText( wfMsg( "nocontribs" ) );
-               return;
-       }
-
-       list($early, $late) = $finder->get_edit_limits();
-       $lastts = count($contribs) ? $contribs[count($contribs) - 1]->rev_timestamp : 0;
-       $atstart = (!count($contribs) || $late == $contribs[0]->rev_timestamp);
-       $atend = (!count($contribs) || $early == $lastts);
-
-       $lasturl = $wgTitle->escapeLocalURL("action=history&limit={$limit}");
+               # Talk page link
+               $tools[] = $sk->makeLinkObj( $talk, wfMsgHtml( 'talkpagelinktext' ) );
+               if( ( $id != 0 && $wgSysopUserBans ) || ( $id == 0 && User::isIP( $nt->getText() ) ) ) {
+                       # Block link
+                       if( $wgUser->isAllowed( 'block' ) )
+                               $tools[] = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Blockip', $nt->getDBkey() ), wfMsgHtml( 'blocklink' ) );
+                       # Block log link
+                       $tools[] = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Log' ), wfMsgHtml( 'sp-contributions-blocklog' ), 'type=block&page=' . $nt->getPrefixedUrl() );
+               }
+               # Other logs link
+               $tools[] = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Log' ), wfMsgHtml( 'log' ), 'user=' . $nt->getPartialUrl() );
 
-       $firsttext = wfMsgHtml("histfirst");
-       $lasttext = wfMsgHtml("histlast");
+               wfRunHooks( 'ContributionsToolLinks', array( $id, $nt, &$tools ) );
 
-       $prevtext = wfMsg("prevn", $limit);
-       if ($atstart) {
-               $lastlink = $lasttext;
-               $prevlink = $prevtext;
-       } else {
-               $lastlink = "<a href=\"$myurl&amp;limit=$limit$xnsurl\">$lasttext</a>";
-               $prevlink = "<a href=\"$myurl&amp;offset=$offset&amp;limit=$limit$xnsurl&amp;go=prev\">$prevtext</a>";
+               $links = implode( ' | ', $tools );
        }
 
-       $nexttext = wfMsg("nextn", $limit);
-       if ($atend) {
-               $firstlink = $firsttext;
-               $nextlink = $nexttext;
+       // Old message 'contribsub' had one parameter, but that doesn't work for
+       // languages that want to put the "for" bit right after $user but before
+       // $links.  If 'contribsub' is around, use it for reverse compatibility,
+       // otherwise use 'contribsub2'.
+       if( wfEmptyMsg( 'contribsub', wfMsg( 'contribsub' ) ) ) {
+               return wfMsgHtml( 'contribsub2', $user, $links );
        } else {
-               $firstlink = "<a href=\"$myurl&amp;limit=$limit$xnsurl&amp;go=first\">$firsttext</a>";
-               $nextlink = "<a href=\"$myurl&amp;offset=$lastts&amp;limit=$limit$xnsurl\">$nexttext</a>";
+               return wfMsgHtml( 'contribsub', "$user ($links)" );
        }
-       $firstlast = "($lastlink | $firstlink)";
-
-       $urls = array();
-       foreach (array(20, 50, 100, 250, 500) as $num)
-               $urls[] = "<a href=\"$myurl&amp;offset=$offset&amp;limit={$num}$xnsurl\">".$wgLang->formatNum($num)."</a>";
-       $bits = implode($urls, ' | ');
-
-       $prevnextbits = "$firstlast " . wfMsgHtml("viewprevnext", $prevlink, $nextlink, $bits);
-
-       $wgOut->addHTML( "<p>{$prevnextbits}</p>\n");
-
-       $wgOut->addHTML( "<ul>\n" );
-
-       foreach ($contribs as $contrib)
-               $wgOut->addHTML(ucListEdit($sk, $contrib));
-
-       $wgOut->addHTML( "</ul>\n" );
-       $wgOut->addHTML( "<p>{$prevnextbits}</p>\n");
 }
 
-
 /**
- * Generates each row in the contributions list.
- *
- * Contributions which are marked "top" are currently on top of the history.
- * For these contributions, a [rollback] link is shown for users with sysop
- * privileges. The rollback link restores the most recent version that was not
- * written by the target user.
- *
- * If the contributions page is called with the parameter &bot=1, all rollback
- * links also get that parameter. It causes the edit itself and the rollback
- * to be marked as "bot" edits. Bot edits are hidden by default from recent
- * changes, so this allows sysops to combat a busy vandal without bothering
- * other users.
- *
- * @todo This would probably look a lot nicer in a table.
+ * Generates the namespace selector form with hidden attributes.
+ * @param $options Array: the options to be included.
  */
-function ucListEdit( $sk, $row ) {
-       $fname = 'ucListEdit';
-       wfProfileIn( $fname );
+function contributionsForm( $options ) {
+       global $wgScript, $wgTitle, $wgRequest;
 
-       global $wgLang, $wgOut, $wgUser, $wgRequest;
-       static $messages;
-       if( !isset( $messages ) ) {
-               foreach( explode( ' ', 'uctop diff newarticle rollbacklink diff hist minoreditletter' ) as $msg ) {
-                       $messages[$msg] = wfMsg( $msg );
-               }
+       $options['title'] = $wgTitle->getPrefixedText();
+       if ( !isset( $options['target'] ) ) {
+               $options['target'] = '';
+       } else {
+               $options['target'] = str_replace( '_' , ' ' , $options['target'] );
        }
 
-       $page =& Title::makeTitle( $row->page_namespace, $row->page_title );
-       $link = $sk->makeKnownLinkObj( $page, '' );
-       $difftext = $topmarktext = '';
-       if( $row->rev_id == $row->page_latest ) {
-               $topmarktext .= '<strong>' . $messages['uctop'] . '</strong>';
-               if( !$row->page_is_new ) {
-                       $difftext .= '(' . $sk->makeKnownLinkObj( $page, $messages['diff'], 'diff=0' ) . ')';
-               } else {
-                       $difftext .= $messages['newarticle'];
-               }
-
-               if( $wgUser->isAllowed('rollback') ) {
-                       $extraRollback = $wgRequest->getBool( 'bot' ) ? '&bot=1' : '';
-                       $extraRollback .= '&token=' . urlencode(
-                               $wgUser->editToken( array( $page->getPrefixedText(), $row->rev_user_text ) ) );
-                       $topmarktext .= ' ['. $sk->makeKnownLinkObj( $page,
-                               $messages['rollbacklink'],
-                               'action=rollback&from=' . urlencode( $row->rev_user_text ) . $extraRollback ) .']';
-               }
+       if ( !isset( $options['namespace'] ) ) {
+               $options['namespace'] = '';
+       }
 
+       if ( !isset( $options['contribs'] ) ) {
+               $options['contribs'] = 'user';
        }
-       if( $row->rev_deleted && !$wgUser->isAllowed( 'undelete' ) ) {
-               $difftext = '(' . $messages['diff'] . ')';
-       } else {
-               $difftext = '(' . $sk->makeKnownLinkObj( $page, $messages['diff'], 'diff=prev&oldid='.$row->rev_id ) . ')';
+       
+       if ( !isset( $options['year'] ) ) {
+               $options['year'] = '';
        }
-       $histlink='('.$sk->makeKnownLinkObj( $page, $messages['hist'], 'action=history' ) . ')';
 
-       $comment = $sk->commentBlock( $row->rev_comment, $page );
-       $d = $wgLang->timeanddate( $row->rev_timestamp, true );
+       if ( !isset( $options['month'] ) ) {
+               $options['month'] = '';
+       }
 
-       if( $row->rev_minor_edit ) {
-               $mflag = '<span class="minor">' . $messages['minoreditletter'] . '</span> ';
-       } else {
-               $mflag = '';
+       if ( $options['contribs'] == 'newbie' ) {
+               $options['target'] = '';
        }
 
-       $ret = "{$d} {$histlink} {$difftext} {$mflag} {$link} {$comment} {$topmarktext}";
-       if( $row->rev_deleted ) {
-               $ret = '<span class="deleted">' . $ret . '</span> ' . htmlspecialchars( wfMsg( 'deletedrev' ) );
+       $f = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
+
+       foreach ( $options as $name => $value ) {
+               if ( in_array( $name, array( 'namespace', 'target', 'contribs', 'year', 'month' ) ) ) {
+                       continue;
+               }
+               $f .= "\t" . Xml::hidden( $name, $value ) . "\n";
        }
-       $ret = "<li>$ret</li>\n";
-       wfProfileOut( $fname );
-       return $ret;
-}
 
-?>
+       $f .= '<fieldset>' .
+               Xml::element( 'legend', array(), wfMsg( 'sp-contributions-search' ) ) .
+               Xml::radioLabel( wfMsgExt( 'sp-contributions-newbies', array( 'parseinline' ) ), 'contribs' , 'newbie' , 'newbie', $options['contribs'] == 'newbie' ? true : false ) . '<br />' .
+               Xml::radioLabel( wfMsgExt( 'sp-contributions-username', array( 'parseinline' ) ), 'contribs' , 'user', 'user', $options['contribs'] == 'user' ? true : false ) . ' ' .
+               Xml::input( 'target', 20, $options['target']) . ' '.
+               Xml::label( wfMsg( 'namespace' ), 'namespace' ) .
+               Xml::namespaceSelector( $options['namespace'], '' ) .
+               Xml::openElement( 'p' ) .
+               Xml::label( wfMsg( 'year' ), 'year' ) . ' '.
+               Xml::input( 'year', 4, $options['year'], array('id' => 'year', 'maxlength' => 4) ) . ' '.
+               Xml::label( wfMsg( 'month' ), 'month' ) . ' '.
+               Xml::monthSelector( $options['month'], -1 ) . ' '.
+               Xml::submitButton( wfMsg( 'sp-contributions-submit' ) ) .
+               Xml::closeElement( 'p' );
+       
+       $explain = wfMsgExt( 'sp-contributions-explain', 'parseinline' );
+       if( !wfEmptyMsg( 'sp-contributions-explain', $explain ) )
+               $f .= "<p>{$explain}</p>";
+               
+       $f .= '</fieldset>' .
+               Xml::closeElement( 'form' );
+       return $f;
+}