1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\MediaWiki\Specials\PropertyLabelSimilarity; |
4
|
|
|
|
5
|
|
|
use SMW\MediaWiki\Renderer\HtmlFormRenderer; |
6
|
|
|
use SMW\Message; |
7
|
|
|
use SMW\RequestOptions; |
8
|
|
|
use SMW\SQLStore\Lookup\PropertyLabelSimilarityLookup; |
9
|
|
|
use Html; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @license GNU GPL v2+ |
13
|
|
|
* @since 2.5 |
14
|
|
|
* |
15
|
|
|
* @author mwjames |
16
|
|
|
*/ |
17
|
|
|
class ContentsBuilder { |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var PropertyLabelSimilarityLookup |
21
|
|
|
*/ |
22
|
|
|
private $propertyLabelSimilarityLookup; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var HtmlFormRenderer |
26
|
|
|
*/ |
27
|
|
|
private $htmlFormRenderer; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @since 2.5 |
31
|
|
|
* |
32
|
|
|
* @param PropertyLabelSimilarityLookup $propertyLabelSimilarityLookup |
33
|
|
|
* @param HtmlFormRenderer $htmlFormRenderer |
34
|
|
|
*/ |
35
|
|
|
public function __construct( PropertyLabelSimilarityLookup $propertyLabelSimilarityLookup, HtmlFormRenderer $htmlFormRenderer ) { |
36
|
|
|
$this->propertyLabelSimilarityLookup = $propertyLabelSimilarityLookup; |
37
|
|
|
$this->htmlFormRenderer = $htmlFormRenderer; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @since 2.5 |
42
|
|
|
* |
43
|
|
|
* @param RequestOptions $requestOption |
|
|
|
|
44
|
|
|
*/ |
45
|
|
|
public function getHtml( RequestOptions $requestOptions ) { |
46
|
|
|
|
47
|
|
|
$threshold = 90; |
48
|
|
|
$type = ''; |
49
|
|
|
|
50
|
|
|
foreach ( $requestOptions->getExtraConditions() as $extraCondition ) { |
51
|
|
|
if ( isset( $extraCondition['type'] ) ) { |
52
|
|
|
$type = $extraCondition['type']; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
if ( isset( $extraCondition['threshold'] ) ) { |
56
|
|
|
$threshold = $extraCondition['threshold']; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$this->propertyLabelSimilarityLookup->setThreshold( |
61
|
|
|
$threshold |
62
|
|
|
); |
63
|
|
|
|
64
|
|
|
$result = $this->propertyLabelSimilarityLookup->compareAndFindLabels( |
65
|
|
|
$requestOptions |
66
|
|
|
); |
67
|
|
|
|
68
|
|
|
$count = $this->propertyLabelSimilarityLookup->getLookupCount(); |
69
|
|
|
|
70
|
|
|
$html = $this->getForm( |
71
|
|
|
$requestOptions->getLimit(), |
72
|
|
|
$requestOptions->getOffset(), |
73
|
|
|
$count, |
74
|
|
|
count( $result ), |
75
|
|
|
$threshold, |
76
|
|
|
$type |
77
|
|
|
); |
78
|
|
|
|
79
|
|
|
if ( $result !== array() ) { |
80
|
|
|
$html .= '<pre>' . json_encode( $result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ) . '</pre>'; |
81
|
|
|
} else { |
82
|
|
|
$html .= $this->getMessageAsString( 'smw-property-label-similarity-noresult' ); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
return $html; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
private function getForm( $limit, $offset, $count, $resultCount, $threshold, $type ) { |
89
|
|
|
|
90
|
|
|
$exemptionProperty = $this->propertyLabelSimilarityLookup->getExemptionProperty(); |
91
|
|
|
|
92
|
|
|
$html = $this->getMessageAsString( |
93
|
|
|
array( 'smw-property-label-similarity-docu', $exemptionProperty ), |
94
|
|
|
Message::PARSE |
95
|
|
|
); |
96
|
|
|
|
97
|
|
|
$html .= $this->htmlFormRenderer |
98
|
|
|
->setName( 'smw-property-label-similarity-title' ) |
99
|
|
|
->setMethod( 'get' ) |
100
|
|
|
->withFieldset() |
101
|
|
|
->addPaging( |
102
|
|
|
$limit, |
103
|
|
|
$offset, |
104
|
|
|
$count, |
105
|
|
|
$resultCount ) |
106
|
|
|
->addHiddenField( 'limit', $limit ) |
107
|
|
|
->addHiddenField( 'offset', $offset ) |
108
|
|
|
->addInputField( |
109
|
|
|
$this->getMessageAsString( 'smw-property-label-similarity-threshold' ), |
110
|
|
|
'threshold', |
111
|
|
|
$threshold, |
112
|
|
|
'', |
113
|
|
|
5 |
114
|
|
|
) |
115
|
|
|
->addNonBreakingSpace() |
116
|
|
|
->addCheckbox( |
117
|
|
|
$this->getMessageAsString( 'smw-property-label-similarity-type' ), |
118
|
|
|
'type', |
119
|
|
|
'yes', |
120
|
|
|
$type === 'yes', |
121
|
|
|
null, |
122
|
|
|
array( |
123
|
|
|
'style' => 'float:right' |
124
|
|
|
) |
125
|
|
|
) |
126
|
|
|
->addQueryParameter( 'type', $type ) |
127
|
|
|
->addSubmitButton( $this->getMessageAsString( 'allpagessubmit' ) ) |
128
|
|
|
->getForm(); |
129
|
|
|
|
130
|
|
|
return Html::rawElement( 'div', array( 'class' => 'plainlinks'), $html ) . Html::element( 'p', array(), '' ); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
private function getMessageAsString( $parameters, $type = Message::TEXT ) { |
134
|
|
|
return Message::get( $parameters, $type, Message::USER_LANGUAGE ); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
} |
138
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$ireland
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was changed, but the annotation was not.