GithubHelp home page GithubHelp logo

wikimedia / mediawiki-api-demos Goto Github PK

View Code? Open in Web Editor NEW
151.0 19.0 82.0 7.97 MB

Demo apps and code snippets in Python, Javascript and PHP demonstrating how to use various modules of the MediaWiki Action API

License: MIT License

Python 26.97% HTML 4.49% CSS 1.49% JavaScript 37.58% PHP 29.47%
mediawiki-api mediawiki code-snipets demo-apps web-apis

mediawiki-api-demos's Introduction

MediaWiki

MediaWiki API Demos

The MediaWiki Action API is a web service that allows access to some wiki-features like authentication, page operations, and search. It can provide meta information about the wiki and the logged-in user. This repository contains code snippets and demo apps in various programming languages to assist developers for easy use of various modules of the API.

ℹ️ View a showcase of interactive demo apps built using the API on Wikimedia Toolforge: https://tools.wmflabs.org/apps-gallery/

Code snippets

Demo apps

Installation

$ git clone https://github.com/wikimedia/mediawiki-api-demos.git
$ cd mediawiki-api-demos

For running python code samples: 
$ cd python
$ python3 filename.py 
Note: Install any necessary python modules with pip and enter any credentials 
required in the file to run the sample code

For running javascript code samples:
$ cd javascript
$ node filename.js
Note: Install any necessary node modules with npm and enter any credentials required
in the file to run the sample code

For running php code samples:
$ cd php
$ php filename.php
Note: Install necessary modules by `apt-get install php-cli php-curl` and enter any credentials
required in the file to run the sample code

mediawiki-api-demos's People

Contributors

aashuli avatar aklapper avatar ammarpad avatar apaskulin avatar arsquare avatar brendajerop avatar didicodes avatar eisheeta avatar evigian avatar guptadiksha307 avatar jayprakash-se avatar lizwkariuki58 avatar mansiag avatar martyav avatar minervalong avatar ndiberaymond avatar nikitarana07 avatar olena-stoliarova avatar priscilavilemen avatar reefagirl avatar shivanshbindal9 avatar silkypriya avatar simon04 avatar sivaraam avatar sra-013 avatar srish avatar tuxology avatar tybanash avatar webong avatar zaycodes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mediawiki-api-demos's Issues

Implement "API:Get the contents of a page" in Python

Hi! I'm learning to use Wiki API to get the public information of users. I found the script, "get_users.py", in MediaWiki-API-demos that can help us get general information, like edit count or email address. However, the personal description on the user page can not be fetched in this way.

(An example is shown below. I want to get the text information like "I'm not usually active on English Wikipedia. Please refer ...")

Screen Shot 2020-06-05 at 5 49 41 PM

I found that "API: Get the contents of a page" offers an option to achieve that. Because I know nothing about PHP, may I ask is there any way we can get these text contents using the API in Python?

Thank you a lot for your time in advance!

SSL connection issue

Hi,

I had installed your python code and found it worked on wikipedia. I tried to connect my private wiki and found ssl issues.

After lots of try and error, suddenly I found the code succeed to make new wiki document. But it is not repeated.

Would you kindly advice me what to check to avoid ssl iissues?

Thanks in advance.

Extending the "Nearby Places Viewer" with street address using GeoPi

Hi @srish ,
I was wondering if I can extend the "Nearby Places Viewer" by adding a street address to the form and
using GeoPi to produce the latitude and longitude? Please let me know if this is something that you will accept a contribution from. I have a deadline to meet to submit contributions with Outreachy as well as Udacity. Thank you for your attention.

Reorganize README.md

Currently, README.md contain links to all Python files that live inside the Python directory. But, this repository is not just about Python files anymore and also include Javascript files. There might be PHP files too in the future.

Some ideas for improvements:

  • There could be a logo of MediaWiki on the top in the README.
  • All Python files could be linked from a README that lives in the Python directory.
  • All Javascript files could be linked from a README that lives in the Javascript directory.
  • If there is some magic way to reduce the number of lines in the current README that would be great.
  • The main README can then only have an overview of the modules or demo apps that are in the repo.
  • Also, installation and contributing code samples section can be removed as they will be taken care of here: #107.

Integrate more demo apps and make design improvements to the Apps gallery

Integrate demo apps with the Gallery

There are a lot of interesting demo apps using the MediaWiki API that meet the criteria listed here and could be added to the Apps Gallery: https://tools.wmflabs.org/apps-gallery/. Apps (some shared by @brendajerop), that we could add to the Gallery are listed below:

Design improvements to the Gallery

Apps gallery could be made more responsive, adhered to the Wikimedia style guide https://design.wikimedia.org/style-guide/ and less bright perhaps ;-) It appears as shown below on lower resolutions: Screen Shot 2019-08-09 at 2 36 22 PM

response.json() produces JSONDecodeError error since content is in invalid format

Bug

When trying to work with the clientlogin method and using the default example from the documentation the user may encounter an issue where the response.json() produces json encoding error in the runtime. For example a common error would be:

simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Expected behavior

Received the response that is documented in the docs:

{  
   "clientlogin":{  
      "status":"PASS",
      "username":"William"
   }
}

Workaround

I'd suggest parsing the response using:

data = json.loads(response.content)

instead of:

data = response.json()

Develop a bot that mass edits sample code in this repo to API namespace on MediaWiki.org and vice-versa

The bot script can be made to run automatically or manually. In either case, the bot should be able to detect any new changes made in the "Javascript", "PHP", "Python" and "MediawikiJS" folder since its previous version either in this repository or in the API namespace on MediaWiki.org. If any new changes are detected, then the corresponding API module pages should receive updates. Also, figure out an appropriate way to sync the changes made to the module pages on MediaWiki.org with this repository. One vague idea - every change made to a page could open a pull request in this repo.

This would require a change in the modules.json structure, probably an addition of a new parameter in every module item (e.g., filename) that stores its page name on MediaWiki.org. A few additional changes required in all the sample code files:

  • Document this repository's URL in all files.
  • Remove the line that says: "This file is auto-generated..."

Rewrite API:Deletedrevs

Deletedrevs should remove from the modules.json because to make such request we have to give the login user session. So we have to write this module again.

Apps Gallery: "View on GitHub" does not go to GitHub for numerous tools

  1. Go to https://apps-gallery.toolforge.org/
  2. Click "View on GitHub" links for numerous tools

How to use Signature or User ID to get user's information?

Hi there,

I'm a beginner at Wikimedia, and I'm using Wiki API to finish my project. My dataset looks like this:

rev_id | comment | timestamp | page_id | page_title | user_id | user_text
-- -- -- -- -- -- -- -- -- -- -- --
352194497 | Welcome   to Wikipedia | 2010-03-26T18:16:48Z | 26709696 | 116.197.206.138 | 8356162 | Mlpearc

I'm trying to find some user information of these comment posters. However, I find the "user_text" here is not the user name but the signature. If I use the official API demos get_users.py to get the information, it turns out the error because some signature have space in it, but usernames are all single word. Like in the code below, I can get the information of Catrope and Bob using Catrope|Bob. But it doesn't work if I use Catrope|Bob Ben, if Bob Ben is Bob's signature.

import requests

S = requests.Session()

URL = "https://en.wikipedia.org/w/api.php"

PARAMS = {
    "action": "query",
    "format": "json",
    "list": "users",
    "ususers": "Catrope|Bob",
    "usprop": "blockinfo|groups|editcount|registration|emailable|gender"
}

R = S.get(url=URL, params=PARAMS)
DATA = R.json()

USERS = DATA["query"]["users"]

for u in USERS:
    print(str(u["name"]) + " has " + str(u["editcount"]) + " edits.")

So my question is, is there any way we can get user information through the signature using API? And since we also have page_id and user_id here, will this information be helpful? Thank you so much in advance!

filename not generic in modules.json

Currently, in the modules.json file the filename key has .py extension in all instances. But when generating code for javascript and php the filenames extension should be .js and .php respectievly. So, it should be made generic so that it can be used with any of them.
I would like to take up this issue

Create code samples demonstrating account creation on the wiki via API for different cases

The account creation via the API is a complex process. It works differently in different cases: when creating an account for someone else, on a wiki with or without special authentication extensions installed. It might be good to develop code samples for different use cases and embed them here: https://www.mediawiki.org/wiki/API:Account_creation. Three use cases to develop code samples for:

  • A simple example, the case of a wiki where there aren't any special authentication extensions installed
  • Complex example, the case of a wiki with special authentication extensions installed
  • On a wiki with captcha enabled (Extension:ConfirmEdit)
  • On a wiki with two factor authentication enabled (Extension:OpenID or OATHAuth)

Update README.md

Update README.md to include instructions for how to resolve a merge conflict in a pull request

"Account Creator" down and source 404

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.