Need example code in Javascript to login API

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Need example code in Javascript to login API

Shrinivasan T
Hello all,

I am trying to develop a chrome extension to work with wikipedia.

Started exploring javascript for login api.

Got this example.

https://www.mediawiki.org/wiki/Example_login_code_in_JS_%28using_JQuery%29

Stored the code as test.html and opened in chrome.
Got the following error.

 No 'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'null' is therefore not allowed access.

How to solve this error?

https://www.mediawiki.org/wiki/Manual:CORS
The examples here are not helpful.

Please guide me on how to login to mediawiki via javascript?

Thanks.

--
Regards,
T.Shrinivasan


My Life with GNU/Linux : http://goinggnu.wordpress.com
Free E-Magazine on Free Open Source Software in Tamil : http://kaniyam.com

Get Free Tamil Ebooks for Android, iOS, Kindle, Computer :
http://FreeTamilEbooks.com

_______________________________________________
Wikitech-l mailing list
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Reply | Threaded
Open this post in threaded view
|

Re: Need example code in Javascript to login API

Bartosz Dziewoński
Firstly, I'm afraid that page might not be up to date; there have been
some changes to modernize the login API recently, and that page was last
updated in 2013. The canonical documentation is
<https://www.mediawiki.org/wiki/API:Login> (in English).

Secondly, login API is mostly intended for scripts running in the
context of the wiki you want to log in to, not for scripts running on
other pages or browser extensions. I'm not an expert on this, but I
think you'll want to look into using OAuth:
<https://www.mediawiki.org/wiki/OAuth>.

--
Bartosz Dziewoński

_______________________________________________
Wikitech-l mailing list
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Reply | Threaded
Open this post in threaded view
|

Re: Need example code in Javascript to login API

Gergo Tisza
On Wed, Oct 26, 2016 at 12:26 PM, Bartosz Dziewoński <[hidden email]>
wrote:

> Firstly, I'm afraid that page might not be up to date; there have been
> some changes to modernize the login API recently, and that page was last
> updated in 2013. The canonical documentation is <
> https://www.mediawiki.org/wiki/API:Login> (in English).
>
> Secondly, login API is mostly intended for scripts running in the context
> of the wiki you want to log in to, not for scripts running on other pages
> or browser extensions. I'm not an expert on this, but I think you'll want
> to look into using OAuth: <https://www.mediawiki.org/wiki/OAuth>.


OAuth is unfortunately hard to do in a browser plugin, as its security
relies on the assumption that the application secret is only known to the
developer.

It's not easy to give useful advice without knowing what is it you are
trying to build (see the XY problem -
http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem ) or
at least why the CORS manual was not helpful.
_______________________________________________
Wikitech-l mailing list
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Reply | Threaded
Open this post in threaded view
|

Re: Need example code in Javascript to login API

Moriel Schottlender
As a side note, chrome extensions can authorize a domain and use it as if
they're requesting while on the site, it seems, to prevent cors errors.

https://developer.chrome.com/extensions/declare_permissions

That may require that your user login directly in Wikipedia rather than
through your extension - but once the login is recognized, the API calls
pass through without CORS issues, as long as you add the URL format to your
permission declaration in the manifest.

I've created a small extension testing out some Echo functionality using
exactly that. The API calls were successful, the only issue I had was that
the user had to be logged into Wikipedia already.

This may not be a perfect solution, but it might save you the trouble of
working with OAuth and doing the login yourself.



On Thu, Oct 27, 2016 at 2:34 PM, Gergo Tisza <[hidden email]> wrote:

> On Wed, Oct 26, 2016 at 12:26 PM, Bartosz Dziewoński <[hidden email]>
> wrote:
>
> > Firstly, I'm afraid that page might not be up to date; there have been
> > some changes to modernize the login API recently, and that page was last
> > updated in 2013. The canonical documentation is <
> > https://www.mediawiki.org/wiki/API:Login> (in English).
> >
> > Secondly, login API is mostly intended for scripts running in the context
> > of the wiki you want to log in to, not for scripts running on other pages
> > or browser extensions. I'm not an expert on this, but I think you'll want
> > to look into using OAuth: <https://www.mediawiki.org/wiki/OAuth>.
>
>
> OAuth is unfortunately hard to do in a browser plugin, as its security
> relies on the assumption that the application secret is only known to the
> developer.
>
> It's not easy to give useful advice without knowing what is it you are
> trying to build (see the XY problem -
> http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem ) or
> at least why the CORS manual was not helpful.
> _______________________________________________
> Wikitech-l mailing list
> [hidden email]
> https://lists.wikimedia.org/mailman/listinfo/wikitech-l
>



--
No trees were harmed in the creation of this post.
But billions of electrons, photons, and electromagnetic waves were terribly
inconvenienced during its transmission!
_______________________________________________
Wikitech-l mailing list
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Reply | Threaded
Open this post in threaded view
|

Re: Need example code in Javascript to login API

Shrinivasan T
Gergo Tisza,

Recently, we added more then 2000 books to Tamil WikiSource using
Google OCR with OCR4WikiSource
https://github.com/tshrinivasan/OCR4wikisource

Most of the books have 30-40% spell errors. To fix them, editing the
pages manually is not easy.

I am thinking of a browser plugin with the following workflow.

1. user logins to tamil wikisource
2. reads a wiki page for any book
3. Finds a word with spelling error
4. double clicks it
5. Inline textbox opens there
6. Writes correct word and click ok button
7. The change is saved automatically in background
8. The old word and new word are sent to remote server and stored
9. Mass find and replace for the stored wrong,correct words are
executed periodically

With this design plan, hope users can easily contribute to fix the spell errors.

Hope there may be even better solutions. Share your thoughts on this.


Now, I am in point 1.
Cant find any javascript code login to wikipedia without getting
 No 'Access-Control-Allow-Origin' header is present
error.

The CORS link is not useful for beginner.

Example code in javascript to login to wikipedia will be much helpful.




Moriel Schottlender,

Your solution is fine.
Please share the code so that I can extend from there.

Thanks.

--
Regards,
T.Shrinivasan


My Life with GNU/Linux : http://goinggnu.wordpress.com
Free E-Magazine on Free Open Source Software in Tamil : http://kaniyam.com

Get Free Tamil Ebooks for Android, iOS, Kindle, Computer :
http://FreeTamilEbooks.com

_______________________________________________
Wikitech-l mailing list
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Reply | Threaded
Open this post in threaded view
|

Re: Need example code in Javascript to login API

Sam Wilson-2
This sounds like a great idea (something akin to PGDP's WordCheck tool
<http://www.pgdp.net/wiki/WordCheck>?) But I wonder if implementing it as a
Gadget would be easier? That way, the user is already logged in, and can
access all the normal APIs etc.

The word lists (both good and bad?) could be saved as subpages of the Index
page. Could probably make sense to have site-wide word lists too, for all
the really common ones.

Do you have an idea of the interface for correcting words (the right-click
drop down list)?

This could be really useful for all language Wikisources I think!

—Sam


On 3 November 2016 at 06:11, Shrinivasan T <[hidden email]> wrote:

> Gergo Tisza,
>
> Recently, we added more then 2000 books to Tamil WikiSource using
> Google OCR with OCR4WikiSource
> https://github.com/tshrinivasan/OCR4wikisource
>
> Most of the books have 30-40% spell errors. To fix them, editing the
> pages manually is not easy.
>
> I am thinking of a browser plugin with the following workflow.
>
> 1. user logins to tamil wikisource
> 2. reads a wiki page for any book
> 3. Finds a word with spelling error
> 4. double clicks it
> 5. Inline textbox opens there
> 6. Writes correct word and click ok button
> 7. The change is saved automatically in background
> 8. The old word and new word are sent to remote server and stored
> 9. Mass find and replace for the stored wrong,correct words are
> executed periodically
>
> With this design plan, hope users can easily contribute to fix the spell
> errors.
>
> Hope there may be even better solutions. Share your thoughts on this.
>
>
> Now, I am in point 1.
> Cant find any javascript code login to wikipedia without getting
>  No 'Access-Control-Allow-Origin' header is present
> error.
>
> The CORS link is not useful for beginner.
>
> Example code in javascript to login to wikipedia will be much helpful.
>
>
>
>
> Moriel Schottlender,
>
> Your solution is fine.
> Please share the code so that I can extend from there.
>
> Thanks.
>
> --
> Regards,
> T.Shrinivasan
>
>
> My Life with GNU/Linux : http://goinggnu.wordpress.com
> Free E-Magazine on Free Open Source Software in Tamil : http://kaniyam.com
>
> Get Free Tamil Ebooks for Android, iOS, Kindle, Computer :
> http://FreeTamilEbooks.com
>
> _______________________________________________
> Wikitech-l mailing list
> [hidden email]
> https://lists.wikimedia.org/mailman/listinfo/wikitech-l
>



--
User:SWilson (WMF) <https://meta.wikimedia.org/wiki/User:SWilson_(WMF)>
Community Tech
Fremantle, Western Australia
_______________________________________________
Wikitech-l mailing list
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Reply | Threaded
Open this post in threaded view
|

Re: Need example code in Javascript to login API

Thomas PT
Thank you very much for this idea!

+1 for a gadget or maybe, in the future, a part of the ProofreadPage extension.

An issue that we probably need to tackle when designing this tool: what about not-existing words that could be a typo of two different words? If we replace all instances of the typo by one of the two word, we will change the meaning of the text by introducing a worst typo when the other word is the correct one.

Thomas

> Le 3 nov. 2016 à 01:34, Sam Wilson <[hidden email]> a écrit :
>
> This sounds like a great idea (something akin to PGDP's WordCheck tool
> <http://www.pgdp.net/wiki/WordCheck>?) But I wonder if implementing it as a
> Gadget would be easier? That way, the user is already logged in, and can
> access all the normal APIs etc.
>
> The word lists (both good and bad?) could be saved as subpages of the Index
> page. Could probably make sense to have site-wide word lists too, for all
> the really common ones.
>
> Do you have an idea of the interface for correcting words (the right-click
> drop down list)?
>
> This could be really useful for all language Wikisources I think!
>
> —Sam
>
>
> On 3 November 2016 at 06:11, Shrinivasan T <[hidden email]> wrote:
>
>> Gergo Tisza,
>>
>> Recently, we added more then 2000 books to Tamil WikiSource using
>> Google OCR with OCR4WikiSource
>> https://github.com/tshrinivasan/OCR4wikisource
>>
>> Most of the books have 30-40% spell errors. To fix them, editing the
>> pages manually is not easy.
>>
>> I am thinking of a browser plugin with the following workflow.
>>
>> 1. user logins to tamil wikisource
>> 2. reads a wiki page for any book
>> 3. Finds a word with spelling error
>> 4. double clicks it
>> 5. Inline textbox opens there
>> 6. Writes correct word and click ok button
>> 7. The change is saved automatically in background
>> 8. The old word and new word are sent to remote server and stored
>> 9. Mass find and replace for the stored wrong,correct words are
>> executed periodically
>>
>> With this design plan, hope users can easily contribute to fix the spell
>> errors.
>>
>> Hope there may be even better solutions. Share your thoughts on this.
>>
>>
>> Now, I am in point 1.
>> Cant find any javascript code login to wikipedia without getting
>> No 'Access-Control-Allow-Origin' header is present
>> error.
>>
>> The CORS link is not useful for beginner.
>>
>> Example code in javascript to login to wikipedia will be much helpful.
>>
>>
>>
>>
>> Moriel Schottlender,
>>
>> Your solution is fine.
>> Please share the code so that I can extend from there.
>>
>> Thanks.
>>
>> --
>> Regards,
>> T.Shrinivasan
>>
>>
>> My Life with GNU/Linux : http://goinggnu.wordpress.com
>> Free E-Magazine on Free Open Source Software in Tamil : http://kaniyam.com
>>
>> Get Free Tamil Ebooks for Android, iOS, Kindle, Computer :
>> http://FreeTamilEbooks.com
>>
>> _______________________________________________
>> Wikitech-l mailing list
>> [hidden email]
>> https://lists.wikimedia.org/mailman/listinfo/wikitech-l
>>
>
>
>
> --
> User:SWilson (WMF) <https://meta.wikimedia.org/wiki/User:SWilson_(WMF)>
> Community Tech
> Fremantle, Western Australia
> _______________________________________________
> Wikitech-l mailing list
> [hidden email]
> https://lists.wikimedia.org/mailman/listinfo/wikitech-l

_______________________________________________
Wikitech-l mailing list
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Reply | Threaded
Open this post in threaded view
|

Re: Need example code in Javascript to login API

Sam Wilson-2
Yes, I'm not sure about the automatic replacement of words in pages other
than the current one — something more along the lines of a
spelling-checker, maybe? Where the dictionary can be customised per-work.
Is Extension:SpellingDictionary
<https://www.mediawiki.org/wiki/Extension:SpellingDictionary> worth looking
into? But no, perhaps not, because if such a thing were built as part of
ProofreadPage, it could handle scannos as well (punctuation etc.; i.e. be
more specialised than just spelling). For example, the PGDP WordCheck
system presents the user with a syntax-highlighted view of each page prior
to saving, highlighting *all* punctuation and spaces and newlines, and
making each miss-spelled word a dropdown or suggest box.

—sam


On 3 November 2016 at 18:04, Thomas PT <[hidden email]> wrote:

> Thank you very much for this idea!
>
> +1 for a gadget or maybe, in the future, a part of the ProofreadPage
> extension.
>
> An issue that we probably need to tackle when designing this tool: what
> about not-existing words that could be a typo of two different words? If we
> replace all instances of the typo by one of the two word, we will change
> the meaning of the text by introducing a worst typo when the other word is
> the correct one.
>
> Thomas
>
> > Le 3 nov. 2016 à 01:34, Sam Wilson <[hidden email]> a écrit :
> >
> > This sounds like a great idea (something akin to PGDP's WordCheck tool
> > <http://www.pgdp.net/wiki/WordCheck>?) But I wonder if implementing it
> as a
> > Gadget would be easier? That way, the user is already logged in, and can
> > access all the normal APIs etc.
> >
> > The word lists (both good and bad?) could be saved as subpages of the
> Index
> > page. Could probably make sense to have site-wide word lists too, for all
> > the really common ones.
> >
> > Do you have an idea of the interface for correcting words (the
> right-click
> > drop down list)?
> >
> > This could be really useful for all language Wikisources I think!
> >
> > —Sam
> >
> >
> > On 3 November 2016 at 06:11, Shrinivasan T <[hidden email]>
> wrote:
> >
> >> Gergo Tisza,
> >>
> >> Recently, we added more then 2000 books to Tamil WikiSource using
> >> Google OCR with OCR4WikiSource
> >> https://github.com/tshrinivasan/OCR4wikisource
> >>
> >> Most of the books have 30-40% spell errors. To fix them, editing the
> >> pages manually is not easy.
> >>
> >> I am thinking of a browser plugin with the following workflow.
> >>
> >> 1. user logins to tamil wikisource
> >> 2. reads a wiki page for any book
> >> 3. Finds a word with spelling error
> >> 4. double clicks it
> >> 5. Inline textbox opens there
> >> 6. Writes correct word and click ok button
> >> 7. The change is saved automatically in background
> >> 8. The old word and new word are sent to remote server and stored
> >> 9. Mass find and replace for the stored wrong,correct words are
> >> executed periodically
> >>
> >> With this design plan, hope users can easily contribute to fix the spell
> >> errors.
> >>
> >> Hope there may be even better solutions. Share your thoughts on this.
> >>
> >>
> >> Now, I am in point 1.
> >> Cant find any javascript code login to wikipedia without getting
> >> No 'Access-Control-Allow-Origin' header is present
> >> error.
> >>
> >> The CORS link is not useful for beginner.
> >>
> >> Example code in javascript to login to wikipedia will be much helpful.
> >>
> >>
> >>
> >>
> >> Moriel Schottlender,
> >>
> >> Your solution is fine.
> >> Please share the code so that I can extend from there.
> >>
> >> Thanks.
> >>
> >> --
> >> Regards,
> >> T.Shrinivasan
> >>
> >>
> >> My Life with GNU/Linux : http://goinggnu.wordpress.com
> >> Free E-Magazine on Free Open Source Software in Tamil :
> http://kaniyam.com
> >>
> >> Get Free Tamil Ebooks for Android, iOS, Kindle, Computer :
> >> http://FreeTamilEbooks.com
> >>
> >> _______________________________________________
> >> Wikitech-l mailing list
> >> [hidden email]
> >> https://lists.wikimedia.org/mailman/listinfo/wikitech-l
> >>
> >
> >
> >
> > --
> > User:SWilson (WMF) <https://meta.wikimedia.org/wiki/User:SWilson_(WMF)>
> > Community Tech
> > Fremantle, Western Australia
> > _______________________________________________
> > Wikitech-l mailing list
> > [hidden email]
> > https://lists.wikimedia.org/mailman/listinfo/wikitech-l
>
> _______________________________________________
> Wikitech-l mailing list
> [hidden email]
> https://lists.wikimedia.org/mailman/listinfo/wikitech-l
>



--
User:SWilson (WMF) <https://meta.wikimedia.org/wiki/User:SWilson_(WMF)>
Community Tech
Fremantle, Western Australia
_______________________________________________
Wikitech-l mailing list
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Reply | Threaded
Open this post in threaded view
|

Re: Need example code in Javascript to login API

Nick Wilson (Quiddity)
On Thu, Nov 3, 2016 at 9:24 PM, Sam Wilson <[hidden email]> wrote:
>
> [...] For example, the PGDP WordCheck
> system presents the user with a syntax-highlighted view of each page prior
> to saving, highlighting *all* punctuation and spaces and newlines, and
> making each miss-spelled word a dropdown or suggest box.

Screenshot of PGDP Wordcheck interface:
http://imagizer.imageshack.com/img921/2270/gtQCda.png
and PGDP standard interface:
http://imagizer.imageshack.com/img923/6371/hFWOnQ.png
(And here it's having problems with curved-lines in the scan:
http://imagizer.imageshack.com/img921/2090/8vvhpi.png
or: http://imagizer.imageshack.com/img924/3403/sHomJS.png )

The few pages I tried didn't have any dropdown boxes, so there might
be additional functionality not captured in those images? HTH.

_______________________________________________
Wikitech-l mailing list
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l