Skip to content

Added Wikipedia extension (fixed)#1941

Open
samuellouf wants to merge 22 commits into
TurboWarp:masterfrom
samuellouf:Wikipedia
Open

Added Wikipedia extension (fixed)#1941
samuellouf wants to merge 22 commits into
TurboWarp:masterfrom
samuellouf:Wikipedia

Conversation

@samuellouf

Copy link
Copy Markdown
Contributor

Hello!
I'm re-pulling my "Wikipedia" extension.
I fixed the issues adressed it my previous pull request (#1075) :
See here.
It still uses MediaWiki public API.
Enjoy !
Post-scriptum :
Here is the logo :
Logo

And here is the banner :

Wikipedia Banner

samuellouf and others added 6 commits October 2, 2023 18:40
Added my Wikipedia extension to the list
Replaced 'fetch()' by 'Scratch.fetch()'
Detail :
 - Created my own logo (Puzzle piece with a W)
 - Added License
 - Returns empty strings instead of 'Error : [...]'
 - Added a fallback empty string for "getLanguage"
 - Removed "isString" cause I didn't need it
 - Switched the function names to camel case
 - Removed "wikipedia" from the function names
 - Added "addLanguage"
 - Edited JSON array filter to return JSON objects
 - Made a banner
@github-actions github-actions Bot added the pr: new extension Pull requests that add a new extension label Feb 19, 2025
@NexusKitten

Copy link
Copy Markdown
Contributor

Just for future reference, I'm pretty sure you're allowed to reopen a commit marked as stale if you've updated it. Typically, there's nothing wrong with a stale PR, they're just closed to cut down on the amount of inactive pull requests.

- Changed User Adress
- Removed text from banner
@samuellouf

Copy link
Copy Markdown
Contributor Author

Oh! Ok. Thanks!

@samuellouf

Copy link
Copy Markdown
Contributor Author

Finished!

@Brackets-Coder Brackets-Coder left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The code looks alright, but I don't know about merging this, there's some crazy stuff on Wikipedia...

Comment thread extensions/SamuelLouf/Wikipedia.js Outdated
Comment on lines +166 to +167
"---",
"---",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is there two breaks here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have no Idea

Comment thread extensions/SamuelLouf/Wikipedia.js Outdated
Comment on lines +212 to +214
return Scratch.fetch(
`https://${this.wikipediaLanguages}.wikipedia.org/w/api.php?action=query&prop=extracts&exlimit=1&titles=${encodeURIComponent(args.NAME)}&explaintext=1&exsectionformat=plain&format=json&origin=*`
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't know about you, but I think we didn't like referencing external domains? I know some other extensions do it so I'm unsure...

  1. it could go down
  2. it could be whitelisted

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ohhh... I didn't think about that.
You're probably right

@Brackets-Coder

Copy link
Copy Markdown
Contributor

@CubesterYT we closing this one too for the same reasons as #1972?

@Brackets-Coder

This comment was marked as resolved.

@Brackets-Coder

This comment was marked as resolved.

@Brackets-Coder

This comment was marked as resolved.

@samuellouf samuellouf left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

My bad!
English is my second language.
Thanks for noticing!

@Brackets-Coder

Copy link
Copy Markdown
Contributor

I'll take another look when I get the chance, but I know for certain I'm crazy busy until the weekend

@Brackets-Coder Brackets-Coder self-assigned this Jan 15, 2026

@Brackets-Coder Brackets-Coder left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Switching to any language other than English and returning the default first paragraph returns this error:
TypeError: undefined is not an object (evaluating 'extract.replace')

Switching the language also makes the "short phrase" block return nothing

Also, it might be nice if you could make the block "paragraph [number] on (article) article," but I could see how that could easily be used for plagiarizing large amounts of content

executing the default "add a language block" returns vm"error""Unexpected input recieved in replaceUnsafeChars"

Comment thread extensions/SamuelLouf/Wikipedia.js Outdated
Comment thread extensions/SamuelLouf/Wikipedia.js Outdated
Comment thread extensions/SamuelLouf/Wikipedia.js Outdated
Comment thread extensions/SamuelLouf/Wikipedia.js Outdated
Comment on lines +212 to +221
return Scratch.fetch(
`https://${this.wikipediaLanguages}.wikipedia.org/w/api.php?action=query&prop=extracts&exlimit=1&titles=${encodeURIComponent(args.NAME)}&explaintext=1&exsectionformat=plain&format=json&origin=*`
)
.then((response) => {
if (response.ok == true) {
return response.json();
} else {
return "";
}
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe make some kind of function for this repetitive part?

e.g,

fetchWiki(args).then((data) => { ... }

samuellouf and others added 2 commits January 31, 2026 06:27
Egypt->Egyptian

Co-authored-by: Brackets-Coder <142950368+Brackets-Coder@users.noreply.github.com>
Co-authored-by: Brackets-Coder <142950368+Brackets-Coder@users.noreply.github.com>
samuellouf and others added 2 commits January 31, 2026 06:28
Co-authored-by: Brackets-Coder <142950368+Brackets-Coder@users.noreply.github.com>
 - Added fetchWikipedia function
 - Replaced phrase by sentence
@Brackets-Coder Brackets-Coder dismissed a stale review May 19, 2026 14:55

outdated

@Brackets-Coder

Copy link
Copy Markdown
Contributor

@samuellouf remind me to review this

@samuellouf samuellouf requested a review from a team as a code owner July 9, 2026 16:30

@Brackets-Coder Brackets-Coder left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

More coming soon

Comment on lines +102 to +116
function fetchWikipedia(language, name) {
return Scratch.fetch(
`https://${language}.wikipedia.org/w/api.php?action=query&prop=extracts&exlimit=1&titles=${encodeURIComponent(name)}&explaintext=1&exsectionformat=plain&format=json&origin=*`
)
.then((response) => {
if (response.ok == true) {
return response.json();
} else {
return "";
}
})
.catch((error) => {
return "";
});
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Wrap this in Scratch.canFetch

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No it uses scratch.fetch already

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm confused? I thought we were supposed to wrap even non-native Scratch.fetch with Scratch.canFetch anyway

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I knew for sure regular fetch was supposed to be wrapped

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

which existing extensions wrap Scratch.fetch in canFetch?

@Brackets-Coder Brackets-Coder Jul 10, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't know, maybe I just misunderstood

Lily's skins does

async _createURLSkin(URL, rotationCenter) {
    let imageData;
    if (await Scratch.canFetch(URL)) {
      imageData = await Scratch.fetch(URL);
    } else {
       return;
    }

     ...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

it probably shouldn't

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Scratch.fetch is literally

        if (!await Scratch.canFetch(actualURL)) {
            throw new Error(`Permission to fetch ${actualURL} rejected.`);
        }
        return fetch(url, options);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

okay

@Brackets-Coder

Copy link
Copy Markdown
Contributor

Getting this error on fetching anything from Wikipedia:

TypeError: undefined is not an object (evaluating 'extract.replace')

@Brackets-Coder

Copy link
Copy Markdown
Contributor
Screenshot 2026-07-09 at 1 28 40 PM

<does page [Scratch (programming language)] exist? returns false

@samuellouf

Copy link
Copy Markdown
Contributor Author

As it turns out, I was encoding the page's name as an URI component, then re-encoding it.

@samuellouf

Copy link
Copy Markdown
Contributor Author

This didn't fix the problem. I'm working on it.

@samuellouf

Copy link
Copy Markdown
Contributor Author

It should be work now.

@samuellouf

Copy link
Copy Markdown
Contributor Author

!format

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: new extension Pull requests that add a new extension

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants