Index: branches/RL2/extensions/Gadgets/SpecialGadgets.php |
— | — | @@ -1,176 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * SpecialPage for Gadget manager |
5 | | - * |
6 | | - * @file |
7 | | - * @ingroup Extensions |
8 | | - */ |
9 | | - |
10 | | -class SpecialGadgetManager extends SpecialPage { |
11 | | - |
12 | | - public function __construct() { |
13 | | - parent::__construct( 'GadgetManager' ); |
14 | | - } |
15 | | - |
16 | | - /** |
17 | | - * @param $par String: Optionally the id of the gadget to show info for. |
18 | | - */ |
19 | | - public function execute( $par ) { |
20 | | - $out = $this->getOutput(); |
21 | | - |
22 | | - $this->setHeaders(); |
23 | | - $out->setPagetitle( wfMsg( 'gadgetmanager-title' ) ); |
24 | | - $out->addModuleStyles( 'ext.gadgets.gadgetmanager.prejs' ); |
25 | | - |
26 | | - // Only load ajax editor if user is allowed to edit |
27 | | - if ( $this->getUser()->isAllowed( 'gadgets-definition-edit' ) ) { |
28 | | - $out->addModules( 'ext.gadgets.gadgetmanager.ui' ); |
29 | | - } |
30 | | - |
31 | | - // Determine view |
32 | | - if ( is_string( $par ) && $par !== '' ) { |
33 | | - $html = $this->generateGadgetView( $par ); |
34 | | - } else { |
35 | | - $html = $this->generateOverview(); |
36 | | - } |
37 | | - |
38 | | - $out->addHtml( $html ); |
39 | | - } |
40 | | - |
41 | | - /** |
42 | | - * @return String: HTML |
43 | | - */ |
44 | | - private function generateOverview() { |
45 | | - global $wgGadgetEnableSharing; |
46 | | - |
47 | | - $repo = LocalGadgetRepo::singleton(); |
48 | | - $gadgetsByCategory = $repo->getGadgetsByCategory(); |
49 | | - |
50 | | - // If there there are no gadgets at all, exit early. |
51 | | - if ( !count( $gadgetsByCategory ) ) { |
52 | | - $noGadgetsMsgHtml = Html::element( 'p', |
53 | | - array( |
54 | | - 'class' => 'mw-gadgetmanager-nogadgets' |
55 | | - ), wfMessage( 'gadgetmanager-nogadgets' )->plain() |
56 | | - ); |
57 | | - $this->getOutput()->addHtml( $noGadgetsMsgHtml ); |
58 | | - return; |
59 | | - } |
60 | | - // There is atleast one gadget, let's get started. |
61 | | - $this->getOutput()->addWikiMsg( 'gadgetmanager-pagetext', SpecialPage::getTitleFor( 'Recentchanges' )->getFullURL('namespace=' . NS_GADGET_DEFINITION ) ); |
62 | | - $html = ''; |
63 | | - |
64 | | - // Sort categories alphabetically |
65 | | - // @todo Sort causes the key "''" to be at the top, it should be on the bottom. |
66 | | - ksort( $gadgetsByCategory ); |
67 | | - |
68 | | - foreach ( $gadgetsByCategory as $category => $gadgets ) { |
69 | | - // Avoid broken or empty headings. Fallback to a special message |
70 | | - // for uncategorized gadgets (e.g. gadgets with category '' ). |
71 | | - if ( $category !== '' ) { |
72 | | - $categoryTitle = $repo->getCategoryTitle( $category ); |
73 | | - } else { |
74 | | - $categoryTitle = wfMessage( 'gadgetmanager-uncategorized' )->plain(); |
75 | | - } |
76 | | - |
77 | | - // Category header |
78 | | - $html .= Html::element( 'h2', |
79 | | - array( 'class' => 'mw-gadgetmanager-category' ), |
80 | | - $categoryTitle |
81 | | - ); |
82 | | - |
83 | | - // Start per-category gadgets table |
84 | | - $html .= '<table class="mw-gadgetmanager-gadgets mw-datatable sortable"><thead><tr>'; |
85 | | - $html .= |
86 | | - '<th>' . wfMessage( 'gadgetmanager-tablehead-title' )->escaped() |
87 | | - . '</th><th>' . wfMessage( 'gadgetmanager-tablehead-default' )->escaped() |
88 | | - . '</th><th>' . wfMessage( 'gadgetmanager-tablehead-hidden' )->escaped() |
89 | | - . '</th>'; |
90 | | - if ( $wgGadgetEnableSharing ) { |
91 | | - $html .= '<th>' . wfMessage( 'gadgetmanager-tablehead-shared' )->escaped() . '</th>'; |
92 | | - } |
93 | | - $html .= '<th>' . wfMessage( 'gadgetmanager-tablehead-lastmod' )->escaped() . '</th>'; |
94 | | - $html .= '</tr></thead><tbody>'; |
95 | | - |
96 | | - // Populate table rows for the current category |
97 | | - foreach ( $gadgets as $gadgetId => $gadget ) { |
98 | | - $html .= '<tr>'; |
99 | | - |
100 | | - $tickedCheckboxHtml = Html::element( 'input', array( |
101 | | - 'type' => 'checkbox', |
102 | | - 'disabled' => 'disabled', |
103 | | - 'value' => 1, |
104 | | - 'checked' => 'checked', |
105 | | - ) ); |
106 | | - |
107 | | - // Title |
108 | | - $titleLink = Linker::link( |
109 | | - $this->getTitle( $gadget->getId() ), |
110 | | - $gadget->getTitleMessage(), |
111 | | - array( 'data-gadget-id' => $gadget->getId() ) |
112 | | - ); |
113 | | - $html .= "<td class=\"mw-gadgetmanager-gadgets-title\">$titleLink</td>"; |
114 | | - // Default |
115 | | - $html .= '<td class="mw-gadgetmanager-gadgets-default">' |
116 | | - . ( $gadget->isEnabledByDefault() ? $tickedCheckboxHtml : '' ) . '</td>'; |
117 | | - // Hidden |
118 | | - $html .= '<td class="mw-gadgetmanager-gadgets-hidden">' |
119 | | - . ( $gadget->isHidden() ? $tickedCheckboxHtml : '' ) . '</td>'; |
120 | | - // Shared |
121 | | - if ( $wgGadgetEnableSharing ) { |
122 | | - $html .= '<td class="mw-gadgetmanager-gadgets-shared">' |
123 | | - . ( $gadget->isShared() ? $tickedCheckboxHtml : '' ) . '</td>'; |
124 | | - } |
125 | | - |
126 | | - // Last modified |
127 | | - $lastModText = ''; |
128 | | - $definitionTitle = Title::makeTitleSafe( NS_GADGET_DEFINITION, $gadget->getId() . '.js' ); |
129 | | - if ( $definitionTitle ) { |
130 | | - $definitionRev = Revision::newFromTitle( $definitionTitle ); |
131 | | - if ( $definitionRev ) { |
132 | | - $userLang = $this->getLang(); |
133 | | - $revTimestamp = $definitionRev->getTimestamp(); |
134 | | - $userText = $definitionRev->getUserText(); |
135 | | - $userLinks = |
136 | | - Linker::userLink( |
137 | | - $definitionRev->getUser(), |
138 | | - $userText |
139 | | - ) . |
140 | | - Linker::userToolLinks( |
141 | | - $definitionRev->getUser(), |
142 | | - $userText |
143 | | - ); |
144 | | - $lastModText = wfMsgExt( |
145 | | - 'gadgetmanager-tablecell-lastmod', |
146 | | - array( 'replaceafter', 'parseinline' ), |
147 | | - array( |
148 | | - $userLang->timeanddate( $revTimestamp, true ), |
149 | | - $userLinks, |
150 | | - $userLang->date( $revTimestamp, true ), |
151 | | - $userLang->time( $revTimestamp, true ), |
152 | | - $userText |
153 | | - ) |
154 | | - ); |
155 | | - } |
156 | | - $html .= "<td class=\"mw-gadgetmanager-gadgets-lastmod\">$lastModText</td>"; |
157 | | - } |
158 | | - |
159 | | - $html .= '</tr>'; |
160 | | - } |
161 | | - |
162 | | - // End of per-category gadgets table |
163 | | - $html .= '</tbody></table>'; |
164 | | - } |
165 | | - |
166 | | - return $html; |
167 | | - } |
168 | | - |
169 | | - /** |
170 | | - * @return String: HTML |
171 | | - */ |
172 | | - public function generateGadgetView( $gadgetId ) { |
173 | | - return 'TODO - This page is about "' |
174 | | - . htmlspecialchars( $gadgetId ) |
175 | | - . '". Also used as permalink from other places.'; |
176 | | - } |
177 | | -} |