public function testParsing() { $title = Title::newFromText('MediaWiki:Ugakey/nl'); $page = WikiPage::factory($title); $content = ContentHandler::makeContent('$1 van $2', $title); $status = $page->doEditContent($content, __METHOD__); $value = $status->getValue(); /** * @var Revision $rev */ $rev = $value['revision']; $revision = $rev->getId(); $dbw = wfGetDB(DB_MASTER); $conds = array('rt_page' => $title->getArticleID(), 'rt_type' => RevTag::getType('fuzzy'), 'rt_revision' => $revision); $index = array_keys($conds); $dbw->replace('revtag', array($index), $conds, __METHOD__); $handle = new MessageHandle($title); $this->assertTrue($handle->isValid(), 'Message is known'); $this->assertTrue($handle->isFuzzy(), 'Message is fuzzy after database fuzzying'); // Update the translation without the fuzzy string $content = ContentHandler::makeContent('$1 van $2', $title); $page->doEditContent($content, __METHOD__); $this->assertFalse($handle->isFuzzy(), 'Message is unfuzzy after edit'); $content = ContentHandler::makeContent('!!FUZZY!!$1 van $2', $title); $page->doEditContent($content, __METHOD__); $this->assertTrue($handle->isFuzzy(), 'Message is fuzzy after manual fuzzying'); // Update the translation without the fuzzy string $content = ContentHandler::makeContent('$1 van $2', $title); $page->doEditContent($content, __METHOD__); $this->assertFalse($handle->isFuzzy(), 'Message is unfuzzy after edit'); }
public function execute() { $user = $this->getUser(); $params = $this->extractRequestParams(); // WikiPage::doRollback needs a Web UI token, so get one of those if we // validated based on an API rollback token. $token = $params['token']; if ($user->matchEditToken($token, 'rollback', $this->getRequest())) { $token = $this->getUser()->getEditToken($this->getWebUITokenSalt($params), $this->getRequest()); } $titleObj = $this->getRbTitle($params); $pageObj = WikiPage::factory($titleObj); $summary = $params['summary']; $details = array(); $retval = $pageObj->doRollback($this->getRbUser($params), $summary, $token, $params['markbot'], $details, $user); if ($retval) { // We don't care about multiple errors, just report one of them $this->dieUsageMsg(reset($retval)); } $watch = 'preferences'; if (isset($params['watchlist'])) { $watch = $params['watchlist']; } // Watch pages $this->setWatch($watch, $titleObj, 'watchrollback'); $info = array('title' => $titleObj->getPrefixedText(), 'pageid' => intval($details['current']->getPage()), 'summary' => $details['summary'], 'revid' => intval($details['newid']), 'old_revid' => intval($details['current']->getID()), 'last_revid' => intval($details['target']->getID())); $this->getResult()->addValue(null, $this->getModuleName(), $info); }
public function execute() { $this->println('Adding missing file links for attachments.'); try { $dbr = \wfGetDB(DB_SLAVE); $res = $dbr->select('page_attachment_data', '*'); if (!$res->numRows()) { $this->println('No attachments found. No links added.'); break; } else { foreach ($res as $row) { $linkFromPageId = $row->attached_to_page_id; $linkToFileId = $row->attachment_page_id; $linkToFileTitle = \Title::newFromId($linkToFileId); $linkToFileDatabaseKey = $linkToFileTitle->getDBkey(); if (!$this->isLinkExist($linkFromPageId, $linkToFileDatabaseKey)) { $linkFromPageTitle = \Title::newFromId($linkFromPageId); $linkToFileName = $linkToFileTitle->getText(); $this->println('Adding missing link from page [' . $linkFromPageTitle . '] to attachment file [' . $linkToFileName . ']'); $linkToFileWikiPage = \WikiPage::factory($linkToFileTitle); $linkToFileWikiPage->doPurge(); $this->addLink($linkFromPageId, $linkToFileDatabaseKey); } } $this->println('Finished adding file links.'); } } catch (Exception $e) { $this->println('Failed to add file links. Error: [' . $e->getMessage() . ']'); } }
public function execute() { global $wgUser; $this->output("Checking existence of old default messages..."); $dbr = $this->getDB(DB_REPLICA); $res = $dbr->select(['page', 'revision'], ['page_namespace', 'page_title'], ['page_namespace' => NS_MEDIAWIKI, 'page_latest=rev_id', 'rev_user_text' => 'MediaWiki default']); if ($dbr->numRows($res) == 0) { # No more messages left $this->output("done.\n"); return; } # Deletions will be made by $user temporarly added to the bot group # in order to hide it in RecentChanges. $user = User::newFromName('MediaWiki default'); if (!$user) { $this->error("Invalid username", true); } $user->addGroup('bot'); $wgUser = $user; # Handle deletion $this->output("\n...deleting old default messages (this may take a long time!)...", 'msg'); $dbw = $this->getDB(DB_MASTER); foreach ($res as $row) { wfWaitForSlaves(); $dbw->ping(); $title = Title::makeTitle($row->page_namespace, $row->page_title); $page = WikiPage::factory($title); $error = ''; // Passed by ref // FIXME: Deletion failures should be reported, not silently ignored. $page->doDeleteArticle('No longer required', false, 0, true, $error, $user); } $this->output("done!\n", 'msg'); }
/** * @param Title $pageTitle * @param UUID|null $workflowId * @return WorkflowLoader * @throws InvalidInputException * @throws CrossWikiException */ public function createWorkflowLoader(Title $pageTitle, $workflowId = null) { if ($pageTitle === null) { throw new InvalidInputException('Invalid article requested', 'invalid-title'); } if ($pageTitle && $pageTitle->isExternal()) { throw new CrossWikiException('Interwiki to ' . $pageTitle->getInterwiki() . ' not implemented ', 'default'); } // @todo: ideally, workflowId is always set and this stuff is done in the places that call this if ($workflowId === null) { if ($pageTitle->getNamespace() === NS_TOPIC) { // topic page: workflow UUID is page title $workflowId = self::uuidFromTitle($pageTitle); } else { // board page: workflow UUID is inside content model $page = \WikiPage::factory($pageTitle); $content = $page->getContent(); if ($content instanceof BoardContent) { $workflowId = $content->getWorkflowId(); } } } if ($workflowId === null) { // no existing workflow found, create new one $workflow = Workflow::create($this->defaultWorkflowName, $pageTitle); } else { $workflow = $this->loadWorkflowById($pageTitle, $workflowId); } return new WorkflowLoader($workflow, $this->blockFactory->createBlocks($workflow), $this->submissionHandler); }
public function execute() { global $wgUser; $username = $this->getOption('username', false); if ($username === false) { $user = User::newSystemUser('ScriptImporter', ['steal' => true]); } else { $user = User::newFromName($username); } $wgUser = $user; $baseUrl = $this->getArg(1); $pageList = $this->fetchScriptList(); $this->output('Importing ' . count($pageList) . " pages\n"); foreach ($pageList as $page) { $title = Title::makeTitleSafe(NS_MEDIAWIKI, $page); if (!$title) { $this->error("{$page} is an invalid title; it will not be imported\n"); continue; } $this->output("Importing {$page}\n"); $url = wfAppendQuery($baseUrl, ['action' => 'raw', 'title' => "MediaWiki:{$page}"]); $text = Http::get($url, [], __METHOD__); $wikiPage = WikiPage::factory($title); $content = ContentHandler::makeContent($text, $wikiPage->getTitle()); $wikiPage->doEditContent($content, "Importing from {$url}", 0, false, $user); } }
public function testMessage() { $user = new MockSuperUser(); $user->setId(123); $title = Title::newFromText('MediaWiki:translated/fi'); $page = WikiPage::factory($title); $content = ContentHandler::makeContent('pupuliini', $title); $status = $page->doEditContent($content, __METHOD__, 0, false, $user); $value = $status->getValue(); $rev = $value['revision']; $revision = $rev->getId(); $group = MessageGroups::getGroup('test-group'); $collection = $group->initCollection('fi'); $collection->loadTranslations(); /** @var TMessage $translated */ $translated = $collection['translated']; $this->assertInstanceof('TMessage', $translated); $this->assertEquals('translated', $translated->key()); $this->assertEquals('bunny', $translated->definition()); $this->assertEquals('pupuliini', $translated->translation()); $this->assertEquals('SuperUser', $translated->getProperty('last-translator-text')); $this->assertEquals(123, $translated->getProperty('last-translator-id')); $this->assertEquals('translated', $translated->getProperty('status'), 'message status is translated'); $this->assertEquals($revision, $translated->getProperty('revision')); /** @var TMessage $untranslated */ $untranslated = $collection['untranslated']; $this->assertInstanceof('TMessage', $untranslated); $this->assertEquals(null, $untranslated->translation(), 'no translation is null'); $this->assertEquals(false, $untranslated->getProperty('last-translator-text')); $this->assertEquals(false, $untranslated->getProperty('last-translator-id')); $this->assertEquals('untranslated', $untranslated->getProperty('status'), 'message status is untranslated'); $this->assertEquals(false, $untranslated->getProperty('revision')); }
public function replaceVideoGalleryTag($pageId, $test = null) { global $wgTitle; $wgTitle = Title::newFromID($pageId); if (!$wgTitle) { $this->error("Invalid title", true); } $page = WikiPage::factory($wgTitle); # Read the text $text = $page->getText(); $text = preg_replace('/<(\\/?)videogallery([^>]*)>/', '<$1gallery$2>', $text); $summary = 'Updating <videogallery> to <gallery>'; # Do the edit $this->output("Replacing page (" . $wgTitle->getDBkey() . ") ... "); if ($test) { $this->output("(test: no changes) done\n"); } else { $status = $page->doEdit($text, $summary, EDIT_MINOR | EDIT_FORCE_BOT | EDIT_SUPPRESS_RC); if ($status->isOK()) { $this->output("done\n"); } else { $this->output("failed\n"); return 0; } if (!$status->isGood()) { $this->output($status->getWikiText() . "\n"); } } return 1; }
function run() { // Initialization $title = $this->title; list(, $code) = TranslateUtils::figureMessage($title->getPrefixedText()); // Return the actual translation page... $page = TranslatablePage::isTranslationPage($title); if (!$page) { var_dump($this->params); var_dump($title); throw new MWException("Oops, this should not happen!"); } $group = $page->getMessageGroup(); $collection = $group->initCollection($code); $text = $page->getParse()->getTranslationPageText($collection); // Other stuff $user = $this->getUser(); $summary = $this->getSummary(); $flags = $this->getFlags(); $page = WikiPage::factory($title); // @todo FuzzyBot hack PageTranslationHooks::$allowTargetEdit = true; $content = ContentHandler::makeContent($text, $page->getTitle()); $page->doEditContent($content, $summary, $flags, false, $user); PageTranslationHooks::$allowTargetEdit = false; return true; }
/** * @see BaseDependencyContainer::registerDefinitions * * @since 1.9 * * @return array */ protected function getDefinitions() { return array('ParserData' => $this->getParserData(), 'NamespaceExaminer' => $this->getNamespaceExaminer(), 'JobFactory' => function (DependencyBuilder $builder) { return new \SMW\MediaWiki\Jobs\JobFactory(); }, 'ContentParser' => function (DependencyBuilder $builder) { return new ContentParser($builder->getArgument('Title')); }, 'RequestContext' => function (DependencyBuilder $builder) { $instance = new \RequestContext(); if ($builder->hasArgument('Title')) { $instance->setTitle($builder->getArgument('Title')); } if ($builder->hasArgument('Language')) { $instance->setLanguage($builder->getArgument('Language')); } return $instance; }, 'WikiPage' => function (DependencyBuilder $builder) { return \WikiPage::factory($builder->getArgument('Title')); }, 'TitleCreator' => function (DependencyBuilder $builder) { return new TitleCreator(new PageCreator()); }, 'PageCreator' => function (DependencyBuilder $builder) { return new PageCreator(); }, 'MessageFormatter' => function (DependencyBuilder $builder) { return new MessageFormatter($builder->getArgument('Language')); }); }
function addDBData() { $this->tablesUsed[] = 'page'; $this->tablesUsed[] = 'revision'; $this->tablesUsed[] = 'text'; try { $title = Title::newFromText('BackupDumperTestP1'); $page = WikiPage::factory($title); list($this->revId1_1, $this->textId1_1) = $this->addRevision($page, "BackupDumperTestP1Text1", "BackupDumperTestP1Summary1"); $this->pageId1 = $page->getId(); $title = Title::newFromText('BackupDumperTestP2'); $page = WikiPage::factory($title); list($this->revId2_1, $this->textId2_1) = $this->addRevision($page, "BackupDumperTestP2Text1", "BackupDumperTestP2Summary1"); list($this->revId2_2, $this->textId2_2) = $this->addRevision($page, "BackupDumperTestP2Text2", "BackupDumperTestP2Summary2"); list($this->revId2_3, $this->textId2_3) = $this->addRevision($page, "BackupDumperTestP2Text3", "BackupDumperTestP2Summary3"); list($this->revId2_4, $this->textId2_4) = $this->addRevision($page, "BackupDumperTestP2Text4 some additional Text ", "BackupDumperTestP2Summary4 extra "); $this->pageId2 = $page->getId(); $title = Title::newFromText('BackupDumperTestP3'); $page = WikiPage::factory($title); list($this->revId3_1, $this->textId3_1) = $this->addRevision($page, "BackupDumperTestP3Text1", "BackupDumperTestP2Summary1"); list($this->revId3_2, $this->textId3_2) = $this->addRevision($page, "BackupDumperTestP3Text2", "BackupDumperTestP2Summary2"); $this->pageId3 = $page->getId(); $page->doDeleteArticle("Testing ;)"); $title = Title::newFromText('BackupDumperTestP1', NS_TALK); $page = WikiPage::factory($title); list($this->revId4_1, $this->textId4_1) = $this->addRevision($page, "Talk about BackupDumperTestP1 Text1", "Talk BackupDumperTestP1 Summary1"); $this->pageId4 = $page->getId(); } catch (Exception $e) { // We'd love to pass $e directly. However, ... see // documentation of exceptionFromAddDBData in // DumpTestCase $this->exceptionFromAddDBData = $e; } }
public function execute() { $userName = $this->getOption('u', 'Maintenance script'); $reason = $this->getOption('r', ''); $cascade = $this->hasOption('cascade'); $protection = "sysop"; if ($this->hasOption('semiprotect')) { $protection = "autoconfirmed"; } elseif ($this->hasOption('unprotect')) { $protection = ""; } $user = User::newFromName($userName); if (!$user) { $this->error("Invalid username", true); } // @todo FIXME: This is reset 7 lines down. $restrictions = array('edit' => $protection, 'move' => $protection); $t = Title::newFromText($this->getArg()); if (!$t) { $this->error("Invalid title", true); } $restrictions = array(); foreach ($t->getRestrictionTypes() as $type) { $restrictions[$type] = $protection; } # un/protect the article $this->output("Updating protection status... "); $page = WikiPage::factory($t); $status = $page->doUpdateRestrictions($restrictions, array(), $cascade, $reason, $user); if ($status->isOK()) { $this->output("done\n"); } else { $this->output("failed\n"); } }
public function execute() { $this->output("Looking for pages with page_latest set to 0...\n"); $dbw = wfGetDB(DB_MASTER); $result = $dbw->select('page', array('page_id', 'page_namespace', 'page_title'), array('page_latest' => 0), __METHOD__); $n = 0; foreach ($result as $row) { $pageId = intval($row->page_id); $title = Title::makeTitle($row->page_namespace, $row->page_title); $name = $title->getPrefixedText(); $latestTime = $dbw->selectField('revision', 'MAX(rev_timestamp)', array('rev_page' => $pageId), __METHOD__); if (!$latestTime) { $this->output(wfWikiID() . " {$pageId} [[{$name}]] can't find latest rev time?!\n"); continue; } $revision = Revision::loadFromTimestamp($dbw, $title, $latestTime); if (is_null($revision)) { $this->output(wfWikiID() . " {$pageId} [[{$name}]] latest time {$latestTime}, can't find revision id\n"); continue; } $id = $revision->getId(); $this->output(wfWikiID() . " {$pageId} [[{$name}]] latest time {$latestTime}, rev id {$id}\n"); if ($this->hasOption('fix')) { $page = WikiPage::factory($title); $page->updateRevisionOn($dbw, $revision); } $n++; } $this->output("Done! Processed {$n} pages.\n"); if (!$this->hasOption('fix')) { $this->output("This was a dry run; rerun with --fix to update page_latest.\n"); } }
/** * Purges the cache of a page */ public function execute() { $params = $this->extractRequestParams(); $forceLinkUpdate = $params['forcelinkupdate']; $pageSet = $this->getPageSet(); $pageSet->execute(); $result = array(); self::addValues($result, $pageSet->getInvalidTitles(), 'invalid', 'title'); self::addValues($result, $pageSet->getSpecialTitles(), 'special', 'title'); self::addValues($result, $pageSet->getMissingPageIDs(), 'missing', 'pageid'); self::addValues($result, $pageSet->getMissingRevisionIDs(), 'missing', 'revid'); self::addValues($result, $pageSet->getMissingTitles(), 'missing'); self::addValues($result, $pageSet->getInterwikiTitlesAsResult()); foreach ($pageSet->getGoodTitles() as $title) { $r = array(); ApiQueryBase::addTitleInfo($r, $title); $page = WikiPage::factory($title); $page->doPurge(); // Directly purge and skip the UI part of purge(). $r['purged'] = ''; if ($forceLinkUpdate) { if (!$this->getUser()->pingLimiter()) { global $wgEnableParserCache; $popts = $page->makeParserOptions('canonical'); # Parse content; note that HTML generation is only needed if we want to cache the result. $content = $page->getContent(Revision::RAW); $p_result = $content->getParserOutput($title, $page->getLatest(), $popts, $wgEnableParserCache); # Update the links tables $updates = $content->getSecondaryDataUpdates($title, null, true, $p_result); DataUpdate::runUpdates($updates); $r['linkupdate'] = ''; if ($wgEnableParserCache) { $pcache = ParserCache::singleton(); $pcache->save($p_result, $page, $popts); } } else { $error = $this->parseMsg(array('actionthrottledtext')); $this->setWarning($error['info']); $forceLinkUpdate = false; } } $result[] = $r; } $apiResult = $this->getResult(); $apiResult->setIndexedTagName($result, 'page'); $apiResult->addValue(null, $this->getModuleName(), $result); $values = $pageSet->getNormalizedTitlesAsResult($apiResult); if ($values) { $apiResult->addValue(null, 'normalized', $values); } $values = $pageSet->getConvertedTitlesAsResult($apiResult); if ($values) { $apiResult->addValue(null, 'converted', $values); } $values = $pageSet->getRedirectTitlesAsResult($apiResult); if ($values) { $apiResult->addValue(null, 'redirects', $values); } }
public function addDBDataOnce() { $info = $this->insertPage(self::$pageName); $title = $info['title']; $page = WikiPage::factory($title); self::$pageRev = $page->getRevision(); self::$revUser = User::newFromId(self::$pageRev->getUser(Revision::RAW)); }
/** * Deletes a user page if it exists. * This is needed especially when deleting sandbox users * that were created as part of the integration tests. * @param User $user */ protected function deleteUserPage($user) { $userpage = WikiPage::factory($user->getUserPage()); if ($userpage->exists()) { $dummyError = ''; $userpage->doDeleteArticleReal(wfMessage('tsb-delete-userpage-summary')->inContentLanguage()->text(), false, 0, true, $dummyError, $this->getUser()); } }
/** * ParserOptions::optionsHash was not giving consistent results when $wgUseDynamicDates was set * @group Database */ function testGetParserCacheKeyWithDynamicDates() { $title = Title::newFromText("Some test article"); $page = WikiPage::factory($title); $pcacheKeyBefore = $this->pcache->getKey($page, $this->popts); $this->assertNotNull($this->popts->getDateFormat()); $pcacheKeyAfter = $this->pcache->getKey($page, $this->popts); $this->assertEquals($pcacheKeyBefore, $pcacheKeyAfter); }
public static function deleteArticle($titletext, $namespace = NS_NOVA_RESOURCE) { if (!OpenStackNovaArticle::canCreatePages()) { return; } $title = Title::newFromText($titletext, $namespace); $article = WikiPage::factory($title); $article->doDeleteArticle(''); }
/** * @param string $text new page text * * @return int|null */ private function editPageText($text) { $page = WikiPage::factory($this->title); $editResult = $page->doEditContent(ContentHandler::makeContent($text, $this->title), __METHOD__); /** @var Revision $revision */ $revision = $editResult->value['revision']; $this->runJobs(); return $revision->getId(); }
/** * @covers WikiImporter * @dataProvider getUnknownTagsXML * @param string $xml * @param string $text * @param string $title */ public function testUnknownXMLTags($xml, $text, $title) { $source = $this->getDataSource($xml); $importer = new WikiImporter($source, ConfigFactory::getDefaultInstance()->makeConfig('main')); $importer->doImport(); $title = Title::newFromText($title); $this->assertTrue($title->exists()); $this->assertEquals(WikiPage::factory($title)->getContent()->getNativeData(), $text); }
/** * Clear the info cache for a given Title. * * @since 1.22 * @param Title $title Title to clear cache for */ public static function invalidateCache( Title $title ) { global $wgMemc; // Clear page info. $revision = WikiPage::factory( $title )->getRevision(); if ( $revision !== null ) { $key = wfMemcKey( 'infoaction', sha1( $title->getPrefixedText() ), $revision->getId() ); $wgMemc->delete( $key ); } }
public function testStuff() { $user = self::$users[__CLASS__]->getUser(); $page = WikiPage::factory(Title::newFromText('UTPage')); $user->addWatch($page->getTitle()); $result = $this->doApiRequestWithToken(['action' => 'setnotificationtimestamp', 'timestamp' => '20160101020202', 'pageids' => $page->getId()], null, $user); $this->assertEquals(['batchcomplete' => true, 'setnotificationtimestamp' => [['ns' => 0, 'title' => 'UTPage', 'notificationtimestamp' => '2016-01-01T02:02:02Z']]], $result[0]); $watchedItemStore = MediaWikiServices::getInstance()->getWatchedItemStore(); $this->assertEquals($watchedItemStore->getNotificationTimestampsBatch($user, [$page->getTitle()]), [['UTPage' => '20160101020202']]); }
/** * Integration test to catch regressions like T74870. Taken and modified * from SemanticMediaWiki */ public function testTitleMoveCompleteIntegrationTest() { $oldTitle = Title::newFromText('Help:Some title'); WikiPage::factory($oldTitle)->doEditContent(new WikitextContent('foo'), 'bar'); $newTitle = Title::newFromText('Help:Some other title'); $this->assertNull(WikiPage::factory($newTitle)->getRevision()); $this->assertTrue($oldTitle->moveTo($newTitle, false, 'test1', true)); $this->assertNotNull(WikiPage::factory($oldTitle)->getRevision()); $this->assertNotNull(WikiPage::factory($newTitle)->getRevision()); }
protected function getRedirectTarget($row) { if (isset($row->rd_title)) { return Title::makeTitle($row->rd_namespace, $row->rd_title, $row->rd_fragment, $row->rd_interwiki); } else { $title = Title::makeTitle($row->namespace, $row->title); $article = WikiPage::factory($title); return $article->getRedirectTarget(); } }
public static function setUpBeforeClass() { parent::setUpBeforeClass(); $page = WikiPage::factory(Title::newFromText('MediaWiki:ApiFormatXmlTest.xsl')); $page->doEditContent(new WikitextContent('<?xml version="1.0"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" />'), 'Summary'); $page = WikiPage::factory(Title::newFromText('MediaWiki:ApiFormatXmlTest')); $page->doEditContent(new WikitextContent('Bogus'), 'Summary'); $page = WikiPage::factory(Title::newFromText('ApiFormatXmlTest')); $page->doEditContent(new WikitextContent('Bogus'), 'Summary'); }
public function addDBDataOnce() { $titles = ['Page/Another', 'Page/Another/ru']; foreach ($titles as $title) { $page = WikiPage::factory(Title::newFromText($title)); if ($page->getId() == 0) { $page->doEditContent(new WikitextContent('UTContent'), 'UTPageSummary', EDIT_NEW, false, User::newFromName('UTSysop')); } } }
/** *Test bug 25702 *Prefixes of API search requests are not handled with case sensitivity and may result *in wrong search results */ public function testPrefixNormalizationSearchBug() { $title = Title::newFromText('Category:Template:xyz'); $page = WikiPage::factory($title); $page->doEdit('Some text', 'inserting content'); $result = $this->doApiRequest(['action' => 'query', 'list' => 'allpages', 'apnamespace' => NS_CATEGORY, 'apprefix' => 'Template:x']); $this->assertArrayHasKey('query', $result[0]); $this->assertArrayHasKey('allpages', $result[0]['query']); $this->assertNotEquals(0, count($result[0]['query']['allpages']), 'allpages list does not contain page Category:Template:xyz'); }
protected function setUp() { global $wgHooks; parent::setUp(); // Hook to inject our interwiki prefix $this->hooks = $wgHooks; $wgHooks['InterwikiLoadPrefix'][] = function ($prefix, &$data) { if ($prefix !== 'scribuntotitletest') { return true; } $data = array('iw_prefix' => 'scribuntotitletest', 'iw_url' => '//test.wikipedia.org/wiki/$1', 'iw_api' => 1, 'iw_wikiid' => 0, 'iw_local' => 0, 'iw_trans' => 0); return false; }; // Page for getContent test $page = WikiPage::factory(Title::newFromText('ScribuntoTestPage')); $page->doEditContent(new WikitextContent('{{int:mainpage}}<includeonly>...</includeonly><noinclude>...</noinclude>'), 'Summary'); // Set restrictions for protectionLevels and cascadingProtection tests // Since mRestrictionsLoaded is true, they don't count as expensive $title = Title::newFromText('Main Page'); $title->mRestrictionsLoaded = true; $title->mRestrictions = array('edit' => array(), 'move' => array()); $title->mCascadeSources = array(Title::makeTitle(NS_MAIN, "Lockbox"), Title::makeTitle(NS_MAIN, "Lockbox2")); $title->mCascadingRestrictions = array('edit' => array('sysop')); $title = Title::newFromText('Module:TestFramework'); $title->mRestrictionsLoaded = true; $title->mRestrictions = array('edit' => array('sysop', 'bogus'), 'move' => array('sysop', 'bogus')); $title->mCascadeSources = array(); $title->mCascadingRestrictions = array(); $title = Title::newFromText('scribuntotitletest:Module:TestFramework'); $title->mRestrictionsLoaded = true; $title->mRestrictions = array(); $title->mCascadeSources = array(); $title->mCascadingRestrictions = array(); $title = Title::newFromText('Talk:Has/A/Subpage'); $title->mRestrictionsLoaded = true; $title->mRestrictions = array('create' => array('sysop')); $title->mCascadeSources = array(); $title->mCascadingRestrictions = array(); $title = Title::newFromText('Not/A/Subpage'); $title->mRestrictionsLoaded = true; $title->mRestrictions = array('edit' => array('autoconfirmed'), 'move' => array('sysop')); $title->mCascadeSources = array(); $title->mCascadingRestrictions = array(); $title = Title::newFromText('Module talk:Test Framework'); $title->mRestrictionsLoaded = true; $title->mRestrictions = array('edit' => array(), 'move' => array('sysop')); $title->mCascadeSources = array(); $title->mCascadingRestrictions = array(); // Note this depends on every iteration of the data provider running with a clean parser $this->getEngine()->getParser()->getOptions()->setExpensiveParserFunctionLimit(10); // Indicate to the tests that it's safe to create the title objects $interpreter = $this->getEngine()->getInterpreter(); $interpreter->callFunction($interpreter->loadString("mw.title.testPageId = {$page->getId()}", 'fortest')); $this->setMwGlobals(array('wgServer' => '//wiki.local', 'wgCanonicalServer' => 'http://wiki.local', 'wgUsePathInfo' => true, 'wgActionPaths' => array(), 'wgScript' => '/w/index.php', 'wgScriptPath' => '/w', 'wgArticlePath' => '/wiki/$1')); }
/** * Creates pages from an array on install if thishas not been done already */ public static function create() { $wikiPageData = array('Category:RDFIO Data Source' => array('title' => 'RDFIO Data Source', 'content' => 'URL containing RDF data or a SPARQL endpoint which has been used to import triples into the wiki through the RDFIO extension<br />[[Has type::URL]]', 'summary' => 'Created by RDFIO', 'namespace' => 'NS_CATEGORY'), 'Property:RDFIO Import Type' => array('title' => 'RDFIO Import Type', 'content' => 'RDF or SPARQL import<br />[[Allows value::RDF]]<br />[[Allows value::SPARQL]]', 'summary' => 'Created by RDFIO', 'namespace' => 'NS_PROPERTY'), 'Property:Has template' => array('title' => 'Has template', 'content' => 'Template used for pages in this category on creation<br />[[Has type::Page]]', 'summary' => 'Created by RDFIO', 'namespace' => 'NS_PROPERTY'), 'RDF' => array('title' => 'RDF', 'content' => 'Resource Description Framwork (RDF)', 'summary' => 'Created by RDFIO', 'namespace' => 'NS_MAIN'), 'SPARQL' => array('title' => 'SPARQL', 'content' => 'SPARQL endpoint', 'summary' => 'Created by RDFIO', 'namespace' => 'NS_MAIN')); foreach ($wikiPageData as $pageTitle => $page) { $pageTitleObj = Title::newFromText($pageTitle); $pageObj = WikiPage::factory($pageTitleObj); $content = $page['content']; $summary = $page['summary']; $pageObj->doEdit($content, $summary); } }
function testWikiPageFactory() { $title = Title::makeTitle(NS_FILE, 'Someimage.png'); $page = WikiPage::factory($title); $this->assertEquals('WikiFilePage', get_class($page)); $title = Title::makeTitle(NS_CATEGORY, 'SomeCategory'); $page = WikiPage::factory($title); $this->assertEquals('WikiCategoryPage', get_class($page)); $title = Title::makeTitle(NS_MAIN, 'SomePage'); $page = WikiPage::factory($title); $this->assertEquals('WikiPage', get_class($page)); }