diff --git a/include/functions.php b/include/functions.php index fd6fa57..aff1092 100644 --- a/include/functions.php +++ b/include/functions.php @@ -1,72 +1,94 @@ . /** * 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 ); } /** * Get Wikidata * * @return wm\Wikidata */ function wikidata() { return wiki( 'wikidatawiki' ); } /** * Get Wikimedia Commons * * @return wm\Wikidata */ function commons() { return wiki( 'commonswiki' ); } /** * Get the Italian Wikipedia * * @return wm\WikipediaIt */ function itwiki() { return wiki( 'itwiki' ); } /** * Enable debug mode * * @param $status status Enable debug or not */ function bozmw_debug( $status = true ) { \cli\Log::$DEBUG = $status; } + +/** + * Serialize some data and write into a file + * + * @param $file string File path + * @param $data mixed Your data + */ +function file_put_data( $file, $data ) { + $data_raw = serialize( $data ); + file_put_contents( $file, $data_raw ); +} + +/** + * Unserialize some data from a file + * + * @param $file string File path + * @return mixed Data + */ +function file_get_data( $file ) { + $contents = file_get_contents( $file ); + return unserialize( $contents ); +}