These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | use SMW\ApplicationFactory; |
||
4 | use SMW\DataValueFactory; |
||
5 | use SMW\RequestOptions; |
||
6 | use SMW\StringCondition; |
||
7 | use SMW\Localizer; |
||
8 | |||
9 | /** |
||
10 | * Implementation of MediaWiki's Article that shows additional information on |
||
11 | * property pages. Very similar to CategoryPage, but with different printout |
||
12 | * that also displays values for each subject with the given property. |
||
13 | * |
||
14 | * @ingroup SMW |
||
15 | * |
||
16 | * @author Markus Krötzsch |
||
17 | */ |
||
18 | class SMWPropertyPage extends SMWOrderedListPage { |
||
0 ignored issues
–
show
|
|||
19 | |||
20 | /** |
||
21 | * @see SMWOrderedListPage::initParameters() |
||
22 | * @note We use a smaller limit here; property pages might become large. |
||
23 | */ |
||
24 | protected function initParameters() { |
||
25 | global $smwgPropertyPagingLimit; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
Loading history...
|
|||
26 | $this->limit = $smwgPropertyPagingLimit; |
||
27 | $this->mProperty = SMW\DIProperty::newFromUserLabel( $this->mTitle->getText() ); |
||
28 | $this->store = ApplicationFactory::getInstance()->getStore(); |
||
29 | return true; |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * Returns the HTML which is added to $wgOut after the article text. |
||
34 | * |
||
35 | * @return string |
||
36 | */ |
||
37 | protected function getHtml() { |
||
38 | |||
39 | if ( !$this->store->getRedirectTarget( $this->mProperty )->equals( $this->mProperty ) ) { |
||
40 | return ''; |
||
41 | } |
||
42 | |||
43 | $list = $this->getSubpropertyList() . $this->getPropertyValueList(); |
||
44 | $result = ( $list !== '' ? Html::element( 'div', array( 'id' => 'smwfootbr' ) ) . $list : '' ); |
||
45 | |||
46 | return $result; |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * Returns an introductory text for a predefined property |
||
51 | * |
||
52 | * @note In order to enable a more detailed description for a specific |
||
53 | * predefined property a concatenated message key can be used (e.g |
||
54 | * 'smw-pa-property-predefined' + <internal property key> => '_asksi' ) |
||
55 | * |
||
56 | * @since 1.9 |
||
57 | * |
||
58 | * @return string |
||
59 | */ |
||
60 | protected function getIntroductoryText() { |
||
61 | $propertyName = htmlspecialchars( $this->mTitle->getText() ); |
||
62 | $message = ''; |
||
63 | |||
64 | if ( !$this->mProperty->isUserDefined() ) { |
||
65 | $propertyKey = 'smw-pa-property-predefined' . strtolower( $this->mProperty->getKey() ); |
||
66 | $messageKey = wfMessage( $propertyKey )->exists() ? $propertyKey : 'smw-pa-property-predefined-default'; |
||
67 | $message .= wfMessage( $messageKey, $propertyName )->parse(); |
||
68 | $message .= wfMessage( 'smw-pa-property-predefined-long' . strtolower( $this->mProperty->getKey() ) )->exists() ? ' ' . wfMessage( 'smw-pa-property-predefined-long' . strtolower( $this->mProperty->getKey() ) )->parse() : ''; |
||
69 | $message .= ' ' . wfMessage( 'smw-pa-property-predefined-common' )->parse(); |
||
70 | } |
||
71 | |||
72 | return Html::rawElement( 'div', array( 'class' => 'smw-property-predefined-intro' ), $message ); |
||
73 | } |
||
74 | |||
75 | protected function getTopIndicator() { |
||
76 | |||
77 | $propertyName = htmlspecialchars( $this->mTitle->getText() ); |
||
78 | |||
79 | $usageCount = ''; |
||
80 | $requestOptions = new RequestOptions(); |
||
81 | $requestOptions->limit = 1; |
||
82 | $requestOptions->addStringCondition( $propertyName, StringCondition::STRCOND_PRE ); |
||
83 | $cachedLookupList = $this->store->getPropertiesSpecial( $requestOptions ); |
||
84 | $usageList = $cachedLookupList->fetchList(); |
||
85 | |||
86 | if ( $usageList && $usageList !== array() ) { |
||
87 | $usage = end( $usageList ); |
||
88 | $usageCount = Html::rawElement( |
||
89 | 'div' , array( |
||
90 | 'title' => $this->getContext()->getLanguage()->timeanddate( $cachedLookupList->getTimestamp() ), |
||
91 | 'class' => 'smw-page-indicator usage-count' ), |
||
92 | $usage[1] |
||
93 | ); |
||
94 | } |
||
95 | |||
96 | return Html::rawElement( 'div', array(), Html::rawElement( |
||
97 | 'div', array( |
||
98 | 'class' => 'smw-page-indicator property-type', |
||
99 | 'title' => wfMessage( 'smw-page-indicator-type-info', $this->mProperty->isUserDefined() )->parse() |
||
100 | ), ( $this->mProperty->isUserDefined() ? 'U' : 'S' ) |
||
101 | ) . $usageCount ); |
||
102 | } |
||
103 | |||
104 | /** |
||
105 | * Get the HTML for displaying subproperties of this property. This list |
||
106 | * is usually short and we implement no additional navigation. |
||
107 | * |
||
108 | * @return string |
||
109 | */ |
||
110 | protected function getSubpropertyList() { |
||
111 | |||
112 | $options = new SMWRequestOptions(); |
||
113 | $options->sort = true; |
||
114 | $options->ascending = true; |
||
115 | $subproperties = $this->store->getPropertySubjects( new SMW\DIProperty( '_SUBP' ), $this->getDataItem(), $options ); |
||
116 | |||
117 | $result = ''; |
||
118 | |||
119 | $resultCount = count( $subproperties ); |
||
120 | if ( $resultCount > 0 ) { |
||
121 | $titleText = htmlspecialchars( $this->mTitle->getText() ); |
||
122 | $result .= "<div id=\"mw-subcategories\">\n<h2>" . wfMessage( 'smw_subproperty_header', $titleText )->text() . "</h2>\n<p>"; |
||
123 | |||
124 | if ( !$this->mProperty->isUserDefined() ) { |
||
125 | $result .= wfMessage( 'smw_isspecprop' )->text() . ' '; |
||
126 | } |
||
127 | |||
128 | $result .= wfMessage( 'smw_subpropertyarticlecount' )->numParams( $resultCount )->text() . "</p>\n"; |
||
129 | |||
130 | if ( $resultCount < 6 ) { |
||
131 | $result .= SMWPageLister::getShortList( 0, $resultCount, $subproperties, null ); |
||
132 | } else { |
||
133 | $result .= SMWPageLister::getColumnList( 0, $resultCount, $subproperties, null ); |
||
134 | } |
||
135 | |||
136 | $result .= "\n</div>"; |
||
137 | } |
||
138 | |||
139 | return $result; |
||
140 | } |
||
141 | |||
142 | /** |
||
143 | * Get the HTML for displaying values of this property, based on the |
||
144 | * current from/until and limit settings. |
||
145 | * |
||
146 | * @return string |
||
147 | */ |
||
148 | protected function getPropertyValueList() { |
||
149 | global $smwgPropertyPagingLimit, $wgRequest; |
||
150 | |||
151 | if ( $this->limit > 0 ) { // limit==0: configuration setting to disable this completely |
||
152 | $options = SMWPageLister::getRequestOptions( $this->limit, $this->from, $this->until ); |
||
153 | |||
154 | $options->limit = $wgRequest->getVal( 'limit', $smwgPropertyPagingLimit ); |
||
155 | $options->offset = $wgRequest->getVal( 'offset', '0' ); |
||
156 | |||
157 | $diWikiPages = $this->store->getAllPropertySubjects( $this->mProperty, $options ); |
||
158 | |||
159 | if ( !$options->ascending ) { |
||
160 | $diWikiPages = array_reverse( $diWikiPages ); |
||
161 | } |
||
162 | } else { |
||
163 | return ''; |
||
164 | } |
||
165 | |||
166 | $result = ''; |
||
167 | |||
168 | if ( count( $diWikiPages ) > 0 ) { |
||
169 | $pageLister = new SMWPageLister( $diWikiPages, null, $this->limit, $this->from, $this->until ); |
||
170 | |||
171 | $this->mTitle->setFragment( '#SMWResults' ); // Make navigation point to the result list. |
||
172 | $navigation = $pageLister->getNavigationLinks( $this->mTitle ); |
||
0 ignored issues
–
show
$navigation is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the
Loading history...
|
|||
173 | |||
174 | $dvWikiPage = DataValueFactory::getInstance()->newDataItemValue( |
||
175 | $this->mProperty |
||
176 | ); |
||
177 | |||
178 | // Allow the DV formatter to access a specific language code |
||
179 | $dvWikiPage->setOption( |
||
180 | 'user.language', |
||
181 | Localizer::getInstance()->getUserLanguage()->getCode() |
||
182 | ); |
||
183 | |||
184 | $titleText = htmlspecialchars( $dvWikiPage->getWikiValue() ); |
||
185 | $resultNumber = min( $this->limit, count( $diWikiPages ) ); |
||
0 ignored issues
–
show
$resultNumber is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the
Loading history...
|
|||
186 | |||
187 | $result .= "<a name=\"SMWResults\"></a><div id=\"mw-pages\">\n" . |
||
188 | '<h2>' . wfMessage( 'smw_attribute_header', $titleText )->text() . "</h2>\n<p>"; |
||
189 | |||
190 | $result .= $this->getNavigationLinks( 'smw_attributearticlecount', $diWikiPages, $smwgPropertyPagingLimit ) . |
||
191 | $this->subjectObjectList( $diWikiPages ) . "\n</div>"; |
||
192 | } |
||
193 | |||
194 | return $result; |
||
195 | } |
||
196 | |||
197 | /** |
||
198 | * Format $diWikiPages chunked by letter in a table that shows subject |
||
199 | * articles in one column and object articles/values in the other one. |
||
200 | * |
||
201 | * @param $diWikiPages array |
||
202 | * @return string |
||
203 | */ |
||
204 | protected function subjectObjectList( array $diWikiPages ) { |
||
205 | global $wgContLang, $smwgMaxPropertyValues; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
Loading history...
|
|||
206 | |||
207 | $ac = count( $diWikiPages ); |
||
208 | |||
209 | if ( $ac > $this->limit ) { |
||
210 | if ( $this->until !== '' ) { |
||
211 | $start = 1; |
||
212 | } else { |
||
213 | $start = 0; |
||
214 | $ac = $ac - 1; |
||
215 | } |
||
216 | } else { |
||
217 | $start = 0; |
||
218 | } |
||
219 | |||
220 | $r = '<table class="property-page-results" style="width: 100%;" cellspacing="0" cellpadding="0">'; |
||
221 | $prev_start_char = 'None'; |
||
222 | |||
223 | for ( $index = $start; $index < $ac; $index++ ) { |
||
224 | $diWikiPage = $diWikiPages[$index]; |
||
225 | $dvWikiPage = DataValueFactory::getInstance()->newDataItemValue( $diWikiPage, null ); |
||
226 | |||
227 | $sortkey = $this->store->getWikiPageSortKey( $diWikiPage ); |
||
228 | $start_char = $wgContLang->convert( $wgContLang->firstChar( $sortkey ) ); |
||
229 | |||
230 | // Header for index letters |
||
231 | if ( $start_char != $prev_start_char ) { |
||
232 | $r .= '<tr class="header-row" ><th class="smwpropname"><div class="header-title">' . htmlspecialchars( $start_char ) . "</div></th><th></th></tr>\n"; |
||
233 | $prev_start_char = $start_char; |
||
234 | } |
||
235 | |||
236 | // Property name |
||
237 | $searchlink = SMWInfolink::newBrowsingLink( '+', $dvWikiPage->getWikiValue() ); |
||
238 | $r .= '<tr class="value-row" ><td class="smwpropname">' . $dvWikiPage->getShortHTMLText( smwfGetLinker() ) . |
||
239 | ' ' . $searchlink->getHTML( smwfGetLinker() ) . '</td><td class="smwprops">'; |
||
240 | |||
241 | // Property values |
||
242 | $ropts = new SMWRequestOptions(); |
||
243 | $ropts->limit = $smwgMaxPropertyValues + 1; |
||
244 | $values = $this->store->getPropertyValues( $diWikiPage, $this->mProperty, $ropts ); |
||
245 | $i = 0; |
||
246 | |||
247 | foreach ( $values as $di ) { |
||
248 | if ( $i != 0 ) { |
||
249 | $r .= ', '; |
||
250 | } |
||
251 | $i++; |
||
252 | |||
253 | if ( $i < $smwgMaxPropertyValues + 1 ) { |
||
254 | $dv = DataValueFactory::getInstance()->newDataItemValue( $di, $this->mProperty ); |
||
255 | |||
256 | $dv->setOutputFormat( 'LOCL' ); |
||
257 | |||
258 | $r .= $dv->getShortHTMLText( smwfGetLinker() ) . $dv->getInfolinkText( SMW_OUTPUT_HTML, smwfGetLinker() ); |
||
259 | } else { |
||
260 | $searchlink = SMWInfolink::newInversePropertySearchLink( '…', $dvWikiPage->getWikiValue(), $this->mTitle->getText() ); |
||
261 | $r .= $searchlink->getHTML( smwfGetLinker() ); |
||
262 | } |
||
263 | } |
||
264 | |||
265 | $r .= "</td></tr>\n"; |
||
266 | } |
||
267 | |||
268 | $r .= '</table>'; |
||
269 | |||
270 | return $r; |
||
271 | } |
||
272 | |||
273 | } |
||
274 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.