class LogEventsList {
const NO_ACTION_LINK = 1;
-
+
private $skin;
+ private $out;
public $flags;
- function __construct( &$skin, $flags = 0 ) {
+ function __construct( &$skin, &$out, $flags = 0 ) {
$this->skin =& $skin;
+ $this->out =& $out;
$this->flags = $flags;
$this->preCacheMessages();
}
}
}
}
-
+
/**
* Set page title and show header for this log type
- * @param OutputPage $out where to send output
- * @param strin $type
+ * @param string $type
*/
- public function showHeader( $out, $type ) {
+ public function showHeader( $type ) {
if( LogPage::isLogType( $type ) ) {
- $out->setPageTitle( LogPage::logName( $type ) );
- $out->addWikiText( LogPage::logHeader( $type ) );
+ $this->out->setPageTitle( LogPage::logName( $type ) );
+ $this->out->addHtml( LogPage::logHeader( $type ) );
}
}
/**
* Show options for the log list
- * @param OutputPage $out where to send output
* @param string $type,
* @param string $user,
* @param string $page,
* @param string $pattern
+ * @param int $year
+ * @parm int $month
*/
- public function showOptions( $out, $type, $user, $page, $pattern ) {
+ public function showOptions( $type='', $user='', $page='', $pattern='', $year='', $month='' ) {
global $wgScript, $wgMiserMode;
$action = htmlspecialchars( $wgScript );
$title = SpecialPage::getTitleFor( 'Log' );
$special = htmlspecialchars( $title->getPrefixedDBkey() );
- $out->addHTML( "<form action=\"$action\" method=\"get\"><fieldset>" .
+
+ $this->out->addHTML( "<form action=\"$action\" method=\"get\"><fieldset>" .
Xml::element( 'legend', array(), wfMsg( 'log' ) ) .
Xml::hidden( 'title', $special ) . "\n" .
$this->getTypeMenu( $type ) . "\n" .
$this->getUserInput( $user ) . "\n" .
$this->getTitleInput( $page ) . "\n" .
( !$wgMiserMode ? ($this->getTitlePattern( $pattern )."\n") : "" ) .
- Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
+ "<p>" . $this->getDateMenu( $year, $month ) . "\n" .
+ Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "</p>\n" .
"</fieldset></form>" );
}
/**
* @return string Formatted HTML
+ * @param string $queryType
*/
private function getTypeMenu( $queryType ) {
global $wgLogRestrictions, $wgUser;
-
- $out = "<select name='type'>\n";
+
+ $html = "<select name='type'>\n";
$validTypes = LogPage::validTypes();
$m = array(); // Temporary array
// Restricted types
if ( isset($wgLogRestrictions[$type]) ) {
if ( $wgUser->isAllowed( $wgLogRestrictions[$type] ) ) {
- $out .= Xml::option( $text, $type, $selected ) . "\n";
+ $html .= Xml::option( $text, $type, $selected ) . "\n";
}
} else {
- $out .= Xml::option( $text, $type, $selected ) . "\n";
+ $html .= Xml::option( $text, $type, $selected ) . "\n";
}
}
- $out .= '</select>';
- return $out;
+ $html .= '</select>';
+ return $html;
}
/**
* @return string Formatted HTML
+ * @param string $user
*/
private function getUserInput( $user ) {
- return Xml::inputLabel( wfMsg( 'specialloguserlabel' ), 'user', 'user', 12, $user );
+ return Xml::inputLabel( wfMsg( 'specialloguserlabel' ), 'user', 'user', 15, $user );
}
/**
* @return string Formatted HTML
+ * @param string $title
*/
private function getTitleInput( $title ) {
return Xml::inputLabel( wfMsg( 'speciallogtitlelabel' ), 'page', 'page', 20, $title );
}
+ /**
+ * @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 );
+ }
+
/**
* @return boolean Checkbox
*/
private function getTitlePattern( $pattern ) {
- return Xml::checkLabel( wfMsg( 'log-title-wildcard' ), 'pattern', 'pattern', $pattern );
+ return '<span style="white-space: nowrap">' .
+ Xml::checkLabel( wfMsg( 'log-title-wildcard' ), 'pattern', 'pattern', $pattern ) .
+ '</span>';
}
-
+
public function beginLogEventsList() {
return "<ul>\n";
}
-
+
public function endLogEventsList() {
return "</ul>\n";
}
-
+
/**
* @param Row $row a single row from the result set
* @return string Formatted HTML list item
*/
public function logLine( $row ) {
global $wgLang, $wgUser, $wgContLang;
-
+
$title = Title::makeTitle( $row->log_namespace, $row->log_title );
$time = $wgLang->timeanddate( wfTimestamp(TS_MW, $row->log_timestamp), true );
// User links
$userLink = '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
} else {
$userLink = $this->skin->userLink( $row->log_user, $row->user_name ) .
- $this->skin->userToolLinks( $row->log_user, $row->user_name );
+ $this->skin->userToolLinks( $row->log_user, $row->user_name, true, 0, $row->user_editcount );
}
// Comment
if( self::isDeleted($row,LogPage::DELETED_COMMENT) ) {
}
// Add review links and such...
if( !($this->flags & self::NO_ACTION_LINK) && !($row->log_deleted & LogPage::DELETED_ACTION) ) {
- if( $row->log_type == 'move' && isset( $paramArray[0] ) && $wgUser->isAllowed( 'move' ) ) {
+ if( self::typeAction($row,'move','move') && isset( $paramArray[0] ) && $wgUser->isAllowed( 'move' ) ) {
$destTitle = Title::newFromText( $paramArray[0] );
if( $destTitle ) {
$revert = '(' . $this->skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Movepage' ),
'&wpMovetalk=0' ) . ')';
}
// Show undelete link
- } else if( $row->log_action == 'delete' && $wgUser->isAllowed( 'delete' ) ) {
+ } else if( self::typeAction($row,array('delete','suppress'),'delete') && $wgUser->isAllowed( 'delete' ) ) {
$revert = '(' . $this->skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Undelete' ),
$this->message['undeletelink'], 'target='. urlencode( $title->getPrefixedDBkey() ) ) . ')';
// Show unblock link
- } else if( $row->log_action == 'block' && $wgUser->isAllowed( 'block' ) ) {
+ } else if( self::typeAction($row,array('block','suppress'),'block') && $wgUser->isAllowed( 'block' ) ) {
$revert = '(' . $this->skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Ipblocklist' ),
$this->message['unblocklink'],
'action=unblock&ip=' . urlencode( $row->log_title ) ) . ')';
// Show change protection link
- } else if( ( $row->log_action == 'protect' || $row->log_action == 'modify' ) && $wgUser->isAllowed( 'protect' ) ) {
+ } else if( self::typeAction($row,'protect','modify') && $wgUser->isAllowed( 'protect' ) ) {
$revert = '(' . $this->skin->makeKnownLinkObj( $title, $this->message['protect_change'], 'action=unprotect' ) . ')';
// Show unmerge link
- } else if ( $row->log_action == 'merge' ) {
+ } else if ( self::typeAction($row,'merge','merge') ) {
$merge = SpecialPage::getTitleFor( 'Mergehistory' );
$revert = '(' . $this->skin->makeKnownLinkObj( $merge, $this->message['revertmerge'],
- wfArrayToCGI(
- array('target' => $paramArray[0], 'dest' => $title->getPrefixedText(), 'mergepoint' => $paramArray[1] )
- )
- ) . ')';
+ wfArrayToCGI( array('target' => $paramArray[0], 'dest' => $title->getPrefixedDBkey(),
+ 'mergepoint' => $paramArray[1] ) ) ) . ')';
// If an edit was hidden from a page give a review link to the history
- } else if( $row->log_action == 'revision' && $wgUser->isAllowed( 'deleterevision' ) && isset($paramArray[2]) ) {
- $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
- // Different revision types use different URL params...
- $subtype = isset($paramArray[2]) ? $paramArray[1] : '';
- // Link to each hidden object ID, $paramArray[1] is the url param. List if several...
- $Ids = explode( ',', $paramArray[2] );
- if( count($Ids) == 1 ) {
- $revert = $this->skin->makeKnownLinkObj( $revdel, $this->message['revdel-restore'],
- wfArrayToCGI( array('target' => $paramArray[0], $paramArray[1] => $Ids[0] ) ) );
- } else {
- $revert .= $this->message['revdel-restore'].':';
+ } else if( self::typeAction($row,array('delete','suppress'),'revision') && $wgUser->isAllowed( 'deleterevision' ) ) {
+ if( count($paramArray) == 2 ) {
+ $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
+ // Different revision types use different URL params...
+ $key = $paramArray[0];
+ // Link to each hidden object ID, $paramArray[1] is the url param
+ $Ids = explode( ',', $paramArray[1] );
+ $revParams = '';
foreach( $Ids as $n => $id ) {
- $revert .= ' '.$this->skin->makeKnownLinkObj( $revdel, '#'.($n+1),
- wfArrayToCGI( array('target' => $paramArray[0], $paramArray[1] => $id ) ) );
+ $revParams .= '&' . urlencode($key) . '[]=' . urlencode($id);
}
+ $revert = '(' . $this->skin->makeKnownLinkObj( $revdel, $this->message['revdel-restore'],
+ 'target=' . $title->getPrefixedUrl() . $revParams ) . ')';
}
- $revert = "($revert)";
// Hidden log items, give review link
- } else if( $row->log_action == 'event' && $wgUser->isAllowed( 'deleterevision' ) && isset($paramArray[0]) ) {
- $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
- $revert .= $this->message['revdel-restore'];
- $Ids = explode( ',', $paramArray[0] );
- // Link to each hidden object ID, $paramArray[1] is the url param. List if several...
- if( count($Ids) == 1 ) {
- $revert = $this->skin->makeKnownLinkObj( $revdel, $this->message['revdel-restore'],
- wfArrayToCGI( array('logid' => $Ids[0] ) ) );
- } else {
+ } else if( self::typeAction($row,array('delete','suppress'),'event') && $wgUser->isAllowed( 'deleterevision' ) ) {
+ if( count($paramArray) == 1 ) {
+ $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
+ $Ids = explode( ',', $paramArray[0] );
+ // Link to each hidden object ID, $paramArray[1] is the url param
+ $logParams = '';
foreach( $Ids as $n => $id ) {
- $revert .= $this->skin->makeKnownLinkObj( $revdel, '#'.($n+1),
- wfArrayToCGI( array('logid' => $id ) ) );
+ $logParams .= '&logid[]=' . intval($id);
}
+ $revert = '(' . $this->skin->makeKnownLinkObj( $revdel, $this->message['revdel-restore'],
+ 'target=' . $title->getPrefixedUrl() . $logParams ) . ')';
}
- $revert = "($revert)";
} else {
- wfRunHooks( 'LogLine', array( $row->log_type, $row->log_action, $title, $paramArray,
+ wfRunHooks( 'LogLine', array( $row->log_type, $row->log_action, $title, $paramArray,
&$comment, &$revert, $row->log_timestamp ) );
// wfDebug( "Invoked LogLine hook for " $row->log_type . ", " . $row->log_action . "\n" );
// Do nothing. The implementation is handled by the hook modifiying the passed-by-ref parameters.
} else {
$action = LogPage::actionText( $row->log_type, $row->log_action, $title, $this->skin, $paramArray, true );
}
-
+
return "<li>$del$time $userLink $action $comment $revert</li>\n";
}
-
+
/**
* @param Row $row
- * @private
+ * @return string
*/
private function showhideLinks( $row ) {
- global $wgAllowLogDeletion;
-
- if( !$wgAllowLogDeletion )
- return "";
-
$revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
// If event was hidden from sysops
if( !self::userCan( $row, LogPage::DELETED_RESTRICTED ) ) {
// No one should be hiding from the oversight log
$del = $this->message['rev-delundel'];
} else {
- $del = $this->skin->makeKnownLinkObj( $revdel, $this->message['rev-delundel'], 'logid='.$row->log_id );
+ $target = SpecialPage::getTitleFor( 'Log', $row->log_type );
+ $del = $this->skin->makeKnownLinkObj( $revdel, $this->message['rev-delundel'],
+ 'target=' . $target->getPrefixedUrl() . '&logid='.$row->log_id );
// Bolden oversighted content
if( self::isDeleted( $row, LogPage::DELETED_RESTRICTED ) )
$del = "<strong>$del</strong>";
}
return "<tt>(<small>$del</small>)</tt>";
}
-
+
+ /**
+ * @param Row $row
+ * @param mixed $type (string/array)
+ * @param string $action
+ * @return bool
+ */
+ public static function typeAction( $row, $type, $action ) {
+ if( is_array($type) ) {
+ return ( in_array($row->log_type,$type) && $row->log_action == $action );
+ } else {
+ return ( $row->log_type == $type && $row->log_action == $action );
+ }
+ }
+
/**
* Determine if the current user is allowed to view a particular
* field of this log row, if it's marked as deleted.
public static function isDeleted( $row, $field ) {
return ($row->log_deleted & $field) == $field;
}
-
+
/**
* Quick function to show a short log extract
* @param OutputPage $out
public static function showLogExtract( $out, $type='', $page='', $user='' ) {
global $wgUser;
# Insert list of top 50 or so items
- $loglist = new LogEventsList( $wgUser->getSkin() );
+ $loglist = new LogEventsList( $wgUser->getSkin(), $out, 0 );
$pager = new LogPager( $loglist, $type, $user, $page, '' );
$logBody = $pager->getBody();
if( $logBody ) {
$out->addWikiMsg( 'logempty' );
}
}
-
+
/**
* SQL clause to skip forbidden log types for this user
* @param Database $db
* @addtogroup Pager
*/
class LogPager extends ReverseChronologicalPager {
- private $type = '', $user = '', $title = '', $pattern = '';
+ private $type = '', $user = '', $title = '', $pattern = '', $year = '', $month = '';
public $mLogEventsList;
/**
* constructor
* @param string $pattern
* @param array $conds
*/
- function __construct( $loglist, $type='', $user='', $title='', $pattern='', $conds = array() ) {
+ function __construct( $list, $type='', $user='', $title='', $pattern='', $conds=array(), $y=false, $m=false ) {
parent::__construct();
$this->mConds = $conds;
-
- $this->mLogEventsList = $loglist;
-
+
+ $this->mLogEventsList = $list;
+
$this->limitType( $type );
$this->limitUser( $user );
$this->limitTitle( $title, $pattern );
+ $this->limitDate( $y, $m );
}
-
+
function getDefaultQuery() {
$query = parent::getDefaultQuery();
$query['type'] = $this->type;
+ $query['month'] = $this->month;
+ $query['year'] = $this->year;
return $query;
}
-
+
/**
* Set the log reader to return only entries of the given type.
* Type restrictions enforced here
$this->type = $type;
$this->mConds['log_type'] = $type;
}
-
+
/**
* Set the log reader to return only entries by the given user.
* @param string $name (In)valid user name
if( is_null($usertitle) ) {
return false;
}
- $this->user = $usertitle->getText();
/* Fetch userid at first, if known, provides awesome query plan afterwards */
- $userid = User::idFromName( $this->user );
+ $userid = User::idFromName( $name );
if( !$userid ) {
- /* It should be nicer to abort query at all,
+ /* It should be nicer to abort query at all,
but for now it won't pass anywhere behind the optimizer */
$this->mConds[] = "NULL";
} else {
$this->mConds['log_user'] = $userid;
+ $this->user = $usertitle->getText();
}
}
*/
function limitTitle( $page, $pattern ) {
global $wgMiserMode;
-
+
$title = Title::newFromText( $page );
if( strlen($page) == 0 || !$title instanceof Title )
return false;
-
+
$this->title = $title->getPrefixedText();
- $this->pattern = $pattern;
$ns = $title->getNamespace();
if( $pattern && !$wgMiserMode ) {
# use escapeLike to avoid expensive search patterns like 't%st%'
$safetitle = $this->mDb->escapeLike( $title->getDBkey() );
$this->mConds['log_namespace'] = $ns;
$this->mConds[] = "log_title LIKE '$safetitle%'";
+ $this->pattern = $pattern;
} else {
$this->mConds['log_namespace'] = $ns;
$this->mConds['log_title'] = $title->getDBkey();
}
}
+ /**
+ * Set the log reader to return only entries from given date.
+ * @param int $year
+ * @param int $month
+ * @private
+ */
+ function limitDate( $year, $month ) {
+ $year = intval($year);
+ $month = intval($month);
+
+ $this->year = ($year > 0 && $year < 10000) ? $year : '';
+ $this->month = ($month > 0 && $month < 13) ? $month : '';
+
+ 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;
+ }
+ }
+
function getQueryInfo() {
$this->mConds[] = 'user_id = log_user';
- # Hack this until live
- global $wgAllowLogDeletion;
- $log_id = $wgAllowLogDeletion ? 'log_id' : '0 AS log_id';
# Don't use the wrong logging index
if( $this->title || $this->pattern || $this->user ) {
$index = array( 'USE INDEX' => array( 'logging' => array('page_time','user_time') ) );
}
return array(
'tables' => array( 'logging', 'user' ),
- 'fields' => array( 'log_type', 'log_action', 'log_user', 'log_namespace', 'log_title',
- 'log_params', 'log_comment', $log_id, 'log_deleted', 'log_timestamp', 'user_name' ),
+ 'fields' => array( 'log_type', 'log_action', 'log_user', 'log_namespace', 'log_title', 'log_params',
+ 'log_comment', 'log_id', 'log_deleted', 'log_timestamp', 'user_name', 'user_editcount' ),
'conds' => $this->mConds,
'options' => $index
);
function getIndexField() {
return 'log_timestamp';
}
-
+
function getStartBody() {
wfProfileIn( __METHOD__ );
# Do a link batch query
- $lb = new LinkBatch;
- while( $row = $this->mResult->fetchObject() ) {
- $lb->add( $row->log_namespace, $row->log_title );
- $lb->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) );
- $lb->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->user_name ) );
+ if( $this->getNumRows() > 0 ) {
+ $lb = new LinkBatch;
+ while( $row = $this->mResult->fetchObject() ) {
+ $lb->add( $row->log_namespace, $row->log_title );
+ $lb->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) );
+ $lb->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->user_name ) );
+ }
+ $lb->execute();
+ $this->mResult->seek( 0 );
}
- $lb->execute();
- $this->mResult->seek( 0 );
wfProfileOut( __METHOD__ );
return '';
}
function formatRow( $row ) {
return $this->mLogEventsList->logLine( $row );
}
-
+
public function getType() {
return $this->type;
}
-
+
public function getUser() {
return $this->user;
}
-
+
public function getPage() {
return $this->title;
}
-
+
public function getPattern() {
return $this->pattern;
}
+
+ public function getYear() {
+ return $this->year;
+ }
+
+ public function getMonth() {
+ return $this->month;
+ }
}
/**
- *
+ * @Deprecated
* @addtogroup SpecialPage
*/
class LogReader {
* @param WebRequest $request For internal use use a FauxRequest object to pass arbitrary parameters.
*/
function __construct( $request ) {
- global $wgUser;
+ global $wgUser, $wgOut;
# Get parameters
$type = $request->getVal( 'type' );
$user = $request->getText( 'user' );
$title = $request->getText( 'page' );
$pattern = $request->getBool( 'pattern' );
-
- $loglist = new LogEventsList( $wgUser->getSkin() );
- $this->pager = new LogPager( $loglist, $type, $user, $title, $pattern );
+ $y = $request->getIntOrNull( 'year' );
+ $m = $request->getIntOrNull( 'month' );
+ # Don't let the user get stuck with a certain date
+ $skip = $request->getText( 'offset' ) || $request->getText( 'dir' ) == 'prev';
+ if( $skip ) {
+ $y = '';
+ $m = '';
+ }
+ # Use new list class to output results
+ $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut, 0 );
+ $this->pager = new LogPager( $loglist, $type, $user, $title, $pattern, $y, $m );
}
-
+
/**
* Is there at least one row?
* @return bool
}
/**
- *
+ * @Deprecated
* @addtogroup SpecialPage
*/
class LogViewer {
$this->reader->pager->mLogEventsList->flags = $flags;
# Aliases for shorter code...
$this->pager =& $this->reader->pager;
- $this->logEventsList =& $this->reader->pager->mLogEventsList;
+ $this->list =& $this->reader->pager->mLogEventsList;
}
/**
* Take over the whole output page in $wgOut with the log display.
*/
public function show() {
- global $wgOut;
# Set title and add header
- $this->logEventsList->showHeader( $wgOut, $pager->getType() );
+ $this->list->showHeader( $pager->getType() );
# Show form options
- $this->logEventsList->showOptions( $wgOut, $this->pager->getType(), $this->pager->getUser(),
- $this->pager->getPage(), $this->pager->getPattern() );
+ $this->list->showOptions( $this->pager->getType(), $this->pager->getUser(), $this->pager->getPage(),
+ $this->pager->getPattern(), $this->pager->getYear(), $this->pager->getMonth() );
# Insert list
$logBody = $this->pager->getBody();
if( $logBody ) {
$wgOut->addHTML(
- $this->pager->getNavigationBar() .
- $this->logEventsList->beginLogEventsList() .
+ $this->pager->getNavigationBar() .
+ $this->list->beginLogEventsList() .
$logBody .
- $this->logEventsList->endLogEventsList() .
+ $this->list->endLogEventsList() .
$this->pager->getNavigationBar()
);
} else {
$logBody = $this->pager->getBody();
if( $logBody ) {
$out->addHTML(
- $this->logEventsList->beginLogEventsList() .
+ $this->list->beginLogEventsList() .
$logBody .
- $this->logEventsList->endLogEventsList()
+ $this->list->endLogEventsList()
);
} else {
$out->addWikiMsg( 'logempty' );
}
}
}
-