You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.5 KiB

  1. <?php
  2. function ajax_ImageLoaderWikimediaCategoryList ($param) {
  3. $ret = array();
  4. $retData = array();
  5. $wm_url = "https://commons.wikimedia.org/w/index.php?title=" . urlencode(strtr($param['page'], array(" " => "_")));
  6. if (isset($param['continue'])) {
  7. $wm_url .= "&filefrom=" . urlencode(strtr($param['continue'], array(" " => "_")));
  8. }
  9. $content = file_get_contents($wm_url);
  10. $dom = new DOMDocument();
  11. $dom->loadHTML($content);
  12. $uls = $dom->getElementsByTagName('ul');//interlanguage-link interwiki-bar');
  13. for ($i = 0; $i < $uls->length; $i++) {
  14. $ul = $uls->item($i);
  15. if ($ul->getAttribute('class') === 'gallery mw-gallery-traditional') {
  16. $imgs = $ul->getElementsByTagName('img');
  17. for ($j = 0; $j < $imgs->length; $j++) {
  18. $ret[] = $imgs->item($j)->getAttribute('alt');
  19. $retData[] = array(
  20. 'id' => $imgs->item($j)->getAttribute('alt'),
  21. 'width' => $imgs->item($j)->getAttribute('data-file-width'),
  22. 'height' => $imgs->item($j)->getAttribute('data-file-height'),
  23. );
  24. }
  25. }
  26. }
  27. $continue = false;
  28. $as = $dom->getElementsByTagName('a');
  29. for ($i = 0; $i < $as->length; $i++) {
  30. $a = $as->item($i);
  31. if (preg_match("/^\/w\/index.php\?title=(.*)&filefrom=([^#]+)#mw-category-media$/", $a->getAttribute('href'), $m)) {
  32. $continue = $m[2];
  33. }
  34. }
  35. return array(
  36. 'images' => $ret, // deprecated as of 2017-09-27
  37. 'imageData' => $retData,
  38. 'continue' => $continue,
  39. );
  40. }