setFunctionHook( 'gitsnack', array( 'GitSnaxHooks', 'getGitSnack' ) ); return true; } /** * Retrieve the github content * * @param Parser $parser: the Parser object * @param string $mode: 'code' or 'gist' link * @param string $file: the URL part minus hostname, no leading / * @return string|false: either the content or false */ public static function getGitSnack( $parser, $mode = '', $file = '' ) { global $wgGitSnaxCode, $wgGitSnaxGist, $wgGitSnaxCTTL; switch ( $mode ) { case "gist": $gitURL = $wgGitSnaxGist; break; case "code": $gitURL = $wgGitSnaxCode; break; default: return false; } if ( $file === '' ) { return false; } else { $gitURL = $gitURL . $file; $cacheKey = wfMemcKey( __METHOD__, $gitURL ); $cachedValue = wfGetMainCache()->get( $cacheKey ); if ( is_string( $cachedValue ) ) { $data = $cachedValue; } else { $data = \Http::get( $gitURL ); wfGetMainCache()->set( $cacheKey, $data, $wgGitSnaxCTTL ); } $result = "
$data"; return array( $result, 'nowiki' => true, 'noparse' => true, 'noargs' => true, 'isHTML' => true, ); } } // getGitSnack } // GitSnaxHooks