Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhardcode "/w" from the path to api.php (for non-Wikimedia wikis) #4

Merged
merged 1 commit into from
Jan 16, 2023

Conversation

edwardspec
Copy link
Contributor

See https://phabricator.wikimedia.org/T297337

/w/api.php is only correct if $wgScriptPath == "/w". Non-Wikimedia wikis can have a different value here.

Extension:Graph will be modified to provide correct "scriptPath" to this library via the options.

See https://phabricator.wikimedia.org/T297337

/w/api.php is only correct if $wgScriptPath = "/w".
Non-Wikimedia wikis can have a different value here.

Extension:Graph will be modified to provide correct "scriptPath"
to this library via the options.
@brettz9
Copy link

brettz9 commented Jan 16, 2023

@nyurik : Any chance you could take a look?

@@ -116,6 +116,9 @@ class VegaWrapper2 {
const host = urlObj.wiki ? urlObj.wiki : options.domain;
const sanitizedHost = this.sanitizeHost(host);

// Path to api.php, e.g. "/w" for Wikimedia projects.
const scriptPath = options.scriptPath !== undefined ? options.scriptPath : '/w'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not certain, but wouldn't this be simpler? I might be a bit rusty on my javascript though. Also, needs a semicolon.

Suggested change
const scriptPath = options.scriptPath !== undefined ? options.scriptPath : '/w'
const scriptPath = options.scriptPath ?? '/w';

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?? would also allow for null (which I wouldn't think would be a problem here), but is indeed otherwise equivalent; however, depending on your versions of JavaScript support, this "nullish coalescing operator" was added more recently in JavaScript. Still, is now pretty good: https://caniuse.com/mdn-javascript_operators_nullish_coalescing .

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also do options.scriptPath || '/w'; i think

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would unfortunately choose the default when the script path was the empty string, which I imagine could be a problem here.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think an empty string is valid - it must start with a /, or else it won't work

Copy link
Owner

@nyurik nyurik Jan 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, oops, you are right.... I think the better path would be to introduce a full API endpoint url rather than a part of it. E.g. apiEndpoint = "/w/api.php" ? This would allow the proper override, wouldn't it? I just feel string concat magic is a bit more ... unpredictable

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have any strong opinions about it myself, but I can see your point. Not sure if the submitter, @edwardspec , has any opinions about it...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't matter to me. Feel free to change the syntax if needed.

Copy link
Owner

@nyurik nyurik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, not worth it i guess, and there is no server-side var i think that represents the entire api endpoint

@nyurik nyurik merged commit 3d72dec into nyurik:master Jan 16, 2023
@brettz9
Copy link

brettz9 commented Jan 16, 2023

Thanks very much! Do you think you could put out a release too, so the graph extension can offer this fix to users?

@nyurik
Copy link
Owner

nyurik commented Jan 17, 2023

ok, did a minor update, pushed and released as 0.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants