当前位置: 首页>>代码示例>>PHP>>正文


PHP ContentHandler::getForModelID方法代码示例

本文整理汇总了PHP中ContentHandler::getForModelID方法的典型用法代码示例。如果您正苦于以下问题:PHP ContentHandler::getForModelID方法的具体用法?PHP ContentHandler::getForModelID怎么用?PHP ContentHandler::getForModelID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ContentHandler的用法示例。


在下文中一共展示了ContentHandler::getForModelID方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: provideHandlers

 public static function provideHandlers()
 {
     $models = ContentHandler::getContentModels();
     $handlers = [];
     foreach ($models as $model) {
         $handlers[] = [ContentHandler::getForModelID($model)];
     }
     return $handlers;
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:9,代码来源:ContentHandlerSanityTest.php

示例2: showConflict

 /**
  * Show an edit conflict. textbox1 is already shown in showEditForm().
  * If you want to use another entry point to this function, be careful.
  */
 protected function showConflict()
 {
     global $wgOut;
     if (wfRunHooks('EditPageBeforeConflictDiff', array(&$this, &$wgOut))) {
         $wgOut->wrapWikiMsg('<h2>$1</h2>', "yourdiff");
         $content1 = $this->toEditContent($this->textbox1);
         $content2 = $this->toEditContent($this->textbox2);
         $handler = ContentHandler::getForModelID($this->contentModel);
         $de = $handler->createDifferenceEngine($this->mArticle->getContext());
         $de->setContent($content2, $content1);
         $de->showDiff(wfMessage('yourtext')->parse(), wfMessage('storedversion')->text());
         $wgOut->wrapWikiMsg('<h2>$1</h2>', "yourtext");
         $this->showTextbox2();
     }
 }
开发者ID:whysasse,项目名称:kmwiki,代码行数:19,代码来源:EditPage.php

示例3: execute

 public function execute()
 {
     $user = $this->getUser();
     $params = $this->extractRequestParams();
     if ($user->isBot()) {
         // sanity
         $this->dieUsage('This interface is not supported for bots', 'botsnotsupported');
     }
     $cache = ObjectCache::getLocalClusterInstance();
     $page = $this->getTitleOrPageId($params);
     $title = $page->getTitle();
     if (!ContentHandler::getForModelID($params['contentmodel'])->isSupportedFormat($params['contentformat'])) {
         $this->dieUsage('Unsupported content model/format', 'badmodelformat');
     }
     $text = null;
     $textHash = null;
     if (strlen($params['stashedtexthash'])) {
         // Load from cache since the client indicates the text is the same as last stash
         $textHash = $params['stashedtexthash'];
         $textKey = $cache->makeKey('stashedit', 'text', $textHash);
         $text = $cache->get($textKey);
         if (!is_string($text)) {
             $this->dieUsage('No stashed text found with the given hash', 'missingtext');
         }
     } elseif ($params['text'] !== null) {
         // Trim and fix newlines so the key SHA1's match (see WebRequest::getText())
         $text = rtrim(str_replace("\r\n", "\n", $params['text']));
         $textHash = sha1($text);
     } else {
         $this->dieUsage('The text or stashedtexthash parameter must be given', 'missingtextparam');
     }
     $textContent = ContentHandler::makeContent($text, $title, $params['contentmodel'], $params['contentformat']);
     $page = WikiPage::factory($title);
     if ($page->exists()) {
         // Page exists: get the merged content with the proposed change
         $baseRev = Revision::newFromPageId($page->getId(), $params['baserevid']);
         if (!$baseRev) {
             $this->dieUsage("No revision ID {$params['baserevid']}", 'missingrev');
         }
         $currentRev = $page->getRevision();
         if (!$currentRev) {
             $this->dieUsage("No current revision of page ID {$page->getId()}", 'missingrev');
         }
         // Merge in the new version of the section to get the proposed version
         $editContent = $page->replaceSectionAtRev($params['section'], $textContent, $params['sectiontitle'], $baseRev->getId());
         if (!$editContent) {
             $this->dieUsage('Could not merge updated section.', 'replacefailed');
         }
         if ($currentRev->getId() == $baseRev->getId()) {
             // Base revision was still the latest; nothing to merge
             $content = $editContent;
         } else {
             // Merge the edit into the current version
             $baseContent = $baseRev->getContent();
             $currentContent = $currentRev->getContent();
             if (!$baseContent || !$currentContent) {
                 $this->dieUsage("Missing content for page ID {$page->getId()}", 'missingrev');
             }
             $handler = ContentHandler::getForModelID($baseContent->getModel());
             $content = $handler->merge3($baseContent, $editContent, $currentContent);
         }
     } else {
         // New pages: use the user-provided content model
         $content = $textContent;
     }
     if (!$content) {
         // merge3() failed
         $this->getResult()->addValue(null, $this->getModuleName(), ['status' => 'editconflict']);
         return;
     }
     // The user will abort the AJAX request by pressing "save", so ignore that
     ignore_user_abort(true);
     if ($user->pingLimiter('stashedit')) {
         $status = 'ratelimited';
     } else {
         $status = self::parseAndStash($page, $content, $user, $params['summary']);
         $textKey = $cache->makeKey('stashedit', 'text', $textHash);
         $cache->set($textKey, $text, self::MAX_CACHE_TTL);
     }
     $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
     $stats->increment("editstash.cache_stores.{$status}");
     $this->getResult()->addValue(null, $this->getModuleName(), ['status' => $status, 'texthash' => $textHash]);
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:83,代码来源:ApiStashEdit.php

示例4: getContentHandler

 /**
  * @return ContentHandler
  */
 function getContentHandler()
 {
     if (is_null($this->contentHandler)) {
         $this->contentHandler = ContentHandler::getForModelID($this->getModel());
     }
     return $this->contentHandler;
 }
开发者ID:eliagbayani,项目名称:LiteratureEditor,代码行数:10,代码来源:Import.php

示例5: execute

 public function execute()
 {
     $out = $this->mSpecial->getOutput();
     $out->addModuleStyles('mediawiki.action.history.diff');
     $dbr = wfGetDB(DB_SLAVE);
     $row = $dbr->selectRow('moderation', array('mod_user AS user', 'mod_user_text AS user_text', 'mod_last_oldid AS last_oldid', 'mod_cur_id AS cur_id', 'mod_namespace AS namespace', 'mod_title AS title', 'mod_text AS text', 'mod_stash_key AS stash_key'), array('mod_id' => $this->id), __METHOD__);
     if (!$row) {
         throw new ModerationError('moderation-edit-not-found');
     }
     $title = Title::makeTitle($row->namespace, $row->title);
     $model = $title->getContentModel();
     $out->setPageTitle(wfMessage('difference-title', $title->getPrefixedText()));
     $old_content = false;
     if ($row->cur_id != 0) {
         # Existing page
         $rev = Revision::newFromId($row->last_oldid);
         if ($rev) {
             $old_content = $rev->getContent(Revision::RAW);
             $model = $old_content->getModel();
         }
     }
     if (!$old_content) {
         # New or previously deleted page
         $old_content = ContentHandler::makeContent("", null, $model);
     }
     if ($row->stash_key) {
         $url_params = array('modaction' => 'showimg', 'modid' => $this->id);
         $url_full = $this->mSpecial->getTitle()->getLinkURL($url_params);
         # Check if this file is not an image (e.g. OGG file)
         $is_image = 1;
         $user = $row->user ? User::newFromId($row->user) : User::newFromName($row->user_text, false);
         $stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash($user);
         try {
             $meta = $stash->getMetadata($row->stash_key);
             if ($meta['us_media_type'] != 'BITMAP' && $meta['us_media_type'] != 'DRAWING') {
                 $is_image = 0;
             }
         } catch (MWException $e) {
             # If we can't find it, thumbnail won't work either
             $is_image = 0;
         }
         if ($is_image) {
             $url_params['thumb'] = 1;
             $url_thumb = $this->mSpecial->getTitle()->getLinkURL($url_params);
             $html_img = Xml::element('img', array('src' => $url_thumb));
         } else {
             # Not an image, so no thumbnail is needed.
             # Just print a filename.
             $html_img = $title->getFullText();
         }
         $html_a = Xml::tags('a', array('href' => $url_full), $html_img);
         $out->addHTML($html_a);
     }
     $de = ContentHandler::getForModelID($model)->createDifferenceEngine($this->mSpecial->getContext(), $row->last_oldid, 0, 0, 0, 0);
     $diff = '';
     if (!$row->stash_key || !$title->exists()) {
         $new_content = ContentHandler::makeContent($row->text, null, $model);
         $diff = $de->generateContentDiffBody($old_content, $new_content);
     }
     if ($diff) {
         // TODO: add more information into headers (username, timestamp etc.), as in usual diffs
         $header_before = wfMessage('moderation-diff-header-before')->text();
         $header_after = wfMessage('moderation-diff-header-after')->text();
         $out->addHTML($de->addHeader($diff, $header_before, $header_after));
     } else {
         $out->addWikiMsg($row->stash_key ? $title->exists() ? 'moderation-diff-reupload' : 'moderation-diff-upload-notext' : 'moderation-diff-no-changes');
     }
 }
开发者ID:ATCARES,项目名称:mediawiki-moderation,代码行数:68,代码来源:ModerationActionShow.php

示例6: extractRevisionInfo


//.........这里部分代码省略.........
             $anyHidden = true;
         } elseif (!$content) {
             $vals['textmissing'] = true;
         }
     }
     if ($this->fld_content && $content) {
         $text = null;
         if ($this->generateXML) {
             if ($content->getModel() === CONTENT_MODEL_WIKITEXT) {
                 $t = $content->getNativeData();
                 # note: don't set $text
                 $wgParser->startExternalParse($title, ParserOptions::newFromContext($this->getContext()), Parser::OT_PREPROCESS);
                 $dom = $wgParser->preprocessToDom($t);
                 if (is_callable(array($dom, 'saveXML'))) {
                     $xml = $dom->saveXML();
                 } else {
                     $xml = $dom->__toString();
                 }
                 $vals['parsetree'] = $xml;
             } else {
                 $vals['badcontentformatforparsetree'] = true;
                 $this->setWarning("Conversion to XML is supported for wikitext only, " . $title->getPrefixedDBkey() . " uses content model " . $content->getModel());
             }
         }
         if ($this->expandTemplates && !$this->parseContent) {
             #XXX: implement template expansion for all content types in ContentHandler?
             if ($content->getModel() === CONTENT_MODEL_WIKITEXT) {
                 $text = $content->getNativeData();
                 $text = $wgParser->preprocess($text, $title, ParserOptions::newFromContext($this->getContext()));
             } else {
                 $this->setWarning("Template expansion is supported for wikitext only, " . $title->getPrefixedDBkey() . " uses content model " . $content->getModel());
                 $vals['badcontentformat'] = true;
                 $text = false;
             }
         }
         if ($this->parseContent) {
             $po = $content->getParserOutput($title, $revision->getId(), ParserOptions::newFromContext($this->getContext()));
             $text = $po->getText();
         }
         if ($text === null) {
             $format = $this->contentFormat ? $this->contentFormat : $content->getDefaultFormat();
             $model = $content->getModel();
             if (!$content->isSupportedFormat($format)) {
                 $name = $title->getPrefixedDBkey();
                 $this->setWarning("The requested format {$this->contentFormat} is not " . "supported for content model {$model} used by {$name}");
                 $vals['badcontentformat'] = true;
                 $text = false;
             } else {
                 $text = $content->serialize($format);
                 // always include format and model.
                 // Format is needed to deserialize, model is needed to interpret.
                 $vals['contentformat'] = $format;
                 $vals['contentmodel'] = $model;
             }
         }
         if ($text !== false) {
             ApiResult::setContentValue($vals, 'content', $text);
         }
     }
     if ($content && (!is_null($this->diffto) || !is_null($this->difftotext))) {
         static $n = 0;
         // Number of uncached diffs we've had
         if ($n < $this->getConfig()->get('APIMaxUncachedDiffs')) {
             $vals['diff'] = array();
             $context = new DerivativeContext($this->getContext());
             $context->setTitle($title);
             $handler = $revision->getContentHandler();
             if (!is_null($this->difftotext)) {
                 $model = $title->getContentModel();
                 if ($this->contentFormat && !ContentHandler::getForModelID($model)->isSupportedFormat($this->contentFormat)) {
                     $name = $title->getPrefixedDBkey();
                     $this->setWarning("The requested format {$this->contentFormat} is not " . "supported for content model {$model} used by {$name}");
                     $vals['diff']['badcontentformat'] = true;
                     $engine = null;
                 } else {
                     $difftocontent = ContentHandler::makeContent($this->difftotext, $title, $model, $this->contentFormat);
                     $engine = $handler->createDifferenceEngine($context);
                     $engine->setContent($content, $difftocontent);
                 }
             } else {
                 $engine = $handler->createDifferenceEngine($context, $revision->getID(), $this->diffto);
                 $vals['diff']['from'] = $engine->getOldid();
                 $vals['diff']['to'] = $engine->getNewid();
             }
             if ($engine) {
                 $difftext = $engine->getDiffBody();
                 ApiResult::setContentValue($vals['diff'], 'body', $difftext);
                 if (!$engine->wasCacheHit()) {
                     $n++;
                 }
             }
         } else {
             $vals['diff']['notcached'] = true;
         }
     }
     if ($anyHidden && $revision->isDeleted(Revision::DELETED_RESTRICTED)) {
         $vals['suppressed'] = true;
     }
     return $vals;
 }
开发者ID:eliagbayani,项目名称:LiteratureEditor,代码行数:101,代码来源:ApiQueryRevisionsBase.php

示例7: getAllContentFormats

 public static function getAllContentFormats()
 {
     global $wgContentHandlers;
     $formats = array();
     foreach ($wgContentHandlers as $model => $class) {
         $handler = ContentHandler::getForModelID($model);
         $formats = array_merge($formats, $handler->getSupportedFormats());
     }
     $formats = array_unique($formats);
     return $formats;
 }
开发者ID:Tarendai,项目名称:spring-website,代码行数:11,代码来源:ContentHandler.php

示例8: execute

 public function execute()
 {
     global $wgMemc;
     $user = $this->getUser();
     $params = $this->extractRequestParams();
     $page = $this->getTitleOrPageId($params);
     $title = $page->getTitle();
     if (!ContentHandler::getForModelID($params['contentmodel'])->isSupportedFormat($params['contentformat'])) {
         $this->dieUsage("Unsupported content model/format", 'badmodelformat');
     }
     // Trim and fix newlines so the key SHA1's match (see RequestContext::getText())
     $text = rtrim(str_replace("\r\n", "\n", $params['text']));
     $textContent = ContentHandler::makeContent($text, $title, $params['contentmodel'], $params['contentformat']);
     $page = WikiPage::factory($title);
     if ($page->exists()) {
         // Page exists: get the merged content with the proposed change
         $baseRev = Revision::newFromPageId($page->getId(), $params['baserevid']);
         if (!$baseRev) {
             $this->dieUsage("No revision ID {$params['baserevid']}", 'missingrev');
         }
         $currentRev = $page->getRevision();
         if (!$currentRev) {
             $this->dieUsage("No current revision of page ID {$page->getId()}", 'missingrev');
         }
         // Merge in the new version of the section to get the proposed version
         $editContent = $page->replaceSectionAtRev($params['section'], $textContent, $params['sectiontitle'], $baseRev->getId());
         if (!$editContent) {
             $this->dieUsage("Could not merge updated section.", 'replacefailed');
         }
         if ($currentRev->getId() == $baseRev->getId()) {
             // Base revision was still the latest; nothing to merge
             $content = $editContent;
         } else {
             // Merge the edit into the current version
             $baseContent = $baseRev->getContent();
             $currentContent = $currentRev->getContent();
             if (!$baseContent || !$currentContent) {
                 $this->dieUsage("Missing content for page ID {$page->getId()}", 'missingrev');
             }
             $handler = ContentHandler::getForModelID($baseContent->getModel());
             $content = $handler->merge3($baseContent, $editContent, $currentContent);
         }
     } else {
         // New pages: use the user-provided content model
         $content = $textContent;
     }
     if (!$content) {
         // merge3() failed
         $this->getResult()->addValue(null, $this->getModuleName(), array('status' => 'editconflict'));
         return;
     }
     // The user will abort the AJAX request by pressing "save", so ignore that
     ignore_user_abort(true);
     // Get a key based on the source text, format, and user preferences
     $key = self::getStashKey($title, $content, $user);
     // De-duplicate requests on the same key
     if ($user->pingLimiter('stashedit')) {
         $status = 'ratelimited';
     } elseif ($wgMemc->lock($key, 0, 30)) {
         /** @noinspection PhpUnusedLocalVariableInspection */
         $unlocker = new ScopedCallback(function () use($key) {
             global $wgMemc;
             $wgMemc->unlock($key);
         });
         $status = self::parseAndStash($page, $content, $user);
     } else {
         $status = 'busy';
     }
     $this->getResult()->addValue(null, $this->getModuleName(), array('status' => $status));
 }
开发者ID:natebrunette,项目名称:sphericalcow,代码行数:70,代码来源:ApiStashEdit.php

示例9: testGetModelForID

 /**
  * @dataProvider provideGetModelForID
  */
 public function testGetModelForID($modelId, $handlerClass)
 {
     $handler = ContentHandler::getForModelID($modelId);
     $this->assertInstanceOf($handlerClass, $handler);
 }
开发者ID:OrBin,项目名称:mediawiki,代码行数:8,代码来源:ContentHandlerTest.php

示例10: onShowMissingArticle

 public static function onShowMissingArticle(Article $article)
 {
     if ($article->getPage()->getContentModel() !== CONTENT_MODEL_FLOW_BOARD) {
         return true;
     }
     if ($article->getTitle()->getNamespace() === NS_TOPIC) {
         // @todo pretty message about invalid workflow
         throw new FlowException('Non-existent topic');
     }
     $emptyContent = ContentHandler::getForModelID(CONTENT_MODEL_FLOW_BOARD)->makeEmptyContent();
     $parserOutput = $emptyContent->getParserOutput($article->getTitle());
     $article->getContext()->getOutput()->addParserOutput($parserOutput);
     return false;
 }
开发者ID:TarLocesilion,项目名称:mediawiki-extensions-Flow,代码行数:14,代码来源:Hooks.php

示例11: testGetFieldsForSearchIndex

 public function testGetFieldsForSearchIndex()
 {
     $searchEngine = $this->newSearchEngine();
     $handler = ContentHandler::getForModelID(CONTENT_MODEL_WIKITEXT);
     $fields = $handler->getFieldsForSearchIndex($searchEngine);
     $this->assertArrayHasKey('category', $fields);
     $this->assertArrayHasKey('external_link', $fields);
     $this->assertArrayHasKey('outgoing_link', $fields);
     $this->assertArrayHasKey('template', $fields);
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:10,代码来源:ContentHandlerTest.php

示例12: writeOutput

 function writeOutput($par)
 {
     global $wgLang, $wgMemc, $wgDBname, $wgUser;
     global $wgSitename, $wgLanguageCode;
     global $wgFeedClasses, $wgFilterCallback, $wgWhitelistEdit, $wgParser;
     $this->getOutput()->setRobotpolicy("noindex,nofollow");
     $target = !empty($par) ? $par : $this->getRequest()->getVal("target");
     $t = Title::newFromDBKey($target);
     $update = true;
     if (!$t || !$t->userCan('edit')) {
         return;
     }
     if (!$this->getUser()->isAllowed('edit')) {
         return;
     }
     $article = new Article($t);
     $user = $this->getUser()->getName();
     $real_name = User::whoIsReal($this->getUser()->getID());
     if ($real_name == "") {
         $real_name = $user;
     }
     $dateStr = $wgLang->timeanddate(wfTimestampNow());
     $comment = $this->getRequest()->getVal("comment_text");
     foreach ($this->getRequest()->getValues() as $key => $value) {
         if (strpos($key, "comment_text") === 0) {
             $comment = $value;
             break;
         }
     }
     $topic = $this->getRequest()->getVal("topic_name");
     //echo "$dateStr<br/>";
     // remove leading space, tends to be a problem with a lot of talk page comments as it breaks the
     // HTML on the page
     $comment = preg_replace('/\\n[ ]*/', "\n", trim($comment));
     // Check to see if the user is also getting a thumbs up. If so, append the thumbs message and give a thumbs up
     if ($this->getRequest()->getVal('thumb')) {
         $comment .= "\n\n" . wfMsg('qn_thumbs_up');
         $userName = explode(":", $this->getRequest()->getVal('target'));
         ThumbsUp::quickNoteThumb($this->getRequest()->getVal('revold'), $this->getRequest()->getVal('revnew'), $this->getRequest()->getVal('pageid'), $userName[1]);
     }
     $formattedComment = wfMsg('postcomment_formatted_comment', $dateStr, $user, $real_name, $comment);
     if ($this->getRequest()->getVal('fromajax') == 'true') {
         $this->getOutput()->setArticleBodyOnly(true);
     }
     $text = "";
     $r = Revision::newFromTitle($t);
     if ($r) {
         $text = $r->getText();
     }
     $text .= "\n\n{$formattedComment}\n\n";
     $this->getOutput()->setStatusCode(409);
     //echo "updating with text:<br/> $text";
     //exit;
     $tmp = "";
     if ($this->getUser()->isBlocked()) {
         $this->getOutput()->blockedPage();
         return;
     }
     if (!$this->getUser()->getID() && $wgWhitelistEdit) {
         $this->userNotLoggedInPage();
         return;
     }
     if (wfReadOnly()) {
         $this->getOutput()->readOnlyPage();
         return;
     }
     if ($target == "Spam-Blacklist") {
         $this->getOutput()->readOnlyPage();
         return;
     }
     if ($this->getUser()->pingLimiter()) {
         $this->getOutput()->rateLimited();
         return;
     }
     $editPage = new EditPage($article);
     $contentModel = $t->getContentModel();
     $handler = ContentHandler::getForModelID($contentModel);
     $contentFormat = $handler->getDefaultFormat();
     $content = ContentHandler::makeContent($text, $t, $contentModel, $contentFormat);
     $status = Status::newGood();
     if (!wfRunHooks('EditFilterMergedContent', array($this->getContext(), $content, &$status, '', $wgUser, false))) {
         return;
     }
     if (!$status->isGood()) {
         $errors = $status->getErrorsArray(true);
         foreach ($errors as $error) {
             if (is_array($error)) {
                 $error = count($error) ? $error[0] : '';
             }
             if (preg_match('@^spamprotection@', $error)) {
                 $message = 'Error: found spam link';
                 $this->getOutput()->addHTML($message);
                 return;
             }
         }
         $message = 'EditFilterMergedContent returned an error -- cannot post comment';
         return;
     }
     $matches = array();
     $preg = "/http:\\/\\/[^] \n'\">]*/";
//.........这里部分代码省略.........
开发者ID:biribogos,项目名称:wikihow-src,代码行数:101,代码来源:SpecialPostComment.body.php

示例13: approveEditById

 function approveEditById($id)
 {
     $dbw = wfGetDB(DB_MASTER);
     $row = $dbw->selectRow('moderation', array('mod_id AS id', 'mod_timestamp AS timestamp', 'mod_user AS user', 'mod_user_text AS user_text', 'mod_cur_id AS cur_id', 'mod_namespace AS namespace', 'mod_title AS title', 'mod_comment AS comment', 'mod_minor AS minor', 'mod_bot AS bot', 'mod_last_oldid AS last_oldid', 'mod_ip AS ip', 'mod_header_xff AS header_xff', 'mod_header_ua AS header_ua', 'mod_text AS text', 'mod_merged_revid AS merged_revid', 'mod_rejected AS rejected', 'mod_stash_key AS stash_key'), array('mod_id' => $id), __METHOD__);
     if (!$row) {
         throw new ModerationError('moderation-edit-not-found');
     }
     if ($row->merged_revid) {
         throw new ModerationError('moderation-already-merged');
     }
     if ($row->rejected && $row->timestamp < $this->mSpecial->earliestReapprovableTimestamp) {
         throw new ModerationError('moderation-rejected-long-ago');
     }
     # Prepare everything
     $title = Title::makeTitle($row->namespace, $row->title);
     $model = $title->getContentModel();
     $user = $row->user ? User::newFromId($row->user) : User::newFromName($row->user_text, false);
     $flags = EDIT_DEFER_UPDATES | EDIT_AUTOSUMMARY;
     if ($row->bot && $user->isAllowed('bot')) {
         $flags |= EDIT_FORCE_BOT;
     }
     if ($row->minor) {
         # doEditContent() checks the right
         $flags |= EDIT_MINOR;
     }
     # For CheckUser extension to work properly, IP, XFF and UA
     # should be set to the correct values for the original user
     # (not from the moderator)
     $cuHook = new ModerationCheckUserHook();
     $cuHook->install($row->ip, $row->header_xff, $row->header_ua);
     $approveHook = new ModerationApproveHook();
     $approveHook->install(array('rev_timestamp' => $dbw->timestamp($row->timestamp), 'rev_user' => $user->getId(), 'rev_user_text' => $user->getName()));
     $status = Status::newGood();
     if ($row->stash_key) {
         # This is the upload from stash.
         $stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash($user);
         try {
             $file = $stash->getFile($row->stash_key);
         } catch (MWException $e) {
             throw new ModerationError('moderation-missing-stashed-image');
         }
         $upload = new UploadFromStash($user, $stash);
         $upload->initialize($row->stash_key, $title->getText());
         $status = $upload->performUpload($row->comment, $row->text, 0, $user);
     } else {
         # This is normal edit (not an upload).
         $new_content = ContentHandler::makeContent($row->text, null, $model);
         $page = new WikiPage($title);
         if (!$page->exists()) {
             # New page
             $status = $page->doEditContent($new_content, $row->comment, $flags, false, $user);
         } else {
             # Existing page
             $latest = $page->getLatest();
             if ($latest == $row->last_oldid) {
                 # Page hasn't changed since this edit was queued for moderation.
                 $status = $page->doEditContent($new_content, $row->comment, $flags, $row->last_oldid, $user);
             } else {
                 # Page has changed!
                 # Let's attempt merging, as MediaWiki does in private EditPage::mergeChangesIntoContent().
                 $base_content = $row->last_oldid ? Revision::newFromId($row->last_oldid)->getContent(Revision::RAW) : ContentHandler::makeContent('', null, $model);
                 $latest_content = Revision::newFromId($latest)->getContent(Revision::RAW);
                 $handler = ContentHandler::getForModelID($base_content->getModel());
                 $merged_content = $handler->merge3($base_content, $new_content, $latest_content);
                 if ($merged_content) {
                     $status = $page->doEditContent($merged_content, $row->comment, $flags, $latest, $user);
                 } else {
                     $dbw = wfGetDB(DB_MASTER);
                     $dbw->update('moderation', array('mod_conflict' => 1), array('mod_id' => $id), __METHOD__);
                     $dbw->commit(__METHOD__);
                     throw new ModerationError('moderation-edit-conflict');
                 }
             }
         }
     }
     $approveHook->deinstall();
     $cuHook->deinstall();
     if (!$status->isGood()) {
         throw new ModerationError($status->getMessage());
     }
     $logEntry = new ManualLogEntry('moderation', 'approve');
     $logEntry->setPerformer($this->moderator);
     $logEntry->setTarget($title);
     $logEntry->setParameters(array('revid' => $approveHook->lastRevId));
     $logid = $logEntry->insert();
     $logEntry->publish($logid);
     # Approved edits are removed from "moderation" table,
     # because they already exist in page history, recentchanges etc.
     $dbw = wfGetDB(DB_MASTER);
     $dbw->delete('moderation', array('mod_id' => $id), __METHOD__);
 }
开发者ID:ATCARES,项目名称:mediawiki-moderation,代码行数:91,代码来源:ModerationActionApprove.php

示例14: setUp

 protected function setUp()
 {
     parent::setUp();
     $this->handler = ContentHandler::getForModelID(CONTENT_MODEL_WIKITEXT);
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:5,代码来源:WikitextContentHandlerTest.php

示例15: extractRowInfo


//.........这里部分代码省略.........
                 $vals[$t . 'token'] = $val;
             }
         }
     }
     $content = null;
     global $wgParser;
     if ($this->fld_content || !is_null($this->difftotext)) {
         $content = $revision->getContent();
         // Expand templates after getting section content because
         // template-added sections don't count and Parser::preprocess()
         // will have less input
         if ($this->section !== false) {
             $content = $content->getSection($this->section, false);
             if (!$content) {
                 $this->dieUsage("There is no section {$this->section} in r" . $revision->getId(), 'nosuchsection');
             }
         }
     }
     if ($this->fld_content && !$revision->isDeleted(Revision::DELETED_TEXT)) {
         $text = null;
         if ($this->generateXML) {
             if ($content->getModel() === CONTENT_MODEL_WIKITEXT) {
                 $t = $content->getNativeData();
                 # note: don't set $text
                 $wgParser->startExternalParse($title, ParserOptions::newFromContext($this->getContext()), OT_PREPROCESS);
                 $dom = $wgParser->preprocessToDom($t);
                 if (is_callable(array($dom, 'saveXML'))) {
                     $xml = $dom->saveXML();
                 } else {
                     $xml = $dom->__toString();
                 }
                 $vals['parsetree'] = $xml;
             } else {
                 $this->setWarning("Conversion to XML is supported for wikitext only, " . $title->getPrefixedDBkey() . " uses content model " . $content->getModel() . ")");
             }
         }
         if ($this->expandTemplates && !$this->parseContent) {
             #XXX: implement template expansion for all content types in ContentHandler?
             if ($content->getModel() === CONTENT_MODEL_WIKITEXT) {
                 $text = $content->getNativeData();
                 $text = $wgParser->preprocess($text, $title, ParserOptions::newFromContext($this->getContext()));
             } else {
                 $this->setWarning("Template expansion is supported for wikitext only, " . $title->getPrefixedDBkey() . " uses content model " . $content->getModel() . ")");
                 $text = false;
             }
         }
         if ($this->parseContent) {
             $po = $content->getParserOutput($title, $revision->getId(), ParserOptions::newFromContext($this->getContext()));
             $text = $po->getText();
         }
         if ($text === null) {
             $format = $this->contentFormat ? $this->contentFormat : $content->getDefaultFormat();
             if (!$content->isSupportedFormat($format)) {
                 $model = $content->getModel();
                 $name = $title->getPrefixedDBkey();
                 $this->dieUsage("The requested format {$this->contentFormat} is not supported " . "for content model {$model} used by {$name}", 'badformat');
             }
             $text = $content->serialize($format);
             $vals['contentformat'] = $format;
         }
         if ($text !== false) {
             ApiResult::setContent($vals, $text);
         }
     } elseif ($this->fld_content) {
         $vals['texthidden'] = '';
     }
     if (!is_null($this->diffto) || !is_null($this->difftotext)) {
         global $wgAPIMaxUncachedDiffs;
         static $n = 0;
         // Number of uncached diffs we've had
         if ($n < $wgAPIMaxUncachedDiffs) {
             $vals['diff'] = array();
             $context = new DerivativeContext($this->getContext());
             $context->setTitle($title);
             $handler = $revision->getContentHandler();
             if (!is_null($this->difftotext)) {
                 $model = $title->getContentModel();
                 if ($this->contentFormat && !ContentHandler::getForModelID($model)->isSupportedFormat($this->contentFormat)) {
                     $name = $title->getPrefixedDBkey();
                     $this->dieUsage("The requested format {$this->contentFormat} is not supported for " . "content model {$model} used by {$name}", 'badformat');
                 }
                 $difftocontent = ContentHandler::makeContent($this->difftotext, $title, $model, $this->contentFormat);
                 $engine = $handler->createDifferenceEngine($context);
                 $engine->setContent($content, $difftocontent);
             } else {
                 $engine = $handler->createDifferenceEngine($context, $revision->getID(), $this->diffto);
                 $vals['diff']['from'] = $engine->getOldid();
                 $vals['diff']['to'] = $engine->getNewid();
             }
             $difftext = $engine->getDiffBody();
             ApiResult::setContent($vals['diff'], $difftext);
             if (!$engine->wasCacheHit()) {
                 $n++;
             }
         } else {
             $vals['diff']['notcached'] = '';
         }
     }
     return $vals;
 }
开发者ID:nischayn22,项目名称:mediawiki-core,代码行数:101,代码来源:ApiQueryRevisions.php


注:本文中的ContentHandler::getForModelID方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。