本文整理汇总了PHP中ContentHandler::getContentText方法的典型用法代码示例。如果您正苦于以下问题:PHP ContentHandler::getContentText方法的具体用法?PHP ContentHandler::getContentText怎么用?PHP ContentHandler::getContentText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ContentHandler
的用法示例。
在下文中一共展示了ContentHandler::getContentText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updatePageContent
function updatePageContent($article, $rev, $baseID, $user)
{
global $wgHuijiPrefix, $wgSitename;
$title = $article->getId() == 1 ? $wgSitename : $article->getTitle()->getText();
$post_data = array('timestamp' => $rev->getTimestamp(), 'content' => ContentHandler::getContentText($rev->getContent(Revision::RAW)), 'sitePrefix' => $wgHuijiPrefix, 'siteName' => $wgSitename, 'id' => $article->getId(), 'title' => $title);
$post_data_string = json_encode($post_data);
curl_post_json('upsert', $post_data_string);
}
示例2: newFromTitle
static function newFromTitle($title)
{
// see if we already have this as our main instance...
if (self::$instance && self::$instance->mTitle == $title) {
return self::$instance;
}
$wikiPage = new WikiPage($title);
if (!$wikiPage) {
return null;
}
$whow = new WikihowArticleEditor();
$whow->mTitleObj = $wikiPage->getTitle();
$whow->mWikiPage = $wikiPage;
$whow->mTitle = $wikiPage->getTitle()->getText();
$text = ContentHandler::getContentText($wikiPage->getContent(Revision::RAW));
$whow->loadFromText($text);
return $whow;
}
示例3: parserHook
/**
* Parser hook
*
* @param string $text
* @param array $args
* @param Parser $parser
* @return string
*/
public static function parserHook($input, array $args, Parser $wgParser)
{
global $wgIncMarkupTranscludeContent, $wgIncMarkupEscapeContent;
$text = $input;
$pageTitle = Title::newFromText(substr($input, 2, -2), NS_TEMPLATE);
if (isset($pageTitle) && $pageTitle->exists()) {
$page = WikiPage::factory($pageTitle);
if ($wgIncMarkupTranscludeContent) {
$parser = $wgParser->getFreshParser();
$parserOptions = is_null($parser->getOptions()) ? new ParserOptions() : $parser->getOptions();
$text = $parser->getPreloadText($page->getContent()->getWikitextForTransclusion(), $pageTitle, $parserOptions);
} else {
// $content = $page->getContent(Revision::RAW);
$content = $page->getContent(Revision::FOR_THIS_USER);
$text = ContentHandler::getContentText($content);
}
}
if ($wgIncMarkupEscapeContent) {
$text = htmlentities($text);
}
return "<pre>\n" . $text . "\n</pre>";
}
示例4: onContentGetParserOutput
/**
* Hook into Content::getParserOutput to provide syntax highlighting for
* script content.
*
* @return bool
* @since MW 1.21
*/
public static function onContentGetParserOutput(Content $content, Title $title, $revId, ParserOptions $options, $generateHtml, ParserOutput &$output)
{
global $wgParser, $wgTextModelsToParse;
if (!$generateHtml) {
// Nothing special for us to do, let MediaWiki handle this.
return true;
}
// Determine the language
$extension = ExtensionRegistry::getInstance();
$models = $extension->getAttribute('SyntaxHighlightModels');
$model = $content->getModel();
if (!isset($models[$model])) {
// We don't care about this model, carry on.
return true;
}
$lexer = $models[$model];
// Hope that $wgSyntaxHighlightModels does not contain silly types.
$text = ContentHandler::getContentText($content);
if (!$text) {
// Oops! Non-text content? Let MediaWiki handle this.
return true;
}
// Parse using the standard parser to get links etc. into the database, HTML is replaced below.
// We could do this using $content->fillParserOutput(), but alas it is 'protected'.
if ($content instanceof TextContent && in_array($model, $wgTextModelsToParse)) {
$output = $wgParser->parse($text, $title, $options, true, true, $revId);
}
$status = self::highlight($text, $lexer);
if (!$status->isOK()) {
return true;
}
$out = $status->getValue();
$output->addModuleStyles('ext.pygments');
$output->setText('<div dir="ltr">' . $out . '</div>');
// Inform MediaWiki that we have parsed this page and it shouldn't mess with it.
return false;
}
示例5: populateBodyContent
protected function populateBodyContent()
{
if ($this->dirtyFlags['content'] !== null) {
return;
}
$bodyPage = $this->getTitle();
$curRev = Revision::newFromTitle($bodyPage);
if (!$curRev) {
throw new AdContentException("No content for ad: {$this->name}");
}
$this->bodyContent = ContentHandler::getContentText($curRev->getContent());
$this->markBodyContentDirty(false);
}
示例6: getText
/**
* Fetch revision text if it's available to the specified audience.
* If the specified audience does not have the ability to view this
* revision, an empty string will be returned.
*
* @param $audience Integer: one of:
* Revision::FOR_PUBLIC to be displayed to all users
* Revision::FOR_THIS_USER to be displayed to the given user
* Revision::RAW get the text regardless of permissions
* @param $user User object to check for, only if FOR_THIS_USER is passed
* to the $audience parameter
*
* @deprecated in 1.21, use getContent() instead
* @todo Replace usage in core
* @return String
*/
public function getText($audience = self::FOR_PUBLIC, User $user = null)
{
ContentHandler::deprecated(__METHOD__, '1.21');
$content = $this->getContent($audience, $user);
return ContentHandler::getContentText($content);
# returns the raw content text, if applicable
}
示例7: internalAttemptSave
//.........这里部分代码省略.........
} elseif ($this->section == '' && Revision::userWasLastToEdit(DB_MASTER, $this->mTitle->getArticleID(), $wgUser->getId(), $this->edittime)) {
# Suppress edit conflict with self, except for section edits where merging is required.
wfDebug(__METHOD__ . ": Suppressing edit conflict, same user.\n");
$this->isConflict = false;
}
}
// If sectiontitle is set, use it, otherwise use the summary as the section title.
if ($this->sectiontitle !== '') {
$sectionTitle = $this->sectiontitle;
} else {
$sectionTitle = $this->summary;
}
$content = null;
if ($this->isConflict) {
wfDebug(__METHOD__ . ": conflict! getting section '{$this->section}' for time '{$this->edittime}'" . " (article time '{$timestamp}')\n");
$content = $this->mArticle->replaceSectionContent($this->section, $textbox_content, $sectionTitle, $this->edittime);
} else {
wfDebug(__METHOD__ . ": getting section '{$this->section}'\n");
$content = $this->mArticle->replaceSectionContent($this->section, $textbox_content, $sectionTitle);
}
if (is_null($content)) {
wfDebug(__METHOD__ . ": activating conflict; section replace failed.\n");
$this->isConflict = true;
$content = $textbox_content;
// do not try to merge here!
} elseif ($this->isConflict) {
# Attempt merge
if ($this->mergeChangesIntoContent($content)) {
// Successful merge! Maybe we should tell the user the good news?
$this->isConflict = false;
wfDebug(__METHOD__ . ": Suppressing edit conflict, successful merge.\n");
} else {
$this->section = '';
$this->textbox1 = ContentHandler::getContentText($content);
wfDebug(__METHOD__ . ": Keeping edit conflict, failed merge.\n");
}
}
if ($this->isConflict) {
$status->setResult(false, self::AS_CONFLICT_DETECTED);
wfProfileOut(__METHOD__);
return $status;
}
if (!$this->runPostMergeFilters($content, $status, $wgUser)) {
wfProfileOut(__METHOD__);
return $status;
}
if ($this->section == 'new') {
// Handle the user preference to force summaries here
if (!$this->allowBlankSummary && trim($this->summary) == '') {
$this->missingSummary = true;
$status->fatal('missingsummary');
// or 'missingcommentheader' if $section == 'new'. Blegh
$status->value = self::AS_SUMMARY_NEEDED;
wfProfileOut(__METHOD__);
return $status;
}
// Do not allow the user to post an empty comment
if ($this->textbox1 == '') {
$this->missingComment = true;
$status->fatal('missingcommenttext');
$status->value = self::AS_TEXTBOX_EMPTY;
wfProfileOut(__METHOD__);
return $status;
}
} elseif (!$this->allowBlankSummary && !$content->equals($this->getOriginalContent($wgUser)) && !$content->isRedirect() && md5($this->summary) == $this->autoSumm) {
$this->missingSummary = true;
示例8: getMessage
/**
* Returns of stored translation of message specified by the $key in language
* code $code.
*
* @param string $key Message key
* @param string $code Language code
* @return string|null Stored translation or null.
*/
public function getMessage($key, $code)
{
if ($this->isSourceLanguage($code)) {
$stuff = $this->load($code);
$title = Title::newFromText($key);
if ($title) {
$key = $title->getPrefixedDBKey();
}
return isset($stuff[$key]) ? $stuff[$key] : null;
}
$title = Title::makeTitleSafe($this->getNamespace(), "{$key}/{$code}");
$rev = Revision::newFromTitle($title, false, Revision::READ_LATEST);
if (!$rev) {
return null;
}
return ContentHandler::getContentText($rev->getContent());
}
示例9: fetchContent
/**
* Get text of an article from database
* Does *NOT* follow redirects.
*
* @protected
* @note This is really internal functionality that should really NOT be
* used by other functions. For accessing article content, use the WikiPage
* class, especially WikiBase::getContent(). However, a lot of legacy code
* uses this method to retrieve page text from the database, so the function
* has to remain public for now.
*
* @return string|bool String containing article contents, or false if null
* @deprecated since 1.21, use WikiPage::getContent() instead
*/
function fetchContent()
{
// BC cruft!
ContentHandler::deprecated(__METHOD__, '1.21');
if ($this->mContentLoaded && $this->mContent) {
return $this->mContent;
}
$content = $this->fetchContentObject();
if (!$content) {
return false;
}
// @todo Get rid of mContent everywhere!
$this->mContent = ContentHandler::getContentText($content);
ContentHandler::runLegacyHooks('ArticleAfterFetchContent', array(&$this, &$this->mContent));
return $this->mContent;
}
示例10: testGetContentText_NonTextContent_ignore
public function testGetContentText_NonTextContent_ignore()
{
$this->setMwGlobals('wgContentHandlerTextFallback', 'ignore');
$content = new DummyContentForTesting("hello world");
$text = ContentHandler::getContentText($content);
$this->assertNull($text);
}
示例11: getText
/**
* Returns the text for this translatable page.
* @throws MWException
* @return string
*/
public function getText()
{
if ($this->init === false) {
switch ($this->source) {
case 'text':
break;
case 'title':
$this->revision = $this->getMarkedTag();
// There is no break statement here on purpose
// There is no break statement here on purpose
case 'revision':
$rev = Revision::newFromTitle($this->getTitle(), $this->revision);
$this->text = ContentHandler::getContentText($rev->getContent());
break;
}
}
if (!is_string($this->text)) {
throw new MWException('We have no text');
}
$this->init = true;
return $this->text;
}
示例12: getBlacklist
/**
* Returns the blacklist, which is a non-associative array of user NSIDs and path_aliases
* (the name name which can be seen in the pretty URL). For a given user, usually only one
* of the NSID and the path_alias will be present; it is the responsibility of the consumers
* of the blacklist to check it against both.
* @return array
*/
public function getBlacklist()
{
if (!isset(self::$blacklist)) {
self::$blacklist = array();
if ($this->flickrBlacklistPage) {
$title = Title::newFromText($this->flickrBlacklistPage);
$page = WikiPage::factory($title);
$text = ContentHandler::getContentText($page->getContent());
$text = preg_replace('/^\\s*#.*$/m', '', $text);
preg_match_all('/\\S+/', $text, $match);
self::$blacklist = $match[0];
}
}
return self::$blacklist;
}
示例13: execute
//.........这里部分代码省略.........
//INTL: International search just uses Google custom search
$top_search = GoogSearch::getSearchBox("cse-search-box");
}
$text = $this->data['bodytext'];
// Remove stray table under video section. Probably should eventually do it at
// the source, but then have to go through all articles.
if (strpos($text, '<a name="Video">') !== false) {
$vidpattern = "<p><br /></p>\n<center>\n<table width=\"375px\">\n<tr>\n<td><br /></td>\n<td align=\"left\"></td>\n</tr>\n</table>\n</center>\n<p><br /></p>";
$text = str_replace($vidpattern, "", $text);
}
$this->data['bodytext'] = $text;
// hack to get the FA template working, remove after we go live
$fa = '';
if ($wgLanguageCode != "nl" && strpos($this->data['bodytext'], 'featurestar') !== false) {
$fa = '<p id="feature_star">' . wfMessage('featured_article')->text() . '</p>';
//$this->data['bodytext'] = preg_replace("@<div id=\"featurestar\">(.|\n)*<div style=\"clear:both\"></div>@mU", '', $this->data['bodytext']);
}
$body = '';
if ($wgTitle->userCan('edit') && $action != 'edit' && $action != 'diff' && $action != 'history' && ($isLoggedIn && !in_array($wgTitle->getNamespace(), array(NS_USER, NS_USER_TALK, NS_IMAGE, NS_CATEGORY)) || !in_array($wgTitle->getNamespace(), array(NS_USER, NS_USER_TALK, NS_IMAGE, NS_CATEGORY)))) {
//INTL: Need bigger buttons for non-english sites
$editlink_text = $wgTitle->getNamespace() == NS_MAIN ? wfMessage('editarticle')->text() : wfMessage('edit')->text();
$heading = '<a href="' . $wgTitle->getLocalURL($sk->editUrlOptions()) . '" class="editsection">' . $editlink_text . '</a>' . $heading;
}
if ($isArticlePage || $wgTitle->getNamespace() == NS_PROJECT && $action == 'view' || $wgTitle->getNamespace() == NS_CATEGORY && !$wgTitle->exists()) {
if ($wgTitle->getNamespace() == NS_PROJECT && ($wgTitle->getDbKey() == 'RSS-feed' || $wgTitle->getDbKey() == 'Rising-star-feed')) {
$list_page = true;
$sticky = false;
} else {
$list_page = false;
$sticky = true;
}
$body .= $heading . ArticleAuthors::getAuthorHeader() . $this->data['bodytext'];
$body = '<div id="bodycontents">' . $body . '</div>';
$wikitext = ContentHandler::getContentText($this->getSkin()->getContext()->getWikiPage()->getContent(Revision::RAW));
$magic = WikihowArticleHTML::grabTheMagic($wikitext);
$this->data['bodytext'] = WikihowArticleHTML::processArticleHTML($body, array('sticky-headers' => $sticky, 'ns' => $wgTitle->getNamespace(), 'list-page' => $list_page, 'magic-word' => $magic));
} else {
if ($action == 'edit') {
$heading .= WikihowArticleEditor::grabArticleEditLinks($wgRequest->getVal("guidededitor"));
}
$this->data['bodyheading'] = $heading;
$body = '<div id="bodycontents">' . $this->data['bodytext'] . '</div>';
if (!$isTool) {
$this->data['bodytext'] = WikihowArticleHTML::processHTML($body, $action, array('show-gray-container' => $sk->showGrayContainer()));
} else {
// a little hack to style the no such special page messages for special pages that actually
// exist
if (false !== strpos($body, 'You have arrived at a "special page"')) {
$body = "<div class='minor_section'>{$body}</div>";
}
$this->data['bodytext'] = $body;
}
}
// post-process the Steps section HTML to get the numbers working
if ($wgTitle->getNamespace() == NS_MAIN && !$isMainPage && ($action == 'view' || $action == 'purge')) {
// for preview article after edit, you have to munge the
// steps of the previewHTML manually
$body = $this->data['bodytext'];
$opts = array();
if (!$showAds) {
$opts['no-ads'] = true;
}
//$this->data['bodytext'] = WikihowArticleHTML::postProcess($body, $opts);
}
// insert avatars into discussion, talk, and kudos pages
if (MWNamespace::isTalk($wgTitle->getNamespace()) || $wgTitle->getNamespace() == NS_USER_KUDOS) {
示例14: formatChange
/**
* @param MessageGroup $group
* @param string $code
* @param string $type
* @param array $params
* @param int $limit
* @return string HTML
*/
protected function formatChange(MessageGroup $group, $code, $type, $params, &$limit)
{
$key = $params['key'];
$title = Title::makeTitleSafe($group->getNamespace(), "{$key}/{$code}");
$id = self::changeId($group->getId(), $code, $type, $key);
if ($title && $title->exists() && $type === 'addition') {
// The message has for some reason dropped out from cache
// or perhaps it is being reused. In any case treat it
// as a change for display, so the admin can see if
// action is needed and let the message be processed.
// Otherwise it will end up in the postponed category
// forever and will prevent rebuilding the cache, which
// leads to many other annoying problems.
$type = 'change';
} elseif ($title && !$title->exists() && ($type === 'deletion' || $type === 'change')) {
return '';
}
$text = '';
if ($type === 'deletion') {
$wiki = ContentHandler::getContentText(Revision::newFromTitle($title)->getContent());
$oldContent = ContentHandler::makeContent($wiki, $title);
$newContent = ContentHandler::makeContent('', $title);
$this->diff->setContent($oldContent, $newContent);
$text = $this->diff->getDiff(Linker::link($title), '');
} elseif ($type === 'addition') {
$oldContent = ContentHandler::makeContent('', $title);
$newContent = ContentHandler::makeContent($params['content'], $title);
$this->diff->setContent($oldContent, $newContent);
$text = $this->diff->getDiff('', Linker::link($title));
} elseif ($type === 'change') {
$wiki = ContentHandler::getContentText(Revision::newFromTitle($title)->getContent());
$handle = new MessageHandle($title);
if ($handle->isFuzzy()) {
$wiki = '!!FUZZY!!' . str_replace(TRANSLATE_FUZZY, '', $wiki);
}
$label = $this->msg('translate-manage-action-ignore')->text();
$actions = Xml::checkLabel($label, "i/{$id}", "i/{$id}");
$limit--;
if ($group->getSourceLanguage() === $code) {
$label = $this->msg('translate-manage-action-fuzzy')->text();
$actions .= ' ' . Xml::checkLabel($label, "f/{$id}", "f/{$id}", true);
$limit--;
}
$oldContent = ContentHandler::makeContent($wiki, $title);
$newContent = ContentHandler::makeContent($params['content'], $title);
$this->diff->setContent($oldContent, $newContent);
$text .= $this->diff->getDiff(Linker::link($title), $actions);
}
$hidden = Html::hidden($id, 1);
$limit--;
$text .= $hidden;
$classes = "mw-translate-smg-change smg-change-{$type}";
if ($limit < 0) {
// Don't add if one of the fields might get dropped of at submission
return '';
}
return Html::rawElement('div', array('class' => $classes), $text);
}
示例15: getPageDiff
protected function getPageDiff()
{
$this->mustBeKnownMessage();
$title = $this->handle->getTitle();
$key = $this->handle->getKey();
if (!$title->exists()) {
return null;
}
$definitionTitle = Title::makeTitleSafe($title->getNamespace(), "{$key}/en");
if (!$definitionTitle || !$definitionTitle->exists()) {
return null;
}
$db = wfGetDB(DB_MASTER);
$conds = array('rt_page' => $title->getArticleID(), 'rt_type' => RevTag::getType('tp:transver'));
$options = array('ORDER BY' => 'rt_revision DESC');
$latestRevision = $definitionTitle->getLatestRevID();
$translationRevision = $db->selectField('revtag', 'rt_value', $conds, __METHOD__, $options);
if ($translationRevision === false) {
return null;
}
// Using newFromId instead of newFromTitle, because the page might have been renamed
$oldrev = Revision::newFromId($translationRevision);
if (!$oldrev) {
// And someone might still have deleted it
return null;
}
$oldtext = ContentHandler::getContentText($oldrev->getContent());
$newContent = Revision::newFromTitle($definitionTitle, $latestRevision)->getContent();
$newtext = ContentHandler::getContentText($newContent);
if ($oldtext === $newtext) {
return null;
}
$diff = new DifferenceEngine();
if (method_exists('DifferenceEngine', 'setTextLanguage')) {
$diff->setTextLanguage($this->group->getSourceLanguage());
}
$oldContent = ContentHandler::makeContent($oldtext, $diff->getTitle());
$newContent = ContentHandler::makeContent($newtext, $diff->getTitle());
$diff->setContent($oldContent, $newContent);
$diff->setReducedLineNumbers();
$diff->showDiffStyle();
return $diff->getDiff(wfMessage('tpt-diff-old')->escaped(), wfMessage('tpt-diff-new')->escaped());
}