r56420 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56419‎ | r56420 | r56421 >
Date:17:17, 16 September 2009
Author:churchofemacs
Status:resolved (Comments)
Tags:
Comment:
Follow-up on r56284: LogEventsList::showLogExtract gets associative array for additional parameters. Adjusted all calls that use additional parameters. Also improved Special:Blockip, which now uses those new parameters instead of using own functions. Fixed HistoryPage which was broken with r56251.
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/EditPage.php (modified) (history)
  • /trunk/phase3/includes/HistoryPage.php (modified) (history)
  • /trunk/phase3/includes/LogEventsList.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialBlockip.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialContributions.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialMovepage.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialRevisiondelete.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/maintenance/language/messages.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/language/messages.inc
@@ -1987,7 +1987,8 @@
19881988 'contribslink',
19891989 'autoblocker',
19901990 'blocklogpage',
1991 - 'blocklog-fulllog',
 1991+ 'blocklog-showlog',
 1992+ 'blocklog-showsuppresslog',
19921993 'blocklogentry',
19931994 'reblock-logentry',
19941995 'blocklogtext',
Index: trunk/phase3/includes/Article.php
@@ -1209,19 +1209,14 @@
12101210 $wgOut->wrapWikiMsg( '<div class="mw-userpage-userdoesnotexist error">$1</div>',
12111211 array( 'userpage-userdoesnotexist-view', $this->mTitle->getBaseText() ) );
12121212 }
1213 -
12141213 }
12151214 wfRunHooks( 'ShowMissingArticle', array( $this ) );
12161215 # Show delete and move logs
1217 - LogEventsList::showLogExtract(
1218 - $wgOut,
1219 - array( 'delete', 'move' ),
1220 - $this->mTitle->getPrefixedText(),
1221 - '',
1222 - 10,
1223 - array( "log_action != 'revision'" ),
1224 - false,
1225 - array( 'moveddeleted-notice' )
 1216+ LogEventsList::showLogExtract( $wgOut, array( 'delete', 'move' ), $this->mTitle->getPrefixedText(), '',
 1217+ array( 'lim' => 10,
 1218+ 'conds' => array( "log_action != 'revision'" ),
 1219+ 'showIfEmpty' => false,
 1220+ 'msgKey' => array( 'moveddeleted-notice' ) )
12261221 );
12271222
12281223 # Show error message
Index: trunk/phase3/includes/EditPage.php
@@ -730,8 +730,12 @@
731731 }
732732 # Give a notice if the user is editing a deleted/moved page...
733733 if ( !$this->mTitle->exists() ) {
734 - LogEventsList::showLogExtract( $wgOut, array( 'delete', 'move' ),
735 - $this->mTitle->getPrefixedText(), '', 10, array( "log_action != 'revision'" ), false, 'recreate-moveddeleted-warn');
 734+ LogEventsList::showLogExtract( $wgOut, array( 'delete', 'move' ), $this->mTitle->getPrefixedText(),
 735+ '', array( 'lim' => 10,
 736+ 'conds' => array( "log_action != 'revision'" ),
 737+ 'showIfEmpty' => false,
 738+ 'msgKey' => array( 'recreate-moveddeleted-warn') )
 739+ );
736740 }
737741 }
738742
@@ -1278,10 +1282,8 @@
12791283 $noticeMsg = 'protectedpagewarning';
12801284 $classes[] = 'mw-textarea-protected';
12811285 }
1282 - $wgOut->addHTML( "<div class='mw-warning-with-logexcerpt'>\n" );
1283 - $wgOut->addWikiMsg( $noticeMsg );
1284 - LogEventsList::showLogExtract( $wgOut, 'protect', $this->mTitle->getPrefixedText(), '', 1 );
1285 - $wgOut->addHTML( "</div>\n" );
 1286+ LogEventsList::showLogExtract( $wgOut, 'protect', $this->mTitle->getPrefixedText(), '',
 1287+ array( 'lim' => 1, 'msgKey' => array( $noticeMsg ) ) );
12861288 }
12871289 if ( $this->mTitle->isCascadeProtected() ) {
12881290 # Is this page under cascading protection from some source pages?
Index: trunk/phase3/includes/HistoryPage.php
@@ -105,7 +105,13 @@
106106 */
107107 if( !$this->title->exists() ) {
108108 $wgOut->addWikiMsg( 'nohistory' );
109 - $this->article->showLogs(); // show deletion/move log if there is an entry
 109+ # show deletion/move log if there is an entry
 110+ LogEventsList::showLogExtract( $wgOut, array( 'delete', 'move' ), $this->title->getPrefixedText(), '',
 111+ array( 'lim' => 10,
 112+ 'conds' => array( "log_action != 'revision'" ),
 113+ 'showIfEmpty' => false,
 114+ 'msgKey' => array( 'moveddeleted-notice' ) )
 115+ );
110116 wfProfileOut( __METHOD__ );
111117 return;
112118 }
Index: trunk/phase3/includes/LogEventsList.php
@@ -571,26 +571,36 @@
572572 * @param $types String or Array
573573 * @param $page String The page title to show log entries for
574574 * @param $user String The user who made the log entries
575 - * @param $lim Integer Limit of items to show, default is 50
576 - * @param $conds Array Extra conditions for the query
577 - * @param $showIfEmpty boolean Set to false if you don't want any output in case the loglist is empty
 575+ * @param $param Associative Array with the following additional options:
 576+ * lim Integer Limit of items to show, default is 50
 577+ * conds Array Extra conditions for the query (e.g. "log_action != 'revision'")
 578+ * showIfEmpty boolean Set to false if you don't want any output in case the loglist is empty
578579 * if set to true (default), "No matching items in log" is displayed if loglist is empty
579 - * @param $msgKey Array If you want a nice box with a message, set this
 580+ * msgKey Array If you want a nice box with a message, set this
580581 * to the key of the message. First element is the message
581582 * key, additional optional elements are parameters for the
582583 * key that are processed with wgMsgExt and option 'parse'
583584 * @return Integer Number of total log items (not limited by $lim)
584585 */
585 - public static function showLogExtract( &$out, $types=array(), $page='', $user='', $lim=0, $conds=array(), $showIfEmpty = true, $msgKey = array() ) {
 586+ public static function showLogExtract( &$out, $types=array(), $page='', $user='',
 587+ $param = array( 'lim' => 0, 'conds' => array(), 'showIfEmpty' => true, 'msgKey' => array('') ) ) {
 588+
586589 global $wgUser, $wgOut;
587 - # Insert list of top 50 or so items
 590+ # Convert $param array to individual variables
 591+ $lim = $param['lim'];
 592+ $conds = $param['conds'];
 593+ $showIfEmpty = $param['showIfEmpty'];
 594+ $msgKey = $param['msgKey'];
 595+ if ( !(is_array($msgKey)) )
 596+ $msgKey = array( $msgKey );
 597+ # Insert list of top 50 (or top $lim) items
588598 $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut, 0 );
589599 $pager = new LogPager( $loglist, $types, $user, $page, '', $conds );
590600 if( $lim > 0 ) $pager->mLimit = $lim;
591601 $logBody = $pager->getBody();
592602 $s = '';
593603 if( $logBody ) {
594 - if ( $msgKey ) {
 604+ if ( $msgKey[0] ) {
595605 $s = '<div class="mw-warning-with-logexcerpt">';
596606
597607 if ( count( $msgKey ) == 1 ) {
@@ -627,7 +637,7 @@
628638 );
629639
630640 }
631 - if ( $logBody && $msgKey )
 641+ if ( $logBody && $msgKey[0] )
632642 $s .= '</div>';
633643
634644 if( $out instanceof OutputPage ){
Index: trunk/phase3/includes/specials/SpecialRevisiondelete.php
@@ -184,12 +184,12 @@
185185 # Show relevant lines from the deletion log
186186 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage::logName( 'delete' ) ) . "</h2>\n" );
187187 LogEventsList::showLogExtract( $wgOut, 'delete',
188 - $this->targetObj->getPrefixedText(), '', 25, $qc );
 188+ $this->targetObj->getPrefixedText(), '', array( 'lim' => 25, 'conds' => $qc ) );
189189 # Show relevant lines from the suppression log
190190 if( $wgUser->isAllowed( 'suppressionlog' ) ) {
191191 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage::logName( 'suppress' ) ) . "</h2>\n" );
192192 LogEventsList::showLogExtract( $wgOut, 'suppress',
193 - $this->targetObj->getPrefixedText(), '', 25, $qc );
 193+ $this->targetObj->getPrefixedText(), '', array( 'lim' => 25, 'conds' => $qc ) );
194194 }
195195 }
196196
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 - LogEventsList::showLogExtract( $wgOut, 'block', $nt->getPrefixedText(), '', 1,
231 - array(), false, 'sp-contributions-blocked-notice' );
 230+ LogEventsList::showLogExtract( $wgOut, 'block', $nt->getPrefixedText(), '',
 231+ array( 'lim' => 1, 'showIfEmpty' => false, 'msgKey' => array( 'sp-contributions-blocked-notice' ) ) );
232232 }
233233
234234 // Old message 'contribsub' had one parameter, but that doesn't work for
Index: trunk/phase3/includes/specials/SpecialBlockip.php
@@ -585,22 +585,13 @@
586586
587587 private function showLogFragment( $out, $title ) {
588588 global $wgUser;
589 - $out->addHTML( Xml::element( 'h2', NULL, LogPage::logName( 'block' ) ) );
590 - $count = LogEventsList::showLogExtract( $out, 'block', $title->getPrefixedText(), '', 10 );
591 - if( $count > 10 ) {
592 - $out->addHTML( $wgUser->getSkin()->link(
593 - SpecialPage::getTitleFor( 'Log' ),
594 - wfMsgHtml( 'blocklog-fulllog' ),
595 - array(),
596 - array(
597 - 'type' => 'block',
598 - 'page' => $title->getPrefixedText() ) ) );
599 - }
 589+ LogEventsList::showLogExtract( $out, 'block', $title->getPrefixedText(), '',
 590+ array( 'lim' => 10, 'msgKey' => array( 'blocklog-showlog' ) ) );
600591 // Add suppression block entries if allowed
601 - if( $wgUser->isAllowed('hideuser') ) {
602 - $out->addHTML( Xml::element( 'h2', NULL, LogPage::logName( 'suppress' ) ) );
 592+ if( $wgUser->isAllowed( 'hideuser' ) ) {
603593 LogEventsList::showLogExtract( $out, 'suppress', $title->getPrefixedText(), '',
604 - 10, array('log_action' => array('block','reblock','unblock')) );
 594+ array('lim' => 10, 'conds' => array('log_action' => array('block','reblock','unblock')),
 595+ 'msgKey' => array( 'blocklog-showsuppresslog' ) ) );
605596 }
606597 }
607598
Index: trunk/phase3/includes/specials/SpecialMovepage.php
@@ -180,7 +180,7 @@
181181 }
182182 $wgOut->addHTML( "<div class='mw-warning-with-logexcerpt'>\n" );
183183 $wgOut->addWikiMsg( $noticeMsg );
184 - LogEventsList::showLogExtract( $wgOut, 'protect', $this->oldTitle->getPrefixedText(), '', 1 );
 184+ LogEventsList::showLogExtract( $wgOut, 'protect', $this->oldTitle->getPrefixedText(), '', array( 'lim' => 1 ) );
185185 $wgOut->addHTML( "</div>\n" );
186186 }
187187
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -2945,7 +2945,8 @@
29462946 'autoblocker' => 'Autoblocked because your IP address has been recently used by "[[User:$1|$1]]".
29472947 The reason given for $1\'s block is: "$2"',
29482948 'blocklogpage' => 'Block log',
2949 -'blocklog-fulllog' => 'Full block log',
 2949+'blocklog-showlog' => 'This user has been blocked previously. The block log is provided below for reference:',
 2950+'blocklog-showsuppresslog' => 'This user has been blocked and hidden previously. The suppress log is provided below for reference:',
29502951 'blocklogentry' => 'blocked [[$1]] with an expiry time of $2 $3',
29512952 'reblock-logentry' => 'changed block settings for [[$1]] with an expiry time of $2 $3',
29522953 'blocklogtext' => 'This is a log of user blocking and unblocking actions.

Follow-up revisions

RevisionCommit summaryAuthorDate
r56422Follow-up on r56420 and r56318: adjust SpecialRenameuser to fit to new LogEve...churchofemacs18:00, 16 September 2009
r56596Shut up warnings from r56420 that have annoyed us few days :onikerabbit13:57, 18 September 2009
r56687Follow-up on r55909: showLogExtract can now tell Pager to ignore wgRequest of...churchofemacs22:07, 20 September 2009
r57353Fixed fatal caused by r56420, getting tired of this stuffaaron03:52, 4 October 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
r56284Follow-up on r56251 - merging showLogs and showLogExtractchurchofemacs22:21, 13 September 2009

Comments

#Comment by Siebrand (talk | contribs)   05:50, 17 September 2009

Appears to lead to PHP Notice sometimes: PHP Notice: Undefined index: conds in /var/www/w/includes/LogEventsList.php on line 591

#Comment by Church of emacs (talk | contribs)   13:24, 17 September 2009

Strange, I can't reproduce this error even though I think I enabled error reporting for warnings. But the reason is pretty clear: $param gets only filled up with the default parameters if $param is not defined at all. If $param['lim'] is defined, but $param['conds'] isn't, default values are not set. This should fix it:

		if ( $param['conds'] ) $conds = $param['conds'];
		else $conds = array();

But if I'm correct, it has to be done with all 4 variables in $param. Perhaps there is an easier/nicer way of doing this?

#Comment by Nikerabbit (talk | contribs)   09:41, 18 September 2009

This also applies to all other parameters too. Maybe the default should be just = array(), and then you merge another array with the array passed with suitable merge function.

#Comment by Church of emacs (talk | contribs)   22:17, 20 September 2009

Nikerabbit did that in r56596, thanks. Marking this revision as resolved.

#Comment by Brion VIBBER (talk | contribs)   20:54, 29 September 2009

Getting much more legible. :D

Status & tagging log