Add getExcludeClause(), hide items from API too
authorAaron Schulz <aaron@users.mediawiki.org>
Wed, 2 Apr 2008 07:10:41 +0000 (07:10 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Wed, 2 Apr 2008 07:10:41 +0000 (07:10 +0000)
includes/LogEventList.php
includes/SpecialLog.php
includes/api/ApiQueryLogEvents.php

index 1daa530..467bc2a 100644 (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;
+       }
 }
 
 
index 338aae0..bb9e2de 100644 (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;
                }
index 1290c6c..164a2ff 100644 (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 " .