Skip to content

Commit a1b65f1

Browse files
refactor getCellContent
1 parent f90be40 commit a1b65f1

1 file changed

Lines changed: 42 additions & 19 deletions

File tree

formats/datatables/DataTables.php

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,16 +1014,10 @@ public function getCellContent(
10141014
bool $isSubject,
10151015
?string $propTypeid = null
10161016
): array {
1017-
if ( !$this->prefixParameterProcessor ) {
1018-
$dataValueMethod = 'getShortText';
1019-
} else {
1020-
$dataValueMethod = $this->prefixParameterProcessor->useLongText( $isSubject ) ? 'getLongText' : 'getShortText';
1021-
}
1022-
1017+
// Template support
10231018
$template = null;
10241019
if ( !empty( $this->printoutsParameters[$label]['template'] ) ) {
10251020
$template = $this->printoutsParameters[$label]['template'];
1026-
10271021
} elseif ( $isSubject && !empty( $this->params['mainlabel-template'] ) ) {
10281022
$template = $this->params['mainlabel-template'];
10291023
}
@@ -1032,35 +1026,63 @@ public function getCellContent(
10321026
$outputMode = SMW_OUTPUT_WIKI;
10331027
}
10341028

1035-
// this is only used by SearchPanes
1029+
// Prefix parameter processor fallback
1030+
if ( !$this->prefixParameterProcessor ) {
1031+
$dataValueMethod = 'getShortText';
1032+
} else {
1033+
$dataValueMethod = $this->prefixParameterProcessor->useLongText( $isSubject ) ? 'getLongText' : 'getShortText';
1034+
}
1035+
1036+
$isHtmlOutput = $outputMode === SMW_OUTPUT_HTML;
1037+
1038+
// Keyword handling
1039+
// @FIXME this is not the best way,
1040+
// try to use $isKeyword = $dataItem->getOption( 'is.keyword' );
1041+
// @see DIBlobHandler
10361042
$isKeyword = ( $propTypeid === '_keyw' );
1043+
10371044
$values = [];
10381045
foreach ( $dataValues as $dv ) {
1046+
$linker = $this->getLinker( $isSubject );
10391047
$dataItem = $dv->getDataItem();
1048+
10401049
// Restore output in Special:Ask on:
10411050
// - file/image parsing
10421051
// - text formatting on string elements including italic, bold etc.
1043-
if ( ( $outputMode === SMW_OUTPUT_HTML && $dataItem instanceof DIWikiPage && $dataItem->getNamespace() === NS_FILE ) ||
1044-
( $outputMode === SMW_OUTPUT_HTML && $dataItem instanceof DIBlob ) ) {
1052+
$parseAsWikitext =
1053+
$isHtmlOutput && (
1054+
( $dataItem instanceof DIWikiPage && $dataItem->getNamespace() === NS_FILE ) ||
1055+
( $dataItem instanceof DIBlob )
1056+
);
1057+
1058+
// @see ListResultPrinter\ValueTextsBuilder -> getValueText
1059+
$dv->setOption(
1060+
$dataValueMethod === 'getLongText'
1061+
? $dv::PREFIXED_FORM
1062+
: $dv::SHORT_FORM,
1063+
true
1064+
);
1065+
1066+
if ( $parseAsWikitext ) {
1067+
$raw = $dv->$dataValueMethod( SMW_OUTPUT_WIKI, $linker );
1068+
10451069
// Too lazy to handle the Parser object and besides the Message
10461070
// parse does the job and ensures no other hook is executed
10471071
$value = Message::get(
1048-
[ 'smw-parse', $dv->$dataValueMethod( SMW_OUTPUT_WIKI, $this->getLinker( $isSubject ) ) ],
1072+
[ 'smw-parse', $raw ],
10491073
Message::PARSE
10501074
);
10511075
} else {
1052-
$value = $dv->$dataValueMethod( $outputMode, $this->getLinker( $isSubject ) );
1076+
$value = $dv->$dataValueMethod( $outputMode, $linker );
10531077
}
10541078

1055-
// @FIXME this is not the best way,
1056-
// try to use $isKeyword = $dataItem->getOption( 'is.keyword' );
1057-
// @see DIBlobHandler
1079+
// Keyword normalization
10581080
if ( $isKeyword ) {
10591081
$value = $dataItem->normalize( $value );
10601082
}
10611083

1084+
// Template expansion
10621085
if ( $template ) {
1063-
// @fixme use named parameter ?
10641086
$titleTemplate = Title::makeTitle( NS_TEMPLATE,
10651087
Title::capitalize( trim( $template ), NS_TEMPLATE ) );
10661088
$value_ = $this->expandTemplate( $titleTemplate, [ 1 => $value ] );
@@ -1072,15 +1094,16 @@ public function getCellContent(
10721094
$values[] = $value === '' ? ' ' : $value;
10731095
}
10741096

1075-
$sep = strtolower( $this->params['sep'] );
1076-
1097+
// Multiple values flag
10771098
// *** used to force use of Ajax with
10781099
// searchpanes since a client side solution
10791100
// won't produce reliable matches
10801101
if ( count( $values ) > 1 ) {
10811102
$this->hasMultipleValues = true;
10821103
}
10831104

1105+
$sep = strtolower( $this->params['sep'] );
1106+
10841107
if ( !$isSubject && $sep === 'ul' && count( $values ) > 1 ) {
10851108
$html = '<ul><li>' . implode( '</li><li>', $values ) . '</li></ul>';
10861109
} elseif ( !$isSubject && $sep === 'ol' && count( $values ) > 1 ) {
@@ -1089,7 +1112,7 @@ public function getCellContent(
10891112
$html = implode( $this->params['sep'], $values );
10901113
}
10911114

1092-
// $dataValues could be empty
1115+
// Return array with sort/filter keys (matching first method)
10931116
$sortKey = array_key_exists( 0, $dataValues ) ? $dataValues[0]->getDataItem()->getSortKey() : '';
10941117

10951118
return [

0 commit comments

Comments
 (0)