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\DIProperty; |
||
4 | use SMW\PropertyRegistry; |
||
5 | use SMW\ApplicationFactory; |
||
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 { |
||
0 ignored issues
–
show
|
|||
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; |
||
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...
|
|||
63 | |||
64 | if ( $this->getTitle()->getNamespace() === SMW_NS_PROPERTY ) { |
||
65 | $this->findBasePropertyToRedirectFor( $this->getTitle()->getText() ); |
||
66 | } |
||
67 | |||
68 | $this->initParameters(); |
||
69 | |||
70 | if ( !isset( $diff ) || !$diffOnly ) { |
||
71 | |||
72 | // MW 1.25+ |
||
73 | if ( method_exists( $wgOut, 'setIndicators' ) ) { |
||
74 | $wgOut->setIndicators( array( $this->getTopIndicator() ) ); |
||
75 | } |
||
76 | |||
77 | $wgOut->addHTML( $this->getIntroductoryText() ); |
||
78 | } |
||
79 | |||
80 | parent::view(); |
||
81 | |||
82 | // Copied from CategoryPage |
||
83 | $diff = $wgRequest->getVal( 'diff' ); |
||
84 | $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) ); |
||
85 | if ( !isset( $diff ) || !$diffOnly ) { |
||
86 | $this->showList(); |
||
87 | } |
||
88 | } |
||
89 | |||
90 | private function findBasePropertyToRedirectFor( $label ) { |
||
91 | |||
92 | $property = new DIProperty( |
||
93 | PropertyRegistry::getInstance()->findPropertyIdByLabel( $label ) |
||
94 | ); |
||
95 | |||
96 | if ( $property->getLabel() !== '' && $label !== $property->getLabel() ) { |
||
97 | $outputPage = $this->getContext()->getOutput(); |
||
98 | $outputPage->redirect( $property->getDiWikiPage()->getTitle()->getFullURL() ); |
||
99 | } |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * @since 2.4 |
||
104 | * |
||
105 | * @return string |
||
106 | */ |
||
107 | protected function getTopIndicator() { |
||
108 | return ''; |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * @since 2.4 |
||
113 | * |
||
114 | * @return string |
||
115 | */ |
||
116 | protected function getIntroductoryText() { |
||
117 | return ''; |
||
118 | } |
||
119 | |||
120 | /** |
||
121 | * @since 2.4 |
||
122 | */ |
||
123 | protected function getNavigationLinks( $msgKey, array $diWikiPages, $default = 50 ) { |
||
124 | global $wgRequest; |
||
125 | |||
126 | $mwCollaboratorFactory = ApplicationFactory::getInstance()->newMwCollaboratorFactory(); |
||
127 | |||
128 | $messageBuilder = $mwCollaboratorFactory->newMessageBuilder( |
||
129 | $this->getContext()->getLanguage() |
||
130 | ); |
||
131 | |||
132 | $title = $this->mTitle; |
||
133 | $title->setFragment( '#SMWResults' ); // Make navigation point to the result list. |
||
134 | |||
135 | $resultCount = count( $diWikiPages ); |
||
136 | $navigation = ''; |
||
137 | |||
138 | if ( $resultCount > 0 ) { |
||
139 | $navigation = $messageBuilder->prevNextToText( |
||
140 | $title, |
||
141 | $wgRequest->getVal( 'limit', $default ), |
||
142 | $wgRequest->getVal( 'offset', '0' ), |
||
143 | array(), |
||
144 | $resultCount < $wgRequest->getVal( 'limit', $default ) |
||
145 | ); |
||
146 | |||
147 | $navigation = Html::rawElement('div', array(), $navigation ); |
||
148 | } |
||
149 | |||
150 | return Html::rawElement( |
||
151 | 'p', |
||
152 | array(), |
||
153 | Html::element( 'span', array(), wfMessage( $msgKey, $resultCount )->parse() ) . '<br>' . |
||
154 | $navigation |
||
155 | ); |
||
156 | } |
||
157 | |||
158 | /** |
||
159 | * Main method for adding all additional HTML to the output stream. |
||
160 | */ |
||
161 | protected function showList() { |
||
162 | global $wgOut, $wgRequest; |
||
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...
|
|||
163 | |||
164 | |||
165 | $this->from = $wgRequest->getVal( 'from', '' ); |
||
166 | $this->until = $wgRequest->getVal( 'until', '' ); |
||
167 | |||
168 | if ( $this->initParameters() ) { |
||
169 | $wgOut->addHTML( $this->getHtml() ); |
||
170 | SMWOutputs::commitToOutputPage( $wgOut ); |
||
171 | } |
||
172 | |||
173 | } |
||
174 | |||
175 | /** |
||
176 | * Initialise some parameters that might be changed by subclasses |
||
177 | * (e.g. $limit). Method can be overwritten in this case. |
||
178 | * If the method returns false, nothing will be printed besides |
||
179 | * the original article. |
||
180 | * |
||
181 | * @return true |
||
182 | */ |
||
183 | protected function initParameters() { |
||
184 | $this->limit = 20; |
||
185 | return true; |
||
186 | } |
||
187 | |||
188 | /** |
||
189 | * Returns the HTML which is added to $wgOut after the article text. |
||
190 | * |
||
191 | * @return string |
||
192 | */ |
||
193 | protected abstract function getHtml(); |
||
0 ignored issues
–
show
|
|||
194 | |||
195 | /** |
||
196 | * Like Article's getTitle(), but returning a suitable SMWDIWikiPage. |
||
197 | * |
||
198 | * @since 1.6 |
||
199 | * |
||
200 | * @return SMWDIWikiPage |
||
201 | */ |
||
202 | protected function getDataItem() { |
||
203 | return SMWDIWikiPage::newFromTitle( $this->getTitle() ); |
||
204 | } |
||
205 | |||
206 | } |
||
207 |
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.