Skip to content

Commit

Permalink
Reduce duplication in DisplayMapRenderer
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroenDeDauw committed Nov 26, 2018
1 parent 7239c0f commit e2ac37e
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/MediaWiki/ParserHooks/DisplayMapRenderer.php
Expand Up @@ -139,8 +139,7 @@ private function getLocationJson( array $params ) {
private function getLocationJsonObject( Location $location, array $params, $iconUrl, $visitedIconUrl ) {
$jsonObj = $location->getJSONObject( $params['title'], $params['label'], $iconUrl, '', '', $visitedIconUrl );

$jsonObj['title'] = $this->wikitextParser->wikitextToHtml( $jsonObj['title'] );
$jsonObj['text'] = $this->wikitextParser->wikitextToHtml( $jsonObj['text'] );
$this->titleAndText( $jsonObj );

if ( isset( $jsonObj['inlineLabel'] ) ) {
$jsonObj['inlineLabel'] = strip_tags(
Expand All @@ -149,15 +148,9 @@ private function getLocationJsonObject( Location $location, array $params, $icon
);
}

$hasTitleAndtext = $jsonObj['title'] !== '' && $jsonObj['text'] !== '';
$jsonObj['text'] = ( $hasTitleAndtext ? '<b>' . $jsonObj['title'] . '</b><hr />' : $jsonObj['title'] ) . $jsonObj['text'];
$jsonObj['title'] = strip_tags( $jsonObj['title'] );

return $jsonObj;
}



private function handleShapeData( array &$params ) {
$textContainers = [
&$params['lines'],
Expand All @@ -174,17 +167,21 @@ private function handleShapeData( array &$params ) {
$obj = $obj->getArrayValue();
}

$obj['title'] = $this->wikitextParser->wikitextToHtml( $obj['title'] );
$obj['text'] = $this->wikitextParser->wikitextToHtml( $obj['text'] );

$hasTitleAndtext = $obj['title'] !== '' && $obj['text'] !== '';
$obj['text'] = ( $hasTitleAndtext ? '<b>' . $obj['title'] . '</b><hr />' : $obj['title'] ) . $obj['text'];
$obj['title'] = strip_tags( $obj['title'] );
$this->titleAndText( $obj );
}
}
}
}

private function titleAndText( array &$elementJson ) {
$elementJson['title'] = $this->wikitextParser->wikitextToHtml( $elementJson['title'] );
$elementJson['text'] = $this->wikitextParser->wikitextToHtml( $elementJson['text'] );

$hasTitleAndText = $elementJson['title'] !== '' && $elementJson['text'] !== '';
$elementJson['text'] = ( $hasTitleAndText ? '<b>' . $elementJson['title'] . '</b><hr />' : $elementJson['title'] ) . $elementJson['text'];
$elementJson['title'] = strip_tags( $elementJson['title'] );
}

/**
* FIXME
*
Expand Down

0 comments on commit e2ac37e

Please sign in to comment.