Update api module constructors

This also replaces a deprecated function and adds some code docs.

Change-Id: I22c77d370469c10cad5d504b06280e933eeeeeff
This commit is contained in:
Thiemo Mättig 2015-06-17 20:21:27 +02:00
parent cf0f2310a8
commit 5b1f8a1e50
5 changed files with 46 additions and 24 deletions

View file

@ -152,8 +152,8 @@ class GadgetHooks {
$resourceLoader->register( $g->getModuleName(), $module );
}
}
return true;
return true;
}
/**
@ -189,9 +189,8 @@ class GadgetHooks {
}
}
// Allow other extensions, e.g. MobileFrontend, to disallow legacy gadgets
if ( wfRunHooks( 'Gadgets::allowLegacy', array( $out->getContext() ) ) ) {
if ( Hooks::run( 'Gadgets::allowLegacy', array( $out->getContext() ) ) ) {
$lb->execute( __METHOD__ );
$done = array();

View file

@ -10,10 +10,7 @@
*/
class SpecialGadgets extends SpecialPage {
/**
* Constructor
*/
function __construct() {
public function __construct() {
parent::__construct( 'Gadgets', '', true );
}
@ -21,7 +18,7 @@ class SpecialGadgets extends SpecialPage {
* Main execution function
* @param $par array Parameters passed to the page
*/
function execute( $par ) {
public function execute( $par ) {
$parts = explode( '/', $par );
if ( count( $parts ) == 2 && $parts[0] == 'export' ) {

View file

@ -20,11 +20,18 @@
*/
class ApiQueryGadgetCategories extends ApiQueryBase {
private $props,
$neededNames;
/**
* @var array
*/
private $props;
public function __construct( $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'gc' );
/**
* @var array|bool
*/
private $neededNames;
public function __construct( ApiQuery $queryModule, $moduleName ) {
parent::__construct( $queryModule, $moduleName, 'gc' );
}
public function execute() {

View file

@ -20,14 +20,33 @@
*/
class ApiQueryGadgets extends ApiQueryBase {
private $props,
$categories,
$neededIds,
$listAllowed,
$listEnabled;
/**
* @var array
*/
private $props;
public function __construct( $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'ga' );
/**
* @var array|bool
*/
private $categories;
/**
* @var array|bool
*/
private $neededIds;
/**
* @var bool
*/
private $listAllowed;
/**
* @var bool
*/
private $listEnabled;
public function __construct( ApiQuery $queryModule, $moduleName ) {
parent::__construct( $queryModule, $moduleName, 'ga' );
}
public function execute() {

View file

@ -11,12 +11,12 @@ class GadgetsTest extends MediaWikiTestCase {
return $g;
}
function testInvalidLines() {
public function testInvalidLines() {
$this->assertFalse( Gadget::newFromDefinition( '' ) );
$this->assertFalse( Gadget::newFromDefinition( '<foo|bar>' ) );
}
function testSimpleCases() {
public function testSimpleCases() {
$g = $this->create( '* foo bar| foo.css|foo.js|foo.bar' );
$this->assertEquals( 'foo_bar', $g->getName() );
$this->assertEquals( 'ext.gadget.foo_bar', $g->getModuleName() );
@ -29,21 +29,21 @@ class GadgetsTest extends MediaWikiTestCase {
$this->assertTrue( $g->hasModule() );
}
function testRLtag() {
public function testRLtag() {
$g = $this->create( '*foo [ResourceLoader]|foo.js|foo.css' );
$this->assertEquals( 'foo', $g->getName() );
$this->assertTrue( $g->supportsResourceLoader() );
$this->assertEquals( 0, count( $g->getLegacyScripts() ) );
}
function testDependencies() {
public function testDependencies() {
$g = $this->create( '* foo[ResourceLoader|dependencies=jquery.ui]|bar.js' );
$this->assertEquals( array( 'Gadget-bar.js' ), $g->getScripts() );
$this->assertTrue( $g->supportsResourceLoader() );
$this->assertEquals( array( 'jquery.ui' ), $g->getDependencies() );
}
function testPreferences() {
public function testPreferences() {
$prefs = array();
$gadgets = Gadget::fetchStructuredList( '* foo | foo.js