本文整理汇总了PHP中WikiPage::newFromID方法的典型用法代码示例。如果您正苦于以下问题:PHP WikiPage::newFromID方法的具体用法?PHP WikiPage::newFromID怎么用?PHP WikiPage::newFromID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WikiPage
的用法示例。
在下文中一共展示了WikiPage::newFromID方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doUpdate
/**
* Perform actual update for the entry
*/
public function doUpdate()
{
global $wgDisableSearchUpdate;
if ($wgDisableSearchUpdate || !$this->id) {
return;
}
$page = WikiPage::newFromID($this->id, WikiPage::READ_LATEST);
foreach (SearchEngine::getSearchTypes() as $type) {
$search = SearchEngine::create($type);
$indexTitle = $this->indexTitle($search);
if (!$search->supports('search-update')) {
continue;
}
$normalTitle = $search->normalizeText($indexTitle);
if ($page === null) {
$search->delete($this->id, $normalTitle);
continue;
} elseif ($this->content === false) {
$search->updateTitle($this->id, $normalTitle);
continue;
}
$text = $search->getTextFromContent($this->title, $this->content);
if (!$search->textAlreadyUpdatedForIndex()) {
$text = self::updateText($text);
}
# Perform the actual update
$search->update($this->id, $normalTitle, $search->normalizeText($text));
}
}
示例2: extractTemplatesFromPage
public function extractTemplatesFromPage($pageId, array $flagTypesToExtract)
{
$app = \F::app();
$wikiId = $this->getWikiId();
$wikiPage = \WikiPage::newFromID($pageId);
$app->wg->User = \User::newFromId($wikiPage->getUser());
$content = $wikiPage->getText();
$flagsExtractor = new FlagsExtractor();
/**
* Get the existing flags first
*/
$existingFlags = $app->sendRequest('FlagsApiController', 'getFlagsForPage', ['page_id' => $pageId])->getData()[\FlagsApiController::FLAGS_API_RESPONSE_DATA];
/**
* Prepare actions for the extraction and check which flags should be updated
*/
$actions = [FlagsExtractor::ACTION_REMOVE_ALL_FLAGS];
/**
* Check which flags should be added and which should be updated
*/
$flagsToAdd = $flagsToUpdate = [];
foreach ($flagTypesToExtract as $flagType) {
$actionParams = ['wiki_id' => $wikiId, 'page_id' => $pageId, 'flag_type_id' => $flagType['flag_type_id']];
$flagsExtractor->init($content, $flagType['flag_view'], $actions, $actionParams);
$template = $flagsExtractor->getTemplate()[0];
if (isset($existingFlags[$flagType['flag_type_id']])) {
$flagsToUpdate[] = ['flag_id' => $existingFlags[$flagType['flag_type_id']]['flag_id'], 'params' => $template['params']];
} else {
$flagsToAdd[] = ['flag_type_id' => $flagType['flag_type_id'], 'params' => $template['params']];
}
/**
* Modify the content for the next template
*/
$content = $flagsExtractor->getText();
}
/**
* Send requests
*/
if (!empty($flagsToAdd)) {
$responseData = $app->sendRequest('FlagsApiController', 'addFlagsToPage', ['wiki_id' => $wikiId, 'page_id' => $pageId, 'flags' => $flagsToAdd])->getData();
$this->actionsStatus = $responseData[\FlagsApiController::FLAGS_API_RESPONSE_STATUS];
if ($this->actionsStatus !== true) {
$this->error('The adding operation failed.');
}
}
if (!empty($flagsToUpdate)) {
$responseData = $app->sendRequest('FlagsApiController', 'updateFlagsForPage', ['wiki_id' => $wikiId, 'page_id' => $pageId, 'flags' => $flagsToUpdate])->getData();
$this->actionsStatus = $responseData[\FlagsApiController::FLAGS_API_RESPONSE_STATUS];
if ($this->actionsStatus !== true) {
$this->error('The updating operation failed.');
}
}
/**
* If the actions succeeded - make the actual edit as WikiaBot
*/
if ($this->actionsStatus) {
$user = \User::newFromName('WikiaBot');
$wikiPage->doEdit($content, 'Templates converted to the new Flags feature.', EDIT_FORCE_BOT | EDIT_MINOR, false, $user);
}
}
示例3: run
public function run()
{
$lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
$lb = $lbFactory->getMainLB();
$dbw = $lb->getConnection(DB_MASTER);
$this->ticket = $lbFactory->getEmptyTransactionTicket(__METHOD__);
$page = WikiPage::newFromID($this->params['pageId'], WikiPage::READ_LATEST);
if (!$page) {
$this->setLastError("Could not find page #{$this->params['pageId']}");
return false;
// deleted?
}
// Use a named lock so that jobs for this page see each others' changes
$lockKey = "CategoryMembershipUpdates:{$page->getId()}";
$scopedLock = $dbw->getScopedLockAndFlush($lockKey, __METHOD__, 3);
if (!$scopedLock) {
$this->setLastError("Could not acquire lock '{$lockKey}'");
return false;
}
$dbr = $lb->getConnection(DB_REPLICA, ['recentchanges']);
// Wait till the replica DB is caught up so that jobs for this page see each others' changes
if (!$lb->safeWaitForMasterPos($dbr)) {
$this->setLastError("Timed out while waiting for replica DB to catch up");
return false;
}
// Clear any stale REPEATABLE-READ snapshot
$dbr->flushSnapshot(__METHOD__);
$cutoffUnix = wfTimestamp(TS_UNIX, $this->params['revTimestamp']);
// Using ENQUEUE_FUDGE_SEC handles jobs inserted out of revision order due to the delay
// between COMMIT and actual enqueueing of the CategoryMembershipChangeJob job.
$cutoffUnix -= self::ENQUEUE_FUDGE_SEC;
// Get the newest revision that has a SRC_CATEGORIZE row...
$row = $dbr->selectRow(['revision', 'recentchanges'], ['rev_timestamp', 'rev_id'], ['rev_page' => $page->getId(), 'rev_timestamp >= ' . $dbr->addQuotes($dbr->timestamp($cutoffUnix))], __METHOD__, ['ORDER BY' => 'rev_timestamp DESC, rev_id DESC'], ['recentchanges' => ['INNER JOIN', ['rc_this_oldid = rev_id', 'rc_source' => RecentChange::SRC_CATEGORIZE, 'rc_cur_id = rev_page', 'rc_timestamp >= rev_timestamp']]]);
// Only consider revisions newer than any such revision
if ($row) {
$cutoffUnix = wfTimestamp(TS_UNIX, $row->rev_timestamp);
$lastRevId = (int) $row->rev_id;
} else {
$lastRevId = 0;
}
// Find revisions to this page made around and after this revision which lack category
// notifications in recent changes. This lets jobs pick up were the last one left off.
$encCutoff = $dbr->addQuotes($dbr->timestamp($cutoffUnix));
$res = $dbr->select('revision', Revision::selectFields(), ['rev_page' => $page->getId(), "rev_timestamp > {$encCutoff}" . " OR (rev_timestamp = {$encCutoff} AND rev_id > {$lastRevId})"], __METHOD__, ['ORDER BY' => 'rev_timestamp ASC, rev_id ASC']);
// Apply all category updates in revision timestamp order
foreach ($res as $row) {
$this->notifyUpdatesForRevision($lbFactory, $page, Revision::newFromRow($row));
}
return true;
}
示例4: purgeCache
/**
* Purge the cache for articles related to a given thread
* @param int $threadId
*/
public static function purgeCache($threadId)
{
$relatedPages = new WallRelatedPages();
$ids = $relatedPages->getMessagesRelatedArticleIds($threadId, 'order_index', DB_MASTER);
foreach ($ids as $id) {
$key = wfMemcKey(__CLASS__, 'getData', $id);
WikiaDataAccess::cachePurge($key);
// VOLDEV-46: Update module by purging page, not via AJAX
$wikiaPage = WikiPage::newFromID($id);
if ($wikiaPage) {
$wikiaPage->doPurge();
} else {
self::logError("Found a null related wikipage on thread purge", ["articleID" => $id, "threadID" => $threadId]);
}
}
}
示例5: run
public function run()
{
$page = WikiPage::newFromID($this->params['pageId'], WikiPage::READ_LATEST);
if (!$page) {
$this->setLastError("Could not find page #{$this->params['pageId']}");
return false;
// deleted?
}
$dbw = wfGetDB(DB_MASTER);
// Use a named lock so that jobs for this page see each others' changes
$fname = __METHOD__;
$lockKey = "CategoryMembershipUpdates:{$page->getId()}";
if (!$dbw->lock($lockKey, $fname, 10)) {
$this->setLastError("Could not acquire lock '{$lockKey}'");
return false;
}
$unlocker = new ScopedCallback(function () use($dbw, $lockKey, $fname) {
$dbw->unlock($lockKey, $fname);
});
// Sanity: clear any DB transaction snapshot
$dbw->commit(__METHOD__, 'flush');
$cutoffUnix = wfTimestamp(TS_UNIX, $this->params['revTimestamp']);
// Using ENQUEUE_FUDGE_SEC handles jobs inserted out of revision order due to the delay
// between COMMIT and actual enqueueing of the CategoryMembershipChangeJob job.
$cutoffUnix -= self::ENQUEUE_FUDGE_SEC;
// Get the newest revision that has a SRC_CATEGORIZE row...
$row = $dbw->selectRow(array('revision', 'recentchanges'), array('rev_timestamp', 'rev_id'), array('rev_page' => $page->getId(), 'rev_timestamp >= ' . $dbw->addQuotes($dbw->timestamp($cutoffUnix))), __METHOD__, array('ORDER BY' => 'rev_timestamp DESC, rev_id DESC'), array('recentchanges' => array('INNER JOIN', array('rc_this_oldid = rev_id', 'rc_source' => RecentChange::SRC_CATEGORIZE, 'rc_cur_id = rev_page', 'rc_timestamp >= rev_timestamp'))));
// Only consider revisions newer than any such revision
if ($row) {
$cutoffUnix = wfTimestamp(TS_UNIX, $row->rev_timestamp);
$lastRevId = (int) $row->rev_id;
} else {
$lastRevId = 0;
}
// Find revisions to this page made around and after this revision which lack category
// notifications in recent changes. This lets jobs pick up were the last one left off.
$encCutoff = $dbw->addQuotes($dbw->timestamp($cutoffUnix));
$res = $dbw->select('revision', Revision::selectFields(), array('rev_page' => $page->getId(), "rev_timestamp > {$encCutoff}" . " OR (rev_timestamp = {$encCutoff} AND rev_id > {$lastRevId})"), __METHOD__, array('ORDER BY' => 'rev_timestamp ASC, rev_id ASC'));
// Apply all category updates in revision timestamp order
foreach ($res as $row) {
$this->notifyUpdatesForRevision($page, Revision::newFromRow($row));
}
ScopedCallback::consume($unlocker);
return true;
}
示例6: run
function run()
{
if (is_null($this->title)) {
$this->setLastError("deleteLinks: Invalid title");
return false;
}
$pageId = $this->params['pageId'];
if (WikiPage::newFromID($pageId, WikiPage::READ_LATEST)) {
// The page was restored somehow or something went wrong
$this->setLastError("deleteLinks: Page #{$pageId} exists");
return false;
}
$page = WikiPage::factory($this->title);
// title when deleted
$update = new LinksDeletionUpdate($page, $pageId);
DataUpdate::runUpdates([$update]);
return true;
}
示例7: onEditFormPreloadText
/**
* Triggered if a user edits a Draft subpage of a template.
* It pre-fills the content of the Draft with a converted markup.
* @param $text
* @param Title $title
* @return bool
*/
public static function onEditFormPreloadText(&$text, Title $title)
{
$helper = new TemplateDraftHelper();
if ($helper->isTitleNewDraft($title) && TemplateConverter::isConversion()) {
$parentTitleId = $helper->getParentTitle($title)->getArticleID();
if ($parentTitleId > 0) {
$parentContent = WikiPage::newFromID($parentTitleId)->getText();
/**
* TODO: Introduce a parameter to modify conversion flags
* If you want to perform different conversions, not only the infobox one,
* you can introduce a URL parameter to control the binary sum of flags.
*/
$controller = new TemplateDraftController();
$text = $controller->createDraftContent($title, $parentContent, TemplateClassificationController::TEMPLATE_INFOBOX);
}
}
return true;
}
示例8: approveDraft
/**
* Overrides content of parent page with contents of draft page
* @param Title $draftTitle Title object of sub page (draft)
* @throws PermissionsException
*/
private function approveDraft(Title $draftTitle)
{
// Get Title object of parent page
$helper = new TemplateDraftHelper();
$parentTitle = $helper->getParentTitle($draftTitle);
// Check edit rights
if (!$parentTitle->userCan('templatedraft')) {
throw new PermissionsException('edit');
}
// Get contents of draft page
$article = Article::newFromId($draftTitle->getArticleID());
$draftContent = $article->getContent();
// Get WikiPage object of parent page
$page = WikiPage::newFromID($parentTitle->getArticleID());
// Save to parent page
$page->doEdit($draftContent, wfMessage('templatedraft-approval-summary')->inContentLanguage()->plain());
// Remove Draft page
$draftPage = WikiPage::newFromID($draftTitle->getArticleID());
$draftPage->doDeleteArticle(wfMessage('templatedraft-draft-removal-summary')->inContentLanguage()->plain());
// Show a confirmation message to a user after redirect
BannerNotificationsController::addConfirmation(wfMessage('templatedraft-approval-success-confirmation')->escaped(), BannerNotificationsController::CONFIRMATION_CONFIRM, true);
}
示例9: run
function run()
{
if (is_null($this->title)) {
$this->setLastError("deleteLinks: Invalid title");
return false;
}
$pageId = $this->params['pageId'];
// Serialize links updates by page ID so they see each others' changes
$scopedLock = LinksUpdate::acquirePageLock(wfGetDB(DB_MASTER), $pageId, 'job');
if (WikiPage::newFromID($pageId, WikiPage::READ_LATEST)) {
// The page was restored somehow or something went wrong
$this->setLastError("deleteLinks: Page #{$pageId} exists");
return false;
}
$factory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
$timestamp = isset($this->params['timestamp']) ? $this->params['timestamp'] : null;
$page = WikiPage::factory($this->title);
// title when deleted
$update = new LinksDeletionUpdate($page, $pageId, $timestamp);
$update->setTransactionTicket($factory->getEmptyTransactionTicket(__METHOD__));
$update->doUpdate();
return true;
}
示例10: fixLinksFromArticle
/**
* Run LinksUpdate for all links on a given page_id
* @param int $id The page_id
*/
public static function fixLinksFromArticle($id)
{
$page = WikiPage::newFromID($id);
LinkCache::singleton()->clear();
if ($page === null) {
return;
}
$content = $page->getContent(Revision::RAW);
if ($content === null) {
return;
}
$dbw = wfGetDB(DB_MASTER);
$dbw->begin(__METHOD__);
$updates = $content->getSecondaryDataUpdates($page->getTitle());
DataUpdate::runUpdates($updates);
$dbw->commit(__METHOD__);
}
示例11: fixLinksFromArticle
/**
* Run LinksUpdate for all links on a given page_id
* @param $id int The page_id
*/
public static function fixLinksFromArticle($id)
{
global $wgParser, $wgContLang;
$page = WikiPage::newFromID($id);
LinkCache::singleton()->clear();
if ($page === null) {
return;
}
$text = $page->getRawText();
if ($text === false) {
return;
}
$dbw = wfGetDB(DB_MASTER);
$dbw->begin(__METHOD__);
$options = ParserOptions::newFromUserAndLang(new User(), $wgContLang);
$parserOutput = $wgParser->parse($text, $page->getTitle(), $options, true, true, $page->getLatest());
$update = new LinksUpdate($page->getTitle(), $parserOutput, false);
$update->doUpdate();
$dbw->commit(__METHOD__);
}
示例12: getTitleOrPageId
/**
* @param $params array
* @param $load bool|string Whether load the object's state from the database:
* - false: don't load (if the pageid is given, it will still be loaded)
* - 'fromdb': load from a slave database
* - 'fromdbmaster': load from the master database
* @return WikiPage
*/
public function getTitleOrPageId($params, $load = false)
{
$this->requireOnlyOneParameter($params, 'title', 'pageid');
$pageObj = null;
if (isset($params['title'])) {
$titleObj = Title::newFromText($params['title']);
if (!$titleObj) {
$this->dieUsageMsg(array('invalidtitle', $params['title']));
}
$pageObj = WikiPage::factory($titleObj);
if ($load !== false) {
$pageObj->loadPageData($load);
}
} elseif (isset($params['pageid'])) {
if ($load === false) {
$load = 'fromdb';
}
$pageObj = WikiPage::newFromID($params['pageid'], $load);
if (!$pageObj) {
$this->dieUsageMsg(array('nosuchpageid', $params['pageid']));
}
}
return $pageObj;
}
示例13: modifyFileLinks
/**
* Called on BeforeParserFetchFileAndTitle hook
* Changes links and thumbnails of files to point to the approved revision in all cases except
* the primary file on file pages (e.g. the big image in the top left on File:My File.png). To
* modify that image see self::onImagePageFindFile()
**/
public static function modifyFileLinks($parser, Title $fileTitle, &$options, &$query)
{
if ($fileTitle->getNamespace() == NS_MEDIA) {
$fileTitle = Title::makeTitle(NS_FILE, $fileTitle->getDBkey());
$fileTitle->resetArticleId($fileTitle->getArticleID());
// avoid extra queries
// Media link redirects don't get caught by the normal redirect check, so this
// extra check is required
if ($temp = WikiPage::newFromID($fileTitle->getArticleID())->getRedirectTarget()) {
$fileTitle = $temp;
unset($temp);
}
}
if ($fileTitle->isRedirect()) {
$page = WikiPage::newFromID($fileTitle->getArticleID());
$fileTitle = $page->getRedirectTarget();
$fileTitle->resetArticleId($fileTitle->getArticleID());
// avoid extra queries
}
# Tell Parser what file version to use
list($approvedRevTimestamp, $approvedRevSha1) = ApprovedRevs::getApprovedFileInfo($fileTitle);
// no valid approved timestamp or sha1, so don't modify image or image link
if (!$approvedRevTimestamp || !$approvedRevSha1) {
return true;
}
$options['time'] = wfTimestampOrNull(TS_MW, $approvedRevTimestamp);
$options['sha1'] = $approvedRevSha1;
// $options['broken'] = true; // breaks the link? was in FlaggedRevs...why would we want to do this?
# Stabilize the file link
if ($query != '') {
$query .= '&';
}
$query .= "filetimestamp=" . urlencode(wfTimestamp(TS_MW, $approvedRevTimestamp));
return true;
}
示例14: fixLinksFromArticle
/**
* Run LinksUpdate for all links on a given page_id
* @param int $id The page_id
* @param int|bool $ns Only fix links if it is in this namespace
*/
public static function fixLinksFromArticle($id, $ns = false)
{
$page = WikiPage::newFromID($id);
LinkCache::singleton()->clear();
if ($page === null) {
return;
} elseif ($ns !== false && !$page->getTitle()->inNamespace($ns)) {
return;
}
$content = $page->getContent(Revision::RAW);
if ($content === null) {
return;
}
foreach ($content->getSecondaryDataUpdates($page->getTitle()) as $update) {
DeferredUpdates::addUpdate($update);
}
}
示例15: prepareTextForIndex
/**
* Generates plain text content of a given wiki page without WikiText or HTML tags
* @param object $oTitle Title object
* @return string Plain text content
*/
public function prepareTextForIndex(Title $oTitle)
{
$sText = WikiPage::newFromID($oTitle->getArticleID())->getContent()->getParserOutput($oTitle)->getText();
$sText = Sanitizer::stripAllTags($sText);
$sText = str_replace($this->aFragsToBeReplaced, ' ', $sText);
$sText = html_entity_decode($sText);
return $sText;
}
开发者ID:hfroese,项目名称:mediawiki-extensions-BlueSpiceExtensions,代码行数:13,代码来源:BuildIndexMainControl.class.php