r95095 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95094‎ | r95095 | r95096 >
Date:16:31, 20 August 2011
Author:jeroendedauw
Status:deferred (Comments)
Tags:
Comment:
use MediaWikis native table sort stuff
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/RELEASE-NOTES (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_SetupLight.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_Table.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/RELEASE-NOTES
@@ -1,6 +1,10 @@
22 For a documentation of all features, see http://semantic-mediawiki.org
33
44
 5+== S%W 1.6.2 ==
 6+
 7+* Use of native MediaWiki sortable tables for the table formats.
 8+
59 == SMW 1.6.1 ==
610
711 Released on August 20, 2011.
Index: trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_Table.php
@@ -11,16 +11,6 @@
1212 */
1313 class SMWTableResultPrinter extends SMWResultPrinter {
1414
15 - /**
16 - * List of printrequests for which numeric sort keys are used.
17 - * print request hash => true
18 - *
19 - * @since 1.6.1
20 - *
21 - * @var array
22 - */
23 - protected $columnsWithSortKey = array();
24 -
2515 public function getName() {
2616 smwfLoadExtensionMessages( 'SemanticMediaWiki' );
2717 return wfMsg( 'smw_printername_' . $this->mFormat );
@@ -28,7 +18,6 @@
2919
3020 protected function getResultText( SMWQueryResult $res, $outputmode ) {
3121 global $smwgIQRunningNumber;
32 - SMWOutputs::requireHeadItem( SMW_HEADER_SORTTABLE );
3322
3423 $tableRows = array();
3524
@@ -37,9 +26,9 @@
3827 }
3928
4029 // print header
41 - $result = '<table class="smwtable"' .
 30+ $result = '<table class="sortable wikitable"' .
4231 ( $this->mFormat == 'broadtable' ? ' width="100%"' : '' ) .
43 - " id=\"querytable$smwgIQRunningNumber\">\n";
 32+ ">\n";
4433
4534 if ( $this->mShowHeaders != SMW_HEADERS_HIDE ) { // building headers
4635 $headers = array();
@@ -47,10 +36,6 @@
4837 foreach ( $res->getPrintRequests() as $pr ) {
4938 $attribs = array();
5039
51 - if ( array_key_exists( $pr->getHash(), $this->columnsWithSortKey ) ) {
52 - $attribs['class'] = 'numericsort';
53 - }
54 -
5540 $headers[] = Html::rawElement(
5641 'th',
5742 $attribs,
@@ -58,10 +43,10 @@
5944 );
6045 }
6146
62 - array_unshift( $tableRows, '<tr>' . implode( "\n", $headers ) . '</tr>' );
 47+ array_unshift( $tableRows, '<thead><tr>' . implode( "\n", $headers ) . '</tr></thead><tbody>' );
6348 }
6449
65 - $result .= implode( "\n", $tableRows );
 50+ $result .= implode( "\n", $tableRows ) . '</tbody>';
6651
6752 // print further results footer
6853 if ( $this->linkFurtherResults( $res ) ) {
@@ -109,18 +94,39 @@
11095 * @return string
11196 */
11297 protected function getCellForPropVals( SMWResultArray $resultArray, $outputmode ) {
 98+ $dataValues = array();
 99+
 100+ while ( ( $dv = $resultArray->getNextDataValue() ) !== false ) {
 101+ $dataValues[] = $dv;
 102+ }
 103+
113104 $attribs = array();
 105+ $content = null;
114106
115 - $alignment = trim( $resultArray->getPrintRequest()->getParameter( 'align' ) );
 107+ if ( count( $dataValues ) > 0 ) {
 108+ $sortkey = $dataValues[0]->getDataItem()->getSortKey();
 109+
 110+ if ( is_numeric( $sortkey ) ) {
 111+ $attribs['data-sort-value'] = $sortkey;
 112+ }
 113+
 114+ $alignment = trim( $resultArray->getPrintRequest()->getParameter( 'align' ) );
116115
117 - if ( in_array( $alignment, array( 'right', 'left', 'center' ) ) ) {
118 - $attribs['style'] = "text-align:' . $alignment . ';";
 116+ if ( in_array( $alignment, array( 'right', 'left', 'center' ) ) ) {
 117+ $attribs['style'] = "text-align:' . $alignment . ';";
 118+ }
 119+
 120+ $content = $this->getCellContent(
 121+ $dataValues,
 122+ $outputmode,
 123+ $resultArray->getPrintRequest()->getMode() == SMWPrintRequest::PRINT_THIS
 124+ );
119125 }
120126
121127 return Html::rawElement(
122128 'td',
123129 $attribs,
124 - $this->getCellContent( $resultArray, $outputmode )
 130+ $content
125131 );
126132 }
127133
@@ -129,34 +135,21 @@
130136 *
131137 * @since 1.6.1
132138 *
133 - * @param SMWResultArray $resultArray
 139+ * @param array $dataValues
134140 * @param $outputmode
 141+ * @param boolean $isSubject
135142 *
136143 * @return string
137144 */
138 - protected function getCellContent( SMWResultArray $resultArray, $outputmode ) {
 145+ protected function getCellContent( array /* of SMWDataValue */ $dataValues, $outputmode, $isSubject ) {
139146 $values = array();
140 - $isFirst = true;
141147
142 - while ( ( $dv = $resultArray->getNextDataValue() ) !== false ) {
143 - $sortKey = '';
144 -
145 - if ( $isFirst ) {
146 - $isFirst = false;
147 - $sortkey = $dv->getDataItem()->getSortKey();
148 -
149 - if ( is_numeric( $sortkey ) ) { // additional hidden sortkey for numeric entries
150 - $this->columnsWithSortKey[$resultArray->getPrintRequest()->getHash()] = true;
151 - $sortKey .= '<span class="smwsortkey">' . $sortkey . '</span>';
152 - }
153 - }
154 -
155 - $isSubject = $resultArray->getPrintRequest()->getMode() == SMWPrintRequest::PRINT_THIS;
 148+ foreach ( $dataValues as $dv ) {
156149 $value = ( ( $dv->getTypeID() == '_wpg' ) || ( $dv->getTypeID() == '__sin' ) ) ?
157150 $dv->getLongText( $outputmode, $this->getLinker( $isSubject ) ) :
158151 $dv->getShortText( $outputmode, $this->getLinker( $isSubject ) );
159152
160 - $values[] = $sortKey . $value;
 153+ $values[] = $value;
161154 }
162155
163156 return implode( '<br />', $values );
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_SetupLight.php
@@ -14,7 +14,7 @@
1515 * @ingroup SMW
1616 */
1717
18 -define( 'SMW_VERSION', '1.6.1 light' );
 18+define( 'SMW_VERSION', '1.6.2 alpha light' );
1919
2020 require_once( 'SMW_GlobalFunctions.php' );
2121
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php
@@ -8,7 +8,7 @@
99 */
1010
1111 // The SMW version number.
12 -define( 'SMW_VERSION', '1.6.1' );
 12+define( 'SMW_VERSION', '1.6.2 alpha' );
1313
1414 // A flag used to indicate SMW defines a semantic extension type for extension crdits.
1515 define( 'SEMANTIC_EXTENSION_TYPE', true );

Follow-up revisions

RevisionCommit summaryAuthorDate
r95096fu r95095 - rem dead codejeroendedauw16:33, 20 August 2011
r95097fu r95095 - rem dead codejeroendedauw16:35, 20 August 2011
r95111fixed typojeroendedauw20:35, 20 August 2011

Comments

#Comment by Nikerabbit (talk | contribs)   19:11, 20 August 2011
+== S%W 1.6.2 ==

Woo

#Comment by Nikerabbit (talk | contribs)   09:05, 21 August 2011

Added r95111 to follow-ups manually.