Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Paste
P13
(An Untitled Masterwork)
Active
Public
Actions
Authored by
stwalkerster
on Apr 8 2016, 7:43 PM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Tags
None
Referenced Files
F308:
Apr 8 2016, 7:43 PM
2016-04-08 19:43:29 (UTC+0)
Subscribers
None
<?php
ini_set
(
"user_agent"
,
'ExampleProject/0.0 (wikimedia@stwalkerster.co.uk)'
);
// bomb out early if no username specified
if
(!
isset
(
$_GET
[
'username'
]))
{
echo
"No username specified!"
;
return
;
}
// get the API result as a JSON string
$json
=
file_get_contents
(
"https://en.wikipedia.org/w/api.php?action=query&format=json&list=users&usprop=editcount&ususers="
.
htmlspecialchars
(
$_GET
[
"username"
]));
// decode the JSON in to an associative array (second parameter enforces array rather than object)
$conf
=
json_decode
(
$json
,
true
);
// Use isset() to check if something is set - that way you don't get PHP Notices
if
(!
isset
(
$conf
[
'query'
][
'users'
][
'0'
])
||
isset
(
$conf
[
'query'
][
'users'
][
'0'
][
'missing'
]))
{
echo
"The user '"
.
htmlspecialchars
(
$_GET
[
"username"
])
.
"' does not exist."
;
}
else
{
echo
$conf
[
'query'
][
'users'
][
'0'
][
'editcount'
];
}
Event Timeline
stwalkerster
created this paste.
Apr 8 2016, 7:43 PM
2016-04-08 19:43:29 (UTC+0)
stwalkerster
changed the visibility from "All Users" to "Public (No Login Required)".
•
import-bot
changed the edit policy from "All Users" to "
Community
(Project)".
Feb 3 2017, 3:03 PM
2017-02-03 15:03:53 (UTC+0)
Log In to Comment