Beispiel #1
0
 public function build()
 {
     global $wgServer;
     $dc = MwRdf::Vocabulary('dc');
     $dcterms = MwRdf::Vocabulary('dcterms');
     $dctype = MwRdf::Vocabulary('dctype');
     $model = MwRdf::Model();
     $tr = $this->Agent->titleResource();
     $dbr = wfGetDB(DB_SLAVE);
     $res = $dbr->select('imagelinks', array('il_to'), array('il_from = ' . $this->Agent->getTitle()->getArticleID()), 'MwRdfImage');
     while ($res && ($row = $dbr->fetchObject($res))) {
         $img = wfFindFile($row->il_to);
         if (!$img->exists()) {
             continue;
         }
         $iuri = $img->getURL();
         if ($iuri[0] == '/') {
             $iuri = $wgServer . $iuri;
         }
         $ir = MwRdf::UriNode($iuri);
         $model->addStatement(MwRdf::Statement($tr, $dcterms->hasPart, $ir));
         $model->addStatement(MwRdf::Statement($ir, $dc->type, $dctype->Image));
         $mt = $img->getMimeType();
         if (isset($mt)) {
             $model->addStatement(MwRdf::Statement($ir, $dc->format, MwRdf::MediaType($mt)));
         }
         $hist_line = $img->nextHistoryLine();
         if (!isset($hist_line)) {
             continue;
         }
         $creator = MwRdf::PersonToResource($hist_line->img_user, $hist_line->img_user_text, User::whoIsReal($hist_line->img_user));
         $model->addStatement(MwRdf::Statement($ir, $dc->creator, $creator));
         $model->addStatement(MwRdf::Statement($ir, $dc->date, MwRdf::TimestampResource($hist_line->img_timestamp)));
         $seen = array($hist_line->img_user => true);
         while ($hist_line = $img->nextHistoryLine()) {
             if (isset($seen[$hist_line->img_user])) {
                 continue;
             }
             $contributor = MwRdf::PersonToResource($hist_line->img_user, $hist_line->img_user_text, User::whoIsReal($hist_line->img_user));
             $model->addStatement(MwRdf::Statement($ir, $dc->contributor, $contributor));
             $seen[$hist_line->img_user] = true;
         }
     }
     $dbr->freeResult($res);
     return $model;
 }
Beispiel #2
0
 public function build()
 {
     global $wgContLanguageCode;
     $dc = MwRdf::Vocabulary('dc');
     $dcterms = MwRdf::Vocabulary('dcterms');
     $model = MwRdf::Model();
     $tr = $this->Agent->titleResource();
     $dbr = wfGetDB(DB_SLAVE);
     $res = $dbr->select(array('page', 'revision'), array('rev_id', 'rev_timestamp', 'rev_user', 'rev_user_text'), array('page_namespace = ' . $this->Agent->getTitle()->getNamespace(), 'page_title = ' . $dbr->addQuotes($this->Agent->getTitle()->getDBkey()), 'rev_page = page_id', 'rev_id != page_latest'), 'MwRdfHistory', array('ORDER BY' => 'rev_timestamp DESC'));
     while ($res && ($row = $dbr->fetchObject($res))) {
         $url = $this->Agent->getTitle()->getFullURL('oldid=' . $row->rev_id);
         $ur = MwRdf::UriNode($url);
         $model->addStatement(MwRdf::Statement($tr, $dcterms->hasVersion, $ur));
         $model->addStatement(MwRdf::Statement($ur, $dcterms->isVersionOf, $tr));
         $model->addStatement(MwRdf::Statement($ur, $dc->language, MwRdf::Language($wgContLanguageCode)));
         $realname = $row->rev_user == 0 ? null : User::whoIsReal($row->rev_user);
         $pr = MwRdf::PersonToResource($row->rev_user, $row->rev_user_text, $realname);
         $model->addStatement(MwRdf::Statement($ur, $dc->creator, $pr));
         $model->addStatement(MwRdf::Statement($ur, $dc->date, MwRdf::TimestampResource($row->rev_timestamp)));
     }
     $dbr->freeResult($res);
     return $model;
 }
Beispiel #3
0
 public function getTimestampResource()
 {
     if (!$this->Title->exists()) {
         return false;
     }
     $article = $this->Article;
     $timestamp = $article->getTimestamp();
     return MwRdf::TimestampResource($timestamp);
 }
 public function testTimestampResource()
 {
     $res = MwRdf::TimestampResource(time());
     $this->assertTrue($res instanceof LibRDF_LiteralNode, get_class($res));
     $ns = MwRdf::getNamespace('dc');
     $this->assertEquals($ns . 'W3CDTF', $res->getDatatype());
 }