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

fix(DiffViewer & ArticleViewer): handle moved articles using MediaWik… #6072

Conversation

Abishekcs
Copy link
Contributor

@Abishekcs Abishekcs commented Dec 20, 2024

closes #6056

What this PR does

This PR addresses an issue where the DiffViewer and ArticleViewer components did not handle moved articles correctly, resulting in errors for DiffViewer and Could not fetch authorship data: Requested page not found. [404] for ArticleViewer.

Fix

Check the current article title by fetching it from the Wikipedia API using the article's page ID if first and last revision are undefined and update the title and URL for the respective article.

Screenshots

Before:

Before.mp4

After:

After.mp4

@Abishekcs Abishekcs marked this pull request as draft December 20, 2024 14:16
@Abishekcs Abishekcs force-pushed the fix/diffviewer-handle-moved-articles branch from 3a99736 to f4a8315 Compare December 22, 2024 10:25
@Abishekcs
Copy link
Contributor Author

I don't know why the build is failing for the test article_viewer_spec.rb. It’s passing for me locally.😅

2024-12-22.18-19-58.mp4

@Abishekcs Abishekcs marked this pull request as ready for review December 22, 2024 13:28
@@ -14,7 +14,7 @@ const Article = ({ article, index, course, fetchArticleDetails, updateArticleTra

const fetchMissingArticleDetails = () => {
if (!articleDetails) {
fetchArticleDetails(article.id, course.id);
fetchArticleDetails(article.id, course.id, article.title, article.mw_page_id);
Copy link
Member

Choose a reason for hiding this comment

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

I think this gets called from several places, including Assignment.jsx which you haven't changed. Did you check them all to verify that this doesn't break anything?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did you check everything to ensure this doesn't break anything?

No 😅, I forgot to check.
Now, I have updated fetchArticleDetails to fetch the article title and the MW page ID directly from the Redux store using the existing article ID via getState. This means other places using fetchArticleDetails no longer need to pass the title and page ID.

@@ -12,5 +12,6 @@ json.course do
json.rating_num rating_priority(article.rating)
json.pretty_rating rating_display(article.rating)
json.user_ids ac.user_ids
json.mw_page_id article.mw_page_id
Copy link
Member

Choose a reason for hiding this comment

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

This could probably be done within the json.call(article ...) instead of on its own line? I guess url and user_ids could be consolidated as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay.

return function (dispatch) {
export function fetchArticleDetails(articleId, courseId, articleTitle, article_mw_page_id) {
return async function (dispatch) {
const crossCheckedArticleTitle = await dispatch(crossCheckArticleTitle(articleId, articleTitle, article_mw_page_id));
Copy link
Member

Choose a reason for hiding this comment

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

Hmm... this will add an extra network call to every time we use fetchArticleDetails, even though in most cases the page has not moved.

Is it possible to implement this strategy only for cases where the query for article data doesn't work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it possible to implement this strategy only for cases where the query for article data doesn't work?

Yes, I made the changes to call crossCheckedArticle only if the last and first revisions are undefined, indicating that the article title has been moved.

@Abishekcs Abishekcs marked this pull request as draft December 31, 2024 12:25
…i page ID

- Added "crossCheckArticleTitle" function to verify and update article titles and URLs using the MediaWiki API based on the page ID.
- Introduced "UPDATE_ARTICLE_TITLE_AND_URL" action in the reducer to update article titles and URLs in the Redux store when article title is
changed.
- Updated "fetchArticleDetails" to integrate "crossCheckArticleTitle" for dynamic title validation and updates before if fetching article first and last revision fails.
- Enhanced handling of moved articles by verifying and updating titles via MediaWiki API by using "crossCheckArticleTitle" in ArticleViewer.
@Abishekcs Abishekcs force-pushed the fix/diffviewer-handle-moved-articles branch from f4a8315 to d8d46eb Compare December 31, 2024 16:49
@Abishekcs Abishekcs marked this pull request as ready for review December 31, 2024 16:53
@Abishekcs
Copy link
Contributor Author

Updated.1.mp4

@ragesoss ragesoss merged commit 3465125 into WikiEducationFoundation:master Dec 31, 2024
1 check passed
@Abishekcs Abishekcs deleted the fix/diffviewer-handle-moved-articles branch December 31, 2024 19:09
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.

DiffViewer breaks if article has been moved
2 participants