From fcdbf55b4400ac8ae95068669de6eb7a6201da22 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Thu, 4 Apr 2013 19:19:22 +0200 Subject: [PATCH] Fix HTML output of TablePager - Use Html class instead of Xml - Change some raw string to use Html class Change-Id: If749904450a33e572716a447a40ab34342beb191 --- includes/Pager.php | 64 ++++++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/includes/Pager.php b/includes/Pager.php index d2ac9046b0..56b5d489dd 100644 --- a/includes/Pager.php +++ b/includes/Pager.php @@ -922,16 +922,15 @@ abstract class TablePager extends IndexPager { */ function getStartBody() { global $wgStylePath; - $tableClass = htmlspecialchars( $this->getTableClass() ); - $sortClass = htmlspecialchars( $this->getSortHeaderClass() ); + $sortClass = $this->getSortHeaderClass(); - $s = "\n"; + $s = ''; $fields = $this->getFieldNames(); # Make table header foreach ( $fields as $field => $name ) { if ( strval( $name ) == '' ) { - $s .= "\n"; + $s .= Html::rawElement( 'th', array(), ' ' ) . "\n"; } elseif ( $this->isFieldSortable( $field ) ) { $query = array( 'sort' => $field, 'limit' => $this->mLimit ); if ( $field == $this->mSort ) { @@ -950,20 +949,26 @@ abstract class TablePager extends IndexPager { $query['desc'] = '1'; $alt = $this->msg( 'ascending_abbrev' )->escaped(); } - $image = htmlspecialchars( "$wgStylePath/common/images/$image" ); + $image = "$wgStylePath/common/images/$image"; $link = $this->makeLink( - "\"$alt\"" . - htmlspecialchars( $name ), $query ); - $s .= "\n"; + Html::element( 'img', array( 'width' => 12, 'height' => 12, + 'alt' => $alt, 'src' => $image ) ) . htmlspecialchars( $name ), $query ); + $s .= Html::rawElement( 'th', array( 'class' => $sortClass ), $link ) . "\n"; } else { - $s .= '\n"; + $s .= Html::rawElement( 'th', array(), + $this->makeLink( htmlspecialchars( $name ), $query ) ) . "\n"; } } else { - $s .= '\n"; + $s .= Html::element( 'th', array(), $name ) . "\n"; } } - $s .= "\n"; - return $s; + + $tableClass = $this->getTableClass(); + $ret = Html::openElement( 'table', array( 'style' => 'border:1px;', 'class' => "mw-datatable $tableClass" ) ); + $ret .= Html::rawElement( 'thead', array(), Html::rawElement( 'tr', array(), "\n" . $s . "\n" ) ); + $ret .= Html::openElement( 'tbody' ) . "\n"; + + return $ret; } /** @@ -980,8 +985,9 @@ abstract class TablePager extends IndexPager { */ function getEmptyBody() { $colspan = count( $this->getFieldNames() ); - $msgEmpty = $this->msg( 'table_pager_empty' )->escaped(); - return "\n"; + $msgEmpty = $this->msg( 'table_pager_empty' )->text(); + return Html::rawElement( 'tr', array(), + Html::element( 'td', array( 'colspan' => $colspan ), $msgEmpty ) ); } /** @@ -991,7 +997,7 @@ abstract class TablePager extends IndexPager { */ function formatRow( $row ) { $this->mCurrentRow = $row; // In case formatValue etc need to know - $s = Xml::openElement( 'tr', $this->getRowAttrs( $row ) ); + $s = Html::openElement( 'tr', $this->getRowAttrs( $row ) ) . "\n"; $fieldNames = $this->getFieldNames(); foreach ( $fieldNames as $field => $name ) { @@ -1002,10 +1008,10 @@ abstract class TablePager extends IndexPager { $formatted = ' '; } - $s .= Xml::tags( 'td', $this->getCellAttrs( $field, $value ), $formatted ); + $s .= Html::rawElement( 'td', $this->getCellAttrs( $field, $value ), $formatted ) . "\n"; } - $s .= "\n"; + $s .= Html::closeElement( 'tr' ) . "\n"; return $s; } @@ -1127,18 +1133,20 @@ abstract class TablePager extends IndexPager { $disabledTexts = array(); foreach ( $labels as $type => $label ) { $msgLabel = $this->msg( $label )->escaped(); - $linkTexts[$type] = "\"$msgLabel\"/
$msgLabel"; - $disabledTexts[$type] = "\"$msgLabel\"/
$msgLabel"; + $linkTexts[$type] = Html::element( 'img', array( 'src' => "$path/{$images[$type]}", + 'alt' => $msgLabel ) ) . "
$msgLabel"; + $disabledTexts[$type] = Html::element( 'img', array( 'src' => "$path/{$disabledImages[$type]}", + 'alt' => $msgLabel ) ) . "
$msgLabel"; } $links = $this->getPagingLinks( $linkTexts, $disabledTexts ); - $navClass = htmlspecialchars( $this->getNavClass() ); - $s = "
 $link' . $this->makeLink( htmlspecialchars( $name ), $query ) . "' . htmlspecialchars( $name ) . "
$msgEmpty
\n"; + $s = Html::openElement( 'table', array( 'class' => $this->getNavClass() ) ); + $s .= Html::openElement( 'tr' ) . "\n"; $width = 100 / count( $links ) . '%'; foreach ( $labels as $type => $label ) { - $s .= "\n"; + $s .= Html::rawElement( 'td', array( 'style' => "width:$width;" ), $links[$type] ) . "\n"; } - $s .= "
{$links[$type]}
\n"; + $s .= Html::closeElement( 'tr' ) . Html::closeElement( 'table' ) . "\n"; return $s; } @@ -1188,9 +1196,7 @@ abstract class TablePager extends IndexPager { } $s = ''; foreach ( $query as $name => $value ) { - $encName = htmlspecialchars( $name ); - $encValue = htmlspecialchars( $value ); - $s .= "\n"; + $s .= Html::hidden( $name, $value ) . "\n"; } return $s; } @@ -1203,12 +1209,14 @@ abstract class TablePager extends IndexPager { function getLimitForm() { global $wgScript; - return Xml::openElement( + return Html::rawElement( 'form', array( 'method' => 'get', 'action' => $wgScript - ) ) . "\n" . $this->getLimitDropdown() . "\n"; + ), + "\n" . $this->getLimitDropdown() + ) . "\n"; } /** -- 2.20.1