示例#1
0
 public function retrieve()
 {
     $base_uri = $this->Agent->getTitle()->getFullUrl();
     $query = MwRdf::Query($this->getQueryString(), $base_uri, 'sparql');
     $store = MwRdf::StoredModel();
     $res = $query->execute($store);
     $model = MwRdf::Model();
     foreach ($res as $statement) {
         $model->addStatement($statement);
     }
     return $model;
 }
示例#2
0
 /**
  * As with QueryPage, this is the actual workhorse. It does everything
  * needed to make a real, honest-to-gosh query page.
  *
  * @param $offset database query offset
  * @param $limit database query limit
  * @param $shownavigation show navigation like "next 200"?
  */
 function doQuery($offset, $limit, $shownavigation = true)
 {
     global $wgUser, $wgOut, $wgContLang;
     $this->offset = $offset;
     $this->limit = $limit;
     $sname = $this->getName();
     $fname = get_class($this) . '::doQuery';
     $sk = $wgUser->getSkin();
     $wgOut->setSyndicated($this->isSyndicated());
     $query = MwRdf::Query($this->getQuery(), $this->getBaseUrl(), $this->getQueryLanguage());
     $librdf_res = $query->execute(MwRdf::StoredModel());
     # let's just dump the tuples into a normal php array shall
     # we?  This will avoid memory management hassels.
     $res = array();
     foreach ($librdf_res as $tuple) {
         $res[] = $tuple;
     }
     $num = count($res);
     $res = $this->preprocessResults($res);
     if ($shownavigation) {
         $wgOut->addHTML($this->getPageHeader());
         $top = wfShowingResults($offset, $num);
         $wgOut->addHTML("<p>{$top}\n");
         # often disable 'next' link when we reach the end
         $atend = $num < $limit;
         $sl = wfViewPrevNext($offset, $limit, $wgContLang->specialPage($sname), wfArrayToCGI($this->linkParameters()), $atend);
         $wgOut->addHTML("<br />{$sl}</p>\n");
     }
     if ($num > 0) {
         $s = array();
         if (!$this->listoutput) {
             $s[] = "<ol start='" . ($offset + 1) . "' class='special'>";
         }
         # here's where we do the offset and limit
         for ($i = $offset; $i < $num && $i < $offset + $limit; $i++) {
             $format = $this->formatResult($sk, $res[$i]);
             if ($format) {
                 $s[] = $this->listoutput ? $format : "<li>{$format}</li>\n";
             }
         }
         if (!$this->listoutput) {
             $s[] = '</ol>';
         }
         $str = $this->listoutput ? $wgContLang->listToText($s) : implode('', $s);
         $wgOut->addHTML($str);
     }
     if ($shownavigation) {
         $wgOut->addHTML("<p>{$sl}</p>\n");
     }
     return $num;
 }
示例#3
0
 public function testQueryPage()
 {
     $page = new RdfTitleQueryPage();
     $query = MwRdf::Query($page->getQuery(), $page->getBaseUrl(), $page->getQueryLanguage());
     $res = $query->execute(MwRdf::StoredModel());
     $count = 0;
     foreach ($res as $statement) {
         $count++;
     }
     $this->assertNotEquals(0, $count);
     $this->assertNotEquals(1, $count);
     $page->doQuery(0, 50);
     $this->assertContains("THIS IS A HEADER\n", $this->html, $this->html);
     $this->assertContains("up to <b>{$count}</b> results", $this->html, $this->html);
     $this->assertContains("<li>url, title</li>", $this->html, $this->html);
     $this->assertContains("(previous 50) (next 50)", $this->html, $this->html);
     $this->html = '';
     $page->doQuery(0, 5);
     $this->assertContains("THIS IS A HEADER\n", $this->html, $this->html);
     $this->assertContains("up to <b>{$count}</b> results", $this->html, $this->html);
     $this->assertContains("<li>url, title</li>", $this->html, $this->html);
     $this->assertContains("(previous 5)", $this->html, $this->html);
     $this->assertContains("<ol start='1' class='special'><li>url, title</li>\n<li>url, title</li>\n<li>url, title</li>\n<li>url, title</li>\n<li>url, title</li>\n</ol>", $this->html, $this->html);
 }