本文整理汇总了PHP中Title::getContentModel方法的典型用法代码示例。如果您正苦于以下问题:PHP Title::getContentModel方法的具体用法?PHP Title::getContentModel怎么用?PHP Title::getContentModel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Title
的用法示例。
在下文中一共展示了Title::getContentModel方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getContentModel
/**
* Returns the page's content model id (see the CONTENT_MODEL_XXX constants).
*
* Will use the revisions actual content model if the page exists,
* and the page's default if the page doesn't exist yet.
*
* @return String
*
* @since 1.21
*/
public function getContentModel()
{
if ($this->exists()) {
# look at the revision's actual content model
$rev = $this->getRevision();
if ($rev !== null) {
return $rev->getContentModel();
} else {
$title = $this->mTitle->getPrefixedDBkey();
wfWarn("Page {$title} exists but has no (visible) revisions!");
}
}
# use the default model for this page
return $this->mTitle->getContentModel();
}
示例2: isValidMove
/**
* Does various sanity checks that the move is
* valid. Only things based on the two titles
* should be checked here.
*
* @return Status
*/
public function isValidMove()
{
global $wgContentHandlerUseDB;
$status = new Status();
if ($this->oldTitle->equals($this->newTitle)) {
$status->fatal('selfmove');
}
if (!$this->oldTitle->isMovable()) {
$status->fatal('immobile-source-namespace', $this->oldTitle->getNsText());
}
if ($this->newTitle->isExternal()) {
$status->fatal('immobile-target-namespace-iw');
}
if (!$this->newTitle->isMovable()) {
$status->fatal('immobile-target-namespace', $this->newTitle->getNsText());
}
$oldid = $this->oldTitle->getArticleID();
if (strlen($this->newTitle->getDBkey()) < 1) {
$status->fatal('articleexists');
}
if ($this->oldTitle->getDBkey() == '' || !$oldid || $this->newTitle->getDBkey() == '') {
$status->fatal('badarticleerror');
}
# The move is allowed only if (1) the target doesn't exist, or
# (2) the target is a redirect to the source, and has no history
# (so we can undo bad moves right after they're done).
if ($this->newTitle->getArticleID() && !$this->isValidMoveTarget()) {
$status->fatal('articleexists');
}
// Content model checks
if (!$wgContentHandlerUseDB && $this->oldTitle->getContentModel() !== $this->newTitle->getContentModel()) {
// can't move a page if that would change the page's content model
$status->fatal('bad-target-model', ContentHandler::getLocalizedName($this->oldTitle->getContentModel()), ContentHandler::getLocalizedName($this->newTitle->getContentModel()));
}
// Image-specific checks
if ($this->oldTitle->inNamespace(NS_FILE)) {
$status->merge($this->isValidFileMove());
}
if ($this->newTitle->inNamespace(NS_FILE) && !$this->oldTitle->inNamespace(NS_FILE)) {
$status->fatal('nonfile-cannot-move-to-file');
}
// Hook for extensions to say a title can't be moved for technical reasons
Hooks::run('MovePageIsValidMove', array($this->oldTitle, $this->newTitle, $status));
return $status;
}
示例3: getContentModel
/**
* Returns the page's content model id (see the CONTENT_MODEL_XXX constants).
*
* Will use the revisions actual content model if the page exists,
* and the page's default if the page doesn't exist yet.
*
* @return string
*
* @since 1.21
*/
public function getContentModel()
{
if ($this->exists()) {
$cache = ObjectCache::getMainWANInstance();
return $cache->getWithSetCallback($cache->makeKey('page', 'content-model', $this->getLatest()), $cache::TTL_MONTH, function () {
$rev = $this->getRevision();
if ($rev) {
// Look at the revision's actual content model
return $rev->getContentModel();
} else {
$title = $this->mTitle->getPrefixedDBkey();
wfWarn("Page {$title} exists but has no (visible) revisions!");
return $this->mTitle->getContentModel();
}
});
}
// use the default model for this page
return $this->mTitle->getContentModel();
}
示例4: getForTitle
/**
* Returns the appropriate ContentHandler singleton for the given title.
*
* @since 1.21
*
* @param Title $title
*
* @return ContentHandler
*/
public static function getForTitle(Title $title)
{
$modelId = $title->getContentModel();
return ContentHandler::getForModelID($modelId);
}
示例5: onSubmit
public function onSubmit(array $data)
{
global $wgContLang;
if ($data['pagetitle'] === '') {
// Initial form view of special page, pass
return false;
}
// At this point, it has to be a POST request. This is enforced by HTMLForm,
// but lets be safe verify that.
if (!$this->getRequest()->wasPosted()) {
throw new RuntimeException("Form submission was not POSTed");
}
$this->title = Title::newFromText($data['pagetitle']);
$user = $this->getUser();
// Check permissions and make sure the user has permission to edit the specific page
$errors = $this->title->getUserPermissionsErrors('editcontentmodel', $user);
$errors = wfMergeErrorArrays($errors, $this->title->getUserPermissionsErrors('edit', $user));
if ($errors) {
$out = $this->getOutput();
$wikitext = $out->formatPermissionsErrorMessage($errors);
// Hack to get our wikitext parsed
return Status::newFatal(new RawMessage('$1', array($wikitext)));
}
$page = WikiPage::factory($this->title);
if ($this->oldRevision === null) {
$this->oldRevision = $page->getRevision() ?: false;
}
$oldModel = $this->title->getContentModel();
if ($this->oldRevision) {
$oldContent = $this->oldRevision->getContent();
try {
$newContent = ContentHandler::makeContent($oldContent->getNativeData(), $this->title, $data['model']);
} catch (MWException $e) {
return Status::newFatal($this->msg('changecontentmodel-cannot-convert')->params($this->title->getPrefixedText(), ContentHandler::getLocalizedName($data['model'])));
}
} else {
// Page doesn't exist, create an empty content object
$newContent = ContentHandler::getForModelID($data['model'])->makeEmptyContent();
}
$flags = $this->oldRevision ? EDIT_UPDATE : EDIT_NEW;
if ($user->isAllowed('bot')) {
$flags |= EDIT_FORCE_BOT;
}
$log = new ManualLogEntry('contentmodel', 'change');
$log->setPerformer($user);
$log->setTarget($this->title);
$log->setComment($data['reason']);
$log->setParameters(array('4::oldmodel' => $oldModel, '5::newmodel' => $data['model']));
$formatter = LogFormatter::newFromEntry($log);
$formatter->setContext(RequestContext::newExtraneousContext($this->title));
$reason = $formatter->getPlainActionText();
if ($data['reason'] !== '') {
$reason .= $this->msg('colon-separator')->inContentLanguage()->text() . $data['reason'];
}
# Truncate for whole multibyte characters.
$reason = $wgContLang->truncate($reason, 255);
$status = $page->doEditContent($newContent, $reason, $flags, $this->oldRevision ? $this->oldRevision->getId() : false, $user);
if (!$status->isOK()) {
return $status;
}
$logid = $log->insert();
$log->publish($logid);
return $status;
}
示例6: extractPageInfo
/**
* Get a result array with information about a title
* @param int $pageid Page ID (negative for missing titles)
* @param Title $title
* @return array|null
*/
private function extractPageInfo($pageid, $title)
{
$pageInfo = array();
// $title->exists() needs pageid, which is not set for all title objects
$titleExists = $pageid > 0;
$ns = $title->getNamespace();
$dbkey = $title->getDBkey();
$pageInfo['contentmodel'] = $title->getContentModel();
$pageInfo['pagelanguage'] = $title->getPageLanguage()->getCode();
if ($titleExists) {
$pageInfo['touched'] = wfTimestamp(TS_ISO_8601, $this->pageTouched[$pageid]);
$pageInfo['lastrevid'] = intval($this->pageLatest[$pageid]);
$pageInfo['length'] = intval($this->pageLength[$pageid]);
if (isset($this->pageIsRedir[$pageid]) && $this->pageIsRedir[$pageid]) {
$pageInfo['redirect'] = true;
}
if ($this->pageIsNew[$pageid]) {
$pageInfo['new'] = true;
}
}
if (!is_null($this->params['token'])) {
$tokenFunctions = $this->getTokenFunctions();
$pageInfo['starttimestamp'] = wfTimestamp(TS_ISO_8601, time());
foreach ($this->params['token'] as $t) {
$val = call_user_func($tokenFunctions[$t], $pageid, $title);
if ($val === false) {
$this->setWarning("Action '{$t}' is not allowed for the current user");
} else {
$pageInfo[$t . 'token'] = $val;
}
}
}
if ($this->fld_protection) {
$pageInfo['protection'] = array();
if (isset($this->protections[$ns][$dbkey])) {
$pageInfo['protection'] = $this->protections[$ns][$dbkey];
}
ApiResult::setIndexedTagName($pageInfo['protection'], 'pr');
$pageInfo['restrictiontypes'] = array();
if (isset($this->restrictionTypes[$ns][$dbkey])) {
$pageInfo['restrictiontypes'] = $this->restrictionTypes[$ns][$dbkey];
}
ApiResult::setIndexedTagName($pageInfo['restrictiontypes'], 'rt');
}
if ($this->fld_watched) {
$pageInfo['watched'] = isset($this->watched[$ns][$dbkey]);
}
if ($this->fld_watchers) {
if (isset($this->watchers[$ns][$dbkey])) {
$pageInfo['watchers'] = $this->watchers[$ns][$dbkey];
} elseif ($this->showZeroWatchers) {
$pageInfo['watchers'] = 0;
}
}
if ($this->fld_notificationtimestamp) {
$pageInfo['notificationtimestamp'] = '';
if (isset($this->notificationtimestamps[$ns][$dbkey])) {
$pageInfo['notificationtimestamp'] = wfTimestamp(TS_ISO_8601, $this->notificationtimestamps[$ns][$dbkey]);
}
}
if ($this->fld_talkid && isset($this->talkids[$ns][$dbkey])) {
$pageInfo['talkid'] = $this->talkids[$ns][$dbkey];
}
if ($this->fld_subjectid && isset($this->subjectids[$ns][$dbkey])) {
$pageInfo['subjectid'] = $this->subjectids[$ns][$dbkey];
}
if ($this->fld_url) {
$pageInfo['fullurl'] = wfExpandUrl($title->getFullURL(), PROTO_CURRENT);
$pageInfo['editurl'] = wfExpandUrl($title->getFullURL('action=edit'), PROTO_CURRENT);
$pageInfo['canonicalurl'] = wfExpandUrl($title->getFullURL(), PROTO_CANONICAL);
}
if ($this->fld_readable) {
$pageInfo['readable'] = $title->userCan('read', $this->getUser());
}
if ($this->fld_preload) {
if ($titleExists) {
$pageInfo['preload'] = '';
} else {
$text = null;
Hooks::run('EditFormPreloadText', array(&$text, &$title));
$pageInfo['preload'] = $text;
}
}
if ($this->fld_displaytitle) {
if (isset($this->displaytitles[$pageid])) {
$pageInfo['displaytitle'] = $this->displaytitles[$pageid];
} else {
$pageInfo['displaytitle'] = $title->getPrefixedText();
}
}
if ($this->params['testactions']) {
$limit = $this->getMain()->canApiHighLimits() ? self::LIMIT_SML1 : self::LIMIT_SML2;
if ($this->countTestedActions >= $limit) {
return null;
//.........这里部分代码省略.........
示例7: internalAttemptSave
//.........这里部分代码省略.........
}
if ($wgUser->isBlockedFrom($this->mTitle, false)) {
// Auto-block user's IP if the account was "hard" blocked
$wgUser->spreadAnyEditBlock();
# Check block state against master, thus 'false'.
$status->setResult(false, self::AS_BLOCKED_PAGE_FOR_USER);
wfProfileOut(__METHOD__ . '-checks');
wfProfileOut(__METHOD__);
return $status;
}
$this->kblength = (int) (strlen($this->textbox1) / 1024);
if ($this->kblength > $wgMaxArticleSize) {
// Error will be displayed by showEditForm()
$this->tooBig = true;
$status->setResult(false, self::AS_CONTENT_TOO_BIG);
wfProfileOut(__METHOD__ . '-checks');
wfProfileOut(__METHOD__);
return $status;
}
if (!$wgUser->isAllowed('edit')) {
if ($wgUser->isAnon()) {
$status->setResult(false, self::AS_READ_ONLY_PAGE_ANON);
wfProfileOut(__METHOD__ . '-checks');
wfProfileOut(__METHOD__);
return $status;
} else {
$status->fatal('readonlytext');
$status->value = self::AS_READ_ONLY_PAGE_LOGGED;
wfProfileOut(__METHOD__ . '-checks');
wfProfileOut(__METHOD__);
return $status;
}
}
if ($this->contentModel !== $this->mTitle->getContentModel() && !$wgUser->isAllowed('editcontentmodel')) {
$status->setResult(false, self::AS_NO_CHANGE_CONTENT_MODEL);
wfProfileOut(__METHOD__ . '-checks');
wfProfileOut(__METHOD__);
return $status;
}
if (wfReadOnly()) {
$status->fatal('readonlytext');
$status->value = self::AS_READ_ONLY_PAGE;
wfProfileOut(__METHOD__ . '-checks');
wfProfileOut(__METHOD__);
return $status;
}
if ($wgUser->pingLimiter() || $wgUser->pingLimiter('linkpurge', 0)) {
$status->fatal('actionthrottledtext');
$status->value = self::AS_RATE_LIMITED;
wfProfileOut(__METHOD__ . '-checks');
wfProfileOut(__METHOD__);
return $status;
}
# If the article has been deleted while editing, don't save it without
# confirmation
if ($this->wasDeletedSinceLastEdit() && !$this->recreate) {
$status->setResult(false, self::AS_ARTICLE_WAS_DELETED);
wfProfileOut(__METHOD__ . '-checks');
wfProfileOut(__METHOD__);
return $status;
}
wfProfileOut(__METHOD__ . '-checks');
# Load the page data from the master. If anything changes in the meantime,
# we detect it by using page_latest like a token in a 1 try compare-and-swap.
$this->mArticle->loadPageData('fromdbmaster');
$new = !$this->mArticle->exists();
示例8: moveToInternal
/**
* Move page to a title which is either a redirect to the
* source page or nonexistent
*
* @fixme This was basically directly moved from Title, it should be split into smaller functions
* @param User $user the User doing the move
* @param Title $nt The page to move to, which should be a redirect or nonexistent
* @param string $reason The reason for the move
* @param bool $createRedirect Whether to leave a redirect at the old title. Does not check
* if the user has the suppressredirect right
* @throws MWException
*/
private function moveToInternal(User $user, &$nt, $reason = '', $createRedirect = true)
{
global $wgContLang;
if ($nt->exists()) {
$moveOverRedirect = true;
$logType = 'move_redir';
} else {
$moveOverRedirect = false;
$logType = 'move';
}
if ($createRedirect) {
if ($this->oldTitle->getNamespace() == NS_CATEGORY && !wfMessage('category-move-redirect-override')->inContentLanguage()->isDisabled()) {
$redirectContent = new WikitextContent(wfMessage('category-move-redirect-override')->params($nt->getPrefixedText())->inContentLanguage()->plain());
} else {
$contentHandler = ContentHandler::getForTitle($this->oldTitle);
$redirectContent = $contentHandler->makeRedirectContent($nt, wfMessage('move-redirect-text')->inContentLanguage()->plain());
}
// NOTE: If this page's content model does not support redirects, $redirectContent will be null.
} else {
$redirectContent = null;
}
// Figure out whether the content model is no longer the default
$oldDefault = ContentHandler::getDefaultModelFor($this->oldTitle);
$contentModel = $this->oldTitle->getContentModel();
$newDefault = ContentHandler::getDefaultModelFor($nt);
$defaultContentModelChanging = $oldDefault !== $newDefault && $oldDefault === $contentModel;
// bug 57084: log_page should be the ID of the *moved* page
$oldid = $this->oldTitle->getArticleID();
$logTitle = clone $this->oldTitle;
$logEntry = new ManualLogEntry('move', $logType);
$logEntry->setPerformer($user);
$logEntry->setTarget($logTitle);
$logEntry->setComment($reason);
$logEntry->setParameters(array('4::target' => $nt->getPrefixedText(), '5::noredir' => $redirectContent ? '0' : '1'));
$formatter = LogFormatter::newFromEntry($logEntry);
$formatter->setContext(RequestContext::newExtraneousContext($this->oldTitle));
$comment = $formatter->getPlainActionText();
if ($reason) {
$comment .= wfMessage('colon-separator')->inContentLanguage()->text() . $reason;
}
# Truncate for whole multibyte characters.
$comment = $wgContLang->truncate($comment, 255);
$dbw = wfGetDB(DB_MASTER);
$oldpage = WikiPage::factory($this->oldTitle);
$oldcountable = $oldpage->isCountable();
$newpage = WikiPage::factory($nt);
if ($moveOverRedirect) {
$newid = $nt->getArticleID();
$newcontent = $newpage->getContent();
# Delete the old redirect. We don't save it to history since
# by definition if we've got here it's rather uninteresting.
# We have to remove it so that the next step doesn't trigger
# a conflict on the unique namespace+title index...
$dbw->delete('page', array('page_id' => $newid), __METHOD__);
$newpage->doDeleteUpdates($newid, $newcontent);
}
# Save a null revision in the page's history notifying of the move
$nullRevision = Revision::newNullRevision($dbw, $oldid, $comment, true, $user);
if (!is_object($nullRevision)) {
throw new MWException('No valid null revision produced in ' . __METHOD__);
}
$nullRevision->insertOn($dbw);
# Change the name of the target page:
$dbw->update('page', array('page_namespace' => $nt->getNamespace(), 'page_title' => $nt->getDBkey()), array('page_id' => $oldid), __METHOD__);
// clean up the old title before reset article id - bug 45348
if (!$redirectContent) {
WikiPage::onArticleDelete($this->oldTitle);
}
$this->oldTitle->resetArticleID(0);
// 0 == non existing
$nt->resetArticleID($oldid);
$newpage->loadPageData(WikiPage::READ_LOCKING);
// bug 46397
$newpage->updateRevisionOn($dbw, $nullRevision);
Hooks::run('NewRevisionFromEditComplete', array($newpage, $nullRevision, $nullRevision->getParentId(), $user));
$newpage->doEditUpdates($nullRevision, $user, array('changed' => false, 'moved' => true, 'oldcountable' => $oldcountable));
// If the default content model changes, we need to populate rev_content_model
if ($defaultContentModelChanging) {
$dbw->update('revision', array('rev_content_model' => $contentModel), array('rev_page' => $nt->getArticleID(), 'rev_content_model IS NULL'), __METHOD__);
}
if (!$moveOverRedirect) {
WikiPage::onArticleCreate($nt);
}
# Recreate the redirect, this time in the other direction.
if ($redirectContent) {
$redirectArticle = WikiPage::factory($this->oldTitle);
$redirectArticle->loadFromRow(false, WikiPage::READ_LOCKING);
// bug 46397
//.........这里部分代码省略.........
示例9: __construct
/**
* @param $article Article
*/
public function __construct(Article $article)
{
$this->mArticle = $article;
$this->mTitle = $article->getTitle();
$this->contentModel = $this->mTitle->getContentModel();
$handler = ContentHandler::getForModelID($this->contentModel);
$this->contentFormat = $handler->getDefaultFormat();
}
示例10: onTitleMoveComplete
public static function onTitleMoveComplete(Title $oldTitle, Title $newTitle, User $user, $pageid, $redirid, $reason)
{
if ($newTitle->getContentModel() === CONTENT_MODEL_FLOW_BOARD) {
Container::get('board_mover')->commit();
}
return true;
}