Add getExcludeClause(), hide items from API too

This commit is contained in:
Aaron Schulz 2008-04-02 07:10:41 +00:00
parent 2b3501dc5e
commit 5e24e3b85c
3 changed files with 40 additions and 20 deletions

View file

@ -133,6 +133,14 @@ class LogEventList {
return Xml::checkLabel( wfMsg( 'log-title-wildcard' ), 'pattern', 'pattern', $pattern );
}
public function beginLogEventList() {
return "<ul>\n";
}
public function endLogEventList() {
return "</ul>\n";
}
/**
* @param Row $row a single row from the result set
* @return string Formatted HTML list item
@ -250,7 +258,7 @@ class LogEventList {
$action = LogPage::actionText( $row->log_type, $row->log_action, $title, $this->skin, $paramArray, true );
}
return "<li>$del$time $userLink $action $comment $revert</li>";
return "<li>$del$time $userLink $action $comment $revert</li>\n";
}
/**
@ -277,6 +285,28 @@ class LogEventList {
}
return "<tt>(<small>$del</small>)</tt>";
}
/**
* SQL clause to skip forbidden log types for this user
* @param Database $db
* @returns mixed (string or false)
*/
public static function getExcludeClause( $db ) {
global $wgLogRestrictions, $wgUser;
// Reset the array, clears extra "where" clauses when $par is used
$hiddenLogs = array();
// Don't show private logs to unpriviledged users
foreach( $wgLogRestrictions as $logtype => $right ) {
if( !$wgUser->isAllowed($right) ) {
$safetype = $db->strencode( $logtype );
$hiddenLogs[] = "'$safetype'";
}
}
if( !empty($hiddenLogs) ) {
return 'log_type NOT IN(' . implode(',',$hiddenLogs) . ')';
}
return false;
}
}

View file

@ -43,9 +43,9 @@ function wfSpecialLog( $par = '' ) {
# Insert list
$wgOut->addHTML(
$pager->getNavigationBar() .
'<ul id="logevents">' . "\n" .
$loglist->beginLogEventList() .
$pager->getBody() .
'</ul>' . "\n" .
$loglist->endLogEventList() .
$pager->getNavigationBar()
);
}
@ -82,25 +82,11 @@ class LogPager extends ReverseChronologicalPager {
* @private
*/
private function limitType( $type ) {
global $wgLogRestrictions, $wgUser;
// Reset the array, clears extra "where" clauses when $par is used
$hiddenLogs = array();
// Nothing to show the user requested a log they can't see
if( isset($wgLogRestrictions[$type]) && !$wgUser->isAllowed($wgLogRestrictions[$type]) ) {
$this->mConds[] = "NULL";
return false;
}
// Don't show private logs to unpriviledged users
foreach( $wgLogRestrictions as $logtype => $right ) {
if( !$wgUser->isAllowed($right) || empty($type) ) {
$safetype = $this->mDb->strencode( $logtype );
$hiddenLogs[] = "'$safetype'";
}
$hideLogs = LogEventList::getExcludeClause( $this->mDb );
if( $hideLogs !== false ) {
$this->mConds[] = $hideLogs;
}
if( !empty($hiddenLogs) ) {
$this->mConds[] = 'log_type NOT IN('.implode(',',$hiddenLogs).')';
}
if( empty($type) ) {
return false;
}

View file

@ -54,6 +54,10 @@ class ApiQueryLogEvents extends ApiQueryBase {
list($tbl_logging, $tbl_page, $tbl_user) = $db->tableNamesN('logging', 'page', 'user');
$hideLogs = LogEventList::getExcludeClause($db);
if($hideLogs !== false)
$this->addWhere($hideLogs);
$this->addOption('STRAIGHT_JOIN');
$this->addTables("$tbl_logging LEFT OUTER JOIN $tbl_page ON " .
"log_namespace=page_namespace AND log_title=page_title " .