// Precache various messages
if( !isset( $this->message ) ) {
$messages = array( 'revertmerge', 'protect_change', 'unblocklink', 'change-blocklink',
- 'revertmove', 'undeletelink', 'revdel-restore', 'rev-delundel', 'hist', 'pipe-separator' );
+ 'revertmove', 'undeletelink', 'undeleteviewlink', 'revdel-restore', 'rev-delundel', 'hist', 'diff',
+ 'pipe-separator' );
foreach( $messages as $msg ) {
- $this->message[$msg] = wfMsgExt( $msg, array( 'escape' ) );
+ $this->message[$msg] = wfMsgExt( $msg, array( 'escapenoentities' ) );
}
}
}
/**
* Show options for the log list
- * @param $type String
+ * @param $types string or Array
* @param $user String
* @param $page String
* @param $pattern String
* @param $year Integer: year
* @param $month Integer: month
- * @param $filter Boolean
+ * @param $filter: array
+ * @param $tagFilter: array?
*/
- public function showOptions( $type = '', $user = '', $page = '', $pattern = '', $year = '',
- $month = '', $filter = null, $tagFilter='' )
+ public function showOptions( $types=array(), $user='', $page='', $pattern='', $year='',
+ $month = '', $filter = null, $tagFilter='' )
{
global $wgScript, $wgMiserMode;
$action = htmlspecialchars( $wgScript );
$title = SpecialPage::getTitleFor( 'Log' );
$special = htmlspecialchars( $title->getPrefixedDBkey() );
+ // For B/C, we take strings, but make sure they are converted...
+ $types = ($types === '') ? array() : (array)$types;
+
+ $tagSelector = ChangeTags::buildTagFilterSelector( $tagFilter );
$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->getTypeMenu( $types ) . "\n" .
$this->getUserInput( $user ) . "\n" .
$this->getTitleInput( $page ) . "\n" .
( !$wgMiserMode ? ($this->getTitlePattern( $pattern )."\n") : "" ) .
- "<p>" . $this->getDateMenu( $year, $month ) . "\n" .
- Xml::tags( 'p', null, implode( ' ', ChangeTags::buildTagFilterSelector( $tagFilter ) ) ) . "\n" .
- ( $filter ? "</p><p>".$this->getFilterLinks( $type, $filter )."\n" : "" ) . "\n" .
+ "<p>" . Xml::dateMenu( $year, $month ) . "\n" .
+ ( $tagSelector ? Xml::tags( 'p', null, implode( ' ', $tagSelector ) ) :'' ). "\n" .
+ ( $filter ? "</p><p>".$this->getFilterLinks( $filter )."\n" : "" ) . "\n" .
Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "</p>\n" .
"</fieldset></form>"
);
}
- private function getFilterLinks( $logType, $filter ) {
- global $wgTitle;
+ /**
+ * @param $filter Array
+ * @return String: Formatted HTML
+ */
+ private function getFilterLinks( $filter ) {
+ global $wgTitle, $wgLang;
// show/hide links
$messages = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' ) );
// Option value -> message mapping
$links = array();
+ $hiddens = ''; // keep track for "go" button
foreach( $filter as $type => $val ) {
$hideVal = 1 - intval($val);
$link = $this->skin->makeKnownLinkObj( $wgTitle, $messages[$hideVal],
wfArrayToCGI( array( "hide_{$type}_log" => $hideVal ), $this->getDefaultQuery() )
);
$links[$type] = wfMsgHtml( "log-show-hide-{$type}", $link );
+ $hiddens .= Xml::hidden( "hide_{$type}_log", $val ) . "\n";
}
// Build links
- return implode( ' | ', $links );
+ return '<small>'.$wgLang->pipeList( $links ) . '</small>' . $hiddens;
}
private function getDefaultQuery() {
}
/**
- * @param $queryType String
+ * @param $queryTypes Array
* @return String: Formatted HTML
*/
- private function getTypeMenu( $queryType ) {
+ private function getTypeMenu( $queryTypes ) {
global $wgLogRestrictions, $wgUser;
$html = "<select name='type'>\n";
// Second pass to sort by name
ksort($typesByName);
+ // Note the query type
+ $queryType = count($queryTypes) == 1 ? $queryTypes[0] : '';
// Third pass generates sorted XHTML content
foreach( $typesByName as $text => $type ) {
$selected = ($type == $queryType);
* @return String: Formatted HTML
*/
private function getUserInput( $user ) {
- return Xml::inputLabel( wfMsg( 'specialloguserlabel' ), 'user', 'user', 15, $user );
+ return Xml::inputLabel( wfMsg( 'specialloguserlabel' ), 'user', 'mw-log-user', 15, $user );
}
/**
* @return String: Formatted HTML
*/
private function getTitleInput( $title ) {
- return Xml::inputLabel( wfMsg( 'speciallogtitlelabel' ), 'page', 'page', 20, $title );
- }
-
- /**
- * @param $year Integer
- * @param $month Integer
- * @return string Formatted HTML
- */
- 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 Xml::inputLabel( wfMsg( 'speciallogtitlelabel' ), 'page', 'mw-log-page', 20, $title );
}
/**
$paramArray = LogPage::extractParams( $row->log_params );
$revert = $del = '';
// Some user can hide log items and have review links
- if( $wgUser->isAllowed( 'deleterevision' ) ) {
+ if( !($this->flags & self::NO_ACTION_LINK) && $wgUser->isAllowed( 'deleterevision' ) ) {
$del = $this->getShowHideLinks( $row ) . ' ';
}
// Add review links and such...
'&wpMovetalk=0' ) . ')';
}
// Show undelete link
- } else if( self::typeAction($row,array('delete','suppress'),'delete','delete') ) {
+ } else if( self::typeAction($row,array('delete','suppress'),'delete','deletedhistory') ) {
+ if( !$wgUser->isAllowed( 'undelete' ) )
+ $viewdeleted = $this->message['undeleteviewlink'];
+ else
+ $viewdeleted = $this->message['undeletelink'];
$revert = '(' . $this->skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Undelete' ),
- $this->message['undeletelink'], 'target='. urlencode( $title->getPrefixedDBkey() ) ) . ')';
+ $viewdeleted, 'target='. urlencode( $title->getPrefixedDBkey() ) ) . ')';
// Show unblock/change block link
} else if( self::typeAction($row,array('block','suppress'),array('block','reblock'),'block') ) {
$revert = '(' .
array(),
array( 'action' => 'unblock', 'ip' => $row->log_title ),
'known' )
- . ' ' . $this->message['pipe-separator'] . ' ' .
+ . $this->message['pipe-separator'] .
$this->skin->link( SpecialPage::getTitleFor( 'Blockip', $row->log_title ),
$this->message['change-blocklink'],
array(), array(), 'known' ) .
array(),
array( 'action' => 'history', 'offset' => $row->log_timestamp ) );
if( $wgUser->isAllowed( 'protect' ) ) {
- $revert .= ' ' . $this->message['pipe-separator'] . ' ' .
+ $revert .= $this->message['pipe-separator'] .
$this->skin->link( $title,
$this->message['protect_change'],
array(),
'mergepoint' => $paramArray[1] ) ) ) . ')';
// If an edit was hidden from a page give a review link to the history
} else if( self::typeAction($row,array('delete','suppress'),'revision','deleterevision') ) {
- if( count($paramArray) == 2 ) {
+ 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
+ // $paramArray[1] is a CSV of the IDs
$Ids = explode( ',', $paramArray[1] );
- $revParams = '';
- foreach( $Ids as $n => $id ) {
- $revParams .= '&' . urlencode($key) . '[]=' . urlencode($id);
+ $query = urlencode($paramArray[1]);
+ $revert = array();
+ // Diff link for single rev deletions
+ if( ( $key === 'oldid' || $key == 'revision' ) && count($Ids) == 1 ) {
+ $revert[] = $this->skin->makeKnownLinkObj( $title, $this->message['diff'],
+ 'diff='.intval($Ids[0])."&unhide=1" );
}
- $revert = '(' . $this->skin->makeKnownLinkObj( $revdel, $this->message['revdel-restore'],
- 'target=' . $title->getPrefixedUrl() . $revParams ) . ')';
+ // View/modify link...
+ $revert[] = $this->skin->makeKnownLinkObj( $revdel, $this->message['revdel-restore'],
+ 'target='.$title->getPrefixedUrl()."&type=$key&ids=$query" );
+ // Pipe links
+ $revert = '(' . implode(' | ',$revert) . ')';
}
// Hidden log items, give review link
} else if( self::typeAction($row,array('delete','suppress'),'event','deleterevision') ) {
- if( count($paramArray) == 1 ) {
+ if( count($paramArray) >= 1 ) {
$revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
+ // $paramArray[1] is a CSV of the IDs
$Ids = explode( ',', $paramArray[0] );
+ $query = urlencode($paramArray[0]);
// Link to each hidden object ID, $paramArray[1] is the url param
- $logParams = '';
- foreach( $Ids as $n => $id ) {
- $logParams .= '&logid[]=' . intval($id);
- }
$revert = '(' . $this->skin->makeKnownLinkObj( $revdel, $this->message['revdel-restore'],
- 'target=' . $title->getPrefixedUrl() . $logParams ) . ')';
+ 'target='.$title->getPrefixedUrl()."&type=logging&ids=$query" ) . ')';
}
// Self-created users
} else if( self::typeAction($row,'newusers','create2') ) {
$revert = '<span class="mw-logevent-actionlink">' . $revert . '</span>';
}
+ $time = htmlspecialchars( $time );
+
return Xml::tags( 'li', array( "class" => implode( ' ', $classes ) ),
$del . $time . ' ' . $userLink . ' ' . $action . ' ' . $comment . ' ' . $revert . " $tagDisplay" ) . "\n";
}
* @return string
*/
private function getShowHideLinks( $row ) {
- $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
// If event was hidden from sysops
if( !self::userCan( $row, LogPage::DELETED_RESTRICTED ) ) {
- $del = Xml::tags( 'span', array( 'class'=>'mw-revdelundel-link' ), '('.$this->message['rev-delundel'].')' );
+ $del = Xml::tags( 'span', array( 'class'=>'mw-revdelundel-link' ),
+ '('.$this->message['rev-delundel'].')' );
} else if( $row->log_type == 'suppress' ) {
- // No one should be hiding from the oversight log
- $del = Xml::tags( 'span', array( 'class'=>'mw-revdelundel-link' ), '('.$this->message['rev-delundel'].')' );
+ $del = ''; // No one should be hiding from the oversight log
} else {
$target = SpecialPage::getTitleFor( 'Log', $row->log_type );
- $query = array( 'target' => $target->getPrefixedUrl(),
- 'logid' => $row->log_id
+ $page = Title::makeTitle( $row->log_namespace, $row->log_title );
+ $query = array(
+ 'target' => $target->getPrefixedDBkey(),
+ 'type' => 'logging',
+ 'ids' => $row->log_id,
);
- $del = $this->skin->revDeleteLink( $query, self::isDeleted( $row, LogPage::DELETED_RESTRICTED ) );
+ $del = $this->skin->revDeleteLink( $query,
+ self::isDeleted( $row, LogPage::DELETED_RESTRICTED ) );
}
return $del;
}
* @return bool
*/
public static function typeAction( $row, $type, $action, $right='' ) {
- $match = is_array($type) ? in_array($row->log_type,$type) : $row->log_type == $type;
+ $match = is_array($type) ?
+ in_array($row->log_type,$type) : $row->log_type == $type;
if( $match ) {
$match = is_array($action) ?
in_array($row->log_action,$action) : $row->log_action == $action;
/**
* Quick function to show a short log extract
* @param $out OutputPage
- * @param $type String
+ * @param $types String or Array
* @param $page String
* @param $user String
* @param $lim Integer
* @param $conds Array
*/
- public static function showLogExtract( $out, $type='', $page='', $user='', $lim=0, $conds=array() ) {
+ public static function showLogExtract( $out, $types=array(), $page='', $user='', $lim=0, $conds=array() ) {
global $wgUser;
# Insert list of top 50 or so items
$loglist = new LogEventsList( $wgUser->getSkin(), $out, 0 );
- $pager = new LogPager( $loglist, $type, $user, $page, '', $conds );
+ $pager = new LogPager( $loglist, $types, $user, $page, '', $conds );
if( $lim > 0 ) $pager->mLimit = $lim;
$logBody = $pager->getBody();
if( $logBody ) {
/**
* SQL clause to skip forbidden log types for this user
* @param $db Database
+ * @param $audience string, public/user
* @return mixed (string or false)
*/
- public static function getExcludeClause( $db ) {
+ public static function getExcludeClause( $db, $audience = 'public' ) {
global $wgLogRestrictions, $wgUser;
// Reset the array, clears extra "where" clauses when $par is used
$hiddenLogs = array();
// Don't show private logs to unprivileged users
foreach( $wgLogRestrictions as $logType => $right ) {
- if( !$wgUser->isAllowed($right) ) {
+ if( $audience == 'public' || !$wgUser->isAllowed($right) ) {
$safeType = $db->strencode( $logType );
$hiddenLogs[] = $safeType;
}
* @ingroup Pager
*/
class LogPager extends ReverseChronologicalPager {
- private $type = '', $user = '', $title = '', $pattern = '';
+ private $types = array(), $user = '', $title = '', $pattern = '';
+ private $typeCGI = '';
public $mLogEventsList;
/**
* constructor
* @param $list LogEventsList
- * @param $type String
+ * @param $types String or Array
* @param $user String
* @param $title String
* @param $pattern String
* @param $year Integer
* @param $month Integer
*/
- public function __construct( $list, $type = '', $user = '', $title = '', $pattern = '',
+ public function __construct( $list, $types = array(), $user = '', $title = '', $pattern = '',
$conds = array(), $year = false, $month = false, $tagFilter = '' )
{
parent::__construct();
$this->mLogEventsList = $list;
- $this->limitType( $type );
+ $this->limitType( $types ); // also excludes hidden types
$this->limitUser( $user );
$this->limitTitle( $title, $pattern );
$this->getDateCond( $year, $month );
public function getDefaultQuery() {
$query = parent::getDefaultQuery();
- $query['type'] = $this->type;
+ $query['type'] = $this->typeCGI; // arrays won't work here
$query['user'] = $this->user;
$query['month'] = $this->mMonth;
$query['year'] = $this->mYear;
return $query;
}
+ // Call ONLY after calling $this->limitType() already!
public function getFilterParams() {
global $wgFilterLogTypes, $wgUser, $wgRequest;
$filters = array();
- if( $this->type ) {
+ if( count($this->types) ) {
return $filters;
}
foreach( $wgFilterLogTypes as $type => $default ) {
/**
* Set the log reader to return only entries of the given type.
* Type restrictions enforced here
- * @param $type String: A log type ('upload', 'delete', etc)
+ * @param $types String or array: Log types ('upload', 'delete', etc);
+ * empty string means no restriction
*/
- private function limitType( $type ) {
+ private function limitType( $types ) {
global $wgLogRestrictions, $wgUser;
+ // If $types is not an array, make it an array
+ $types = ($types === '') ? array() : (array)$types;
// Don't even show header for private logs; don't recognize it...
- if( isset($wgLogRestrictions[$type]) && !$wgUser->isAllowed($wgLogRestrictions[$type]) ) {
- $type = '';
+ foreach ( $types as $type ) {
+ if( isset( $wgLogRestrictions[$type] ) && !$wgUser->isAllowed($wgLogRestrictions[$type]) ) {
+ $types = array_diff( $types, array( $type ) );
+ }
}
- // Don't show private logs to unpriviledged users
- $hideLogs = LogEventsList::getExcludeClause( $this->mDb );
+ // Don't show private logs to unprivileged users.
+ // Also, only show them upon specific request to avoid suprises.
+ $audience = $types ? 'user' : 'public';
+ $hideLogs = LogEventsList::getExcludeClause( $this->mDb, $audience );
if( $hideLogs !== false ) {
$this->mConds[] = $hideLogs;
}
- if( !$type ) {
- return false;
+ if( count($types) ) {
+ $this->types = $types;
+ $this->mConds['log_type'] = $types;
+ // Set typeCGI; used in url param for paging
+ if( count($types) == 1 ) $this->typeCGI = $types[0];
}
- $this->type = $type;
- $this->mConds['log_type'] = $type;
}
/**
but for now it won't pass anywhere behind the optimizer */
$this->mConds[] = "NULL";
} else {
+ global $wgUser;
$this->mConds['log_user'] = $userid;
+ // Paranoia: avoid brute force searches (bug 17342)
+ if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
+ $this->mConds[] = 'log_deleted & ' . LogPage::DELETED_USER . ' = 0';
+ }
$this->user = $usertitle->getText();
}
}
* @param $pattern String
*/
private function limitTitle( $page, $pattern ) {
- global $wgMiserMode;
+ global $wgMiserMode, $wgUser;
$title = Title::newFromText( $page );
if( strlen($page) == 0 || !$title instanceof Title )
$this->mConds['log_namespace'] = $ns;
$this->mConds['log_title'] = $title->getDBkey();
}
+ // Paranoia: avoid brute force searches (bug 17342)
+ if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
+ $this->mConds[] = 'log_deleted & ' . LogPage::DELETED_ACTION . ' = 0';
+ }
}
public function getQueryInfo() {
+ $tables = array( 'logging', 'user' );
$this->mConds[] = 'user_id = log_user';
+ $groupBy = false;
+ # Add log_search table if there are conditions on it
+ if( array_key_exists('ls_field',$this->mConds) ) {
+ $tables[] = 'log_search';
+ $index = array( 'log_search' => 'PRIMARY', 'logging' => 'PRIMARY' );
+ $groupBy = 'ls_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') ) );
- } else if( $this->type ) {
- $index = array( 'USE INDEX' => array( 'logging' => 'type_time' ) );
+ } else if( $this->title || $this->pattern || $this->user ) {
+ $index = array( 'logging' => array('page_time','user_time') );
+ } else if( $this->types ) {
+ $index = array( 'logging' => 'type_time' );
} else {
- $index = array( 'USE INDEX' => array( 'logging' => 'times' ) );
+ $index = array( 'logging' => 'times' );
}
+ $options = array( 'USE INDEX' => $index );
+ # Don't show duplicate rows when using log_search
+ if( $groupBy ) $options['GROUP BY'] = $groupBy;
$info = 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', 'user_editcount' ),
- 'conds' => $this->mConds,
- 'options' => $index,
- 'join_conds' => array( 'user' => array( 'INNER JOIN', 'user_id=log_user' ) ),
+ 'tables' => $tables,
+ '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' => $options,
+ 'join_conds' => array(
+ 'user' => array( 'INNER JOIN', 'user_id=log_user' ),
+ 'log_search' => array( 'INNER JOIN', 'ls_log_id=log_id' )
+ )
);
-
- ChangeTags::modifyDisplayQuery( $info['tables'], $info['fields'], $info['conds'], $info['join_conds'], $this->mTagFilter );
+ # Add ChangeTags filter query
+ ChangeTags::modifyDisplayQuery( $info['tables'], $info['fields'], $info['conds'],
+ $info['join_conds'], $info['options'], $this->mTagFilter );
return $info;
}
}
public function getType() {
- return $this->type;
+ return $this->types;
}
public function getUser() {
public function getTagFilter() {
return $this->mTagFilter;
}
+
+ public function doQuery() {
+ // Workaround MySQL optimizer bug
+ $this->mDb->setBigSelects();
+ parent::doQuery();
+ $this->mDb->setBigSelects( 'default' );
+ }
}
/**
* LogEventsList::NO_ACTION_LINK Don't show restore/unblock/block links
*/
function __construct( &$reader, $flags = 0 ) {
- global $wgUser;
wfDeprecated(__METHOD__);
$this->reader =& $reader;
$this->reader->pager->mLogEventsList->flags = $flags;