From 9e2fca384699a17e262ea054dbcc5a86d43c7c86 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Fri, 1 Aug 2008 22:59:06 +0000 Subject: [PATCH] Add date selector to history pages --- includes/PageHistory.php | 55 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/includes/PageHistory.php b/includes/PageHistory.php index 482d93f6ac..f134851774 100644 --- a/includes/PageHistory.php +++ b/includes/PageHistory.php @@ -68,12 +68,11 @@ class PageHistory { * @returns nothing */ function history() { - global $wgOut, $wgRequest, $wgTitle; + global $wgOut, $wgRequest, $wgTitle, $wgScript; /* * Allow client caching. */ - if( $wgOut->checkLastModified( $this->mArticle->getTouched() ) ) /* Client cache fresh and headers sent, nothing more to do. */ return; @@ -124,13 +123,29 @@ class PageHistory { $wgOut->redirect( $wgTitle->getLocalURL( "action=history&limit={$limit}&dir=prev" ) ); return; } + + /** + * Add date selector to quickly get to a certain time + */ + $year = $wgRequest->getInt( 'year' ); + $month = $wgRequest->getInt( 'month' ); + + $action = htmlspecialchars( $wgScript ); + $wgOut->addHTML( + "
" . + Xml::hidden( 'title', $this->mTitle->getPrefixedDBKey() ) . "\n" . + Xml::hidden( 'action', 'history' ) . "\n" . + $this->getDateMenu( $year, $month ) . ' ' . + Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" . + '

' + ); wfRunHooks( 'PageHistoryBeforeList', array( &$this->mArticle ) ); /** * Do the list */ - $pager = new PageHistoryPager( $this ); + $pager = new PageHistoryPager( $this, $year, $month ); $this->linesonpage = $pager->getNumRows(); $wgOut->addHTML( $pager->getNavigationBar() . @@ -141,6 +156,37 @@ class PageHistory { ); wfProfileOut( __METHOD__ ); } + + /** + * @return string Formatted HTML + * @param int $year + * @param int $month + */ + private function getDateMenu( $year, $month ) { + # Offset overrides year/month selection + if( $month && $month !== -1 ) { + $encMonth = intval( $month ); + } else { + $encMonth = ''; + } + if ( $year ) { + $encYear = intval( $year ); + } else if( $encMonth ) { + $thisMonth = intval( gmdate( 'n' ) ); + $thisYear = intval( gmdate( 'Y' ) ); + if( intval($encMonth) > $thisMonth ) { + $thisYear--; + } + $encYear = $thisYear; + } else { + $encYear = ''; + } + return Xml::label( wfMsg( 'year' ), 'year' ) . ' '. + Xml::input( 'year', 4, $encYear, array('id' => 'year', 'maxlength' => 4) ) . + ' '. + Xml::label( wfMsg( 'month' ), 'month' ) . ' '. + Xml::monthSelector( $encMonth, -1 ); + } /** * Creates begin of history list with a submit button @@ -579,9 +625,10 @@ class PageHistory { class PageHistoryPager extends ReverseChronologicalPager { public $mLastRow = false, $mPageHistory; - function __construct( $pageHistory ) { + function __construct( $pageHistory, $year='', $month='' ) { parent::__construct(); $this->mPageHistory = $pageHistory; + $this->getDateCond( $year, $month ); } function getQueryInfo() { -- 2.20.1