1 | <?php |
||
13 | class MapsLayerPage extends Article { |
||
14 | |||
15 | protected $usageTitles = null; |
||
16 | |||
17 | function __construct( Title $title, $oldId = null ) { |
||
18 | parent::__construct( $title, $oldId ); |
||
19 | } |
||
20 | |||
21 | /** |
||
22 | * Designed similar to CategoryPage. |
||
23 | * |
||
24 | * @see Article::view |
||
25 | * |
||
26 | * @since 3.0 |
||
27 | */ |
||
28 | public function view() { |
||
29 | global $wgRequest, $wgUser; |
||
30 | |||
31 | $diff = $wgRequest->getVal( 'diff' ); |
||
32 | $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) ); |
||
33 | |||
34 | if( isset( $diff ) && $diffOnly ) { |
||
35 | return parent::view(); |
||
36 | } |
||
37 | |||
38 | if( !Hooks::run( 'MapsLayerPageView', [ &$this ] ) ) { |
||
39 | return; |
||
40 | } |
||
41 | |||
42 | if( Maps_NS_LAYER == $this->mTitle->getNamespace() ) { |
||
43 | $this->openShowLayer(); |
||
44 | } |
||
45 | |||
46 | parent::view(); |
||
47 | |||
48 | if( Maps_NS_LAYER == $this->mTitle->getNamespace() ) { |
||
49 | $this->closeShowLayer(); |
||
50 | } |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * Function called before page rendering. |
||
55 | * |
||
56 | * @since 3.0 |
||
57 | */ |
||
58 | protected function openShowLayer() { |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * Function called at the end of page rendering. |
||
63 | * |
||
64 | * @since 3.0 |
||
65 | */ |
||
66 | protected function closeShowLayer() { |
||
67 | $this->renderUsage(); |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * Renders the category-page like view which shows the usage of this |
||
72 | * layer page in other pages. |
||
73 | * |
||
74 | * @since 3.0 |
||
75 | */ |
||
76 | public function renderUsage() { |
||
77 | global $wgOut; |
||
78 | $out = ''; |
||
79 | |||
80 | $titles = $this->getUsageTitles(); |
||
81 | |||
82 | $viewer = new CategoryViewer( $this->mTitle, $this->getContext() ); |
||
83 | $viewer->limit = 9999; // just overwrite the default limit of pages displayed in a normal category |
||
84 | |||
85 | // now add apges in sorted order to category viewer: |
||
86 | foreach( $titles as $title ) { |
||
87 | $viewer->addPage( $title, $title->getPrefixedText(), null ); |
||
88 | } |
||
89 | |||
90 | //$wgOut->addHTML( $viewer->formatList( $viewer->articles, '' ) ); |
||
91 | $out = "<div id=\"mw-pages\">\n"; |
||
92 | $out .= '<h2>' . wfMessage( 'maps-layerpage-usage', $this->mTitle->getText() )->text() . "</h2>\n"; |
||
93 | |||
94 | if( !empty( $viewer->articles ) ) { |
||
95 | $out .= $viewer->formatList( $viewer->articles, $viewer->articles_start_char ); |
||
96 | } else { |
||
97 | $out .= wfMessage( 'maps-layerpage-nousage' )->text(); |
||
98 | } |
||
99 | $out .= "\n</div>"; |
||
100 | |||
101 | $wgOut->addHTML( $out ); |
||
102 | } |
||
103 | |||
104 | /** |
||
105 | * returns all Titles using this layer page |
||
106 | * |
||
107 | * @since 3.0 |
||
108 | * |
||
109 | * @return Array |
||
110 | */ |
||
111 | public function getUsageTitles() { |
||
142 | |||
143 | /** |
||
144 | * Returns if the layer page has any layer defined which has a definition that is 'ok', |
||
145 | * meaning, the layer can be used in a map. |
||
146 | * |
||
147 | * @since 3.0 |
||
148 | * |
||
149 | * @param string $name if set, only for the layer definition with this name will be searched. |
||
150 | * @param string $service if set, only layers supporthing this service will be taken in account. |
||
151 | * |
||
152 | * @return boolean |
||
153 | */ |
||
154 | public function hasUsableLayer( $name = null, $service = null ) { |
||
179 | } |
||
180 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.