コード例 #1
0
 public function build()
 {
     global $wgRightsUrl;
     $rdf = MwRdf::Vocabulary('rdf');
     $cc = MwRdf::Vocabulary('cc');
     $model = MwRdf::Model();
     $tr = $this->Agent->titleResource();
     $model->addStatement(MwRdf::Statement($tr, $rdf->a, $cc->Work));
     if (!isset($wgRightsUrl)) {
         return $model;
     }
     $lr = MwRdf::UriNode($wgRightsUrl);
     $model->addStatement(MwRdf::Statement($tr, $cc->license, $lr));
     $model->addStatement(MwRdf::Statement($lr, $rdf->a, $cc->License));
     $terms = MwRdf::GetCcTerms($wgRightsUrl);
     if (!isset($terms)) {
         return $model;
     }
     foreach ($terms as $term) {
         switch ($term) {
             case 're':
                 $model->addStatement(MwRdf::Statement($lr, $cc->permits, $cc->Reproduction));
                 break;
             case 'di':
                 $model->addStatement(MwRdf::Statement($lr, $cc->permits, $cc->Distribution));
                 break;
             case 'de':
                 $model->addStatement(MwRdf::Statement($lr, $cc->permits, $cc->DerivativeWorks));
                 break;
             case 'nc':
                 $model->addStatement(MwRdf::Statement($lr, $cc->prohibits, $cc->CommercialUse));
                 break;
             case 'no':
                 $model->addStatement(MwRdf::Statement($lr, $cc->requires, $cc->Notice));
                 break;
             case 'by':
                 $model->addStatement(MwRdf::Statement($lr, $cc->requires, $cc->Attribution));
                 break;
             case 'sa':
                 $model->addStatement(MwRdf::Statement($lr, $cc->requires, $cc->ShareAlike));
                 break;
             case 'sc':
                 $model->addStatement(MwRdf::Statement($lr, $cc->requires, $cc->SourceCode));
                 break;
         }
     }
     return $model;
 }
コード例 #2
0
ファイル: Image.php プロジェクト: schwarer2006/wikia
 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;
 }
コード例 #3
0
ファイル: History.php プロジェクト: schwarer2006/wikia
 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;
 }
コード例 #4
0
ファイル: MwRdfTest_Load.php プロジェクト: schwarer2006/wikia
 public function testLoad()
 {
     $agent = MwRdf::ModelingAgent($this->title);
     for ($i = 0; $i < 10000; $i++) {
         $model = $agent->retrieveModel('inpage');
         $this->assertType('object', $model);
         $this->assertTrue($model instanceof LibRDF_Model);
         $statement = MwRdf::Statement(MwRdf::UriNode('http://www.w3.org/TR/rdf-syntax-grammar'), MwRdf::UriNode('http://purl.org/dc/elements/1.1/title'), MwRdf::LiteralNode('RDF/XML Syntax Specification (Revised)'));
         $this->assertTrue($model->hasStatement($statement));
         $statements = $model->findStatements(MwRdf::UriNode('http://www.w3.org/TR/rdf-syntax-grammar'), MwRdf::UriNode('http://example.org/stuff/1.0/editor'), null);
         $this->assertType('object', $statements);
         $this->assertTrue($statements instanceof LibRDF_StreamIterator);
         $statement = $statements->current();
         $this->assertTrue($statement instanceof LibRdf_Statement);
         $editor = $statement->getObject();
         $this->assertTrue($editor instanceof LibRdf_BlankNode);
         $statement = MwRdf::Statement($editor, MwRdf::UriNode('http://example.org/stuff/1.0/fullname'), MwRdf::LiteralNode("Dave Beckett"));
         $this->assertTrue($model->hasStatement($statement));
         $statement = MwRdf::Statement($editor, MwRdf::UriNode('http://example.org/stuff/1.0/homePage'), MwRdf::UriNode('http://purl.org/net/dajobe/'));
         $this->assertTrue($model->hasStatement($statement));
         $model->rewind();
     }
 }
コード例 #5
0
ファイル: ModelingAgent.php プロジェクト: schwarer2006/wikia
 public function getContextNode($modelname)
 {
     $url = $this->Title->getFullUrl();
     $query = '';
     if (strpos($url, '?')) {
         list($url, $query) = explode('?', $url);
         return MwRdf::UriNode($url . "#{$modelname}?" . $query);
     } else {
         return MwRdf::UriNode($url . "#{$modelname}");
     }
 }
コード例 #6
0
 public function testStatementFromNodes()
 {
     $terms = MwRdf::Vocabulary('rdf');
     $s = MwRdf::UriNode('http://example.org/ns/a2');
     $p = MwRdf::UriNode('http://example.org/ns/b2');
     $o = MwRdf::UriNode('http://example.org/ns/c2');
     $statement = MwRdf::Statement($s, $p, $o);
     $this->assertTrue($statement instanceof LibRDF_Statement);
     $this->assertEquals("{[http://example.org/ns/a2], [http://example.org/ns/b2], [http://example.org/ns/c2]}", "{$statement}");
 }
コード例 #7
0
ファイル: Vocabulary.php プロジェクト: schwarer2006/wikia
 public function __construct()
 {
     foreach ($this as $key => $value) {
         $this->{$key} = MwRdf::UriNode($this->getNS() . $key);
     }
 }