/** * @since 2.1 * * @param Title $title * * @return text */ public function getContentAsText(Title $title) { $this->page = new \WikiPage($title); if (method_exists($this->page, 'getContent')) { $content = $this->page->getContent(); if ($content instanceof TextContent) { return $content->getNativeData(); } else { return ''; } } return $this->page->getText(); }
function execute() { global $wgParser; $wgParser->parse(' ', Title::newMainPage(), new ParserOptions()); $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select('page', '*', array('page_namespace' => HACL_NS_ACL), __METHOD__); $titles = array(); foreach ($res as $row) { $titles[] = Title::newFromRow($row); } $quiet = $this->hasOption('quiet'); $seen = array(); foreach ($titles as $title) { $page = new WikiPage($title); $pf = IACLParserFunctions::instance($title); IACLParserFunctions::parse($page->getText(), $title); $errors = $pf->consistencyCheckStatus(false); $errors = array_merge($errors, $pf->errors); if ($pf->def) { if (isset($seen[$pf->def['key']])) { $errors[] = "Duplicate definition! Previous one is " . $seen[$pf->def['key']]; } $seen[$pf->def['key']] = "{$title}"; } IACLParserFunctions::destroyInstance($pf); if ($errors) { print "Errors on {$title}:\n"; foreach ($errors as $e) { print "\t{$e}\n"; } } elseif (!$quiet) { print "OK {$title}\n"; } } }
static function onPageContentSave(WikiPage &$wikiPage, User &$user, Content &$content, &$summary, $isMinor, $isWatch, $section, &$flags, Status &$status) { // get the current tags from the page ///////////////////////////////////// $CurrentReferences; preg_match_all(self::GetLabelsRegex, $wikiPage->getText(), $matches); // build it as a "set" foreach (array_merge($matches[2], $matches[3]) as $toAdd) { if ($toAdd != '') { $CurrentReferences[$toAdd] = 1; } } // get the old tags from the database ///////////////////////////////////// $OldReferences; if (($rev = $wikiPage->getRevision()) != null && ($prevRev = $rev->getPrevious()) != null) { preg_match_all(self::GetLabelsRegex, $prevRev->getText(), $matches); // build it as a "set" foreach (array_merge($matches[2], $matches[3]) as $toAdd) { if ($toAdd != '') { $OldReferences[$toAdd] = 1; } } } // Resolve differences ////////////////////// $DB = wfGetDB(DB_MASTER); $DB->begin(); // start a transaction // start with the newOnes and make sure that the database is compatable, and remove them foreach (array_keys($CurrentReferences) as $RefToMakeSureExists) { if (isset($OldReferences[$RefToMakeSureExists])) { // if it is already in the array, then we don't have to worry about it; delete it unset($OldReferences[$RefToMakeSureExists]); } else { // if it doesn't exist, we need to add it try { $DB->insert(ContentReferencerTableName, array('reference_name' => $RefToMakeSureExists, 'reference_page_name' => (string) $wikiPage->getTitle())); } catch (Exception $e) { die($e->getMessage()); } } } // now, anything left in $OldReferences has been deleted. Let's remove it from the database foreach (array_keys($OldReferences) as $RefToDelete) { try { $DB->delete(ContentReferencerTableName, "reference_name='{$RefToDelete}'"); } catch (Exception $e) { die($e->getMessage()); } } $DB->commit(); // end the transaction }
static function insertTaskBoxTemplate($form, $title, $targetContent) { $teile = explode("ask:", $targetContent); $temp = explode("| format=list", $teile[1]); $results = self::getQueryResults($temp[0], array('title'), true); if ($results->getCount() === 0) { return FALSE; } while ($row = $results->getNext()) { $entityTitle = $row[0]->getNextObject(); $targetTitle = Title::newFromText($entityTitle->getLongWikiText()); if (!$targetTitle instanceof Title) { throw new MWException(wfMessage('tm-error-title')); } $page = new WikiPage($targetTitle); $content = $page->getContent(); if (strpos($page->getText(), '{{TaskBox}}') === false) { $page->doEditContent(new WikitextContent('{{TaskBox}}' . $content->getNativeData()), wfMessage('tm-tasbox-added'), EDIT_MINOR); } } return TRUE; }
static function refreshAll() { $dbw = wfGetDB(DB_MASTER); print "Refreshing right definitions...\n"; $res = $dbw->select('page', '*', array('page_namespace' => HACL_NS_ACL), __METHOD__); $titles = array(); foreach ($res as $row) { $titles[] = Title::newFromRow($row); } foreach ($titles as $title) { $article = new WikiPage($title); $article->doEdit($article->getText(), 'Re-parse right definition', EDIT_UPDATE); } }
/** * @covers WikiPage::doQuickEdit */ public function testDoQuickEdit() { global $wgUser; $this->hideDeprecated("WikiPage::doQuickEdit"); //NOTE: assume help namespace will default to wikitext $page = $this->createPage("Help:WikiPageTest_testDoQuickEdit", "original text"); $text = "quick text"; $page->doQuickEdit($text, $wgUser, "testing q"); # --------------------- $page = new WikiPage($page->getTitle()); $this->assertEquals($text, $page->getText()); }
/** * @covers WikiPage::doEdit */ public function testDoEdit() { $this->hideDeprecated("WikiPage::doEdit"); $this->hideDeprecated("WikiPage::getText"); $this->hideDeprecated("Revision::getText"); // NOTE: assume help namespace will default to wikitext $title = Title::newFromText("Help:WikiPageTest_testDoEdit"); $page = $this->newPage($title); $text = "[[Lorem ipsum]] dolor sit amet, consetetur sadipscing elitr, sed diam " . " nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat."; $page->doEdit($text, "[[testing]] 1"); $this->assertTrue($title->getArticleID() > 0, "Title object should have new page id"); $this->assertTrue($page->getId() > 0, "WikiPage should have new page id"); $this->assertTrue($title->exists(), "Title object should indicate that the page now exists"); $this->assertTrue($page->exists(), "WikiPage object should indicate that the page now exists"); $id = $page->getId(); # ------------------------ $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select('pagelinks', '*', array('pl_from' => $id)); $n = $res->numRows(); $res->free(); $this->assertEquals(1, $n, 'pagelinks should contain one link from the page'); # ------------------------ $page = new WikiPage($title); $retrieved = $page->getText(); $this->assertEquals($text, $retrieved, 'retrieved text doesn\'t equal original'); # ------------------------ $text = "At vero eos et accusam et justo duo [[dolores]] et ea rebum. " . "Stet clita kasd [[gubergren]], no sea takimata sanctus est."; $page->doEdit($text, "testing 2"); # ------------------------ $page = new WikiPage($title); $retrieved = $page->getText(); $this->assertEquals($text, $retrieved, 'retrieved text doesn\'t equal original'); # ------------------------ $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select('pagelinks', '*', array('pl_from' => $id)); $n = $res->numRows(); $res->free(); $this->assertEquals(2, $n, 'pagelinks should contain two links from the page'); }
/** * Verwijdert een waarde uit een argument van een blok op een wiki-pagina. * Bijvoorbeeld {{Context|Supercontext=te_verwijderen_waarde}} */ static function verwijderUitBlokargumentVanArtikel($artikel, $bloknaam, $argument, $te_verwijderen_inhoud, $samenvatting) { $titel_te_bewerken_artikel = Title::newFromText($artikel); $te_bewerken_artikel = new WikiPage($titel_te_bewerken_artikel); $inhoud = $te_bewerken_artikel->getText(); $blockstring = '{{' . $bloknaam; $eindstring = '}}'; $posblock = strpos($inhoud, $blockstring); $poseind = strpos($inhoud, $eindstring, $posblock + 1); $preblock = substr($inhoud, 0, $posblock); // De eindstring }} zit in het postblock! $postblock = trim(substr($inhoud, $poseind)); $block = substr($inhoud, $posblock, $poseind); $argumentblockintro = $argument . '='; $argumentblockoutro = '|'; $posintro = strpos($block, $argumentblockintro); $posoutro = strpos($block, $argumentblockoutro, $posintro); $argumentpreblock = substr($block, 0, $posintro); if ($posoutro) { $argumentblock = substr($block, $posintro, $posoutro); $argumentpostblock = substr($block, $posoutro); } else { $argumentblock = substr($block, $posintro); $argumentpostblock = ''; } $argumentblock = strtr($argumentblock, array($te_verwijderen_inhoud => '')); $argumentblock = strtr($argumentblock, array(',,' => ',')); $block = $argumentpreblock . $argumentblock . $argumentpostblock; $nieuwe_inhoud = $preblock . $block . $postblock; $te_bewerken_artikel->doEdit($nieuwe_inhoud, $samenvatting, EDIT_UPDATE); }
/** * @todo FIXME: the above rollback test is better, but it keeps failing in jenkins for some reason. */ public function testDoRollback() { $admin = new User(); $admin->setName("Admin"); $text = "one"; $page = $this->newPage("WikiPageTest_testDoRollback"); $page->doEdit($text, "section one", EDIT_NEW, false, $admin); $rev1 = $page->getRevision(); $user1 = new User(); $user1->setName("127.0.1.11"); $text .= "\n\ntwo"; $page = new WikiPage($page->getTitle()); $page->doEdit($text, "adding section two", 0, false, $user1); # now, try the rollback $admin->addGroup("sysop"); #XXX: make the test user a sysop... $token = $admin->getEditToken(array($page->getTitle()->getPrefixedText(), $user1->getName()), null); $errors = $page->doRollback($user1->getName(), "testing revert", $token, false, $details, $admin); if ($errors) { $this->fail("Rollback failed:\n" . print_r($errors, true) . ";\n" . print_r($details, true)); } $page = new WikiPage($page->getTitle()); $this->assertEquals($rev1->getSha1(), $page->getRevision()->getSha1(), "rollback did not revert to the correct revision"); $this->assertEquals("one", $page->getText()); }
/** * Create/edit ACL definition using interactive editor */ public function html_acl(&$q) { global $wgOut, $wgUser, $wgScript, $haclgHaloScriptPath, $haclgContLang, $wgContLang, $wgScriptPath; $aclTitle = $aclArticle = NULL; $aclContent = '{{#manage rights: assigned to = User:'******'}}'; $aclPEName = $aclPEType = false; if (!empty($q['sd'])) { $aclTitle = Title::newFromText($q['sd'], HACL_NS_ACL); $defId = IACLDefinition::nameOfPE($aclTitle); if ($aclTitle && $defId[0] != IACL::PE_GROUP) { if (($aclArticle = new WikiPage($aclTitle)) && $aclArticle->exists()) { $aclContent = $aclArticle->getText(); $aclSDName = $aclTitle->getText(); } else { $aclArticle = NULL; } list($aclPEType, $aclPEName) = $defId; } } /* Run template */ ob_start(); require dirname(__FILE__) . '/../templates/HACL_ACLEditor.tpl.php'; $html = ob_get_contents(); ob_end_clean(); if ($aclArticle) { $msg = 'hacl_acl_edit'; } elseif ($aclTitle) { $msg = 'hacl_acl_create_title'; } else { $msg = 'hacl_acl_create'; } $wgOut->addModules('ext.intraacl.acleditor'); $wgOut->setPageTitle(wfMsg($msg, $aclTitle ? $aclTitle->getText() : '')); $wgOut->addHTML($html); }
/** * Run a single test - assert $user can/cannot do $action on (depending on $can) * by $user, report status and failure details, if any. */ protected function assertCan($user, $can, $action) { global $haclgCombineMode, $haclgOpenWikiAccess; $info = array_merge(array($haclgOpenWikiAccess ? 'OPEN' : 'CLOSED', $haclgCombineMode), array_keys($this->acls)); $result = false; if (class_exists('IACLEvaluator')) { IACLEvaluator::userCan($this->title, $user, $action, $result); } else { HACLEvaluator::userCan($this->title, $user, $action, $result); } $ok = $can == $result; if ($ok) { $str = "[OK] "; $this->numOk++; } else { $str = "[FAILED] "; $this->numFailed++; } $str = $this->pfx . sprintf("%5d ", $this->numFailed + $this->numOk) . $str . '[' . implode(' ', $info) . '] ' . $user->getName() . ($can ? " can " : " cannot ") . $action . ' ' . $this->title . ($ok ? $this->newline : "\n"); if (!$ok || !$this->onlyFailures) { print $str; } if (!$ok) { global $haclgCombineMode, $haclgOpenWikiAccess; $art = new WikiPage($this->title); print " Details:\n Open Wiki Access = " . ($haclgOpenWikiAccess ? 'true' : 'false') . "\n"; print " Combine Mode = {$haclgCombineMode}\n"; print " Article content = " . trim($art->getText()) . "\n"; if ($this->acls) { print " Applied ACLs:\n"; foreach ($this->acls as $key => $info) { print ' ' . $info['title'] . ' ' . trim((new WikiPage($info['title']))->getText()) . "\n"; } } else { print " No applied ACLs\n"; } wfGetDB(DB_MASTER)->commit(); if ($this->stopOnFailure) { exit; } } }