Index: branches/RL2/extensions/Gadgets/ApiQueryGadgets.php |
— | — | @@ -1,208 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * Created on 15 April 2011 |
5 | | - * API for Gadgets extension |
6 | | - * |
7 | | - * This program is free software; you can redistribute it and/or modify |
8 | | - * it under the terms of the GNU General Public License as published by |
9 | | - * the Free Software Foundation; either version 2 of the License, or |
10 | | - * (at your option) any later version. |
11 | | - * |
12 | | - * This program is distributed in the hope that it will be useful, |
13 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | | - * GNU General Public License for more details. |
16 | | - * |
17 | | - * You should have received a copy of the GNU General Public License along |
18 | | - * with this program; if not, write to the Free Software Foundation, Inc., |
19 | | - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
20 | | - * http://www.gnu.org/copyleft/gpl.html |
21 | | - */ |
22 | | - |
23 | | -class ApiQueryGadgets extends ApiQueryBase { |
24 | | - private $props, |
25 | | - $category, |
26 | | - $neededNames, |
27 | | - $listAllowed, |
28 | | - $listEnabled; |
29 | | - |
30 | | - public function __construct( $query, $moduleName ) { |
31 | | - parent::__construct( $query, $moduleName, 'ga' ); |
32 | | - } |
33 | | - |
34 | | - public function execute() { |
35 | | - $params = $this->extractRequestParams(); |
36 | | - $this->props = array_flip( $params['prop'] ); |
37 | | - $this->categories = isset( $params['categories'] ) |
38 | | - ? array_flip( $params['categories'] ) |
39 | | - : false; |
40 | | - $this->neededNames = isset( $params['names'] ) |
41 | | - ? array_flip( $params['names'] ) |
42 | | - : false; |
43 | | - $this->listAllowed = isset( $params['allowed'] ) && $params['allowed']; |
44 | | - $this->listEnabled = isset( $params['enabled'] ) && $params['enabled']; |
45 | | - |
46 | | - $this->getMain()->setCacheMode( $this->listAllowed || $this->listEnabled |
47 | | - ? 'anon-public-user-private' : 'public' ); |
48 | | - |
49 | | - $this->applyList( $this->getList() ); |
50 | | - } |
51 | | - |
52 | | - private function getList() { |
53 | | - $gadgets = Gadget::loadStructuredList(); |
54 | | - |
55 | | - $result = array(); |
56 | | - foreach ( $gadgets as $category => $list ) { |
57 | | - if ( $this->categories && !isset( $this->categories[$category] ) ) { |
58 | | - continue; |
59 | | - } |
60 | | - foreach ( $list as $g ) { |
61 | | - if ( $this->isNeeded( $g ) ) { |
62 | | - $result[] = $g; |
63 | | - } |
64 | | - } |
65 | | - } |
66 | | - return $result; |
67 | | - } |
68 | | - |
69 | | - private function applyList( $gadgets ) { |
70 | | - $data = array(); |
71 | | - $result = $this->getResult(); |
72 | | - |
73 | | - foreach ( $gadgets as $g ) { |
74 | | - $row = array(); |
75 | | - if ( isset( $this->props['name'] ) ) { |
76 | | - $row['name'] = $g->getName(); |
77 | | - } |
78 | | - if ( isset( $this->props['desc'] ) ) { |
79 | | - $row['desc'] = $g->getDescription(); |
80 | | - } |
81 | | - if ( isset( $this->props['desc-raw'] ) ) { |
82 | | - $row['desc-raw'] = $g->getRawDescription(); |
83 | | - } |
84 | | - if ( isset( $this->props['category'] ) ) { |
85 | | - $row['category'] = $g->getCategory(); |
86 | | - } |
87 | | - if ( isset( $this->props['resourceloader'] ) && $g->supportsResourceLoader() ) { |
88 | | - $row['resourceloader'] = ''; |
89 | | - } |
90 | | - if ( isset( $this->props['scripts'] ) ) { |
91 | | - $row['scripts'] = $g->getScripts(); |
92 | | - $result->setIndexedTagName( $row['scripts'], 'script' ); |
93 | | - } |
94 | | - if ( isset( $this->props['styles'] ) ) { |
95 | | - $row['styles'] = $g->getStyles(); |
96 | | - $result->setIndexedTagName( $row['styles'], 'style' ); |
97 | | - } |
98 | | - if ( isset( $this->props['dependencies'] ) ) { |
99 | | - $row['dependencies'] = $g->getDependencies(); |
100 | | - $result->setIndexedTagName( $row['dependencies'], 'module' ); |
101 | | - } |
102 | | - if ( isset( $this->props['rights'] ) ) { |
103 | | - $row['rights'] = $g->getRequiredRights(); |
104 | | - $result->setIndexedTagName( $row['rights'], 'right' ); |
105 | | - } |
106 | | - if ( isset( $this->props['default'] ) && $g->isOnByDefault() ) { |
107 | | - $row['default'] = ''; |
108 | | - } |
109 | | - if ( isset( $this->props['definition'] ) ) { |
110 | | - $row['definition'] = $g->getDefinition(); |
111 | | - } |
112 | | - $data[] = $row; |
113 | | - } |
114 | | - $result->setIndexedTagName( $data, 'gadget' ); |
115 | | - $result->addValue( 'query', $this->getModuleName(), $data ); |
116 | | - } |
117 | | - |
118 | | - /** |
119 | | - * |
120 | | - */ |
121 | | - private function isNeeded( Gadget $gadget ) { |
122 | | - global $wgUser; |
123 | | - |
124 | | - return ( $this->neededNames === false || isset( $this->neededNames[$gadget->getName()] ) ) |
125 | | - && ( !$this->listAllowed || $gadget->isAllowed( $wgUser ) ) |
126 | | - && ( !$this->listEnabled || $gadget->isEnabled( $wgUser ) ); |
127 | | - } |
128 | | - |
129 | | - public function getAllowedParams() { |
130 | | - return array( |
131 | | - 'prop' => array( |
132 | | - ApiBase::PARAM_DFLT => 'name', |
133 | | - ApiBase::PARAM_ISMULTI => true, |
134 | | - ApiBase::PARAM_TYPE => array( |
135 | | - 'name', |
136 | | - 'desc', |
137 | | - 'desc-raw', |
138 | | - 'category', |
139 | | - 'resourceloader', |
140 | | - 'scripts', |
141 | | - 'styles', |
142 | | - 'dependencies', |
143 | | - 'rights', |
144 | | - 'default', |
145 | | - 'definition', |
146 | | - ), |
147 | | - ), |
148 | | - 'categories' => array( |
149 | | - ApiBase::PARAM_ISMULTI => true, |
150 | | - ApiBase::PARAM_TYPE => 'string', |
151 | | - ), |
152 | | - 'names' => array( |
153 | | - ApiBase::PARAM_TYPE => 'string', |
154 | | - ApiBase::PARAM_ISMULTI => true, |
155 | | - ), |
156 | | - 'allowed' => false, |
157 | | - 'enabled' => false, |
158 | | - ); |
159 | | - } |
160 | | - |
161 | | - public function getDescription() { |
162 | | - return 'Returns a list of gadgets used on this wiki'; |
163 | | - } |
164 | | - |
165 | | - public function getParamDescription() { |
166 | | - return array( |
167 | | - 'prop' => array( |
168 | | - 'What gadget information to get:', |
169 | | - ' name - Internal gadget name', |
170 | | - ' desc - Gadget description transformed into HTML (can be slow, use only if really needed)', |
171 | | - ' desc-raw - Gadget description in raw wikitext', |
172 | | - ' category - Internal name of a category gadget belongs to (empty if top-level gadget)', |
173 | | - ' resourceloader - Whether gadget supports ResourceLoader', |
174 | | - " scripts - List of gadget's scripts", |
175 | | - " styles - List of gadget's styles", |
176 | | - ' dependencies - List of ResourceLoader modules gadget depends on', |
177 | | - ' rights - List of rights required to use gadget, if any', |
178 | | - ' default - Whether gadget is enabled by default', |
179 | | - ' definition - Line from MediaWiki:Gadgets-definition used to define the gadget', |
180 | | - ), |
181 | | - 'categories' => 'Gadgets from what categories to retrieve', |
182 | | - 'names' => 'Name(s) of gadgets to retrieve', |
183 | | - 'allowed' => 'List only gadgets allowed to current user', |
184 | | - 'enabled' => 'List only gadgets enabled by current user', |
185 | | - ); |
186 | | - } |
187 | | - |
188 | | - protected function getExamples() { |
189 | | - $params = $this->getAllowedParams(); |
190 | | - $allProps = implode( '|', $params['prop'][ApiBase::PARAM_TYPE] ); |
191 | | - return array( |
192 | | - 'Get a list of gadgets along with their descriptions:', |
193 | | - ' api.php?action=query&list=gadgets&gaprop=name|desc', |
194 | | - 'Get a list of gadgets with all possble properties:', |
195 | | - " api.php?action=query&list=gadgets&gaprop=$allProps", |
196 | | - 'Get a list of gadgets belonging to caregory "foo":', |
197 | | - ' api.php?action=query&list=gadgets&gacategories=foo', |
198 | | - 'Get information about gadgets named "foo" and "bar":', |
199 | | - ' api.php?action=query&list=gadgets&ganames=foo|bar&gaprop=name|desc|category', |
200 | | - 'Get a list of gadgets enabled by current user:', |
201 | | - ' api.php?action=query&list=gadgets&gaenabled', |
202 | | - ); |
203 | | - } |
204 | | - |
205 | | - public function getVersion() { |
206 | | - return __CLASS__ . ': $Id$'; |
207 | | - } |
208 | | - |
209 | | -} |
Index: branches/RL2/extensions/Gadgets/Gadgets_tests.php |
— | — | @@ -1,82 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -/** |
5 | | - * @group Gadgets |
6 | | - */ |
7 | | -class GadgetsTest extends PHPUnit_Framework_TestCase { |
8 | | - |
9 | | - private function create( $line ) { |
10 | | - $g = Gadget::newFromDefinition( $line ); |
11 | | - // assertInstanceOf() is available since PHPUnit 3.5 |
12 | | - $this->assertEquals( 'Gadget', get_class( $g ) ); |
13 | | - return $g; |
14 | | - } |
15 | | - |
16 | | - function testInvalidLines() { |
17 | | - $this->assertFalse( Gadget::newFromDefinition( '' ) ); |
18 | | - $this->assertFalse( Gadget::newFromDefinition( '<foo|bar>' ) ); |
19 | | - } |
20 | | - |
21 | | - function testSimpleCases() { |
22 | | - $g = $this->create( '* foo bar| foo.css|foo.js|foo.bar' ); |
23 | | - $this->assertEquals( 'foo_bar', $g->getName() ); |
24 | | - $this->assertEquals( 'ext.gadget.foo_bar', $g->getModuleName() ); |
25 | | - $this->assertEquals( array( 'Gadget-foo.js' ), $g->getScripts() ); |
26 | | - $this->assertEquals( array( 'Gadget-foo.css' ), $g->getStyles() ); |
27 | | - $this->assertEquals( array( 'Gadget-foo.js', 'Gadget-foo.css' ), |
28 | | - $g->getScriptsAndStyles() ); |
29 | | - $this->assertEquals( array( 'Gadget-foo.js' ), $g->getLegacyScripts() ); |
30 | | - $this->assertFalse( $g->supportsResourceLoader() ); |
31 | | - $this->assertTrue( $g->hasModule() ); |
32 | | - } |
33 | | - |
34 | | - function testRLtag() { |
35 | | - $g = $this->create( '*foo [ResourceLoader]|foo.js|foo.css' ); |
36 | | - $this->assertEquals( 'foo', $g->getName() ); |
37 | | - $this->assertTrue( $g->supportsResourceLoader() ); |
38 | | - $this->assertEquals(0, count( $g->getLegacyScripts() ) ); |
39 | | - } |
40 | | - |
41 | | - function testDependencies() { |
42 | | - $g = $this->create( '* foo[ResourceLoader|dependencies=jquery.ui]|bar.js' ); |
43 | | - $this->assertEquals( array( 'Gadget-bar.js' ), $g->getScripts() ); |
44 | | - $this->assertTrue( $g->supportsResourceLoader() ); |
45 | | - $this->assertEquals( array( 'jquery.ui' ), $g->getDependencies() ); |
46 | | - } |
47 | | - |
48 | | - function testPreferences() { |
49 | | - global $wgUser; |
50 | | - |
51 | | - // This test makes call to the parser which requires valids Outputpage |
52 | | - // and Title objects. Set them up there, they will be released at the |
53 | | - // end of the test. |
54 | | - global $wgOut, $wgTitle; |
55 | | - $old_wgOut = $wgOut; |
56 | | - $old_wgTitle = $wgTitle; |
57 | | - $wgTitle = Title::newFromText( 'Parser test for Gadgets extension' ); |
58 | | - |
59 | | - // Proceed with test setup: |
60 | | - $prefs = array(); |
61 | | - $context = new RequestContext(); |
62 | | - $wgOut = $context->getOutput(); |
63 | | - $wgOut->setTitle( Title::newFromText( 'test' ) ); |
64 | | - |
65 | | - Gadget::loadStructuredList( '* foo | foo.js |
66 | | -==keep-section1== |
67 | | -* bar| bar.js |
68 | | -==remove-section== |
69 | | -* baz [rights=embezzle] |baz.js |
70 | | -==keep-section2== |
71 | | -* quux [rights=read] | quux.js' ); |
72 | | - $this->assertTrue( GadgetHooks::getPreferences( $wgUser, $prefs ), 'GetPrefences hook should return true' ); |
73 | | - |
74 | | - $options = $prefs['gadgets']['options']; |
75 | | - $this->assertFalse( isset( $options['<gadget-section-remove-section>'] ), 'Must not show empty sections' ); |
76 | | - $this->assertTrue( isset( $options['<gadget-section-keep-section1>'] ) ); |
77 | | - $this->assertTrue( isset( $options['<gadget-section-keep-section2>'] ) ); |
78 | | - |
79 | | - // Restore globals |
80 | | - $wgOut = $old_wgOut; |
81 | | - $wgTitle = $old_wgTitle; |
82 | | - } |
83 | | -} |
Index: branches/RL2/extensions/Gadgets/ApiQueryGadgetCategories.php |
— | — | @@ -1,122 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * Created on 16 April 2011 |
5 | | - * API for Gadgets extension |
6 | | - * |
7 | | - * This program is free software; you can redistribute it and/or modify |
8 | | - * it under the terms of the GNU General Public License as published by |
9 | | - * the Free Software Foundation; either version 2 of the License, or |
10 | | - * (at your option) any later version. |
11 | | - * |
12 | | - * This program is distributed in the hope that it will be useful, |
13 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | | - * GNU General Public License for more details. |
16 | | - * |
17 | | - * You should have received a copy of the GNU General Public License along |
18 | | - * with this program; if not, write to the Free Software Foundation, Inc., |
19 | | - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
20 | | - * http://www.gnu.org/copyleft/gpl.html |
21 | | - */ |
22 | | - |
23 | | -class ApiQueryGadgetCategories extends ApiQueryBase { |
24 | | - private $props, |
25 | | - $neededNames; |
26 | | - |
27 | | - public function __construct( $query, $moduleName ) { |
28 | | - parent::__construct( $query, $moduleName, 'gc' ); |
29 | | - } |
30 | | - |
31 | | - public function execute() { |
32 | | - $params = $this->extractRequestParams(); |
33 | | - $this->props = array_flip( $params['prop'] ); |
34 | | - $this->neededNames = isset( $params['names'] ) |
35 | | - ? array_flip( $params['names'] ) |
36 | | - : false; |
37 | | - |
38 | | - $this->getMain()->setCacheMode( 'public' ); |
39 | | - |
40 | | - $this->getList(); |
41 | | - } |
42 | | - |
43 | | - private function getList() { |
44 | | - $data = array(); |
45 | | - $result = $this->getResult(); |
46 | | - $gadgets = Gadget::loadStructuredList(); |
47 | | - |
48 | | - foreach ( $gadgets as $category => $list ) { |
49 | | - if ( !$this->neededNames || isset( $this->neededNames[$category] ) ) { |
50 | | - $row = array(); |
51 | | - if ( isset( $this->props['name'] ) ) { |
52 | | - $row['name'] = $category; |
53 | | - } |
54 | | - if ( $category !== "" ) { |
55 | | - if ( isset( $this->props['desc'] ) ) { |
56 | | - $row['desc'] = wfMessage( "gadget-section-$category" )->parse(); |
57 | | - } |
58 | | - if ( isset( $this->props['desc-raw'] ) ) { |
59 | | - $row['desc-raw'] = wfMessage( "gadget-section-$category" )->plain(); |
60 | | - } |
61 | | - } |
62 | | - if ( isset( $this->props['members'] ) ) { |
63 | | - $row['members'] = count( $list ); |
64 | | - } |
65 | | - $data[] = $row; |
66 | | - } |
67 | | - } |
68 | | - $result->setIndexedTagName( $data, 'category' ); |
69 | | - $result->addValue( 'query', $this->getModuleName(), $data ); |
70 | | - } |
71 | | - |
72 | | - public function getAllowedParams() { |
73 | | - return array( |
74 | | - 'prop' => array( |
75 | | - ApiBase::PARAM_DFLT => 'name', |
76 | | - ApiBase::PARAM_ISMULTI => true, |
77 | | - ApiBase::PARAM_TYPE => array( |
78 | | - 'name', |
79 | | - 'desc', |
80 | | - 'desc-raw', |
81 | | - 'members', |
82 | | - ), |
83 | | - ), |
84 | | - 'names' => array( |
85 | | - ApiBase::PARAM_TYPE => 'string', |
86 | | - ApiBase::PARAM_ISMULTI => true, |
87 | | - ), |
88 | | - ); |
89 | | - } |
90 | | - |
91 | | - public function getDescription() { |
92 | | - return 'Returns a list of gadget categories'; |
93 | | - } |
94 | | - |
95 | | - public function getParamDescription() { |
96 | | - return array( |
97 | | - 'prop' => array( |
98 | | - 'What gadget category information to get:', |
99 | | - ' name - Internal category name', |
100 | | - ' desc - Category description transformed into HTML (can be slow, use only if really needed)', |
101 | | - ' desc-raw - Category description in raw wikitext', |
102 | | - ' members - Number of gadgets in category', |
103 | | - ), |
104 | | - 'names' => 'Name(s) of gadgets to retrieve', |
105 | | - ); |
106 | | - } |
107 | | - |
108 | | - protected function getExamples() { |
109 | | - $params = $this->getAllowedParams(); |
110 | | - $allProps = implode( '|', $params['prop'][ApiBase::PARAM_TYPE] ); |
111 | | - return array( |
112 | | - 'Get a list of existing gadget categories:', |
113 | | - ' api.php?action=query&list=gadgetcategories', |
114 | | - 'Get all information about categories named "foo" and "bar":', |
115 | | - " api.php?action=query&list=gadgetcategories&gcnames=foo|bar&gcprop=$allProps", |
116 | | - ); |
117 | | - } |
118 | | - |
119 | | - public function getVersion() { |
120 | | - return __CLASS__ . ': $Id$'; |
121 | | - } |
122 | | - |
123 | | -} |
Index: branches/RL2/extensions/Gadgets/tests/GadgetsTest.php |
— | — | @@ -0,0 +1,82 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * @group Gadgets |
| 6 | + */ |
| 7 | +class GadgetsTest extends PHPUnit_Framework_TestCase { |
| 8 | + |
| 9 | + private function create( $line ) { |
| 10 | + $g = Gadget::newFromDefinition( $line ); |
| 11 | + // assertInstanceOf() is available since PHPUnit 3.5 |
| 12 | + $this->assertEquals( 'Gadget', get_class( $g ) ); |
| 13 | + return $g; |
| 14 | + } |
| 15 | + |
| 16 | + function testInvalidLines() { |
| 17 | + $this->assertFalse( Gadget::newFromDefinition( '' ) ); |
| 18 | + $this->assertFalse( Gadget::newFromDefinition( '<foo|bar>' ) ); |
| 19 | + } |
| 20 | + |
| 21 | + function testSimpleCases() { |
| 22 | + $g = $this->create( '* foo bar| foo.css|foo.js|foo.bar' ); |
| 23 | + $this->assertEquals( 'foo_bar', $g->getName() ); |
| 24 | + $this->assertEquals( 'ext.gadget.foo_bar', $g->getModuleName() ); |
| 25 | + $this->assertEquals( array( 'Gadget-foo.js' ), $g->getScripts() ); |
| 26 | + $this->assertEquals( array( 'Gadget-foo.css' ), $g->getStyles() ); |
| 27 | + $this->assertEquals( array( 'Gadget-foo.js', 'Gadget-foo.css' ), |
| 28 | + $g->getScriptsAndStyles() ); |
| 29 | + $this->assertEquals( array( 'Gadget-foo.js' ), $g->getLegacyScripts() ); |
| 30 | + $this->assertFalse( $g->supportsResourceLoader() ); |
| 31 | + $this->assertTrue( $g->hasModule() ); |
| 32 | + } |
| 33 | + |
| 34 | + function testRLtag() { |
| 35 | + $g = $this->create( '*foo [ResourceLoader]|foo.js|foo.css' ); |
| 36 | + $this->assertEquals( 'foo', $g->getName() ); |
| 37 | + $this->assertTrue( $g->supportsResourceLoader() ); |
| 38 | + $this->assertEquals(0, count( $g->getLegacyScripts() ) ); |
| 39 | + } |
| 40 | + |
| 41 | + function testDependencies() { |
| 42 | + $g = $this->create( '* foo[ResourceLoader|dependencies=jquery.ui]|bar.js' ); |
| 43 | + $this->assertEquals( array( 'Gadget-bar.js' ), $g->getScripts() ); |
| 44 | + $this->assertTrue( $g->supportsResourceLoader() ); |
| 45 | + $this->assertEquals( array( 'jquery.ui' ), $g->getDependencies() ); |
| 46 | + } |
| 47 | + |
| 48 | + function testPreferences() { |
| 49 | + global $wgUser; |
| 50 | + |
| 51 | + // This test makes call to the parser which requires valids Outputpage |
| 52 | + // and Title objects. Set them up there, they will be released at the |
| 53 | + // end of the test. |
| 54 | + global $wgOut, $wgTitle; |
| 55 | + $old_wgOut = $wgOut; |
| 56 | + $old_wgTitle = $wgTitle; |
| 57 | + $wgTitle = Title::newFromText( 'Parser test for Gadgets extension' ); |
| 58 | + |
| 59 | + // Proceed with test setup: |
| 60 | + $prefs = array(); |
| 61 | + $context = new RequestContext(); |
| 62 | + $wgOut = $context->getOutput(); |
| 63 | + $wgOut->setTitle( Title::newFromText( 'test' ) ); |
| 64 | + |
| 65 | + Gadget::loadStructuredList( '* foo | foo.js |
| 66 | +==keep-section1== |
| 67 | +* bar| bar.js |
| 68 | +==remove-section== |
| 69 | +* baz [rights=embezzle] |baz.js |
| 70 | +==keep-section2== |
| 71 | +* quux [rights=read] | quux.js' ); |
| 72 | + $this->assertTrue( GadgetHooks::getPreferences( $wgUser, $prefs ), 'GetPrefences hook should return true' ); |
| 73 | + |
| 74 | + $options = $prefs['gadgets']['options']; |
| 75 | + $this->assertFalse( isset( $options['<gadget-section-remove-section>'] ), 'Must not show empty sections' ); |
| 76 | + $this->assertTrue( isset( $options['<gadget-section-keep-section1>'] ) ); |
| 77 | + $this->assertTrue( isset( $options['<gadget-section-keep-section2>'] ) ); |
| 78 | + |
| 79 | + // Restore globals |
| 80 | + $wgOut = $old_wgOut; |
| 81 | + $wgTitle = $old_wgTitle; |
| 82 | + } |
| 83 | +} |
Property changes on: branches/RL2/extensions/Gadgets/tests/GadgetsTest.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 84 | + native |
Index: branches/RL2/extensions/Gadgets/Gadgets.php |
— | — | @@ -54,8 +54,8 @@ |
55 | 55 | $wgExtensionMessagesFiles['GadgetsNamespaces'] = $dir . 'Gadgets.namespaces.php'; |
56 | 56 | $wgExtensionAliasesFiles['Gadgets'] = $dir . 'Gadgets.alias.php'; |
57 | 57 | |
58 | | -$wgAutoloadClasses['ApiQueryGadgetCategories'] = $dir . 'ApiQueryGadgetCategories.php'; |
59 | | -$wgAutoloadClasses['ApiQueryGadgets'] = $dir . 'ApiQueryGadgets.php'; |
| 58 | +$wgAutoloadClasses['ApiQueryGadgetCategories'] = $dir . 'api/ApiQueryGadgetCategories.php'; |
| 59 | +$wgAutoloadClasses['ApiQueryGadgets'] = $dir . 'api/ApiQueryGadgets.php'; |
60 | 60 | $wgAutoloadClasses['GadgetHooks'] = $dir . 'GadgetHooks.php'; |
61 | 61 | $wgAutoloadClasses['SpecialGadgets'] = $dir . 'SpecialGadgets.php'; |
62 | 62 | |
Index: branches/RL2/extensions/Gadgets/GadgetHooks.php |
— | — | @@ -178,7 +178,7 @@ |
179 | 179 | * @param $files Array: List of extension test files |
180 | 180 | */ |
181 | 181 | public static function unitTestsList( $files ) { |
182 | | - $files[] = dirname( __FILE__ ) . '/Gadgets_tests.php'; |
| 182 | + $files[] = dirname( __FILE__ ) . 'tests/GadgetsTest.php'; |
183 | 183 | return true; |
184 | 184 | } |
185 | 185 | |
Index: branches/RL2/extensions/Gadgets/api/ApiQueryGadgets.php |
— | — | @@ -0,0 +1,208 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Created on 15 April 2011 |
| 5 | + * API for Gadgets extension |
| 6 | + * |
| 7 | + * This program is free software; you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU General Public License as published by |
| 9 | + * the Free Software Foundation; either version 2 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License along |
| 18 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 20 | + * http://www.gnu.org/copyleft/gpl.html |
| 21 | + */ |
| 22 | + |
| 23 | +class ApiQueryGadgets extends ApiQueryBase { |
| 24 | + private $props, |
| 25 | + $category, |
| 26 | + $neededNames, |
| 27 | + $listAllowed, |
| 28 | + $listEnabled; |
| 29 | + |
| 30 | + public function __construct( $query, $moduleName ) { |
| 31 | + parent::__construct( $query, $moduleName, 'ga' ); |
| 32 | + } |
| 33 | + |
| 34 | + public function execute() { |
| 35 | + $params = $this->extractRequestParams(); |
| 36 | + $this->props = array_flip( $params['prop'] ); |
| 37 | + $this->categories = isset( $params['categories'] ) |
| 38 | + ? array_flip( $params['categories'] ) |
| 39 | + : false; |
| 40 | + $this->neededNames = isset( $params['names'] ) |
| 41 | + ? array_flip( $params['names'] ) |
| 42 | + : false; |
| 43 | + $this->listAllowed = isset( $params['allowed'] ) && $params['allowed']; |
| 44 | + $this->listEnabled = isset( $params['enabled'] ) && $params['enabled']; |
| 45 | + |
| 46 | + $this->getMain()->setCacheMode( $this->listAllowed || $this->listEnabled |
| 47 | + ? 'anon-public-user-private' : 'public' ); |
| 48 | + |
| 49 | + $this->applyList( $this->getList() ); |
| 50 | + } |
| 51 | + |
| 52 | + private function getList() { |
| 53 | + $gadgets = Gadget::loadStructuredList(); |
| 54 | + |
| 55 | + $result = array(); |
| 56 | + foreach ( $gadgets as $category => $list ) { |
| 57 | + if ( $this->categories && !isset( $this->categories[$category] ) ) { |
| 58 | + continue; |
| 59 | + } |
| 60 | + foreach ( $list as $g ) { |
| 61 | + if ( $this->isNeeded( $g ) ) { |
| 62 | + $result[] = $g; |
| 63 | + } |
| 64 | + } |
| 65 | + } |
| 66 | + return $result; |
| 67 | + } |
| 68 | + |
| 69 | + private function applyList( $gadgets ) { |
| 70 | + $data = array(); |
| 71 | + $result = $this->getResult(); |
| 72 | + |
| 73 | + foreach ( $gadgets as $g ) { |
| 74 | + $row = array(); |
| 75 | + if ( isset( $this->props['name'] ) ) { |
| 76 | + $row['name'] = $g->getName(); |
| 77 | + } |
| 78 | + if ( isset( $this->props['desc'] ) ) { |
| 79 | + $row['desc'] = $g->getDescription(); |
| 80 | + } |
| 81 | + if ( isset( $this->props['desc-raw'] ) ) { |
| 82 | + $row['desc-raw'] = $g->getRawDescription(); |
| 83 | + } |
| 84 | + if ( isset( $this->props['category'] ) ) { |
| 85 | + $row['category'] = $g->getCategory(); |
| 86 | + } |
| 87 | + if ( isset( $this->props['resourceloader'] ) && $g->supportsResourceLoader() ) { |
| 88 | + $row['resourceloader'] = ''; |
| 89 | + } |
| 90 | + if ( isset( $this->props['scripts'] ) ) { |
| 91 | + $row['scripts'] = $g->getScripts(); |
| 92 | + $result->setIndexedTagName( $row['scripts'], 'script' ); |
| 93 | + } |
| 94 | + if ( isset( $this->props['styles'] ) ) { |
| 95 | + $row['styles'] = $g->getStyles(); |
| 96 | + $result->setIndexedTagName( $row['styles'], 'style' ); |
| 97 | + } |
| 98 | + if ( isset( $this->props['dependencies'] ) ) { |
| 99 | + $row['dependencies'] = $g->getDependencies(); |
| 100 | + $result->setIndexedTagName( $row['dependencies'], 'module' ); |
| 101 | + } |
| 102 | + if ( isset( $this->props['rights'] ) ) { |
| 103 | + $row['rights'] = $g->getRequiredRights(); |
| 104 | + $result->setIndexedTagName( $row['rights'], 'right' ); |
| 105 | + } |
| 106 | + if ( isset( $this->props['default'] ) && $g->isOnByDefault() ) { |
| 107 | + $row['default'] = ''; |
| 108 | + } |
| 109 | + if ( isset( $this->props['definition'] ) ) { |
| 110 | + $row['definition'] = $g->getDefinition(); |
| 111 | + } |
| 112 | + $data[] = $row; |
| 113 | + } |
| 114 | + $result->setIndexedTagName( $data, 'gadget' ); |
| 115 | + $result->addValue( 'query', $this->getModuleName(), $data ); |
| 116 | + } |
| 117 | + |
| 118 | + /** |
| 119 | + * |
| 120 | + */ |
| 121 | + private function isNeeded( Gadget $gadget ) { |
| 122 | + global $wgUser; |
| 123 | + |
| 124 | + return ( $this->neededNames === false || isset( $this->neededNames[$gadget->getName()] ) ) |
| 125 | + && ( !$this->listAllowed || $gadget->isAllowed( $wgUser ) ) |
| 126 | + && ( !$this->listEnabled || $gadget->isEnabled( $wgUser ) ); |
| 127 | + } |
| 128 | + |
| 129 | + public function getAllowedParams() { |
| 130 | + return array( |
| 131 | + 'prop' => array( |
| 132 | + ApiBase::PARAM_DFLT => 'name', |
| 133 | + ApiBase::PARAM_ISMULTI => true, |
| 134 | + ApiBase::PARAM_TYPE => array( |
| 135 | + 'name', |
| 136 | + 'desc', |
| 137 | + 'desc-raw', |
| 138 | + 'category', |
| 139 | + 'resourceloader', |
| 140 | + 'scripts', |
| 141 | + 'styles', |
| 142 | + 'dependencies', |
| 143 | + 'rights', |
| 144 | + 'default', |
| 145 | + 'definition', |
| 146 | + ), |
| 147 | + ), |
| 148 | + 'categories' => array( |
| 149 | + ApiBase::PARAM_ISMULTI => true, |
| 150 | + ApiBase::PARAM_TYPE => 'string', |
| 151 | + ), |
| 152 | + 'names' => array( |
| 153 | + ApiBase::PARAM_TYPE => 'string', |
| 154 | + ApiBase::PARAM_ISMULTI => true, |
| 155 | + ), |
| 156 | + 'allowed' => false, |
| 157 | + 'enabled' => false, |
| 158 | + ); |
| 159 | + } |
| 160 | + |
| 161 | + public function getDescription() { |
| 162 | + return 'Returns a list of gadgets used on this wiki'; |
| 163 | + } |
| 164 | + |
| 165 | + public function getParamDescription() { |
| 166 | + return array( |
| 167 | + 'prop' => array( |
| 168 | + 'What gadget information to get:', |
| 169 | + ' name - Internal gadget name', |
| 170 | + ' desc - Gadget description transformed into HTML (can be slow, use only if really needed)', |
| 171 | + ' desc-raw - Gadget description in raw wikitext', |
| 172 | + ' category - Internal name of a category gadget belongs to (empty if top-level gadget)', |
| 173 | + ' resourceloader - Whether gadget supports ResourceLoader', |
| 174 | + " scripts - List of gadget's scripts", |
| 175 | + " styles - List of gadget's styles", |
| 176 | + ' dependencies - List of ResourceLoader modules gadget depends on', |
| 177 | + ' rights - List of rights required to use gadget, if any', |
| 178 | + ' default - Whether gadget is enabled by default', |
| 179 | + ' definition - Line from MediaWiki:Gadgets-definition used to define the gadget', |
| 180 | + ), |
| 181 | + 'categories' => 'Gadgets from what categories to retrieve', |
| 182 | + 'names' => 'Name(s) of gadgets to retrieve', |
| 183 | + 'allowed' => 'List only gadgets allowed to current user', |
| 184 | + 'enabled' => 'List only gadgets enabled by current user', |
| 185 | + ); |
| 186 | + } |
| 187 | + |
| 188 | + protected function getExamples() { |
| 189 | + $params = $this->getAllowedParams(); |
| 190 | + $allProps = implode( '|', $params['prop'][ApiBase::PARAM_TYPE] ); |
| 191 | + return array( |
| 192 | + 'Get a list of gadgets along with their descriptions:', |
| 193 | + ' api.php?action=query&list=gadgets&gaprop=name|desc', |
| 194 | + 'Get a list of gadgets with all possble properties:', |
| 195 | + " api.php?action=query&list=gadgets&gaprop=$allProps", |
| 196 | + 'Get a list of gadgets belonging to caregory "foo":', |
| 197 | + ' api.php?action=query&list=gadgets&gacategories=foo', |
| 198 | + 'Get information about gadgets named "foo" and "bar":', |
| 199 | + ' api.php?action=query&list=gadgets&ganames=foo|bar&gaprop=name|desc|category', |
| 200 | + 'Get a list of gadgets enabled by current user:', |
| 201 | + ' api.php?action=query&list=gadgets&gaenabled', |
| 202 | + ); |
| 203 | + } |
| 204 | + |
| 205 | + public function getVersion() { |
| 206 | + return __CLASS__ . ': $Id$'; |
| 207 | + } |
| 208 | + |
| 209 | +} |
Property changes on: branches/RL2/extensions/Gadgets/api/ApiQueryGadgets.php |
___________________________________________________________________ |
Added: svn:keywords |
1 | 210 | + Id |
Added: svn:eol-style |
2 | 211 | + native |
Index: branches/RL2/extensions/Gadgets/api/ApiQueryGadgetCategories.php |
— | — | @@ -0,0 +1,122 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Created on 16 April 2011 |
| 5 | + * API for Gadgets extension |
| 6 | + * |
| 7 | + * This program is free software; you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU General Public License as published by |
| 9 | + * the Free Software Foundation; either version 2 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License along |
| 18 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 20 | + * http://www.gnu.org/copyleft/gpl.html |
| 21 | + */ |
| 22 | + |
| 23 | +class ApiQueryGadgetCategories extends ApiQueryBase { |
| 24 | + private $props, |
| 25 | + $neededNames; |
| 26 | + |
| 27 | + public function __construct( $query, $moduleName ) { |
| 28 | + parent::__construct( $query, $moduleName, 'gc' ); |
| 29 | + } |
| 30 | + |
| 31 | + public function execute() { |
| 32 | + $params = $this->extractRequestParams(); |
| 33 | + $this->props = array_flip( $params['prop'] ); |
| 34 | + $this->neededNames = isset( $params['names'] ) |
| 35 | + ? array_flip( $params['names'] ) |
| 36 | + : false; |
| 37 | + |
| 38 | + $this->getMain()->setCacheMode( 'public' ); |
| 39 | + |
| 40 | + $this->getList(); |
| 41 | + } |
| 42 | + |
| 43 | + private function getList() { |
| 44 | + $data = array(); |
| 45 | + $result = $this->getResult(); |
| 46 | + $gadgets = Gadget::loadStructuredList(); |
| 47 | + |
| 48 | + foreach ( $gadgets as $category => $list ) { |
| 49 | + if ( !$this->neededNames || isset( $this->neededNames[$category] ) ) { |
| 50 | + $row = array(); |
| 51 | + if ( isset( $this->props['name'] ) ) { |
| 52 | + $row['name'] = $category; |
| 53 | + } |
| 54 | + if ( $category !== "" ) { |
| 55 | + if ( isset( $this->props['desc'] ) ) { |
| 56 | + $row['desc'] = wfMessage( "gadget-section-$category" )->parse(); |
| 57 | + } |
| 58 | + if ( isset( $this->props['desc-raw'] ) ) { |
| 59 | + $row['desc-raw'] = wfMessage( "gadget-section-$category" )->plain(); |
| 60 | + } |
| 61 | + } |
| 62 | + if ( isset( $this->props['members'] ) ) { |
| 63 | + $row['members'] = count( $list ); |
| 64 | + } |
| 65 | + $data[] = $row; |
| 66 | + } |
| 67 | + } |
| 68 | + $result->setIndexedTagName( $data, 'category' ); |
| 69 | + $result->addValue( 'query', $this->getModuleName(), $data ); |
| 70 | + } |
| 71 | + |
| 72 | + public function getAllowedParams() { |
| 73 | + return array( |
| 74 | + 'prop' => array( |
| 75 | + ApiBase::PARAM_DFLT => 'name', |
| 76 | + ApiBase::PARAM_ISMULTI => true, |
| 77 | + ApiBase::PARAM_TYPE => array( |
| 78 | + 'name', |
| 79 | + 'desc', |
| 80 | + 'desc-raw', |
| 81 | + 'members', |
| 82 | + ), |
| 83 | + ), |
| 84 | + 'names' => array( |
| 85 | + ApiBase::PARAM_TYPE => 'string', |
| 86 | + ApiBase::PARAM_ISMULTI => true, |
| 87 | + ), |
| 88 | + ); |
| 89 | + } |
| 90 | + |
| 91 | + public function getDescription() { |
| 92 | + return 'Returns a list of gadget categories'; |
| 93 | + } |
| 94 | + |
| 95 | + public function getParamDescription() { |
| 96 | + return array( |
| 97 | + 'prop' => array( |
| 98 | + 'What gadget category information to get:', |
| 99 | + ' name - Internal category name', |
| 100 | + ' desc - Category description transformed into HTML (can be slow, use only if really needed)', |
| 101 | + ' desc-raw - Category description in raw wikitext', |
| 102 | + ' members - Number of gadgets in category', |
| 103 | + ), |
| 104 | + 'names' => 'Name(s) of gadgets to retrieve', |
| 105 | + ); |
| 106 | + } |
| 107 | + |
| 108 | + protected function getExamples() { |
| 109 | + $params = $this->getAllowedParams(); |
| 110 | + $allProps = implode( '|', $params['prop'][ApiBase::PARAM_TYPE] ); |
| 111 | + return array( |
| 112 | + 'Get a list of existing gadget categories:', |
| 113 | + ' api.php?action=query&list=gadgetcategories', |
| 114 | + 'Get all information about categories named "foo" and "bar":', |
| 115 | + " api.php?action=query&list=gadgetcategories&gcnames=foo|bar&gcprop=$allProps", |
| 116 | + ); |
| 117 | + } |
| 118 | + |
| 119 | + public function getVersion() { |
| 120 | + return __CLASS__ . ': $Id$'; |
| 121 | + } |
| 122 | + |
| 123 | +} |
Property changes on: branches/RL2/extensions/Gadgets/api/ApiQueryGadgetCategories.php |
___________________________________________________________________ |
Added: svn:keywords |
1 | 124 | + Id |
Added: svn:eol-style |
2 | 125 | + native |