Applied and tweaked smart-import patch from Mij, merging with 1.16.
[lhc/web/wiklou.git] / maintenance / importImages.inc
index 1f693fa..61baf7c 100644 (file)
@@ -6,6 +6,7 @@
  * @file
  * @ingroup Maintenance
  * @author Rob Church <robchur@gmail.com>
+ * @author Mij <mij@bitchx.it>
  */
 
 /**
@@ -86,4 +87,26 @@ function findAuxFile( $file, $auxExtension, $maxStrip = 1 ) {
        }
 
        return false;
-}
\ No newline at end of file
+}
+
+# FIXME: Access the api in a saner way and performing just one query (preferably batching files too).
+function getFileCommentFromSourceWiki($wiki_host, $file) {
+    $url = $wiki_host . '/api.php?action=query&format=xml&titles=File:' . $file . '&prop=imageinfo&&iiprop=comment';
+    $body = file_get_contents($url);
+    if (preg_match('#<ii comment="([^"]*)" />#', $body, $matches) == 0) {
+        return false;
+    }
+
+    return $matches[1];
+}
+
+function getFileUserFromSourceWiki($wiki_host, $file) {
+    $url = $wiki_host . '/api.php?action=query&format=xml&titles=File:' . $file . '&prop=imageinfo&&iiprop=user';
+    $body = file_get_contents($url);
+    if (preg_match('#<ii user="([^"]*)" />#', $body, $matches) == 0) {
+        return false;
+    }
+
+    return $matches[1];
+}
+