コード例 #1
0
 public function setUp()
 {
     MwRdfTest::setupStorage();
     $article = MwRdfTest::createStorageTestArticle();
     $this->agent = MwRdf::ModelingAgent($article);
     $this->agent->registerModelMaker('MwRdf_InPage_Modeler');
     $this->agent->registerModelMaker('MwRdf_Categories_Modeler');
     MwRdf::RegisterVocabulary("dc", "MwRdf_Vocabulary_DCmes");
 }
コード例 #2
0
ファイル: Categories.php プロジェクト: schwarer2006/wikia
 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;
 }
コード例 #3
0
ファイル: LinksFrom.php プロジェクト: schwarer2006/wikia
 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;
 }
コード例 #4
0
ファイル: Interwiki.php プロジェクト: schwarer2006/wikia
 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;
 }
コード例 #5
0
ファイル: DCmes.php プロジェクト: schwarer2006/wikia
 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;
 }
コード例 #6
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();
     }
 }
コード例 #7
0
ファイル: SetupRdf.php プロジェクト: schwarer2006/wikia
function wfRdfSpecialPage($par)
{
    global $wgRequest, $wgOut, $_SERVER, $_REQUEST;
    MwRdf::setup();
    $target = $wgRequest->getVal('target');
    if (!isset($target) || $target == null) {
        # no target parameter
        MwRdf::ShowForm();
        return;
    }
    if (strlen($target) == 0) {
        # no target contents
        MwRdf::ShowForm(wfMsg('badtitle'));
        return;
    }
    $nt = Title::newFromText($target);
    if ($nt->getArticleID() == 0) {
        # not an article
        MwRdf::ShowForm(wfMsg('badtitle'));
        return;
    }
    $format = $wgRequest->getVal('format', 'rdfxml');
    $accept = isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : null;
    $rdftype = wfNegotiateType(wfAcceptToPrefs($accept), wfAcceptToPrefs(MwRdf::getTypePrefs($format)));
    if (!$rdftype) {
        wfHttpError(406, "Not Acceptable", wfMsg("notacceptable"));
        return false;
    }
    $wgOut->disable();
    if (!headers_sent()) {
        header("Content-type: {$rdftype}");
    }
    $wgOut->sendCacheControl();
    $mf = MwRdf::ModelingAgent($nt);
    # Note: WebRequest chokes on arrays here
    $modelnames = null;
    if (isset($_REQUEST['modelnames'])) {
        $modelnames = $_REQUEST['modelnames'];
    }
    if (is_null($modelnames)) {
        $modelnames = $mf->listDefaultModels();
    }
    if (is_string($modelnames)) {
        $modelnames = explode(',', $modelnames);
    }
    if (!$modelnames) {
        MwRdf::ShowForm(wfMsg('nomodelsselected'));
        return;
    }
    $model = $mf->retrieveModel($modelnames);
    if (!$model->current()) {
        $mf->storeAllModels();
        $model = $mf->retrieveModel($modelnames);
    }
    $ser = MwRdf::Serializer($format);
    $text = $model->serializeStatements($ser);
    # XXX: Test Hook: it would be better if we could capture the
    # print statement below with an output buffer, but that is
    # disabled for the CLI in PHP 5
    if (isset($_SERVER['CONTEXT']) && $_SERVER['CONTEXT'] == 'phpunit test') {
        return $text;
    } else {
        print $text;
        return true;
    }
}
コード例 #8
0
 public function testTimestamp()
 {
     $this->markTestIncomplete();
     $pagename = self::$username . '/NonArticle';
     $title = Title::newFromText($pagename, NS_USER);
     if ($title->exists()) {
         $article = new Article($title);
         $article->doPurge();
     }
     $agent = MwRdf::ModelingAgent($title);
     $this->assertType('boolean', $agent->getTimestampResource());
     $this->assertFalse($agent->getTimestampResource());
 }
コード例 #9
0
if ($page_count < $start) {
    fwrite(STDOUT, "-1");
    exit(1);
}
MwRdf::Setup();
$dbr = wfGetDB(DB_SLAVE);
$res = $dbr->query("\n\tSELECT page_id,\n\tpage_title,\n\tpage_namespace,\n\tpage_is_redirect\n\tFROM page\n\tORDER BY page_id\n\tLIMIT 200\n\tOFFSET {$start}");
while ($s = $dbr->fetchObject($res)) {
    if ($s->page_is_redirect) {
        continue;
    }
    $title = Title::makeTitle($s->page_namespace, $s->page_title);
    if (!$title) {
        continue;
    }
    $agent = MwRdf::ModelingAgent($title);
    fwrite(STDERR, $s->page_id . ": " . $title->getPrefixedDbKey());
    $agent->storeAllModels();
    $agent = null;
    $title = null;
    fwrite(STDERR, "\n");
}
fwrite(STDOUT, $start + 200);
function get_total_number_of_articles()
{
    $dbr = wfGetDB(DB_SLAVE);
    # get the total number of articles
    $page = $dbr->tableName('page');
    $res = $dbr->query("select count( page_id ) as page_count from {$page};");
    $s = $dbr->fetchObject($res);
    return $s->page_count;
コード例 #10
0
 public function testModelingAgentFromSpecialPageException()
 {
     $rc = Title::newFromText('Special:RecentChanges');
     try {
         $agent = MwRdf::ModelingAgent($rc);
     } catch (Exception $expected) {
         return;
     }
     $this->fail('ModelingAgent() should raise an exeption if called on a special page.');
 }