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

Remove MWCapabilities object (partial impl) #1878

Closed
wants to merge 1 commit into from

Conversation

VadimKovalenkoSNF
Copy link
Collaborator

@VadimKovalenkoSNF VadimKovalenkoSNF commented Aug 4, 2023

Fixes #1357

/**
* veApiUrl based on top of 'new ApiURLDirecto'
*/
public get veapiUrl(): URL {
Copy link
Collaborator

Choose a reason for hiding this comment

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

veApiUrl(), restApiUrl(), etc. are shortcuts and offer lazyness to the URL directors. I see little value to have them. I suggest to just something like this.apiUrlDirector.getVisualEditorURL()` which works in a lazy manner.

If you you think this.apiUrlDirector.getVisualEditorURL() is really too cumbersome, then OK to just keep the redirection part, but I see no reason why the lazyness is not built in the Director itself considering that the configuration of it happens at construction time.

// TODO: This depend on baseUrlDirector.buildURL(this.apiPath) and looks like a weak solution
this._veapiUrl = this.apiUrlDirector.buildVisualEditorURL()
}
return this._veapiUrl
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not easy, considering that you have so many different styles and developers behind the codebase... but think about:

  • Url vs URL
  • VE vs VisualEditor.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'd like that we have a dedicated ticket about naming conventions.

Copy link
Collaborator

Choose a reason for hiding this comment

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

For VE, the answer is in the validation of https://github.com/openzim/mwoffliner/wiki/API-end%E2%80%90points. For URL, I clearly prefer to keep full uppercase for constants but up to you.

Copy link
Collaborator Author

@VadimKovalenkoSNF VadimKovalenkoSNF Aug 14, 2023

Choose a reason for hiding this comment

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

I renamed ve to visualEditor, but regarding Url, I'd rather keep it as is because there are about ~580 entries across mwoffliner that use the same capitalization. Check here.

action: 'query',
format: 'json',
// TODO: Do we need this.mwCapabilities.coordinatesAvailable here?
prop: `redirects|revisions${this.mwCapabilities.coordinatesAvailable ? '|coordinates' : ''}${this.getCategories ? '|categories' : ''}`,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here there is a chicken-egg problem, not sure how this happened, but you clearly need to put |coordinates to then see if this is supported.


this.modulePath = baseUrlDirector.buildModuleURL(config.modulePath)
// Default capabilities
// TODO: check whether to remove this object
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems you are almost done and ready to get rid of this mwCapabilites.

/*
TODO: Cookie is shared between Downloader and Mediawiki, probably antipattern. Use as interim solution for now.
Also, double-check possible race condition - cookies should be set before checking capabilities.
*/
downloader.loginCookie = resp.headers['set-cookie'].join(';')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Indee... here would help to clearly define what is the duty of the Mediawiki and Downloader class. Once this is clear, easier to refactor.

@@ -296,6 +401,12 @@ class MediaWiki {

return mwMetaData
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

A few comments have been lost here, maybe on purpose?! Just try to keep things commented when needed.

@@ -253,3 +254,12 @@ export function mwRetToArticleDetail(obj: QueryMwRet): KVS<ArticleDetail> {
}
return ret
}

Copy link
Collaborator

@kelson42 kelson42 Aug 10, 2023

Choose a reason for hiding this comment

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

Maybe a comment about what the purpose of this? At a first look, I can not remember... or is this totally new? Sounds a bit strange to have it here... but here again, not sure about the really purpose of mw-api.ts.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I replaced checkApiAvailabilty() method from Downloader because it is more like a utility function.

@kelson42
Copy link
Collaborator

@VadimKovalenkoSNF I had a first look and for the MWCapabilities, even if the work is not over, it looks good and coherent to me. I see a lots of code which is not related to the fix, not sure if this is not rebased properly on main, if you have other commits unrelated, ....

@VadimKovalenkoSNF
Copy link
Collaborator Author

This has been fixed in #1839

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.

Remove MWCapabilities
2 participants