From 666a5526948e91f77e8d5cedeb3f46258b415c8d Mon Sep 17 00:00:00 2001 From: Tobias Date: Sun, 13 Sep 2009 22:21:11 +0000 Subject: [PATCH] Follow-up on r56251 - merging showLogs and showLogExtract --- includes/Article.php | 5 ++- includes/EditPage.php | 3 +- includes/LogEventsList.php | 39 ++++++++++++++--- includes/OutputPage.php | 51 ---------------------- includes/specials/SpecialContributions.php | 4 +- 5 files changed, 41 insertions(+), 61 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 175b540676..5999ea4cdd 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -1211,12 +1211,13 @@ class Article { # Show rename log because user does not exist. $parent = $this->mTitle->getNsText() . ":" . $this->mTitle->getBaseText(); - $wgOut->showLogs( $parent, '', array( 'renameuser' ), 'renamed-notice' ); + LogEventsList::showLogExtract( $wgOut, 'renameuser', $parent, '', 10, array(), false, 'renamed-notice' ); } } # Show delete and move logs - $wgOut->showLogs( $this->mTitle->getPrefixedText(), '', array( 'delete', 'move' ), 'moveddeleted-notice' ); + LogEventsList::showLogExtract( $wgOut, array( 'delete', 'move' ), + $this->mTitle->getPrefixedText(), '', 10, array( "log_action != 'revision'" ), false, 'moveddeleted-notice'); # Show error message $oldid = $this->getOldID(); diff --git a/includes/EditPage.php b/includes/EditPage.php index 1daf606c80..ed0966aafa 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -730,7 +730,8 @@ class EditPage { } # Give a notice if the user is editing a deleted/moved page... if ( !$this->mTitle->exists() ) { - $wgOut->showLogs( $this->mTitle->getPrefixedText(), '', array( 'delete', 'move' ), 'recreate-moveddeleted-warn' ); + LogEventsList::showLogExtract( $wgOut, array( 'delete', 'move' ), + $this->mTitle->getPrefixedText(), '', 10, array( "log_action != 'revision'" ), false, 'recreate-moveddeleted-warn'); } } diff --git a/includes/LogEventsList.php b/includes/LogEventsList.php index d6178abc5a..dfe6fa6aea 100644 --- a/includes/LogEventsList.php +++ b/includes/LogEventsList.php @@ -556,15 +556,19 @@ class LogEventsList { } /** - * Quick function to show a short log extract + * Show log extract. Either with text and a box (set $msgKey) or without (don't set $msgKey) * @param $out OutputPage or String-by-reference * @param $types String or Array * @param $page String * @param $user String - * @param $lim Integer + * @param $lim Integer Limit of items to show, default is 50 * @param $conds Array + * @param $showIfEmpty boolean Set to false if you don't want any output in case the loglist is empty + * if set to true (default), "No matching items in log" is displayed if loglist is empty + * @param $msgKey String if you want a nice box with a message, set this to the key of the message + * @return Integer Number of total log items (not limited by $lim) */ - public static function showLogExtract( &$out, $types=array(), $page='', $user='', $lim=0, $conds=array() ) { + public static function showLogExtract( &$out, $types=array(), $page='', $user='', $lim=0, $conds=array(), $showIfEmpty = true, $msgKey = '' ) { global $wgUser, $wgOut; # Insert list of top 50 or so items $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut, 0 ); @@ -572,12 +576,37 @@ class LogEventsList { if( $lim > 0 ) $pager->mLimit = $lim; $logBody = $pager->getBody(); if( $logBody ) { - $s = $loglist->beginLogEventsList() . + if ( $msgKey ) + $s = '
' . wfMsg( $msgKey ) ; + $s .= $loglist->beginLogEventsList() . $logBody . $loglist->endLogEventsList(); } else { - $s = wfMsgExt( 'logempty', array('parse') ); + if ( $showIfEmpty ) + $s = wfMsgExt( 'logempty', array('parse') ); + } + if( $pager->getNumRows() > $pager->mLimit ) { # Show "Full log" link + $urlParam = array(); + if ( $page != '') + $urlParam['page'] = $page; + if ( $user != '') + $urlParam['user'] = $user; + if ( !is_array( $types ) ) # Make it an array, if it isn't + $types = array( $types ); + # If there is exactly one log type, we can link to Special:Log?type=foo + if ( count( $types ) == 1 ) + $urlParam['type'] = $types[0]; + $s .= $wgUser->getSkin()->link( + SpecialPage::getTitleFor( 'Log' ), + wfMsgHtml( 'log-fulllog' ), + array(), + $urlParam + ); + } + if ( $logBody && $msgKey ) + $s .= '
'; + if( $out instanceof OutputPage ){ $out->addHTML( $s ); } else { diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 2a54ddac5c..3843787c8b 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -2115,55 +2115,4 @@ class OutputPage { } $this->addHTML( $this->parse( $s, /*linestart*/true, /*uilang*/true ) ); } - /* - * Show log excerpt. All parameters are optional - * (but it makes sense to define at least $page OR $user) - * @param String $page Page title for filtering the log - * @param String $user Username for filtering the log - * @param String $logtypes Log types, like delete, move, etc. - * May be a single log type or an array of log types - * @param int $numEntries Number of log entries to show at maximum (default: 10) - * If there are too many entries, a "View full log" link is displayed - * @return boolean Returns true if there was something in the log - */ - public function showLogs( $page = '', $user = '', $logtypes = array(), $msgKey = '' , $numEntries = 10 ) { - global $wgUser, $wgOut; - $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut ); - $pager = new LogPager( $loglist, $logtypes, $user, $page); - if( $pager->getNumRows() > 0 ) { - $pager->mLimit = $numEntries; - $wgOut->addHTML( '
' ); - if ( $msgKey ) - $wgOut->addWikiMsg( $msgKey ); - $wgOut->addHTML( - $loglist->beginLogEventsList() . - $pager->getBody() . - $loglist->endLogEventsList() - ); - if( $pager->getNumRows() > $numEntries ) { # Show "Full log" link - $urlParam = array(); - if ( $page != '') - $urlParam['page'] = $page; - if ( $user != '') - $urlParam['user'] = $user; - if ( !is_array( $logtypes ) ) # Make it an array, if it isn't - $logtypes = array( $logtypes ); - # If there is exactly one log type, we can link to Special:Log/type - if ( count( $logtypes ) == 1 ) - $urlParam['type'] = $logtypes[0]; - $wgOut->addHTML( $wgUser->getSkin()->link( - SpecialPage::getTitleFor( 'Log' ), - wfMsgHtml( 'log-fulllog' ), - array(), - $urlParam - ) ); - - } - $wgOut->addHTML( '
' ); - return true; - } - return false; - } - - } diff --git a/includes/specials/SpecialContributions.php b/includes/specials/SpecialContributions.php index daf7413226..f918131590 100644 --- a/includes/specials/SpecialContributions.php +++ b/includes/specials/SpecialContributions.php @@ -226,8 +226,8 @@ class SpecialContributions extends SpecialPage { // Show a note if the user is blocked and display the last block log entry. if ( User::newFromID( $id )->isBlocked() ) - $wgOut->showLogs( $nt->getPrefixedText(), '', array( 'block' ), - 'sp-contributions-blocked-notice', 1 ); + LogEventsList::showLogExtract( $wgOut, 'block', $nt->getPrefixedText(), '', 1, + array(), false, 'sp-contributions-blocked-notice' ); } // Old message 'contribsub' had one parameter, but that doesn't work for -- 2.20.1