title: MediaWiki Query and/or WikidataQuery to find Wikipedia article
body: <p>This isn't so much a question abut AngularJS as it is about the Wikimedia and Wikidata query API's. </p>
  
  <p>Although I am trying to display the content of a Wikipedia article in AngularJS after doing a certain query that isn't the problem. I already know how to display it... the problem is the search for an article or articles.</p>
  
  <p>I'm trying to query Wikipedia by historical event date <em>as well</em> as by geo-location.</p>
  
  <p>Let's pick a random event, any event. Let's say "<strong>1986 Mozambican Tupolev Tu-134 crash</strong>". Link: <a href="http://en.wikipedia.org/wiki/1986_Mozambican_Tupolev_Tu-134_crash" rel="nofollow">http://en.wikipedia.org/wiki/1986_Mozambican_Tupolev_Tu-134_crash</a></p>
  
  <p>From the article, I can see the exact date: <strong>19 October 1986</strong> <br>
  as well as the geo-location of the event: <strong>-25.911389, 31.957222</strong></p>
  
  <p>I'm trying to build a search in AngularJS that can use either a date-range and/or geolocation coordinates to find an event.</p>
  
  <p>I am aware that mediawiki has a geolocation API now, and I am able to find the above event by either keyword or coordinates. The result also turns up any other articles that exist within a certain radius around it using this:</p>
  
  <p><a href="http://en.wikipedia.org/w/api.php?action=query&amp;list=geosearch&amp;gsradius=10000&amp;gscoord=-25.911389|31.957222&amp;prop=extracts|info&amp;exintro&amp;titles=1986_Mozambican_Tupolev_Tu-134_crash&amp;format=json&amp;explaintext&amp;redirects&amp;inprop=url&amp;indexpageids&amp;format=json&amp;callback=JSON_CALLBACK" rel="nofollow">http://en.wikipedia.org/w/api.php?action=query&amp;list=geosearch&amp;gsradius=10000&amp;gscoord=-25.911389|31.957222&amp;prop=extracts|info&amp;exintro&amp;titles=1986_Mozambican_Tupolev_Tu-134_crash&amp;format=json&amp;explaintext&amp;redirects&amp;inprop=url&amp;indexpageids&amp;format=json&amp;callback=JSON_CALLBACK</a></p>
  
  <p>However, there is no way to do a search with mediawiki by a point in time or the date of the event. </p>
  
  <p>Wikidata on the other hand has two methods of searching data... it has a date range as well as geolocation. </p>
  
  <p>However, when a query is run, I have no idea what is being returned. </p>
  
  <p>For example, when I use this query string:</p>
  
  <pre><code>https://wdq.wmflabs.org/api?q=AROUND[625,-25.911389,31.957222,5]%20AND%20BETWEEN[585,1985,1987]
  </code></pre>
  
  <p>it returns this:</p>
  
  <blockquote>
    <p>{"status":{"error":"OK","items":1,"querytime":"544ms","parsed_query":"(AROUND[625,-25.9114,31.9572,5]
    AND
    BETWEEN[585,+00000001985-00-00T00:00:00Z,+00000001987-00-00T00:00:00Z])"},"items":[950273]}</p>
  </blockquote>
  
  <p>Using wikidata's query tool:</p>
  
  <p><a href="http://tools.wmflabs.org/autolist/autolist1.html?q=AROUND[625,-25.911389,31.957222,5]%20AND%20BETWEEN[585,1985,1987]" rel="nofollow">http://tools.wmflabs.org/autolist/autolist1.html?q=AROUND[625,-25.911389,31.957222,5]%20AND%20BETWEEN[585,1985,1987]</a></p>
  
  <p>I can see that <strong>950273</strong> represents the article in some way. I'm just not sure how to use that to direct me to the actual article in wikipedia.</p>
  
  <p>I don't know what "<strong>items": [950273]</strong>" represents, or how to use it to get me to the wikipedia article and display the contents of that article in AngularJS.</p>
  
  <p>Is there a way to do both a query by date of the historical event as well as by geolocation. Either by using mediawiki or wikidata or a combination of the two?</p>
  
  <hr>
  
  <p><strong>EDIT:</strong>
  This is the solution to my question above. It seems like a bit of a hack... but it works. Good enough for now. Here is my controller.</p>
  
  <pre><code>.controller('WikiQueryCtrl', ['$scope', '$http', function($scope, $http) {
      $http({
              //these geo coordinates and the date ranges will eventually be dynamic.
              url: 'https://wdq.wmflabs.org/api?q=AROUND[625,-25.911389,31.957222,5]%20AND%20BETWEEN[585,1985,1987]&amp;callback=JSON_CALLBACK',
              method: 'jsonp'
          })
          .success(function(response) {
              var items = response.items;
              $scope.jason = items;
              var wikiDataString = 'http://www.wikidata.org/w/api.php?action=wbgetentities&amp;format=json&amp;ids=Q' + items + '&amp;props=sitelinks%7Csitelinks%2Furls&amp;callback=JSON_CALLBACK';
              $http({
                      url: wikiDataString,
                      method: 'jsonp'
                  })
                  .success(function(response2) {
                      $scope.jason2 = response2;
                      var url = response2.entities["Q" + items].sitelinks.enwiki.url;
                      var wikipediaTitle = url.substr(24, url.length);
                      var wikipediaURL = 'http://en.wikipedia.org/w/api.php?action=query&amp;prop=extracts|info&amp;exintro&amp;titles=' + wikipediaTitle + '&amp;format=json&amp;explaintext&amp;redirects&amp;inprop=url&amp;indexpageids&amp;format=json&amp;callback=JSON_CALLBACK';
                      $http({
                          url: wikipediaURL,
                          method: 'jsonp'
  
                      }).success(function(response4) {
                          var query = response4.query;
                          var pageID = response4.query.pageids;
                          var title = response4.query.pages[pageID].title;
                          var fullurl = response4.query.pages[pageID].fullurl;
                          var content = response4.query.pages[pageID].extract;
                          $scope.title = title;
                          $scope.content = content;
                          $scope.fullurl = fullurl;
                          $scope.jason = query;
                      });
                  });
          });
  }]);
  </code></pre>