本文整理汇总了PHP中Content::serialize方法的典型用法代码示例。如果您正苦于以下问题:PHP Content::serialize方法的具体用法?PHP Content::serialize怎么用?PHP Content::serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Content
的用法示例。
在下文中一共展示了Content::serialize方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doQuickEditContent
/**
* Edit an article without doing all that other stuff
* The article must already exist; link tables etc
* are not updated, caches are not flushed.
*
* @param Content $content Content submitted
* @param User $user The relevant user
* @param string $comment comment submitted
* @param string $serialisation_format Format for storing the content in the database
* @param bool $minor Whereas it's a minor modification
*/
public function doQuickEditContent( Content $content, User $user, $comment = '', $minor = false,
$serialisation_format = null
) {
wfProfileIn( __METHOD__ );
$serialized = $content->serialize( $serialisation_format );
$dbw = wfGetDB( DB_MASTER );
$revision = new Revision( array(
'title' => $this->getTitle(), // for determining the default content model
'page' => $this->getId(),
'text' => $serialized,
'length' => $content->getSize(),
'comment' => $comment,
'minor_edit' => $minor ? 1 : 0,
) ); // XXX: set the content object?
$revision->insertOn( $dbw );
$this->updateRevisionOn( $dbw, $revision );
wfRunHooks( 'NewRevisionFromEditComplete', array( $this, $revision, false, $user ) );
wfProfileOut( __METHOD__ );
}
示例2: execute
//.........这里部分代码省略.........
$p_result = $this->getParsedContent($pageObj, $popts, $pageid, isset($prop['wikitext']));
}
} else {
// Not $oldid, $pageid, $page. Hence based on $text
$titleObj = Title::newFromText($title);
if (!$titleObj) {
$this->dieUsageMsg(array('invalidtitle', $title));
}
if (!$titleObj->canExist()) {
$this->dieUsage("Namespace doesn't allow actual pages", 'pagecannotexist');
}
$wgTitle = $titleObj;
$pageObj = WikiPage::factory($titleObj);
$popts = $pageObj->makeParserOptions($this->getContext());
$popts->enableLimitReport(!$params['disablepp']);
if (is_null($text)) {
$this->dieUsage('The text parameter should be passed with the title parameter. Should you be using the "page" parameter instead?', 'params');
}
try {
$this->content = ContentHandler::makeContent($text, $titleObj, $model, $format);
} catch (MWContentSerializationException $ex) {
$this->dieUsage($ex->getMessage(), 'parseerror');
}
if ($this->section !== false) {
$this->content = $this->getSectionContent($this->content, $titleObj->getText());
}
if ($params['pst'] || $params['onlypst']) {
$this->pstContent = $this->content->preSaveTransform($titleObj, $this->getUser(), $popts);
}
if ($params['onlypst']) {
// Build a result and bail out
$result_array = array();
$result_array['text'] = array();
$result->setContent($result_array['text'], $this->pstContent->serialize($format));
if (isset($prop['wikitext'])) {
$result_array['wikitext'] = array();
$result->setContent($result_array['wikitext'], $this->content->serialize($format));
}
$result->addValue(null, $this->getModuleName(), $result_array);
return;
}
// Not cached (save or load)
if ($params['pst']) {
$p_result = $this->pstContent->getParserOutput($titleObj, null, $popts);
} else {
$p_result = $this->content->getParserOutput($titleObj, null, $popts);
}
}
$result_array = array();
$result_array['title'] = $titleObj->getPrefixedText();
if (!is_null($oldid)) {
$result_array['revid'] = intval($oldid);
}
if ($params['redirects'] && !is_null($redirValues)) {
$result_array['redirects'] = $redirValues;
}
if (isset($prop['text'])) {
$result_array['text'] = array();
$result->setContent($result_array['text'], $p_result->getText());
}
if (!is_null($params['summary'])) {
$result_array['parsedsummary'] = array();
$result->setContent($result_array['parsedsummary'], Linker::formatComment($params['summary'], $titleObj));
}
if (isset($prop['langlinks'])) {
$result_array['langlinks'] = $this->formatLangLinks($p_result->getLanguageLinks());
示例3: execute
//.........这里部分代码省略.........
if ($titleProvided && ($prop || $params['generatexml'])) {
$this->setWarning("'title' used without 'text', and parsed page properties were requested " . "(did you mean to use 'page' instead of 'title'?)");
}
// Prevent warning from ContentHandler::makeContent()
$text = '';
}
// If we are parsing text, do not use the content model of the default
// API title, but default to wikitext to keep BC.
if ($textProvided && !$titleProvided && is_null($model)) {
$model = CONTENT_MODEL_WIKITEXT;
$this->setWarning("No 'title' or 'contentmodel' was given, assuming {$model}.");
}
try {
$this->content = ContentHandler::makeContent($text, $titleObj, $model, $format);
} catch (MWContentSerializationException $ex) {
$this->dieUsage($ex->getMessage(), 'parseerror');
}
if ($this->section !== false) {
if ($this->section === 'new') {
// Insert the section title above the content.
if (!is_null($params['sectiontitle']) && $params['sectiontitle'] !== '') {
$this->content = $this->content->addSectionHeader($params['sectiontitle']);
}
} else {
$this->content = $this->getSectionContent($this->content, $titleObj->getPrefixedText());
}
}
if ($params['pst'] || $params['onlypst']) {
$this->pstContent = $this->content->preSaveTransform($titleObj, $this->getUser(), $popts);
}
if ($params['onlypst']) {
// Build a result and bail out
$result_array = array();
$result_array['text'] = $this->pstContent->serialize($format);
$result_array[ApiResult::META_BC_SUBELEMENTS][] = 'text';
if (isset($prop['wikitext'])) {
$result_array['wikitext'] = $this->content->serialize($format);
$result_array[ApiResult::META_BC_SUBELEMENTS][] = 'wikitext';
}
if (!is_null($params['summary']) || !is_null($params['sectiontitle']) && $this->section === 'new') {
$result_array['parsedsummary'] = $this->formatSummary($titleObj, $params);
$result_array[ApiResult::META_BC_SUBELEMENTS][] = 'parsedsummary';
}
$result->addValue(null, $this->getModuleName(), $result_array);
return;
}
// Not cached (save or load)
if ($params['pst']) {
$p_result = $this->pstContent->getParserOutput($titleObj, null, $popts);
} else {
$p_result = $this->content->getParserOutput($titleObj, null, $popts);
}
}
$result_array = array();
$result_array['title'] = $titleObj->getPrefixedText();
$result_array['pageid'] = $pageid ? $pageid : $pageObj->getId();
if (!is_null($oldid)) {
$result_array['revid'] = intval($oldid);
}
if ($params['redirects'] && !is_null($redirValues)) {
$result_array['redirects'] = $redirValues;
}
if ($params['disabletoc']) {
$p_result->setTOCEnabled(false);
}
if (isset($prop['text'])) {
示例4: serializeContent
/**
* Serializes Content object of the type supported by this ContentHandler.
*
* @param Content $content the Content object to serialize
* @param null $format the desired serialization format
* @return String serialized form of the content
*/
public function serializeContent(Content $content, $format = null)
{
return $content->serialize();
}
示例5: doQuickEditContent
/**
* Edit an article without doing all that other stuff
* The article must already exist; link tables etc
* are not updated, caches are not flushed.
*
* @param Content $content Content submitted
* @param User $user The relevant user
* @param string $comment Comment submitted
* @param bool $minor Whereas it's a minor modification
* @param string $serialFormat Format for storing the content in the database
*/
public function doQuickEditContent(Content $content, User $user, $comment = '', $minor = false, $serialFormat = null)
{
$serialized = $content->serialize($serialFormat);
$dbw = wfGetDB(DB_MASTER);
$revision = new Revision(array('title' => $this->getTitle(), 'page' => $this->getId(), 'user_text' => $user->getName(), 'user' => $user->getId(), 'text' => $serialized, 'length' => $content->getSize(), 'comment' => $comment, 'minor_edit' => $minor ? 1 : 0));
// XXX: set the content object?
$revision->insertOn($dbw);
$this->updateRevisionOn($dbw, $revision);
Hooks::run('NewRevisionFromEditComplete', array($this, $revision, false, $user));
}
示例6: getStashKey
/**
* Get the temporary prepared edit stash key for a user
*
* This key can be used for caching prepared edits provided:
* - a) The $user was used for PST options
* - b) The parser output was made from the PST using cannonical matching options
*
* @param Title $title
* @param Content $content
* @param User $user User to get parser options from
* @return string
*/
protected static function getStashKey(Title $title, Content $content, User $user)
{
$hash = sha1(implode(':', array($content->getModel(), $content->getDefaultFormat(), sha1($content->serialize($content->getDefaultFormat())), $user->getId() ?: md5($user->getName()), $user->getId() ? $user->getDBTouched() : '-')));
return wfMemcKey('prepared-edit', md5($title->getPrefixedDBkey()), $hash);
}
示例7: getContentHash
/**
* Get hash of the content, factoring in model/format
*
* @param Content $content
* @return string
*/
private static function getContentHash(Content $content)
{
return sha1(implode("\n", [$content->getModel(), $content->getDefaultFormat(), $content->serialize($content->getDefaultFormat())]));
}