diff --git a/README.md b/README.md index f4d9129..1c5d385 100644 --- a/README.md +++ b/README.md @@ -1,56 +1,56 @@ # boz-mw This is another MediaWiki API handler in PHP. ## Tools See [the tools](./tools/README.md). ## API showcase Here some usage examples: ```php fetch( [ 'action' => 'query', 'prop' => 'info', 'titles' => [ 'Pagina principale' ] ] ); print_r( $response ); echo "Simple Italian Wikipedia API query with continuation support:\n"; -$members = \wm\WikipediaIt::getInstance()->createQuery( [ +$members = \wm\WikipediaIt::instance()->createQuery( [ 'action' => 'query', 'list' => 'categorymembers', 'cmtitle' => 'Categoria:Software con licenza GNU GPL', ] ); foreach( $members->getGenerator() as $response ) { print_r( $response ); } echo "Simple POST request:\n"; \mw\API::$DEFAULT_USERNAME = 'My username'; \mw\API::$DEFAULT_PASSWORD = 'My bot password'; -$w = \wm\WikipediaIt::getInstance()->login(); +$w = \wm\WikipediaIt::instance()->login(); $response = $w->edit( [ 'title' => 'Special:Nothing', 'text' => 'My wikitext', 'summary' => 'My edit summary', ] ); print_r( $response ); ``` ## Known usage * [ItalianWikipediaDeletionBot](https://github.com/valerio-bozzolan/ItalianWikipediaDeletionBot) * [wiki-users-leaflet](https://github.com/valerio-bozzolan/wiki-users-leaflet/) hosted at [WMF Labs](https://tools.wmflabs.org/it-wiki-users-leaflet/) diff --git "a/include/class-generic\\Singleton.php" "b/include/class-generic\\Singleton.php" index 98b7edc..77a6fcb 100644 --- "a/include/class-generic\\Singleton.php" +++ "b/include/class-generic\\Singleton.php" @@ -1,58 +1,58 @@ . # generic stuff namespace generic; /** - * A singleton gives a getInstance() method + * A singleton gives an #instance() method */ trait Singleton { /** * Get an instance of this class * * @return self */ - public static function getInstance() { + public static function instance() { static $instance; if( ! $instance ) { $instance = static::create(); } return $instance; } /** * Function to be overrided to create an instance of this class * * @return self */ protected static function create() { return new static(); } /** * Throw an usage error */ protected static function throwSingletonUsage() { throw new \Exception( sprintf( - 'wrong singleton usage, you must call %s::getInstance()', + 'wrong singleton usage, you must call %s::instance()', static::class ) ); } } diff --git "a/include/class-web\\MediaWikis.php" "b/include/class-web\\MediaWikis.php" index b4f7485..3556193 100644 --- "a/include/class-web\\MediaWikis.php" +++ "b/include/class-web\\MediaWikis.php" @@ -1,67 +1,67 @@ . # websites in the Internet namespace web; /** * All the MediaWiki instances in the Internet :^) */ abstract class MediaWikis { /** * Get all the registered MediaWiki classes * * @return array */ protected static function allClasses() { return [ \wm\WikipediaIt ::class, \wm\Wikidata ::class, \wm\Commons ::class, \wm\MetaWiki ::class, \web\LandscapeforWiki::class, ]; } /** * Get all the registered MediaWiki instances * * @generator */ public static function all() { foreach( self::allClasses() as $classname ) { - yield $classname::getInstance(); + yield $classname::instance(); } } /** * Get a specific MediaWiki instance from its UID * * @param $uid string * @return mw\StaticSite|false */ public static function findFromUID( $uid ) { foreach( self::all() as $one ) { if( $one::UID === $uid ) { return $one; } } return false; } }