Made suppress link bold
[lhc/web/wiklou.git] / includes / LogEventsList.php
index d2dc81b..37b5daf 100644 (file)
@@ -39,7 +39,8 @@ class LogEventsList {
                // 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', 'revdel-restore', 'rev-delundel', 'hist', 'diff',
+                               'pipe-separator' );
                        foreach( $messages as $msg ) {
                                $this->message[$msg] = wfMsgExt( $msg, array( 'escapenoentities' ) );
                        }
@@ -65,10 +66,11 @@ class LogEventsList {
         * @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='' ) 
+               $month = '', $filter = null, $tagFilter='' ) 
        {
                global $wgScript, $wgMiserMode;
                $action = htmlspecialchars( $wgScript );
@@ -84,7 +86,7 @@ class LogEventsList {
                        $this->getUserInput( $user ) . "\n" .
                        $this->getTitleInput( $page ) . "\n" .
                        ( !$wgMiserMode ? ($this->getTitlePattern( $pattern )."\n") : "" ) .
-                       "<p>" . $this->getDateMenu( $year, $month ) . "\n" .
+                       "<p>" . Xml::dateMenu( $year, $month ) . "\n" .
                        ( $tagSelector ? Xml::tags( 'p', null, implode( '&nbsp;', $tagSelector ) ) :'' ). "\n" .
                        ( $filter ? "</p><p>".$this->getFilterLinks( $type, $filter )."\n" : "" ) . "\n" .
                        Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "</p>\n" .
@@ -93,20 +95,22 @@ class LogEventsList {
        }
        
        private function getFilterLinks( $logType, $filter ) {
-               global $wgTitle;
+               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() {
@@ -166,7 +170,7 @@ class LogEventsList {
         * @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 );
        }
 
        /**
@@ -174,38 +178,7 @@ class LogEventsList {
         * @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 );
        }
 
        /**
@@ -252,7 +225,7 @@ class LogEventsList {
                $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...
@@ -313,27 +286,32 @@ class LogEventsList {
                                $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 CVS 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' && count($Ids) == 1 ) {
+                                       $token = urlencode( $wgUser->editToken( intval($Ids[0]) ) );
+                                       $revert[] = $this->skin->makeKnownLinkObj( $title, $this->message['diff'], 
+                                               'diff='.intval($Ids[0])."&unhide=1&token=$token" );
                                }
-                               $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()."&$key=$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 ) {
                                $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
+                               // $paramArray[1] is a CVS 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()."&logid=$query" ) . ')';
                        }
                // Self-created users
                } else if( self::typeAction($row,'newusers','create2') ) {
@@ -381,16 +359,17 @@ class LogEventsList {
                $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 );
+                       $page = Title::makeTitle( $row->log_namespace, $row->log_title );
                        $query = array( 'target' => $target->getPrefixedDBkey(),
-                               'logid' => $row->log_id
-                       );
-                       $del = $this->skin->revDeleteLink( $query, self::isDeleted( $row, LogPage::DELETED_RESTRICTED ) );
+                               'logid' => $row->log_id, 'page' => $page->getPrefixedDBkey() );
+                       $del = $this->skin->revDeleteLink( $query,
+                               self::isDeleted( $row, LogPage::DELETED_RESTRICTED ) );
                }
                return $del;
        }
@@ -403,7 +382,8 @@ class LogEventsList {
         * @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;
@@ -475,15 +455,16 @@ class LogEventsList {
        /**
         * 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;
                        }
@@ -523,7 +504,7 @@ class LogPager extends ReverseChronologicalPager {
 
                $this->mLogEventsList = $list;
 
-               $this->limitType( $type );
+               $this->limitType( $type ); // also excludes hidden types
                $this->limitUser( $user );
                $this->limitTitle( $title, $pattern );
                $this->getDateCond( $year, $month );
@@ -568,16 +549,17 @@ class LogPager extends ReverseChronologicalPager {
                if( isset($wgLogRestrictions[$type]) && !$wgUser->isAllowed($wgLogRestrictions[$type]) ) {
                        $type = '';
                }
-               // Don't show private logs to unpriviledged users
-               $hideLogs = LogEventsList::getExcludeClause( $this->mDb );
+               // Don't show private logs to unpriviledged users.
+               // Also, only show them upon specific request to avoid suprises.
+               $audience = $type ? 'user' : 'public';
+               $hideLogs = LogEventsList::getExcludeClause( $this->mDb, $audience );
                if( $hideLogs !== false ) {
                        $this->mConds[] = $hideLogs;
                }
-               if( !$type ) {
-                       return false;
+               if( $type ) {
+                       $this->type = $type;
+                       $this->mConds['log_type'] = $type;
                }
-               $this->type = $type;
-               $this->mConds['log_type'] = $type;
        }
 
        /**
@@ -599,9 +581,12 @@ class LogPager extends ReverseChronologicalPager {
                           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)
-                       $this->mConds[] = 'log_deleted & ' . LogPage::DELETED_USER . ' = 0';
+                       if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
+                               $this->mConds[] = 'log_deleted & ' . LogPage::DELETED_USER . ' = 0';
+                       }
                        $this->user = $usertitle->getText();
                }
        }
@@ -613,7 +598,7 @@ class LogPager extends ReverseChronologicalPager {
         * @param $pattern String
         */
        private function limitTitle( $page, $pattern ) {
-               global $wgMiserMode;
+               global $wgMiserMode, $wgUser;
 
                $title = Title::newFromText( $page );
                if( strlen($page) == 0 || !$title instanceof Title )
@@ -643,7 +628,9 @@ class LogPager extends ReverseChronologicalPager {
                        $this->mConds['log_title'] = $title->getDBkey();
                }
                // Paranoia: avoid brute force searches (bug 17342)
-               $this->mConds[] = 'log_deleted & ' . LogPage::DELETED_ACTION . ' = 0';
+               if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
+                       $this->mConds[] = 'log_deleted & ' . LogPage::DELETED_ACTION . ' = 0';
+               }
        }
 
        public function getQueryInfo() {
@@ -665,7 +652,8 @@ class LogPager extends ReverseChronologicalPager {
                        'join_conds' => array( 'user' => array( 'INNER JOIN', 'user_id=log_user' ) ),
                );
 
-               ChangeTags::modifyDisplayQuery( $info['tables'], $info['fields'], $info['conds'], $info['join_conds'], $this->mTagFilter );
+               ChangeTags::modifyDisplayQuery( $info['tables'], $info['fields'], $info['conds'],
+                       $info['join_conds'], $info['options'], $this->mTagFilter );
 
                return $info;
        }