Last active
November 5, 2020 08:01
-
-
Save VDK/27810b3db4928d2383e76d582ce84570 to your computer and use it in GitHub Desktop.
display the filenames in a category on Wikimedia Commons as a bare list. See https://veertje-tools.toolforge.org/filelist/?cmtitle=Category:Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$text = ''; | |
if(isset($_GET['cmtitle']) && preg_match('/^Category:(.+)/', $_GET['cmtitle'])){ | |
$cmtitle = str_replace(" ", "_", $_GET['cmtitle']); | |
$params = array ("cmtitle" => $cmtitle , "action" => "query", "list" => "categorymembers", "cmlimit" => "500", "format" => "json", "cmtype" => "file"); | |
$files = json_decode(file_get_contents("https://commons.wikimedia.org/w/api.php?".http_build_query($params)), true); | |
$files = $files['query']['categorymembers']; | |
if (count($files) > 0){ | |
foreach ($files as $file) { | |
$text .= $file['title']."<br/>"; | |
} | |
} | |
else{ | |
$text = 'empty category'; | |
} | |
} | |
else { | |
$text = 'no valid cmtitle given'; | |
} | |
?> | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>file list of </title> | |
</head> | |
<body> | |
<?php echo $text; ?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment