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\DIProperty; |
||
5 | use SMW\PropertyRegistry; |
||
6 | |||
7 | /** |
||
8 | * Abstract subclass of MediaWiki's Article that handles the common tasks of |
||
9 | * article pages for Concept and Property pages. This is mainly parameter |
||
10 | * handling and some very basic output control. |
||
11 | * |
||
12 | * @ingroup SMW |
||
13 | * |
||
14 | * @author Nikolas Iwan |
||
15 | * @author Markus Krötzsch |
||
16 | * @author Jeroen De Dauw |
||
17 | */ |
||
18 | abstract class SMWOrderedListPage extends Article { |
||
19 | |||
20 | /** |
||
21 | * Limit for results per page. |
||
22 | * |
||
23 | * @var integer |
||
24 | */ |
||
25 | protected $limit; |
||
26 | |||
27 | /** |
||
28 | * Start string: print $limit results from here. |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | protected $from; |
||
33 | |||
34 | /** |
||
35 | * End string: print $limit results strictly before this article. |
||
36 | * |
||
37 | * @var string |
||
38 | */ |
||
39 | protected $until; |
||
40 | |||
41 | /** |
||
42 | * Cache for the current skin, obtained from $wgUser. |
||
43 | * |
||
44 | * @var Skin |
||
45 | */ |
||
46 | protected $skin; |
||
47 | |||
48 | /** |
||
49 | * Property that the displayed values are for, if any. |
||
50 | * |
||
51 | * @since 1.6 |
||
52 | * |
||
53 | * @var SMWDIProperty |
||
54 | */ |
||
55 | protected $mProperty = null; |
||
56 | |||
57 | /** |
||
58 | * Overwrite view() from Article.php to add additional HTML to the |
||
59 | * output. |
||
60 | */ |
||
61 | public function view() { |
||
62 | global $wgRequest, $wgUser, $wgOut; |
||
63 | |||
64 | if ( !ApplicationFactory::getInstance()->getSettings()->get( 'smwgSemanticsEnabled' ) ) { |
||
65 | $wgOut->setPageTitle( $this->getTitle()->getPrefixedText() ); |
||
66 | $wgOut->addHTML( wfMessage( 'smw-semantics-not-enabled' )->text() ); |
||
67 | return; |
||
68 | } |
||
69 | |||
70 | if ( $this->getTitle()->getNamespace() === SMW_NS_PROPERTY ) { |
||
71 | $this->findBasePropertyToRedirectFor( $this->getTitle()->getText() ); |
||
72 | } |
||
73 | |||
74 | $this->initParameters(); |
||
75 | |||
76 | if ( !isset( $diff ) || !$diffOnly ) { |
||
0 ignored issues
–
show
The variable
$diffOnly seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?
This error can happen if you refactor code and forget to move the variable initialization. Let’s take a look at a simple example: function someFunction() {
$x = 5;
echo $x;
}
The above code is perfectly fine. Now imagine that we re-order the statements: function someFunction() {
echo $x;
$x = 5;
}
In that case,
Loading history...
|
|||
77 | |||
78 | // MW 1.25+ |
||
79 | if ( method_exists( $wgOut, 'setIndicators' ) ) { |
||
80 | $wgOut->setIndicators( array( $this->getTopIndicator() ) ); |
||
81 | } |
||
82 | |||
83 | $wgOut->addHTML( $this->getIntroductoryText() ); |
||
84 | } |
||
85 | |||
86 | parent::view(); |
||
87 | |||
88 | // Copied from CategoryPage |
||
89 | $diff = $wgRequest->getVal( 'diff' ); |
||
90 | $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) ); |
||
91 | if ( !isset( $diff ) || !$diffOnly ) { |
||
92 | $this->showList(); |
||
93 | } |
||
94 | } |
||
95 | |||
96 | private function findBasePropertyToRedirectFor( $label ) { |
||
97 | |||
98 | $property = new DIProperty( |
||
99 | PropertyRegistry::getInstance()->findPropertyIdByLabel( $label ) |
||
100 | ); |
||
101 | |||
102 | // Ensure to redirect to `Property:Modification date` and not using |
||
103 | // a possible user contextualized version such as `Property:Date de modification` |
||
104 | $canonicalLabel = $property->getCanonicalLabel(); |
||
105 | |||
106 | if ( $canonicalLabel !== '' && $label !== $canonicalLabel ) { |
||
107 | $outputPage = $this->getContext()->getOutput(); |
||
108 | $outputPage->redirect( $property->getCanonicalDiWikiPage()->getTitle()->getFullURL() ); |
||
109 | } |
||
110 | } |
||
111 | |||
112 | /** |
||
113 | * @since 2.4 |
||
114 | * |
||
115 | * @return string |
||
116 | */ |
||
117 | protected function getTopIndicator() { |
||
118 | return ''; |
||
119 | } |
||
120 | |||
121 | /** |
||
122 | * @since 2.4 |
||
123 | * |
||
124 | * @return string |
||
125 | */ |
||
126 | protected function getIntroductoryText() { |
||
127 | return ''; |
||
128 | } |
||
129 | |||
130 | /** |
||
131 | * @since 2.4 |
||
132 | */ |
||
133 | protected function getNavigationLinks( $msgKey, array $diWikiPages, $default = 50 ) { |
||
134 | global $wgRequest; |
||
135 | |||
136 | $mwCollaboratorFactory = ApplicationFactory::getInstance()->newMwCollaboratorFactory(); |
||
137 | |||
138 | $messageBuilder = $mwCollaboratorFactory->newMessageBuilder( |
||
139 | $this->getContext()->getLanguage() |
||
140 | ); |
||
141 | |||
142 | $title = $this->mTitle; |
||
143 | $title->setFragment( '#SMWResults' ); // Make navigation point to the result list. |
||
144 | |||
145 | $resultCount = count( $diWikiPages ); |
||
146 | $navigation = ''; |
||
147 | |||
148 | if ( $resultCount > 0 ) { |
||
149 | $navigation = $messageBuilder->prevNextToText( |
||
150 | $title, |
||
151 | $wgRequest->getVal( 'limit', $default ), |
||
152 | $wgRequest->getVal( 'offset', '0' ), |
||
153 | array( |
||
154 | 'value' => $wgRequest->getVal( 'value', '' ), |
||
155 | 'from' => $wgRequest->getVal( 'from', '' ), |
||
156 | 'until' => $wgRequest->getVal( 'until', '' ) |
||
157 | ), |
||
158 | $resultCount < $wgRequest->getVal( 'limit', $default ) |
||
159 | ); |
||
160 | |||
161 | $navigation = Html::rawElement('div', array(), $navigation ); |
||
162 | } |
||
163 | |||
164 | return Html::rawElement( |
||
165 | 'p', |
||
166 | array(), |
||
167 | Html::element( 'span', array(), wfMessage( $msgKey, $resultCount )->parse() ) . '<br>' . |
||
168 | $navigation |
||
169 | ); |
||
170 | } |
||
171 | |||
172 | /** |
||
173 | * Main method for adding all additional HTML to the output stream. |
||
174 | */ |
||
175 | protected function showList() { |
||
176 | global $wgOut, $wgRequest; |
||
177 | |||
178 | |||
179 | $this->from = $wgRequest->getVal( 'from', '' ); |
||
180 | $this->until = $wgRequest->getVal( 'until', '' ); |
||
181 | |||
182 | if ( $this->initParameters() ) { |
||
183 | $wgOut->addHTML( $this->getHtml() ); |
||
184 | SMWOutputs::commitToOutputPage( $wgOut ); |
||
185 | } |
||
186 | |||
187 | } |
||
188 | |||
189 | /** |
||
190 | * Initialise some parameters that might be changed by subclasses |
||
191 | * (e.g. $limit). Method can be overwritten in this case. |
||
192 | * If the method returns false, nothing will be printed besides |
||
193 | * the original article. |
||
194 | * |
||
195 | * @return true |
||
196 | */ |
||
197 | protected function initParameters() { |
||
198 | $this->limit = 20; |
||
199 | return true; |
||
200 | } |
||
201 | |||
202 | /** |
||
203 | * Returns the HTML which is added to $wgOut after the article text. |
||
204 | * |
||
205 | * @return string |
||
206 | */ |
||
207 | protected abstract function getHtml(); |
||
208 | |||
209 | /** |
||
210 | * Like Article's getTitle(), but returning a suitable SMWDIWikiPage. |
||
211 | * |
||
212 | * @since 1.6 |
||
213 | * |
||
214 | * @return SMWDIWikiPage |
||
215 | */ |
||
216 | protected function getDataItem() { |
||
217 | return SMWDIWikiPage::newFromTitle( $this->getTitle() ); |
||
218 | } |
||
219 | |||
220 | } |
||
221 |
This check marks calls to
isset(...)
orempty(...)
that are found before the variable itself is defined. These will always have the same result.This is likely the result of code being shifted around. Consider removing these calls.