From a0455b95354493f261f121d7f659b8abffce0140 Mon Sep 17 00:00:00 2001 From: Roderic Page Date: Sat, 17 Dec 2016 15:39:00 +0000 Subject: [PATCH] Detect namespace version rather than hard code it. --- history.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/history.php b/history.php index 2102f9d..55c3706 100644 --- a/history.php +++ b/history.php @@ -56,11 +56,20 @@ function distanceOfTimeInWords($from_time, $to_time = 0, $include_seconds = fals // Common point of failure is an updated wiki namespace function xml_edits($xml, $limit = 0) { + // detect namespace + + $namespace = 'http://www.mediawiki.org/xml/export-0.8/'; + + if (preg_match('/xmlns="(?http:\/\/www.mediawiki.org\/xml\/export-(\d+(\.\d+))\/)"/U', $xml, $m)) + { + $namespace = $m['namespace']; + } + $dom= new DOMDocument; $dom->loadXML($xml); $xpath = new DOMXPath($dom); // Add namespaces to XPath to ensure our queries work - $xpath->registerNamespace("wiki", "http://www.mediawiki.org/xml/export-0.8/"); + $xpath->registerNamespace("wiki", $namespace); $xpath->registerNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); $nodeCollection = $xpath->query ("//wiki:revision");