From: Aaron Schulz Date: Wed, 2 Apr 2008 07:10:41 +0000 (+0000) Subject: Add getExcludeClause(), hide items from API too X-Git-Tag: 1.31.0-rc.0~48680 X-Git-Url: https://git.cyclocoop.org/%27.%24link.%27?a=commitdiff_plain;h=5e24e3b85c924cb4717810996ad485210b9aeb7b;p=lhc%2Fweb%2Fwiklou.git Add getExcludeClause(), hide items from API too --- diff --git a/includes/LogEventList.php b/includes/LogEventList.php index 1daa5301b1..467bc2a38f 100644 --- a/includes/LogEventList.php +++ b/includes/LogEventList.php @@ -133,6 +133,14 @@ class LogEventList { return Xml::checkLabel( wfMsg( 'log-title-wildcard' ), 'pattern', 'pattern', $pattern ); } + public function beginLogEventList() { + return "\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 "
  • $del$time $userLink $action $comment $revert
  • "; + return "
  • $del$time $userLink $action $comment $revert
  • \n"; } /** @@ -277,6 +285,28 @@ class LogEventList { } return "($del)"; } + + /** + * 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; + } } diff --git a/includes/SpecialLog.php b/includes/SpecialLog.php index 338aae09e7..bb9e2de111 100644 --- a/includes/SpecialLog.php +++ b/includes/SpecialLog.php @@ -43,9 +43,9 @@ function wfSpecialLog( $par = '' ) { # Insert list $wgOut->addHTML( $pager->getNavigationBar() . - '' . "\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; } diff --git a/includes/api/ApiQueryLogEvents.php b/includes/api/ApiQueryLogEvents.php index 1290c6cb4f..164a2ff5bd 100644 --- a/includes/api/ApiQueryLogEvents.php +++ b/includes/api/ApiQueryLogEvents.php @@ -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 " .