@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace ModernTimeline; |
6 | 6 | |
@@ -24,43 +24,43 @@ discard block |
||
24 | 24 | return 'modern_timeline_' . ++$timelineNumber; |
25 | 25 | } |
26 | 26 | |
27 | - public function presentResult( SimpleQueryResult $result ): string { |
|
28 | - SMWOutputs::requireResource( 'ext.modern.timeline' ); |
|
27 | + public function presentResult(SimpleQueryResult $result): string { |
|
28 | + SMWOutputs::requireResource('ext.modern.timeline'); |
|
29 | 29 | |
30 | 30 | SMWOutputs::requireHeadItem( |
31 | 31 | $this->id, |
32 | - $this->createJs( $this->createJsonString( $result ) ) |
|
32 | + $this->createJs($this->createJsonString($result)) |
|
33 | 33 | ); |
34 | 34 | |
35 | - return $this->createDiv( $result->getParameters() ); |
|
35 | + return $this->createDiv($result->getParameters()); |
|
36 | 36 | } |
37 | 37 | |
38 | - private function createJsonString( SimpleQueryResult $result ): string { |
|
39 | - $preJson = $this->newJsonBuilder( $result ) |
|
40 | - ->eventsToTimelineJson( ( new EventExtractor( $result->getParameters() ) )->extractEvents( $result->getSubjects() ) ); |
|
38 | + private function createJsonString(SimpleQueryResult $result): string { |
|
39 | + $preJson = $this->newJsonBuilder($result) |
|
40 | + ->eventsToTimelineJson((new EventExtractor($result->getParameters()))->extractEvents($result->getSubjects())); |
|
41 | 41 | |
42 | - $preJson['options'] = TimelineOptions::processedParamsToJson( $result->getParameters() ); |
|
42 | + $preJson['options'] = TimelineOptions::processedParamsToJson($result->getParameters()); |
|
43 | 43 | |
44 | - return json_encode( $preJson ); |
|
44 | + return json_encode($preJson); |
|
45 | 45 | } |
46 | 46 | |
47 | - private function newJsonBuilder( SimpleQueryResult $result ): JsonBuilder { |
|
47 | + private function newJsonBuilder(SimpleQueryResult $result): JsonBuilder { |
|
48 | 48 | return new JsonBuilder( |
49 | - $this->getSlidePresenter( $result ) |
|
49 | + $this->getSlidePresenter($result) |
|
50 | 50 | ); |
51 | 51 | } |
52 | 52 | |
53 | - private function getSlidePresenter( SimpleQueryResult $result ): SlidePresenter { |
|
53 | + private function getSlidePresenter(SimpleQueryResult $result): SlidePresenter { |
|
54 | 54 | $templateName = $result->getParameters()['template']; |
55 | 55 | |
56 | - if ( $templateName === '' ) { |
|
57 | - return new SimpleSlidePresenter( $result->getProcessingResult()->getParameterArray() ); |
|
56 | + if ($templateName === '') { |
|
57 | + return new SimpleSlidePresenter($result->getProcessingResult()->getParameterArray()); |
|
58 | 58 | } |
59 | 59 | |
60 | - return new TemplateSlidePresenter( $templateName ); |
|
60 | + return new TemplateSlidePresenter($templateName); |
|
61 | 61 | } |
62 | 62 | |
63 | - private function createJs( string $json ): string { |
|
63 | + private function createJs(string $json): string { |
|
64 | 64 | return \Html::rawElement( |
65 | 65 | 'script', |
66 | 66 | [ |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | ); |
72 | 72 | } |
73 | 73 | |
74 | - private function createDiv( array $parameters ): string { |
|
74 | + private function createDiv(array $parameters): string { |
|
75 | 75 | $width = $parameters[TimelineOptions::PARAM_WIDTH]; |
76 | 76 | $height = $parameters[TimelineOptions::PARAM_HEIGHT]; |
77 | 77 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace ModernTimeline\SlidePresenter; |
6 | 6 | |
@@ -16,11 +16,11 @@ discard block |
||
16 | 16 | ) { |
17 | 17 | } |
18 | 18 | |
19 | - public function getText( Subject $subject ): string { |
|
19 | + public function getText(Subject $subject): string { |
|
20 | 20 | $parser = $this->getParser(); |
21 | 21 | |
22 | 22 | return $parser->recursiveTagParseFully( |
23 | - ( new TemplateSlidePresenter( $this->templateName ) )->getTemplateText( $subject ) |
|
23 | + (new TemplateSlidePresenter($this->templateName))->getTemplateText($subject) |
|
24 | 24 | ); |
25 | 25 | } |
26 | 26 | |
@@ -28,21 +28,21 @@ discard block |
||
28 | 28 | return MediaWikiServices::getInstance()->getParser(); |
29 | 29 | } |
30 | 30 | |
31 | - public function getTemplateText( Subject $subject ): string { |
|
32 | - return '{{' . implode( '|', $this->getTemplateSegments( $subject ) ) . '}}'; |
|
31 | + public function getTemplateText(Subject $subject): string { |
|
32 | + return '{{' . implode('|', $this->getTemplateSegments($subject)) . '}}'; |
|
33 | 33 | } |
34 | 34 | |
35 | - private function getTemplateSegments( Subject $subject ): array { |
|
35 | + private function getTemplateSegments(Subject $subject): array { |
|
36 | 36 | return array_merge( |
37 | 37 | [ |
38 | 38 | $this->templateName, |
39 | - $this->parameter( 'title', $subject->getWikiPage()->getTitle()->getFullText() ) |
|
39 | + $this->parameter('title', $subject->getWikiPage()->getTitle()->getFullText()) |
|
40 | 40 | ], |
41 | 41 | array_map( |
42 | - function( PropertyValueCollection $pvc ) { |
|
42 | + function(PropertyValueCollection $pvc) { |
|
43 | 43 | return $this->parameter( |
44 | - $pvc->getPrintRequest()->getText( null ) ?? '', |
|
45 | - $pvc->getDataItems() === [] ? '' : $this->dataItemToText( $pvc->getDataItems()[0] ) |
|
44 | + $pvc->getPrintRequest()->getText(null) ?? '', |
|
45 | + $pvc->getDataItems() === [] ? '' : $this->dataItemToText($pvc->getDataItems()[0]) |
|
46 | 46 | ); |
47 | 47 | }, |
48 | 48 | $subject->getPropertyValueCollections()->toArray() |
@@ -50,11 +50,11 @@ discard block |
||
50 | 50 | ); |
51 | 51 | } |
52 | 52 | |
53 | - private function dataItemToText( \SMWDataItem $dataItem ): string { |
|
54 | - return DataValueFactory::getInstance()->newDataValueByItem( $dataItem )->getLongHTMLText(); |
|
53 | + private function dataItemToText(\SMWDataItem $dataItem): string { |
|
54 | + return DataValueFactory::getInstance()->newDataValueByItem($dataItem)->getLongHTMLText(); |
|
55 | 55 | } |
56 | 56 | |
57 | - private function parameter( string $name, string $value ): string { |
|
57 | + private function parameter(string $name, string $value): string { |
|
58 | 58 | return $name . '=' . $value; |
59 | 59 | } |
60 | 60 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace ModernTimeline\SlidePresenter; |
6 | 6 | |
@@ -16,37 +16,37 @@ discard block |
||
16 | 16 | ) { |
17 | 17 | } |
18 | 18 | |
19 | - public function getText( Subject $subject ): string { |
|
20 | - return implode( '<br>', iterator_to_array( $this->getDisplayValues( $subject ) ) ); |
|
19 | + public function getText(Subject $subject): string { |
|
20 | + return implode('<br>', iterator_to_array($this->getDisplayValues($subject))); |
|
21 | 21 | } |
22 | 22 | |
23 | - private function getDisplayValues( Subject $subject ): Traversable { |
|
24 | - foreach ( $subject->getPropertyValueCollections()->toArray() as $propertyValues ) { |
|
25 | - foreach ( $propertyValues->getDataItems() as $dataItem ) { |
|
26 | - if ( !$this->isHiddenPrintRequest( $propertyValues->getPrintRequest() ) ) { |
|
27 | - yield $this->getDisplayValue( $propertyValues->getPrintRequest(), $dataItem ); |
|
23 | + private function getDisplayValues(Subject $subject): Traversable { |
|
24 | + foreach ($subject->getPropertyValueCollections()->toArray() as $propertyValues) { |
|
25 | + foreach ($propertyValues->getDataItems() as $dataItem) { |
|
26 | + if (!$this->isHiddenPrintRequest($propertyValues->getPrintRequest())) { |
|
27 | + yield $this->getDisplayValue($propertyValues->getPrintRequest(), $dataItem); |
|
28 | 28 | } |
29 | 29 | } |
30 | 30 | } |
31 | 31 | } |
32 | 32 | |
33 | - private function isHiddenPrintRequest( PrintRequest $pr ): bool { |
|
34 | - return $pr->getText( null ) === $this->parameters['image property']; |
|
33 | + private function isHiddenPrintRequest(PrintRequest $pr): bool { |
|
34 | + return $pr->getText(null) === $this->parameters['image property']; |
|
35 | 35 | } |
36 | 36 | |
37 | - private function getDisplayValue( PrintRequest $pr, \SMWDataItem $dataItem ): string { |
|
38 | - $property = $pr->getText( null ); |
|
39 | - $value = $this->dataItemToText( $dataItem ); |
|
37 | + private function getDisplayValue(PrintRequest $pr, \SMWDataItem $dataItem): string { |
|
38 | + $property = $pr->getText(null); |
|
39 | + $value = $this->dataItemToText($dataItem); |
|
40 | 40 | |
41 | - if ( $property === '' ) { |
|
41 | + if ($property === '') { |
|
42 | 42 | return $value; |
43 | 43 | } |
44 | 44 | |
45 | 45 | return $property . ': ' . $value; |
46 | 46 | } |
47 | 47 | |
48 | - private function dataItemToText( \SMWDataItem $dataItem ): string { |
|
49 | - return DataValueFactory::getInstance()->newDataValueByItem( $dataItem )->getLongHTMLText(); |
|
48 | + private function dataItemToText(\SMWDataItem $dataItem): string { |
|
49 | + return DataValueFactory::getInstance()->newDataValueByItem($dataItem)->getLongHTMLText(); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace ModernTimeline; |
6 | 6 | |
@@ -13,10 +13,10 @@ discard block |
||
13 | 13 | } |
14 | 14 | |
15 | 15 | private static function doSmwCheck(): void { |
16 | - if ( !defined( 'SMW_VERSION' ) ) { |
|
16 | + if (!defined('SMW_VERSION')) { |
|
17 | 17 | |
18 | - if ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' ) { |
|
19 | - die( "\nThe 'Modern Timeline' extension requires 'Semantic MediaWiki' to be installed and enabled.\n" ); |
|
18 | + if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') { |
|
19 | + die("\nThe 'Modern Timeline' extension requires 'Semantic MediaWiki' to be installed and enabled.\n"); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | die( |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace ModernTimeline; |
6 | 6 | |
@@ -25,23 +25,23 @@ discard block |
||
25 | 25 | $registry = new ResultFormatRegistry(); |
26 | 26 | |
27 | 27 | $registry->newFormat() |
28 | - ->withName( 'moderntimeline' ) |
|
29 | - ->andMessageKey( 'modern-timeline-format-name' ) |
|
30 | - ->andParameterDefinitions( TimelineOptions::getTimelineParameterDefinitions() ) |
|
31 | - ->andPresenterBuilder( function() { |
|
28 | + ->withName('moderntimeline') |
|
29 | + ->andMessageKey('modern-timeline-format-name') |
|
30 | + ->andParameterDefinitions(TimelineOptions::getTimelineParameterDefinitions()) |
|
31 | + ->andPresenterBuilder(function() { |
|
32 | 32 | return new TimelinePresenter(); |
33 | 33 | } ) |
34 | 34 | ->register(); |
35 | 35 | |
36 | - $this->format = $registry->getFormatByName( 'moderntimeline' ); |
|
36 | + $this->format = $registry->getFormatByName('moderntimeline'); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | public function getName(): string { |
40 | - return wfMessage( $this->format->getNameMessageKey() )->text(); |
|
40 | + return wfMessage($this->format->getNameMessageKey())->text(); |
|
41 | 41 | } |
42 | 42 | |
43 | - public function getParamDefinitions( array $definitions ) { |
|
44 | - return array_merge( $definitions, $this->format->getParameterDefinitions() ); |
|
43 | + public function getParamDefinitions(array $definitions) { |
|
44 | + return array_merge($definitions, $this->format->getParameterDefinitions()); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -51,36 +51,36 @@ discard block |
||
51 | 51 | * |
52 | 52 | * @return string |
53 | 53 | */ |
54 | - public function getResult( QueryResult $result, array $parameters, $outputMode ): string { |
|
54 | + public function getResult(QueryResult $result, array $parameters, $outputMode): string { |
|
55 | 55 | return $this->format->buildPresenter()->presentResult( |
56 | 56 | new SimpleQueryResult( |
57 | - $this->simplifyResult( $result ), |
|
58 | - $this->newProcessingResultFromParams( $parameters ) |
|
57 | + $this->simplifyResult($result), |
|
58 | + $this->newProcessingResultFromParams($parameters) |
|
59 | 59 | ) |
60 | 60 | ); |
61 | 61 | } |
62 | 62 | |
63 | - private function simplifyResult( QueryResult $result ): SubjectCollection { |
|
64 | - return ( new ResultSimplifier() )->newSubjectCollection( $result ); |
|
63 | + private function simplifyResult(QueryResult $result): SubjectCollection { |
|
64 | + return (new ResultSimplifier())->newSubjectCollection($result); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
68 | 68 | * This is code copied over from ParamProcessor to go from the deprecated Param[] to ProcessingResult. |
69 | 69 | * Once the main ResultPrinter interface has been migrated away from Param this can be removed. |
70 | 70 | */ |
71 | - private function newProcessingResultFromParams( array $params ): ProcessingResult { |
|
71 | + private function newProcessingResultFromParams(array $params): ProcessingResult { |
|
72 | 72 | $parameters = []; |
73 | 73 | |
74 | - foreach ( $params as $param ) { |
|
74 | + foreach ($params as $param) { |
|
75 | 75 | $processedParam = new ProcessedParam( |
76 | 76 | $param->getName(), |
77 | 77 | $param->getValue(), |
78 | 78 | $param->wasSetToDefault() |
79 | 79 | ); |
80 | 80 | |
81 | - if ( !$param->wasSetToDefault() ) { |
|
82 | - $processedParam->setOriginalName( $param->getOriginalName() ); |
|
83 | - $processedParam->setOriginalValue( $param->getOriginalValue() ); |
|
81 | + if (!$param->wasSetToDefault()) { |
|
82 | + $processedParam->setOriginalName($param->getOriginalName()); |
|
83 | + $processedParam->setOriginalValue($param->getOriginalValue()); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | $parameters[$processedParam->getName()] = $processedParam; |
@@ -92,11 +92,11 @@ discard block |
||
92 | 92 | ); |
93 | 93 | } |
94 | 94 | |
95 | - public function getQueryMode( $context ): int { |
|
95 | + public function getQueryMode($context): int { |
|
96 | 96 | return SMWQuery::MODE_INSTANCES; |
97 | 97 | } |
98 | 98 | |
99 | - public function setShowErrors( $show ): void { |
|
99 | + public function setShowErrors($show): void { |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | public function isExportFormat(): bool { |
@@ -115,6 +115,6 @@ discard block |
||
115 | 115 | return false; |
116 | 116 | } |
117 | 117 | |
118 | - public function setRecursiveTextProcessor( RecursiveTextProcessor $recursiveTextProcessor ): void { |
|
118 | + public function setRecursiveTextProcessor(RecursiveTextProcessor $recursiveTextProcessor): void { |
|
119 | 119 | } |
120 | 120 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace ModernTimeline; |
6 | 6 | |
@@ -23,20 +23,20 @@ discard block |
||
23 | 23 | * @param SubjectCollection $pages |
24 | 24 | * @return Event[] |
25 | 25 | */ |
26 | - public function extractEvents( SubjectCollection $pages ): array { |
|
26 | + public function extractEvents(SubjectCollection $pages): array { |
|
27 | 27 | $events = []; |
28 | 28 | |
29 | - foreach ( $pages->getSubjects() as $subject ) { |
|
30 | - [ $startDate, $endDate ] = $this->getDates( $subject ); |
|
29 | + foreach ($pages->getSubjects() as $subject) { |
|
30 | + [$startDate, $endDate] = $this->getDates($subject); |
|
31 | 31 | |
32 | - if ( $startDate !== null ) { |
|
33 | - $event = new Event( $subject, $startDate, $endDate ); |
|
32 | + if ($startDate !== null) { |
|
33 | + $event = new Event($subject, $startDate, $endDate); |
|
34 | 34 | |
35 | - foreach ( $subject->getPropertyValueCollections()->toArray() as $propertyValues ) { |
|
36 | - if ( $propertyValues->getPrintRequest()->getText( null ) === $this->parameters['image property'] ) { |
|
37 | - foreach ( $propertyValues->getDataItems() as $dataItem ) { |
|
38 | - if ( $this->isImageValue( $dataItem ) ) { |
|
39 | - $event->setImageUrl( $this->getUrlForFileTitle( $dataItem->getTitle() ) ); |
|
35 | + foreach ($subject->getPropertyValueCollections()->toArray() as $propertyValues) { |
|
36 | + if ($propertyValues->getPrintRequest()->getText(null) === $this->parameters['image property']) { |
|
37 | + foreach ($propertyValues->getDataItems() as $dataItem) { |
|
38 | + if ($this->isImageValue($dataItem)) { |
|
39 | + $event->setImageUrl($this->getUrlForFileTitle($dataItem->getTitle())); |
|
40 | 40 | } |
41 | 41 | } |
42 | 42 | } |
@@ -49,45 +49,45 @@ discard block |
||
49 | 49 | return $events; |
50 | 50 | } |
51 | 51 | |
52 | - private function isImageValue( \SMWDataItem $dataItem ): bool { |
|
52 | + private function isImageValue(\SMWDataItem $dataItem): bool { |
|
53 | 53 | return $dataItem instanceof DIWikiPage |
54 | 54 | && $dataItem->getTitle() instanceof \Title |
55 | 55 | && $dataItem->getTitle()->getNamespace() === NS_FILE |
56 | 56 | && $dataItem->getTitle()->exists(); |
57 | 57 | } |
58 | 58 | |
59 | - public function getUrlForFileTitle( \Title $existingTitle ): string { |
|
60 | - return MediaWikiServices::getInstance()->getRepoGroup()->findFile( $existingTitle )->getURL(); |
|
59 | + public function getUrlForFileTitle(\Title $existingTitle): string { |
|
60 | + return MediaWikiServices::getInstance()->getRepoGroup()->findFile($existingTitle)->getURL(); |
|
61 | 61 | } |
62 | 62 | |
63 | - private function getDates( Subject $subject ): array { |
|
63 | + private function getDates(Subject $subject): array { |
|
64 | 64 | $startDate = null; |
65 | 65 | $endDate = null; |
66 | 66 | |
67 | - foreach ( $this->getPropertyValueCollectionsWithDates( $subject ) as $propertyValues ) { |
|
67 | + foreach ($this->getPropertyValueCollectionsWithDates($subject) as $propertyValues) { |
|
68 | 68 | $dataItem = $propertyValues->getDataItems()[0]; |
69 | 69 | |
70 | - if ( $dataItem instanceof SMWDITime ) { |
|
71 | - if ( $startDate === null ) { |
|
70 | + if ($dataItem instanceof SMWDITime) { |
|
71 | + if ($startDate === null) { |
|
72 | 72 | $startDate = $dataItem; |
73 | 73 | } |
74 | - elseif ( $endDate === null ) { |
|
74 | + elseif ($endDate === null) { |
|
75 | 75 | $endDate = $dataItem; |
76 | 76 | break; |
77 | 77 | } |
78 | 78 | } |
79 | 79 | } |
80 | 80 | |
81 | - return [ $startDate, $endDate ]; |
|
81 | + return [$startDate, $endDate]; |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
85 | 85 | * @return PropertyValueCollection[] |
86 | 86 | */ |
87 | - private function getPropertyValueCollectionsWithDates( Subject $subject ): array { |
|
87 | + private function getPropertyValueCollectionsWithDates(Subject $subject): array { |
|
88 | 88 | return array_filter( |
89 | 89 | $subject->getPropertyValueCollections()->toArray(), |
90 | - function( PropertyValueCollection $pvc ) { |
|
90 | + function(PropertyValueCollection $pvc) { |
|
91 | 91 | return $pvc->getPrintRequest()->getTypeID() === '_dat' |
92 | 92 | && $pvc->getDataItems() !== []; |
93 | 93 | } |
@@ -70,8 +70,7 @@ |
||
70 | 70 | if ( $dataItem instanceof SMWDITime ) { |
71 | 71 | if ( $startDate === null ) { |
72 | 72 | $startDate = $dataItem; |
73 | - } |
|
74 | - elseif ( $endDate === null ) { |
|
73 | + } elseif ( $endDate === null ) { |
|
75 | 74 | $endDate = $dataItem; |
76 | 75 | break; |
77 | 76 | } |