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 $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 testLanguage() { $lang = MwRdf::Language('en'); $this->assertTrue($lang instanceof LibRDF_LiteralNode); $ns = MwRdf::getNamespace('dc'); $this->assertEquals($ns . 'ISO639-2', $lang->getDatatype()); $this->assertEquals("en^^<{$ns}ISO639-2>", "{$lang}"); }