public function build() { $dc = MwRdf::Vocabulary('dc'); $model = MwRdf::Model(); $ar = $this->Agent->titleResource(); $categories = $this->Agent->getTitle()->getParentCategories(); if (is_array($categories)) { foreach (array_keys($categories) as $category) { $catmf = MwRdf::ModelingAgent(Title::newFromText($category)); $model->addStatement(MwRdf::Statement($ar, $dc->subject, $catmf->titleResource())); } } return $model; }
public function build() { $dcterms = MwRdf::Vocabulary('dcterms'); $model = MwRdf::Model(); $tr = $this->Agent->titleResource(); $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select('pagelinks', array('pl_namespace', 'pl_title'), array('pl_from = ' . $this->Agent->getTitle()->getArticleID()), 'MwRdfLinksFrom', array('ORDER BY' => 'pl_namespace, pl_title')); while ($res && ($row = $dbr->fetchObject($res))) { $lt = Title::makeTitle($row->pl_namespace, $row->pl_title); $ltmf = MwRdf::ModelingAgent($lt); $model->addStatement(MwRdf::Statement($tr, $dcterms->references, $ltmf->titleResource())); } $dbr->freeResult($res); return $model; }
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; }
public function build() { global $wgContLang; $dc = MwRdf::Vocabulary('dc'); $dcterms = MwRdf::Vocabulary('dcterms'); $rdfs = MwRdf::Vocabulary('rdfs'); $model = MwRdf::Model(); $tr = $this->Agent->titleResource(); $article = $this->Agent->getArticle(); $text = $article->getContent(true); $parser = new Parser(); $parser->mOptions = new ParserOptions(); $parser->mTitle = $this; $parser->initialiseVariables(); $parser->clearState(); $tags = array('nowiki'); $m = array(); $text = $parser->extractTagsAndParams($tags, $text, $m); # XXX: maybe it would actually be better to do this at another # stage after the parser has already identified interwiki and # lang links # Find prefixed links preg_match_all("/\\[\\[([^|\\]]+:[^|\\]]+)(\\|.*)?\\]\\]/", $text, $m); if (!isset($m[0])) { return $model; } // nothing found so nevermind foreach ($m[1] as $linktext) { $iwlink = Title::newFromText($linktext); if (isset($iwlink)) { $pfx = $iwlink->getInterwiki(); if (strlen($pfx) > 0) { $iwlinkmf = MwRdf::ModelingAgent($iwlink); $iwr = $iwlinkmf->titleResource(); # XXX: Wikitravel uses some 4+ prefixes for sister site links if ($wgContLang->getLanguageName($pfx) && strlen($pfx) < 4) { $model->addStatement(MwRdf::Statement($tr, $dcterms->hasVersion, $iwr)); $model->addStatement(MwRdf::Statement($iwr, $dc->language, MwRdf::Language($pfx))); } else { # XXX: Express the "sister site" relationship better $model->addStatement(MwRdf::Statement($tr, $rdfs->seeAlso, $iwr)); } } } } return $model; }
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; }
public function build() { global $wgSitename, $wgContLanguageCode; $article = $this->Agent->getArticle(); $model = MwRdf::Model(); $rdf = MwRdf::Vocabulary('rdf'); $dc = MwRdf::Vocabulary('dc'); $dctype = MwRdf::Vocabulary('dctype'); $artres = $this->Agent->titleResource(); $model->addStatement(MwRdf::Statement($artres, $dc->title, MwRdf::LiteralNode($this->Agent->getTitle()->getText()))); $model->addStatement(MwRdf::Statement($artres, $dc->publisher, MwRdf::PageOrString(wfMsg('aboutpage'), $wgSitename))); $model->addStatement(MwRdf::Statement($artres, $dc->language, MwRdf::Language($wgContLanguageCode))); $model->addStatement(MwRdf::Statement($artres, $dc->type, $dctype->Text)); $model->addStatement(MwRdf::Statement($artres, $dc->format, MwRdf::MediaType('text/html'))); if ($this->Agent->getTimestampResource()) { $model->addStatement(MwRdf::Statement($artres, $dc->date, $this->Agent->getTimestampResource())); } if (MWNamespace::isTalk($this->Agent->getTitle()->getNamespace())) { $model->addStatement(MwRdf::Statement($artres, $dc->subject, $this->Agent->subjectResource())); } else { $talk = MwRdf::ModelingAgent($this->Agent->getTitle()->getTalkPage()); $model->addStatement(MwRdf::Statement($talk->titleResource(), $dc->subject, $artres)); } # 'Creator' is responsible for this version $creator = MwRdf::PersonToResource($article->getUser()); $model->addStatement(MwRdf::Statement($artres, $dc->creator, $creator)); # 'Contributors' are all other version authors $contributors = $article->getContributors(); foreach ($contributors as $user_parts) { $contributor = MwRdf::PersonToResource($user_parts[0], $user_parts[1], $user_parts[2]); $model->addStatement(MwRdf::Statement($artres, $dc->contributor, $contributor)); } # Rights notification global $wgRightsPage, $wgRightsUrl, $wgRightsText; $rights = MwRdf::RightsResource(); if ($rights) { $model->addStatement(MwRdf::Statement($artres, $dc->rights, $rights)); } return $model; }
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; }
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(); } }
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}"); }