diff --git "a/class-generic\\Singleton.php" "b/class-generic\\Singleton.php" new file mode 100644 index 0000000..c466edd --- /dev/null +++ "b/class-generic\\Singleton.php" @@ -0,0 +1,38 @@ +. + +# generic stuff +namespace generic; + +class Singleton { + + public static function getInstance() { + static $instance; + if( ! $instance ) { + $instance = static::create(); + } + return $instance; + } + + protected static function create() { + throw new \Exception('must override'); + } + + public function __construct() { + throw new \Exception('wrong usage'); + } +} diff --git "a/class-mw\\StaticSite.php" "b/class-mw\\StaticSite.php" new file mode 100644 index 0000000..3f166cc --- /dev/null +++ "b/class-mw\\StaticSite.php" @@ -0,0 +1,58 @@ +. + +# MediaWiki +namespace mw; + +class StaticSite extends \generic\Singleton { + + /** + * @override \generic\Singleton::create() + */ + protected static function create() { + $site = new Site( static::getApiURL() ); + + // Set default namespaces + foreach( Ns::defaultCanonicalNames() as $ns_id => $ns ) { + $site->setNamespace( new Ns( $ns_id, $ns ) ); + } + + // Callback + static::onCreate( $site ); + + return $site; + } + + /** + * To be overloaded. + * + * @return string + */ + protected static function getApiURL() { + throw new \Exception('must overload'); + } + + /** + * To be overloaded. + * + * @param $site mw\Site + */ + protected static function onCreate( & $site ) { + // Please override + } + +} diff --git "a/class-wm\\Commons.php" "b/class-wm\\Commons.php" new file mode 100644 index 0000000..ce61985 --- /dev/null +++ "b/class-wm\\Commons.php" @@ -0,0 +1,29 @@ +. +# Wikimedia +namespace wm; + +class Commons extends \mw\StaticSite { + + /** + * @overload \mw\StaticSite::getApiURL() + */ + protected static function getApiURL() { + return 'https://commons.wikimedia.org/w/api.php'; + } + +} diff --git "a/class-wm\\WikipediaIt.php" "b/class-wm\\WikipediaIt.php" new file mode 100644 index 0000000..7500bfb --- /dev/null +++ "b/class-wm\\WikipediaIt.php" @@ -0,0 +1,56 @@ +. +# Wikimedia +namespace wm; + +class WikipediaIt extends \mw\StaticSite { + + /** + * @overload \mw\StaticSite::getApiURL() + */ + protected static function getApiURL() { + return 'https://it.wikipedia.org/w/api.php'; + } + + /** + * @overload \mw\StaticSite::onCreate( $site ) + */ + protected static function onCreate( $site ) { + $site->setNamespaces( [ + new \mw\Ns( 1, 'Discussione' ), + new \mw\Ns( 2, 'Utente' ), + new \mw\Ns( 3, 'Discussioni utente' ), + new \mw\Ns( 4, 'Wikipedia', ['Wp'] ), + new \mw\Ns( 5, 'Discussioni Wikipedia', ['Dw'] ), + new \mw\Ns( 6, 'File', ['Image', 'Immagine'] ), + new \mw\Ns( 7, 'Discussioni file', ['Discussioni immagine', 'Image talk'] ), + new \mw\Ns( 9, 'Discussioni MediaWiki' ), + new \mw\Ns( 10, 'Template', ['T'] ), + new \mw\Ns( 11, 'Discussioni template' ), + new \mw\Ns( 12, 'Aiuto' ), + new \mw\Ns( 13, 'Discussioni aiuto' ), + new \mw\Ns( 14, 'Categoria', [ 'Cat' ] ), + new \mw\Ns( 15, 'Discussioni categoria' ), + new \mw\Ns( 100, 'Portale' ), + new \mw\Ns( 101, 'Discussioni portale' ), + new \mw\Ns( 102, 'Progetto' ), + new \mw\Ns( 103, 'Discussioni proggetto', ['Dp'] ), + new \mw\Ns( 828, 'Modulo' ), + new \mw\Ns( 829, 'Discussioni modulo' ) + ] ); + } +}