r50131 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r50130‎ | r50131 | r50132 >
Date:14:34, 2 May 2009
Author:aaron
Status:ok
Tags:
Comment:
Fixed dropdown selector display and other log type issues due to string -> array conversion
Modified paths:
  • /trunk/phase3/includes/LogEventsList.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/LogEventsList.php
@@ -60,7 +60,7 @@
6161
6262 /**
6363 * Show options for the log list
64 - * @param $type String
 64+ * @param $types string or Array
6565 * @param $user String
6666 * @param $page String
6767 * @param $pattern String
@@ -69,32 +69,38 @@
7070 * @param $filter: array
7171 * @param $tagFilter: array?
7272 */
73 - public function showOptions( $type = '', $user = '', $page = '', $pattern = '', $year = '',
74 - $month = '', $filter = null, $tagFilter='' )
 73+ public function showOptions( $types=array(), $user='', $page='', $pattern='', $year='',
 74+ $month = '', $filter = null, $tagFilter='' )
7575 {
7676 global $wgScript, $wgMiserMode;
7777 $action = htmlspecialchars( $wgScript );
7878 $title = SpecialPage::getTitleFor( 'Log' );
7979 $special = htmlspecialchars( $title->getPrefixedDBkey() );
 80+ // For B/C, we take strings, but make sure they are converted...
 81+ $types = ($types === '') ? array() : (array)$types;
8082
8183 $tagSelector = ChangeTags::buildTagFilterSelector( $tagFilter );
8284
8385 $this->out->addHTML( "<form action=\"$action\" method=\"get\"><fieldset>" .
8486 Xml::element( 'legend', array(), wfMsg( 'log' ) ) .
8587 Xml::hidden( 'title', $special ) . "\n" .
86 - $this->getTypeMenu( $type ) . "\n" .
 88+ $this->getTypeMenu( $types ) . "\n" .
8789 $this->getUserInput( $user ) . "\n" .
8890 $this->getTitleInput( $page ) . "\n" .
8991 ( !$wgMiserMode ? ($this->getTitlePattern( $pattern )."\n") : "" ) .
9092 "<p>" . Xml::dateMenu( $year, $month ) . "\n" .
9193 ( $tagSelector ? Xml::tags( 'p', null, implode( '&nbsp;', $tagSelector ) ) :'' ). "\n" .
92 - ( $filter ? "</p><p>".$this->getFilterLinks( $type, $filter )."\n" : "" ) . "\n" .
 94+ ( $filter ? "</p><p>".$this->getFilterLinks( $filter )."\n" : "" ) . "\n" .
9395 Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "</p>\n" .
9496 "</fieldset></form>"
9597 );
9698 }
9799
98 - private function getFilterLinks( $logType, $filter ) {
 100+ /**
 101+ * @param $filter Array
 102+ * @return String: Formatted HTML
 103+ */
 104+ private function getFilterLinks( $filter ) {
99105 global $wgTitle, $wgLang;
100106 // show/hide links
101107 $messages = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' ) );
@@ -128,10 +134,10 @@
129135 }
130136
131137 /**
132 - * @param $queryType String
 138+ * @param $queryTypes Array
133139 * @return String: Formatted HTML
134140 */
135 - private function getTypeMenu( $queryType ) {
 141+ private function getTypeMenu( $queryTypes ) {
136142 global $wgLogRestrictions, $wgUser;
137143
138144 $html = "<select name='type'>\n";
@@ -148,6 +154,8 @@
149155 // Second pass to sort by name
150156 ksort($typesByName);
151157
 158+ // Note the query type
 159+ $queryType = count($queryTypes) == 1 ? $queryTypes[0] : '';
152160 // Third pass generates sorted XHTML content
153161 foreach( $typesByName as $text => $type ) {
154162 $selected = ($type == $queryType);
@@ -427,17 +435,17 @@
428436 /**
429437 * Quick function to show a short log extract
430438 * @param $out OutputPage
431 - * @param $type String
 439+ * @param $types String or Array
432440 * @param $page String
433441 * @param $user String
434442 * @param $lim Integer
435443 * @param $conds Array
436444 */
437 - public static function showLogExtract( $out, $type='', $page='', $user='', $lim=0, $conds=array() ) {
 445+ public static function showLogExtract( $out, $types=array(), $page='', $user='', $lim=0, $conds=array() ) {
438446 global $wgUser;
439447 # Insert list of top 50 or so items
440448 $loglist = new LogEventsList( $wgUser->getSkin(), $out, 0 );
441 - $pager = new LogPager( $loglist, $type, $user, $page, '', $conds );
 449+ $pager = new LogPager( $loglist, $types, $user, $page, '', $conds );
442450 if( $lim > 0 ) $pager->mLimit = $lim;
443451 $logBody = $pager->getBody();
444452 if( $logBody ) {
@@ -482,13 +490,14 @@
483491 * @ingroup Pager
484492 */
485493 class LogPager extends ReverseChronologicalPager {
486 - private $type = '', $user = '', $title = '', $pattern = '';
 494+ private $types = array(), $user = '', $title = '', $pattern = '';
 495+ private $typeCGI = '';
487496 public $mLogEventsList;
488497
489498 /**
490499 * constructor
491500 * @param $list LogEventsList
492 - * @param $type String
 501+ * @param $types String or Array
493502 * @param $user String
494503 * @param $title String
495504 * @param $pattern String
@@ -496,7 +505,7 @@
497506 * @param $year Integer
498507 * @param $month Integer
499508 */
500 - public function __construct( $list, $type = '', $user = '', $title = '', $pattern = '',
 509+ public function __construct( $list, $types = array(), $user = '', $title = '', $pattern = '',
501510 $conds = array(), $year = false, $month = false, $tagFilter = '' )
502511 {
503512 parent::__construct();
@@ -504,7 +513,7 @@
505514
506515 $this->mLogEventsList = $list;
507516
508 - $this->limitType( $type ); // also excludes hidden types
 517+ $this->limitType( $types ); // also excludes hidden types
509518 $this->limitUser( $user );
510519 $this->limitTitle( $title, $pattern );
511520 $this->getDateCond( $year, $month );
@@ -513,17 +522,18 @@
514523
515524 public function getDefaultQuery() {
516525 $query = parent::getDefaultQuery();
517 - $query['type'] = $this->type;
 526+ $query['type'] = $this->typeCGI; // arrays won't work here
518527 $query['user'] = $this->user;
519528 $query['month'] = $this->mMonth;
520529 $query['year'] = $this->mYear;
521530 return $query;
522531 }
523532
 533+ // Call ONLY after calling $this->limitType() already!
524534 public function getFilterParams() {
525535 global $wgFilterLogTypes, $wgUser, $wgRequest;
526536 $filters = array();
527 - if( $this->type ) {
 537+ if( count($this->types) ) {
528538 return $filters;
529539 }
530540 foreach( $wgFilterLogTypes as $type => $default ) {
@@ -560,9 +570,11 @@
561571 if( $hideLogs !== false ) {
562572 $this->mConds[] = $hideLogs;
563573 }
564 - if( count($types) > 0 ) {
565 - $this->type = $types;
 574+ if( count($types) ) {
 575+ $this->types = $types;
566576 $this->mConds['log_type'] = $types;
 577+ // Set typeCGI; used in url param for paging
 578+ if( count($types) == 1 ) $this->typeCGI = $types[0];
567579 }
568580 }
569581
@@ -642,7 +654,7 @@
643655 # Don't use the wrong logging index
644656 if( $this->title || $this->pattern || $this->user ) {
645657 $index = array( 'USE INDEX' => array( 'logging' => array('page_time','user_time') ) );
646 - } else if( $this->type ) {
 658+ } else if( $this->types ) {
647659 $index = array( 'USE INDEX' => array( 'logging' => 'type_time' ) );
648660 } else {
649661 $index = array( 'USE INDEX' => array( 'logging' => 'times' ) );
@@ -688,7 +700,7 @@
689701 }
690702
691703 public function getType() {
692 - return $this->type;
 704+ return $this->types;
693705 }
694706
695707 public function getUser() {

Status & tagging log