*Should be greater than 0, not 1 ;)
[lhc/web/wiklou.git] / includes / SpecialContributions.php
index a0effc6..b5715c6 100644 (file)
@@ -7,17 +7,21 @@
 class ContribsPager extends IndexPager {
        public $mDefaultDirection = true;
        var $messages, $target;
-       var $namespace == '', $mDb;
-
-       function __construct( $target, $namespace = false ) {
-               global $wgUser;
+       var $namespace = '', $mDb;
 
+       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->mDb = wfGetDB( DB_SLAVE, 'contributions' );
        }
 
@@ -29,7 +33,7 @@ class ContribsPager extends IndexPager {
 
        function getQueryInfo() {
                list( $index, $userCond ) = $this->getUserCond();
-               $conds = array_merge( array( 'page_id=rev_page' ), $userCond, $this->getNamespaceCond() );
+               $conds = array_merge( array('page_id=rev_page'), $userCond, $this->getNamespaceCond(), $this->GetDateCond() );
 
                return array(
                        'tables' => array( 'page', 'revision' ),
@@ -48,7 +52,7 @@ class ContribsPager extends IndexPager {
 
                if ( $this->target == 'newbies' ) {
                        $max = $this->mDb->selectField( 'user', 'max(user_id)', false, __METHOD__ );
-                       $condition[] = 'rev_user >' . (int)($max - $max / 2/*100*/);
+                       $condition[] = 'rev_user >' . (int)($max - $max / 100);
                        $index = 'user_timestamp';
                } else {
                        $condition['rev_user_text'] = $this->target;
@@ -64,6 +68,39 @@ class ContribsPager extends IndexPager {
                        return array();
                }
        }
+       
+       function getDateCond() {
+               $condition = array();
+               
+               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 );
+                       }
+                       
+                       if ( $this->month ) {
+                               $month_start = str_pad($this->month, 2, '0', STR_PAD_LEFT);
+                               $month_end = str_pad($this->month + 1, 2, '0', STR_PAD_LEFT);
+                               $year_end = $year_start;
+                       } else {
+                               $month_start = 0;
+                               $month_end = 0;
+                               $year_end = $year_start + 1;
+                       }
+                       
+                       $ts_start = str_pad($year_start . $month_start, 14, '0' );
+                       $ts_end = str_pad($year_end . $month_end, 14, '0' );
+                       
+                       $condition[] = "rev_timestamp >= $ts_start";
+                       # If just given the year 9999, we need not enforce an upper bound
+                       if( strlen($year_end) <= 4 )
+                               $condition[] = "rev_timestamp < $ts_end";
+               }
+               
+               return $condition;
+       }
 
        function getIndexField() {
                return 'rev_timestamp';
@@ -140,6 +177,13 @@ class ContribsPager extends IndexPager {
 
                $comment = $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( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
                        $d = '<span class="history-deleted">' . $d . '</span>';
@@ -151,7 +195,7 @@ class ContribsPager extends IndexPager {
                        $mflag = '';
                }
 
-               $ret = "{$d} {$histlink} {$difftext} {$mflag} {$link} {$comment} {$topmarktext}";
+               $ret = "{$d} {$histlink} {$difftext} {$mflag} {$link}{$userlink}{$comment} {$topmarktext}";
                if( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
                        $ret .= ' ' . wfMsgHtml( 'deletedrev' );
                }
@@ -159,6 +203,16 @@ class ContribsPager extends IndexPager {
                wfProfileOut( __METHOD__ );
                return $ret;
        }
+       
+       /**
+        * Get the Database object in use
+        *
+        * @return Database
+        */
+       public function getDatabase() {
+               return $this->mDb;
+       }
+       
 }
 
 /**
@@ -218,16 +272,35 @@ function wfSpecialContributions( $par = null ) {
        if ( $wgUser->isAllowed( 'rollback' ) && $wgRequest->getBool( 'bot' ) ) {
                $options['bot'] = '1';
        }
+       
+       if ( ( $month = $wgRequest->getVal( 'month', null ) ) !== null && $month !== '' ) {
+               $options['month'] = intval( $month );
+       } else {
+               $options['month'] = '';
+       }
+       
+       if ( ( $year = $wgRequest->getVal( 'year', null ) ) !== null && $year !== '' ) {
+               $options['year'] = intval( $year );
+       } else if( $month ) {
+               $options['year'] = intval( substr( wfTimestampNow(), 0, 4 ) );          
+       } else {
+               $options['year'] = '';
+       }
 
        wfRunHooks( 'SpecialContributionsBeforeMainOutput', $id );
 
        $wgOut->addHTML( contributionsForm( $options ) );
 
-       $pager = new ContribsPager( $target, $options['namespace'] );
+       $pager = new ContribsPager( $target, $options['namespace'], $options['year'], $options['month'] );
        if ( !$pager->getNumRows() ) {
                $wgOut->addWikiText( wfMsg( 'nocontribs' ) );
                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() .
@@ -269,7 +342,7 @@ function contributionsSub( $nt, $id ) {
        $talk = $nt->getTalkPage();
        if( $talk ) {
                # Talk page link
-               $tools[] = $sk->makeLinkObj( $talk, $wgLang->getNsText( NS_TALK ) );
+               $tools[] = $sk->makeLinkObj( $talk, wfMsgHtml( 'talkpagelinktext' ) );
                if( ( $id != 0 && $wgSysopUserBans ) || ( $id == 0 && User::isIP( $nt->getText() ) ) ) {
                        # Block link
                        if( $wgUser->isAllowed( 'block' ) )
@@ -314,6 +387,14 @@ function contributionsForm( $options ) {
        if ( !isset( $options['contribs'] ) ) {
                $options['contribs'] = 'user';
        }
+       
+       if ( !isset( $options['year'] ) ) {
+               $options['year'] = '';
+       }
+
+       if ( !isset( $options['month'] ) ) {
+               $options['month'] = '';
+       }
 
        if ( $options['contribs'] == 'newbie' ) {
                $options['target'] = '';
@@ -335,7 +416,13 @@ function contributionsForm( $options ) {
                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' ) .
                '</fieldset>' .
                Xml::closeElement( 'form' );
        return $f;