Skip to content

Commit

Permalink
Optimize onEditFilter
Browse files Browse the repository at this point in the history
Before it always called ConfigJsonValidator::newInstance(),
which reads a JSON file from disk. With a guard clause it
is more efficient and more readable.
  • Loading branch information
JeroenDeDauw committed Jan 5, 2025
1 parent c0ac096 commit 0a47a47
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/EntryPoints/MediaWikiHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ public static function onContentHandlerDefaultModelFor( Title $title, ?string &$
}

public static function onEditFilter( EditPage $editPage, ?string $text, ?string $section, string &$error ): void {
if ( !is_string( $text ) || !WikibaseExportExtension::getInstance()->isConfigTitle( $editPage->getTitle() ) ) {
return;
}

$validator = ConfigJsonValidator::newInstance();

if ( is_string( $text )
&& WikibaseExportExtension::getInstance()->isConfigTitle( $editPage->getTitle() )
&& !$validator->validate( $text )
) {
if ( !$validator->validate( $text ) ) {
$errors = $validator->getErrors();
$error = \Html::errorBox(
wfMessage( 'wikibase-export-config-invalid', count( $errors ) )->escaped() .
Expand Down

0 comments on commit 0a47a47

Please sign in to comment.