Skip to content

Commit

Permalink
feat: Add {{#evu}} parser function
Browse files Browse the repository at this point in the history
  • Loading branch information
octfx committed Aug 16, 2023
1 parent 985b1a1 commit 7e12bd3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions EmbedVideo.i18n.magic.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

$magicWords['en'] = [
'ev' => [ 0, 'ev' ],
'evu' => [ 0, 'evu' ],
'ev_start' => [ 0, 'start=$1' ],
'ev_end' => [ 0, 'end=$1' ],
'cover' => [ 0, 'cover=$1' ],
Expand Down
21 changes: 21 additions & 0 deletions includes/EmbedVideo.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,27 @@ public function __construct( ?Parser $parser, array $args, bool $fromTag = false
$this->config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'EmbedVideo' );
}

/**
* {{#evu}} parser function that tries to extract the service from the host name
*
* @param Parser $parser
* @param PPFrame $frame
* @param array $args
* @param bool $fromTag
* @return array
*/
public static function parseEVU( Parser $parser, PPFrame $frame, array $args, bool $fromTag = false ): array {
$host = parse_url( $args[0] ?? '', PHP_URL_HOST );

if ( is_string( $host ) ) {
$host = explode( '.', trim( $host, 'w.' ) )[0] ?? null;
}

array_unshift( $args, $host );

return self::parseEV( $parser, $frame, $args, $fromTag );
}

/**
* Parse the values input from the {{#ev}} parser function
*
Expand Down
10 changes: 10 additions & 0 deletions includes/EmbedVideoHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ public function onParserFirstCallInit( $parser ): void {
wfLogWarning( $e->getMessage() );
}

try {
$parser->setFunctionHook(
'evu',
[ EmbedVideo::class, 'parseEVU' ],
Parser::SFH_OBJECT_ARGS
);
} catch ( MWException $e ) {
wfLogWarning( $e->getMessage() );
}

$enabledServices = $this->config->get( 'EmbedVideoEnabledServices' );
$checkEnabledServices = !empty( $enabledServices );

Expand Down

0 comments on commit 7e12bd3

Please sign in to comment.