diff --git a/autoload.php b/autoload-with-laser-cannon.php similarity index 66% copy from autoload.php copy to autoload-with-laser-cannon.php index 58a888a..2505b73 100644 --- a/autoload.php +++ b/autoload-with-laser-cannon.php @@ -1,23 +1,30 @@ . -spl_autoload_register( function( $name ) { - $path = __DIR__ . DIRECTORY_SEPARATOR . 'include' . DIRECTORY_SEPARATOR . "class-$name.php"; - if( is_file( $path ) ) { - require $path; - } -} ); +/** + * Complete autoload (with functions) + * + * This is useful if you like to create bots. + * + * If you love creating frameworks instead, see the 'autoload.php'. + */ + +// autoload the classes +require __DIR__ . '/autoload.php'; + +// load some functions +require __DIR__ . '/include/functions.php'; diff --git a/autoload.php b/autoload.php index 58a888a..5d014cd 100644 --- a/autoload.php +++ b/autoload.php @@ -1,23 +1,34 @@ . +/** + * Minimal autoload (without functions) + * + * This is useful if you like creating frameworks. + * + * If you love creating bots instead, see the 'autoload-with-laser-cannon.php'. + */ + +/** + * Autoload classes on-demand + */ spl_autoload_register( function( $name ) { - $path = __DIR__ . DIRECTORY_SEPARATOR . 'include' . DIRECTORY_SEPARATOR . "class-$name.php"; + $path = __DIR__ . "/include/class-$name.php"; if( is_file( $path ) ) { require $path; } } ); diff --git a/autoload.php b/include/functions.php similarity index 57% copy from autoload.php copy to include/functions.php index 58a888a..935b25a 100644 --- a/autoload.php +++ b/include/functions.php @@ -1,23 +1,37 @@ +#!/usr/bin/php . -spl_autoload_register( function( $name ) { - $path = __DIR__ . DIRECTORY_SEPARATOR . 'include' . DIRECTORY_SEPARATOR . "class-$name.php"; - if( is_file( $path ) ) { - require $path; - } -} ); +/** + * Shortcuts very useful when you are creating a bot + */ + +/** + * Get a single wiki from its UID + * + * Some known UIDs: + * wikidatawiki - Wikidata + * commonswiki - Wikimedia Commons + * metawiki - Meta-wiki + * itwiki - Wikipedia (it) + * + * @param string $uid + * @return mw\StaticSite + */ +function wiki( $uid ) { + return \web\MediaWikis::findFromUID( $uid ); +}