Index: branches/RL2/extensions/Gadgets/api/ApiQueryGadgets.php |
— | — | @@ -41,6 +41,7 @@ |
42 | 42 | : false; |
43 | 43 | $this->listAllowed = isset( $params['allowedonly'] ) && $params['allowedonly']; |
44 | 44 | $this->listEnabled = isset( $params['enabledonly'] ) && $params['enabledonly']; |
| 45 | + $this->listShared = isset( $params['sharedonly'] ) && $params['sharedonly']; |
45 | 46 | |
46 | 47 | $this->getMain()->setCacheMode( $this->listAllowed || $this->listEnabled |
47 | 48 | ? 'anon-public-user-private' : 'public' ); |
— | — | @@ -49,19 +50,24 @@ |
50 | 51 | } |
51 | 52 | |
52 | 53 | private function getList() { |
53 | | - $gadgets = Gadget::loadStructuredList(); |
54 | | - |
| 54 | + $repo = new LocalGadgetRepo( array() ); |
55 | 55 | $result = array(); |
56 | | - foreach ( $gadgets as $category => $list ) { |
57 | | - if ( $this->categories && !isset( $this->categories[$category] ) ) { |
58 | | - continue; |
| 56 | + |
| 57 | + if ( $this->neededNames ) { |
| 58 | + // Get all requested gadgets by name |
| 59 | + $names = $this->neededNames; |
| 60 | + } else { |
| 61 | + // Get them all |
| 62 | + $names = $repo->getGadgetNames(); |
| 63 | + } |
| 64 | + |
| 65 | + foreach ( $names as $name ) { |
| 66 | + $gadget = $repo->getGadget( $name ); |
| 67 | + if ( $gadget && $this->isNeeded( $gadget ) ) { |
| 68 | + $result[$name] = $gadget; |
59 | 69 | } |
60 | | - foreach ( $list as $g ) { |
61 | | - if ( $this->isNeeded( $g ) ) { |
62 | | - $result[] = $g; |
63 | | - } |
64 | | - } |
65 | 70 | } |
| 71 | + |
66 | 72 | return $result; |
67 | 73 | } |
68 | 74 | |
— | — | @@ -69,21 +75,26 @@ |
70 | 76 | $data = array(); |
71 | 77 | $result = $this->getResult(); |
72 | 78 | |
73 | | - foreach ( $gadgets as $g ) { |
| 79 | + foreach ( $gadgets as $name => $g ) { |
74 | 80 | $row = array(); |
75 | 81 | if ( isset( $this->props['name'] ) ) { |
76 | | - $row['name'] = $g->getName(); |
| 82 | + $row['name'] = $name; |
77 | 83 | } |
| 84 | + if ( isset( $this->props['json'] ) ) { |
| 85 | + $row['json'] = $g->getJSON(); |
| 86 | + } |
78 | 87 | if ( isset( $this->props['desc'] ) ) { |
79 | | - $row['desc'] = $g->getDescription(); |
| 88 | + $row['desc'] = wfMessage( $g->getDescriptionMsg() )->parse(); |
80 | 89 | } |
81 | 90 | if ( isset( $this->props['desc-raw'] ) ) { |
82 | | - $row['desc-raw'] = $g->getRawDescription(); |
| 91 | + $row['desc-raw'] = $row['desc'] = wfMessage( $g->getDescriptionMsg() )->plain(); |
83 | 92 | } |
84 | 93 | if ( isset( $this->props['category'] ) ) { |
85 | | - $row['category'] = $g->getCategory(); |
| 94 | + $row['category'] = $g->getSection(); // TODO: clean up category vs. section mess in favor category |
86 | 95 | } |
87 | | - if ( isset( $this->props['resourceloader'] ) && $g->supportsResourceLoader() ) { |
| 96 | + if ( isset( $this->props['resourceloader'] ) /*&& $g->supportsResourceLoader()*/ ) { |
| 97 | + // Everything supports resourceloader now :D |
| 98 | + // FIXME: We need to figure something out for legacy gadgets, or at least MaxSem thinks so |
88 | 99 | $row['resourceloader'] = ''; |
89 | 100 | } |
90 | 101 | if ( isset( $this->props['scripts'] ) ) { |
— | — | @@ -102,12 +113,9 @@ |
103 | 114 | $row['rights'] = $g->getRequiredRights(); |
104 | 115 | $result->setIndexedTagName( $row['rights'], 'right' ); |
105 | 116 | } |
106 | | - if ( isset( $this->props['default'] ) && $g->isOnByDefault() ) { |
| 117 | + if ( isset( $this->props['default'] ) && $g->isEnabledByDefault() ) { |
107 | 118 | $row['default'] = ''; |
108 | 119 | } |
109 | | - if ( isset( $this->props['definition'] ) ) { |
110 | | - $row['definition'] = $g->getDefinition(); |
111 | | - } |
112 | 120 | $data[] = $row; |
113 | 121 | } |
114 | 122 | $result->setIndexedTagName( $data, 'gadget' ); |
— | — | @@ -122,16 +130,19 @@ |
123 | 131 | |
124 | 132 | return ( $this->neededNames === false || isset( $this->neededNames[$gadget->getName()] ) ) |
125 | 133 | && ( !$this->listAllowed || $gadget->isAllowed( $wgUser ) ) |
126 | | - && ( !$this->listEnabled || $gadget->isEnabled( $wgUser ) ); |
| 134 | + && ( !$this->listEnabled || $gadget->isEnabled( $wgUser ) ) |
| 135 | + && ( !$this->listShared || $gadget->isShared() ) |
| 136 | + && ( !$this->categories || isset( $this->categories[$g->getSection()] ) ); |
127 | 137 | } |
128 | 138 | |
129 | 139 | public function getAllowedParams() { |
130 | 140 | return array( |
131 | 141 | 'prop' => array( |
132 | | - ApiBase::PARAM_DFLT => 'name', |
| 142 | + ApiBase::PARAM_DFLT => 'name|json', |
133 | 143 | ApiBase::PARAM_ISMULTI => true, |
134 | 144 | ApiBase::PARAM_TYPE => array( |
135 | 145 | 'name', |
| 146 | + 'json', |
136 | 147 | 'desc', |
137 | 148 | 'desc-raw', |
138 | 149 | 'category', |
— | — | @@ -141,7 +152,6 @@ |
142 | 153 | 'dependencies', |
143 | 154 | 'rights', |
144 | 155 | 'default', |
145 | | - 'definition', |
146 | 156 | ), |
147 | 157 | ), |
148 | 158 | 'categories' => array( |
— | — | @@ -154,6 +164,7 @@ |
155 | 165 | ), |
156 | 166 | 'allowedonly' => false, |
157 | 167 | 'enabledonly' => false, |
| 168 | + 'sharedonly' => false, |
158 | 169 | ); |
159 | 170 | } |
160 | 171 | |
— | — | @@ -166,6 +177,7 @@ |
167 | 178 | 'prop' => array( |
168 | 179 | 'What gadget information to get:', |
169 | 180 | ' name - Internal gadget name', |
| 181 | + ' json - JSON representation of the gadget metadata. All other prop attributes below are deprecated but provided for backwards compatibility', |
170 | 182 | ' desc - Gadget description transformed into HTML (can be slow, use only if really needed)', |
171 | 183 | ' desc-raw - Gadget description in raw wikitext', |
172 | 184 | ' category - Internal name of a category gadget belongs to (empty if top-level gadget)', |
— | — | @@ -175,12 +187,12 @@ |
176 | 188 | ' dependencies - List of ResourceLoader modules gadget depends on', |
177 | 189 | ' rights - List of rights required to use gadget, if any', |
178 | 190 | ' default - Whether gadget is enabled by default', |
179 | | - ' definition - Line from MediaWiki:Gadgets-definition used to define the gadget', |
180 | 191 | ), |
181 | 192 | 'categories' => 'Gadgets from what categories to retrieve', |
182 | 193 | 'names' => 'Name(s) of gadgets to retrieve', |
183 | 194 | 'allowedonly' => 'List only gadgets allowed to current user', |
184 | 195 | 'enabledonly' => 'List only gadgets enabled by current user', |
| 196 | + 'sharedonly' => 'Only list shared gadgets', |
185 | 197 | ); |
186 | 198 | } |
187 | 199 | |