r56284 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56283‎ | r56284 | r56285 >
Date:22:21, 13 September 2009
Author:churchofemacs
Status:resolved (Comments)
Tags:
Comment:
Follow-up on r56251 - merging showLogs and showLogExtract
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/EditPage.php (modified) (history)
  • /trunk/phase3/includes/LogEventsList.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialContributions.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/OutputPage.php
@@ -2115,55 +2115,4 @@
21162116 }
21172117 $this->addHTML( $this->parse( $s, /*linestart*/true, /*uilang*/true ) );
21182118 }
2119 - /*
2120 - * Show log excerpt. All parameters are optional
2121 - * (but it makes sense to define at least $page OR $user)
2122 - * @param String $page Page title for filtering the log
2123 - * @param String $user Username for filtering the log
2124 - * @param String $logtypes Log types, like delete, move, etc.
2125 - * May be a single log type or an array of log types
2126 - * @param int $numEntries Number of log entries to show at maximum (default: 10)
2127 - * If there are too many entries, a "View full log" link is displayed
2128 - * @return boolean Returns true if there was something in the log
2129 - */
2130 - public function showLogs( $page = '', $user = '', $logtypes = array(), $msgKey = '' , $numEntries = 10 ) {
2131 - global $wgUser, $wgOut;
2132 - $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut );
2133 - $pager = new LogPager( $loglist, $logtypes, $user, $page);
2134 - if( $pager->getNumRows() > 0 ) {
2135 - $pager->mLimit = $numEntries;
2136 - $wgOut->addHTML( '<div class="mw-warning-with-logexcerpt">' );
2137 - if ( $msgKey )
2138 - $wgOut->addWikiMsg( $msgKey );
2139 - $wgOut->addHTML(
2140 - $loglist->beginLogEventsList() .
2141 - $pager->getBody() .
2142 - $loglist->endLogEventsList()
2143 - );
2144 - if( $pager->getNumRows() > $numEntries ) { # Show "Full log" link
2145 - $urlParam = array();
2146 - if ( $page != '')
2147 - $urlParam['page'] = $page;
2148 - if ( $user != '')
2149 - $urlParam['user'] = $user;
2150 - if ( !is_array( $logtypes ) ) # Make it an array, if it isn't
2151 - $logtypes = array( $logtypes );
2152 - # If there is exactly one log type, we can link to Special:Log/type
2153 - if ( count( $logtypes ) == 1 )
2154 - $urlParam['type'] = $logtypes[0];
2155 - $wgOut->addHTML( $wgUser->getSkin()->link(
2156 - SpecialPage::getTitleFor( 'Log' ),
2157 - wfMsgHtml( 'log-fulllog' ),
2158 - array(),
2159 - $urlParam
2160 - ) );
2161 -
2162 - }
2163 - $wgOut->addHTML( '</div>' );
2164 - return true;
2165 - }
2166 - return false;
2167 - }
2168 -
2169 -
21702119 }
Index: trunk/phase3/includes/specials/SpecialContributions.php
@@ -226,8 +226,8 @@
227227
228228 // Show a note if the user is blocked and display the last block log entry.
229229 if ( User::newFromID( $id )->isBlocked() )
230 - $wgOut->showLogs( $nt->getPrefixedText(), '', array( 'block' ),
231 - 'sp-contributions-blocked-notice', 1 );
 230+ LogEventsList::showLogExtract( $wgOut, 'block', $nt->getPrefixedText(), '', 1,
 231+ array(), false, 'sp-contributions-blocked-notice' );
232232 }
233233
234234 // Old message 'contribsub' had one parameter, but that doesn't work for
Index: trunk/phase3/includes/Article.php
@@ -1211,12 +1211,13 @@
12121212
12131213 # Show rename log because user does not exist.
12141214 $parent = $this->mTitle->getNsText() . ":" . $this->mTitle->getBaseText();
1215 - $wgOut->showLogs( $parent, '', array( 'renameuser' ), 'renamed-notice' );
 1215+ LogEventsList::showLogExtract( $wgOut, 'renameuser', $parent, '', 10, array(), false, 'renamed-notice' );
12161216 }
12171217
12181218 }
12191219 # Show delete and move logs
1220 - $wgOut->showLogs( $this->mTitle->getPrefixedText(), '', array( 'delete', 'move' ), 'moveddeleted-notice' );
 1220+ LogEventsList::showLogExtract( $wgOut, array( 'delete', 'move' ),
 1221+ $this->mTitle->getPrefixedText(), '', 10, array( "log_action != 'revision'" ), false, 'moveddeleted-notice');
12211222
12221223 # Show error message
12231224 $oldid = $this->getOldID();
Index: trunk/phase3/includes/EditPage.php
@@ -730,7 +730,8 @@
731731 }
732732 # Give a notice if the user is editing a deleted/moved page...
733733 if ( !$this->mTitle->exists() ) {
734 - $wgOut->showLogs( $this->mTitle->getPrefixedText(), '', array( 'delete', 'move' ), 'recreate-moveddeleted-warn' );
 734+ LogEventsList::showLogExtract( $wgOut, array( 'delete', 'move' ),
 735+ $this->mTitle->getPrefixedText(), '', 10, array( "log_action != 'revision'" ), false, 'recreate-moveddeleted-warn');
735736 }
736737 }
737738
Index: trunk/phase3/includes/LogEventsList.php
@@ -556,15 +556,19 @@
557557 }
558558
559559 /**
560 - * Quick function to show a short log extract
 560+ * Show log extract. Either with text and a box (set $msgKey) or without (don't set $msgKey)
561561 * @param $out OutputPage or String-by-reference
562562 * @param $types String or Array
563563 * @param $page String
564564 * @param $user String
565 - * @param $lim Integer
 565+ * @param $lim Integer Limit of items to show, default is 50
566566 * @param $conds Array
 567+ * @param $showIfEmpty boolean Set to false if you don't want any output in case the loglist is empty
 568+ * if set to true (default), "No matching items in log" is displayed if loglist is empty
 569+ * @param $msgKey String if you want a nice box with a message, set this to the key of the message
 570+ * @return Integer Number of total log items (not limited by $lim)
567571 */
568 - public static function showLogExtract( &$out, $types=array(), $page='', $user='', $lim=0, $conds=array() ) {
 572+ public static function showLogExtract( &$out, $types=array(), $page='', $user='', $lim=0, $conds=array(), $showIfEmpty = true, $msgKey = '' ) {
569573 global $wgUser, $wgOut;
570574 # Insert list of top 50 or so items
571575 $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut, 0 );
@@ -572,12 +576,37 @@
573577 if( $lim > 0 ) $pager->mLimit = $lim;
574578 $logBody = $pager->getBody();
575579 if( $logBody ) {
576 - $s = $loglist->beginLogEventsList() .
 580+ if ( $msgKey )
 581+ $s = '<div class="mw-warning-with-logexcerpt">' . wfMsg( $msgKey ) ;
 582+ $s .= $loglist->beginLogEventsList() .
577583 $logBody .
578584 $loglist->endLogEventsList();
579585 } else {
580 - $s = wfMsgExt( 'logempty', array('parse') );
 586+ if ( $showIfEmpty )
 587+ $s = wfMsgExt( 'logempty', array('parse') );
581588 }
 589+ if( $pager->getNumRows() > $pager->mLimit ) { # Show "Full log" link
 590+ $urlParam = array();
 591+ if ( $page != '')
 592+ $urlParam['page'] = $page;
 593+ if ( $user != '')
 594+ $urlParam['user'] = $user;
 595+ if ( !is_array( $types ) ) # Make it an array, if it isn't
 596+ $types = array( $types );
 597+ # If there is exactly one log type, we can link to Special:Log?type=foo
 598+ if ( count( $types ) == 1 )
 599+ $urlParam['type'] = $types[0];
 600+ $s .= $wgUser->getSkin()->link(
 601+ SpecialPage::getTitleFor( 'Log' ),
 602+ wfMsgHtml( 'log-fulllog' ),
 603+ array(),
 604+ $urlParam
 605+ );
 606+
 607+ }
 608+ if ( $logBody && $msgKey )
 609+ $s .= '</div>';
 610+
582611 if( $out instanceof OutputPage ){
583612 $out->addHTML( $s );
584613 } else {

Follow-up revisions

RevisionCommit summaryAuthorDate
r56289Fixes for r56284:...mrzman02:17, 14 September 2009
r56420Follow-up on r56284: LogEventsList::showLogExtract gets associative array for...churchofemacs17:17, 16 September 2009

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r56251Creating new function wgOutput->showLogs and including new information on vie...churchofemacs02:07, 13 September 2009

Comments

#Comment by Siebrand (talk | contribs)   05:56, 15 September 2009

Marking this FIXME per Brion's comment on r56324: <quote>Note that this changes the function interface incompatibly; however the new params weren't present in 1.15 and appear to be otherwise unused...

I still think it's kind of icky just on the general phase of parameter bloat though. Reading the call it's very unobvious what the later parameters mean; would be much easier if we pass the more esoteric options in an options array or soemthing.</quote>

#Comment by Church of emacs (talk | contribs)   11:35, 15 September 2009

Okay, I guess that's true. The question is, do we want to
(A) Include all parameters in one single array (looks nice, but if we pick (a) (see below), we break stuff! (I counted about 26 calls of showLogExtract including extensions))
(B) Include only "non-obvious" parameters (everything from $lim to $msgKey)

Possible solutions:
(a) change showLogExtract to only accept an option-array (if we picked (A), we will break stuff - not worth the effort)
(b) change showLogExtract to accept option-array, but also accept normal parameters (first parameter can then be OutputPage-object, String-by-reference, or param-array. Icky!)
(c) Add another function (maybe call it showLog or showLogs or something) that accepts an option-array and calls showLogExtract using the old scheme.

Personally I think (B) (a) is practical, because only a handful of existing calls have to be modified.

#Comment by Church of emacs (talk | contribs)   18:03, 16 September 2009

I've done that in r56420. Can this revision be marked as resolved? :)

Status & tagging log