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


PHP EditPage::internalAttemptSave方法代码示例

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


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

示例1: createComment

function createComment($title = null, $commenter = null, $text = null)
{
    global $wgTitle;
    $text = $text ? $text : 'The quick brown fox jumps over the lazy dog';
    $commentTitle = Title::newFromText(sprintf("%s/%s-%s", $title->getText(), $commenter, wfTimestampNow()), NS_BLOG_ARTICLE_TALK);
    $wgTitle = $commentTitle;
    /**
     * add article using EditPage class (for hooks)
     */
    $result = null;
    $article = new Article($commentTitle, 0);
    $editPage = new EditPage($article);
    $editPage->edittime = $article->getTimestamp();
    $editPage->textbox1 = $text;
    $retval = $editPage->internalAttemptSave($result);
    $value = $retval->value;
    Wikia::log(__METHOD__, "editpage", "Returned value {$value}");
    return array($value, $article);
}
开发者ID:Tjorriemorrie,项目名称:app,代码行数:19,代码来源:createComments.php

示例2: submitFlags

 public function submitFlags(&$params)
 {
     global $wgUser, $webplatformSectionCommentsSMW;
     $aTemp = json_decode($params['flags'], true);
     $aProperties = array();
     foreach ($aTemp as $key => $value) {
         $aTempKey = array();
         if (preg_match('#.*?\\[(.*?)\\]\\[.*?\\]#', $key, $aTempKey) && $value != '1') {
             $aProperties[$aTempKey[1]][] = $value;
         }
     }
     $sbuiltString = '';
     foreach ($aProperties as $key => $value) {
         $sbuiltString .= "\n|" . $key . '=';
         $aTemp = array();
         foreach ($value as $key => $val) {
             $aTemp[] = $val;
         }
         $sbuiltString .= implode(',', $aTemp);
     }
     $oArticle = Article::newFromID($params['pageId']);
     $sContent = $oArticle->fetchContent();
     $sNewContent = preg_replace('#(\\{\\{' . $webplatformSectionCommentsSMW['template'] . ').*?(\\}\\})#s', "\$1{$sbuiltString}\n\$2", $sContent);
     $aData = array('wpTextbox1' => $sNewContent, 'wpSummary' => 'no summary', 'wpStarttime' => 'nostarttime', 'wpEdittime' => 'noedittime', 'wpEditToken' => $wgUser->isLoggedIn() ? $wgUser->editToken() : EDIT_TOKEN_SUFFIX, 'wpSave' => '', 'action' => 'submit');
     $oRequest = new FauxRequest($aData, true);
     $oEditor = new EditPage($oArticle);
     $oEditor->importFormData($oRequest);
     // Try to save the page!
     $aResultDetails = array();
     $oSaveResult = $oEditor->internalAttemptSave($aResultDetails);
     // Return value was made an object in MW 1.19
     if (is_object($oSaveResult)) {
         $sSaveResultCode = $oSaveResult->value;
     } else {
         $sSaveResultCode = $oSaveResult;
     }
     $params['html_response'] = $sSaveResultCode;
 }
开发者ID:renoirb,项目名称:mediawiki-1,代码行数:38,代码来源:ApiWebplatformSectionCommentsSMW.php

示例3: save

 /**
  * Save categories sent via AJAX into article
  */
 public function save()
 {
     wfProfileIn(__METHOD__);
     $articleId = $this->request->getVal('articleId', 0);
     $categories = $this->request->getVal('categories', array());
     $response = array();
     $title = Title::newFromID($articleId);
     if (wfReadOnly()) {
         $response['error'] = wfMessage('categoryselect-error-db-locked')->text();
     } else {
         if (is_null($title)) {
             $response['error'] = wfMessage('categoryselect-error-article-doesnt-exist', $articleId)->text();
         } else {
             if (!$title->userCan('edit') || $this->wg->User->isBlocked()) {
                 $response['error'] = wfMessage('categoryselect-error-user-rights')->text();
             } else {
                 if (!empty($categories) && is_array($categories)) {
                     Wikia::setVar('EditFromViewMode', 'CategorySelect');
                     $article = new Article($title);
                     $wikitext = $article->fetchContent();
                     // Pull in categories from templates inside of the article (BugId:100980)
                     $options = new ParserOptions();
                     $preprocessedWikitext = ParserPool::preprocess($wikitext, $title, $options);
                     $preprocessedData = CategoryHelper::extractCategoriesFromWikitext($preprocessedWikitext, true);
                     // Compare the new categories with those already in the article to weed out duplicates
                     $newCategories = CategoryHelper::getDiffCategories($preprocessedData['categories'], $categories);
                     // Append the new categories to the end of the article wikitext
                     $wikitext .= CategoryHelper::changeFormat($newCategories, 'array', 'wikitext');
                     // Update the array of categories for the front-end
                     $categories = array_merge($preprocessedData['categories'], $newCategories);
                     $dbw = wfGetDB(DB_MASTER);
                     $dbw->begin();
                     $editPage = new EditPage($article);
                     $editPage->edittime = $article->getTimestamp();
                     $editPage->recreate = true;
                     $editPage->textbox1 = $wikitext;
                     $editPage->summary = wfMessage('categoryselect-edit-summary')->inContentLanguage()->text();
                     $editPage->watchthis = $editPage->mTitle->userIsWatching();
                     $bot = $this->wg->User->isAllowed('bot');
                     $status = $editPage->internalAttemptSave($result, $bot)->value;
                     $response['status'] = $status;
                     switch ($status) {
                         case EditPage::AS_SUCCESS_UPDATE:
                         case EditPage::AS_SUCCESS_NEW_ARTICLE:
                             $dbw->commit();
                             $title->invalidateCache();
                             Article::onArticleEdit($title);
                             $response['html'] = $this->app->renderView('CategorySelectController', 'categories', array('categories' => $categories));
                             wfRunHooks('CategorySelectSave', array($title, $newCategories));
                             break;
                         case EditPage::AS_SPAM_ERROR:
                             $dbw->rollback();
                             $response['error'] = wfMessage('spamprotectiontext')->text() . '<p>( Case #8 )</p>';
                             break;
                         default:
                             $dbw->rollback();
                             $response['error'] = wfMessage('categoryselect-error-edit-abort')->text();
                     }
                 }
             }
         }
     }
     $this->response->setData($response);
     wfProfileOut(__METHOD__);
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:68,代码来源:CategorySelectController.class.php

示例4: save

 protected function save()
 {
     global $wgOut, $wgUser, $wgContLang, $wgRequest;
     // CategorySelect compatibility (add categories to article body)
     if ($this->mCategorySelectEnabled) {
         CategorySelectHooksHelper::onEditPageImportFormData($this->mEditPage, $wgRequest);
     }
     $sPostBody = $this->mEditPage->textbox1;
     $editPage = new EditPage($this->mPostArticle);
     $editPage->initialiseForm();
     $editPage->textbox1 = $sPostBody;
     $editPage->summary = isset($this->mFormData['postEditSummary']) ? $this->mFormData['postEditSummary'] : '';
     $editPage->recreate = true;
     $result = false;
     $status = $editPage->internalAttemptSave($result);
     switch ($status->value) {
         case EditPage::AS_SUCCESS_UPDATE:
         case EditPage::AS_SUCCESS_NEW_ARTICLE:
         case EditPage::AS_ARTICLE_WAS_DELETED:
             $wgOut->redirect($this->mPostArticle->getTitle()->getFullUrl());
             break;
         default:
             /**
              * PLATFORM-1160: Log the entire $status to ELK
              *
              * Recommendation: use $status->value for comparisons and messages rather than $status in the following block.
              */
             Wikia\Logger\WikiaLogger::instance()->warning('PLATFORM-1160', ['method' => __METHOD__, 'status_object' => $status]);
             if ($status->value == EditPage::AS_READ_ONLY_PAGE_LOGGED || $status->value == EditPage::AS_READ_ONLY_PAGE_ANON) {
                 $sMsg = wfMsg('createpage_cant_edit');
             } else {
                 $sMsg = wfMsg('createpage_spam');
             }
             $this->mFormErrors[] = $sMsg . " ({$status->value})";
             global $wgCreatePageCaptchaTriggered;
             // do not display form - there is already one invoked from Captcha [RT#21902] - Marooned
             if (empty($wgCreatePageCaptchaTriggered)) {
                 $this->renderForm();
             }
             break;
     }
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:42,代码来源:SpecialCreatePage.class.php

示例5: save

 protected function save()
 {
     global $wgOut, $wgUser, $wgContLang, $wgRequest;
     // CategorySelect compatibility (add categories to article body)
     if ($this->mCategorySelectEnabled) {
         CategorySelectImportFormData($this->mEditPage, $wgRequest);
     }
     $sPostBody = $this->mEditPage->textbox1;
     $editPage = new EditPage($this->mPostArticle);
     $editPage->initialiseForm();
     $editPage->textbox1 = $sPostBody;
     $editPage->summary = isset($this->mFormData['postEditSummary']) ? $this->mFormData['postEditSummary'] : '';
     $editPage->recreate = true;
     $result = false;
     $status = $editPage->internalAttemptSave($result);
     switch ($status->value) {
         case EditPage::AS_SUCCESS_UPDATE:
         case EditPage::AS_SUCCESS_NEW_ARTICLE:
         case EditPage::AS_ARTICLE_WAS_DELETED:
             $wgOut->redirect($this->mPostArticle->getTitle()->getFullUrl());
             break;
         default:
             Wikia::log(__METHOD__, "createpage", $status);
             if ($status == EditPage::AS_READ_ONLY_PAGE_LOGGED || $status == EditPage::AS_READ_ONLY_PAGE_ANON) {
                 $sMsg = wfMsg('createpage_cant_edit');
             } else {
                 $sMsg = wfMsg('createpage_spam');
             }
             $this->mFormErrors[] = $sMsg . " ({$status})";
             global $wgCreatePageCaptchaTriggered;
             // do not display form - there is already one invoked from Captcha [RT#21902] - Marooned
             if (empty($wgCreatePageCaptchaTriggered)) {
                 $this->renderForm();
             }
             break;
     }
 }
开发者ID:schwarer2006,项目名称:wikia,代码行数:37,代码来源:SpecialCreatePage.class.php

示例6: testCheckDirectEditingDisallowed_forNonTextContent

 /**
  * @depends testAutoMerge
  */
 public function testCheckDirectEditingDisallowed_forNonTextContent()
 {
     $title = Title::newFromText('Dummy:NonTextPageForEditPage');
     $page = WikiPage::factory($title);
     $article = new Article($title);
     $article->getContext()->setTitle($title);
     $ep = new EditPage($article);
     $ep->setContextTitle($title);
     $user = $GLOBALS['wgUser'];
     $edit = ['wpTextbox1' => serialize('non-text content'), 'wpEditToken' => $user->getEditToken(), 'wpEdittime' => '', 'wpStarttime' => wfTimestampNow()];
     $req = new FauxRequest($edit, true);
     $ep->importFormData($req);
     $this->setExpectedException('MWException', 'This content model is not supported: testing');
     $ep->internalAttemptSave($result, false);
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:18,代码来源:EditPageTest.php

示例7: assertEdit

 /**
  * Performs an edit and checks the result.
  *
  * @param string|Title $title The title of the page to edit
  * @param string|null $baseText Some text to create the page with before attempting the edit.
  * @param User|string|null $user The user to perform the edit as.
  * @param array $edit An array of request parameters used to define the edit to perform.
  *              Some well known fields are:
  *              * wpTextbox1: the text to submit
  *              * wpSummary: the edit summary
  *              * wpEditToken: the edit token (will be inserted if not provided)
  *              * wpEdittime: timestamp of the edit's base revision (will be inserted
  *                if not provided)
  *              * wpStarttime: timestamp when the edit started (will be inserted if not provided)
  *              * wpSectionTitle: the section to edit
  *              * wpMinorEdit: mark as minor edit
  *              * wpWatchthis: whether to watch the page
  * @param int|null $expectedCode The expected result code (EditPage::AS_XXX constants).
  *                  Set to null to skip the check.
  * @param string|null $expectedText The text expected to be on the page after the edit.
  *                  Set to null to skip the check.
  * @param string|null $message An optional message to show along with any error message.
  *
  * @return WikiPage The page that was just edited, useful for getting the edit's rev_id, etc.
  */
 protected function assertEdit($title, $baseText, $user = null, array $edit, $expectedCode = null, $expectedText = null, $message = null)
 {
     if (is_string($title)) {
         $ns = $this->getDefaultWikitextNS();
         $title = Title::newFromText($title, $ns);
     }
     $this->assertNotNull($title);
     if (is_string($user)) {
         $user = User::newFromName($user);
         if ($user->getId() === 0) {
             $user->addToDatabase();
         }
     }
     $page = WikiPage::factory($title);
     if ($baseText !== null) {
         $content = ContentHandler::makeContent($baseText, $title);
         $page->doEditContent($content, "base text for test");
         $this->forceRevisionDate($page, '20120101000000');
         //sanity check
         $page->clear();
         $currentText = ContentHandler::getContentText($page->getContent());
         # EditPage rtrim() the user input, so we alter our expected text
         # to reflect that.
         $this->assertEditedTextEquals($baseText, $currentText);
     }
     if ($user == null) {
         $user = $GLOBALS['wgUser'];
     } else {
         $this->setMwGlobals('wgUser', $user);
     }
     if (!isset($edit['wpEditToken'])) {
         $edit['wpEditToken'] = $user->getEditToken();
     }
     if (!isset($edit['wpEdittime'])) {
         $edit['wpEdittime'] = $page->exists() ? $page->getTimestamp() : '';
     }
     if (!isset($edit['wpStarttime'])) {
         $edit['wpStarttime'] = wfTimestampNow();
     }
     $req = new FauxRequest($edit, true);
     // session ??
     $article = new Article($title);
     $article->getContext()->setTitle($title);
     $ep = new EditPage($article);
     $ep->setContextTitle($title);
     $ep->importFormData($req);
     $bot = isset($edit['bot']) ? (bool) $edit['bot'] : false;
     // this is where the edit happens!
     // Note: don't want to use EditPage::AttemptSave, because it messes with $wgOut
     // and throws exceptions like PermissionsError
     $status = $ep->internalAttemptSave($result, $bot);
     if ($expectedCode !== null) {
         // check edit code
         $this->assertEquals($expectedCode, $status->value, "Expected result code mismatch. {$message}");
     }
     $page = WikiPage::factory($title);
     if ($expectedText !== null) {
         // check resulting page text
         $content = $page->getContent();
         $text = ContentHandler::getContentText($content);
         # EditPage rtrim() the user input, so we alter our expected text
         # to reflect that.
         $this->assertEditedTextEquals($expectedText, $text, "Expected article text mismatch. {$message}");
     }
     return $page;
 }
开发者ID:eliagbayani,项目名称:LiteratureEditor,代码行数:91,代码来源:EditPageTest.php

示例8: saveGalleryDataByHash

 /**
  * AJAX helper called from view mode to save gallery data
  * @author Marooned
  */
 public static function saveGalleryDataByHash($hash, $wikitext, $starttime)
 {
     global $wgTitle, $wgUser;
     wfProfileIn(__METHOD__);
     wfDebug(__METHOD__ . ": {$wikitext}\n");
     $result = array();
     // save changed gallery
     $rev = Revision::newFromTitle($wgTitle);
     // try to fix fatal (article has been removed since user opened the page)
     if (empty($rev)) {
         $result['info'] = 'conflict';
         wfDebug(__METHOD__ . ": revision is empty\n");
         wfProfileOut(__METHOD__);
         return $result;
     }
     $articleWikitext = $rev->getText();
     $gallery = '';
     preg_match_all('%<gallery([^>]*)>(.*?)</gallery>%s', $articleWikitext, $matches, PREG_PATTERN_ORDER);
     for ($i = 0; $i < count($matches[0]); $i++) {
         $attribs = Sanitizer::decodeTagAttributes($matches[1][$i]);
         //count hash from attribs and content
         if (md5($matches[2][$i] . implode('', $attribs)) == $hash) {
             $gallery = $matches[0][$i];
             break;
         }
     }
     if (empty($gallery)) {
         $result['info'] = 'conflict';
         wfDebug(__METHOD__ . ": conflict found\n");
     } else {
         $articleWikitext = str_replace($gallery, $wikitext, $articleWikitext);
         //saving
         if ($wgTitle->userCan('edit') && !$wgUser->isBlocked()) {
             $result = null;
             $article = new Article($wgTitle);
             $editPage = new EditPage($article);
             $editPage->edittime = $article->getTimestamp();
             $editPage->starttime = $starttime;
             $editPage->textbox1 = $articleWikitext;
             $editPage->summary = wfMsgForContent('wikiaPhotoGallery-edit-summary');
             // watch all my edits / preserve watchlist (RT #59138)
             if ($wgUser->getOption('watchdefault')) {
                 $editPage->watchthis = true;
             } else {
                 $editPage->watchthis = $editPage->mTitle->userIsWatching();
             }
             $bot = $wgUser->isAllowed('bot');
             $status = $editPage->internalAttemptSave($result, $bot);
             $retval = $status->value;
             Wikia::log(__METHOD__, "editpage", "Returned value {$retval}");
             switch ($retval) {
                 case EditPage::AS_SUCCESS_UPDATE:
                 case EditPage::AS_SUCCESS_NEW_ARTICLE:
                     $wgTitle->invalidateCache();
                     Article::onArticleEdit($wgTitle);
                     $result['info'] = 'ok';
                     break;
                 case EditPage::AS_SPAM_ERROR:
                     $result['error'] = wfMsg('spamprotectiontext') . '<p>( Call #4 )</p>';
                     break;
                 default:
                     $result['error'] = wfMsg('wikiaPhotoGallery-edit-abort');
             }
         } else {
             $result['error'] = wfMsg('wikiaPhotoGallery-error-user-rights');
         }
         if (isset($result['error'])) {
             $result['errorCaption'] = wfMsg('wikiaPhotoGallery-error-caption');
         }
         //end of saving
         wfDebug(__METHOD__ . ": saving from view mode done\n");
         // commit (RT #48304)
         $dbw = wfGetDB(DB_MASTER);
         $dbw->commit();
     }
     wfProfileOut(__METHOD__);
     return $result;
 }
开发者ID:schwarer2006,项目名称:wikia,代码行数:82,代码来源:WikiaPhotoGalleryHelper.class.php

示例9: doSaveAsArticle

 /**
  * doSaveAsArticle store comment as article
  *
  * @static
  *
  * @param String $text
  * @param Article|WikiPage $article
  * @param User $user
  * @param array $metadata
  * @param string $summary
  *
  * @return Status TODO: Document
  */
 protected static function doSaveAsArticle($text, $article, $user, $metadata = array(), $summary = '')
 {
     $result = null;
     $editPage = new EditPage($article);
     $editPage->edittime = $article->getTimestamp();
     $editPage->textbox1 = self::removeMetadataTag($text);
     $editPage->summary = $summary;
     $editPage->watchthis = $user->isWatched($article->getTitle());
     if (!empty($metadata)) {
         $editPage->textbox1 = $text . Xml::element('ac_metadata', $metadata, ' ');
     }
     $bot = $user->isAllowed('bot');
     return $editPage->internalAttemptSave($result, $bot);
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:27,代码来源:ArticleComment.class.php

示例10: internalAttemptSave

 /**
  * Attempt submission (no UI)
  * @return one of the constants describing the result
  */
 function internalAttemptSave(&$result, $bot = false)
 {
     if (!empty($this->mSpecialPage)) {
         $this->mSpecialPage->beforeSave();
     }
     if (!$this->mEditNotices->isEmpty()) {
         wfDebug(__METHOD__ . ": custom edit notices found - submit prevented\n");
         $ret = Status::newGood();
         $ret->setResult(false, self::AS_SUMMARY_NEEDED);
     } else {
         // tell MW core to save the article
         $ret = parent::internalAttemptSave($result, $bot);
         // add a message returned by hook
         if ($this->hookError !== '') {
             $this->mEditNotices->add($this->hookError, 'HookError');
         }
     }
     $this->lastSaveStatus = $ret;
     wfDebug(__METHOD__ . ": returned #" . $ret->value . "\n");
     // fire a custom hook when an edit from the edit page is successful (BugId:1317)
     if (in_array($ret->value, array(self::AS_SUCCESS_UPDATE, self::AS_SUCCESS_NEW_ARTICLE, self::AS_OK, self::AS_END))) {
         wfDebug(__METHOD__ . ": successful save\n");
         $this->app->wf->RunHooks('EditPageSuccessfulSave', array($this, $ret));
     }
     return $ret;
 }
开发者ID:schwarer2006,项目名称:wikia,代码行数:30,代码来源:EditPageLayout.class.php

示例11: internalAttemptSave

 function internalAttemptSave(&$result, $bot = false)
 {
     global $wgHooks;
     // clear confirmEdit for ajax edits:
     if (isset($wgHooks['EditFilter'])) {
         foreach ($wgHooks['EditFilter'] as $k => $hook) {
             unset($wgHooks['EditFilter'][$k]);
         }
     }
     return parent::internalAttemptSave($result, $bot = false);
 }
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:11,代码来源:MV_EditPageAjax.php

示例12: internalAttemptSave

	public function internalAttemptSave( &$result, $bot = false ) {
		$res = parent::internalAttemptSave( $result, $bot );
		$this->code = $res->value;
		if ( isset( $result['sectionanchor'] ) ) {
			$this->sectionanchor = $result['sectionanchor'];
		}
		return $res;
	}
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:8,代码来源:TalkHereHooks.php

示例13: execute

    /**
     * Show the special page.
     *
     * @param $par Mixed: parameter passed to the special page or null
     */
    public function execute($par)
    {
        global $wgRequest, $wgOut, $wgUser;
        if (wfReadOnly()) {
            $wgOut->readOnlyPage();
            return;
        }
        $this->setHeaders();
        if ($wgRequest->wasPosted()) {
            // 1. Retrieve POST vars. First, we want "crOrigTitle", holding the
            // title of the page we're writing to, and "crRedirectTitle",
            // holding the title of the page we're redirecting to.
            $crOrigTitle = $wgRequest->getText('crOrigTitle');
            $crRedirectTitle = $wgRequest->getText('crRedirectTitle');
            // 2. We need to construct a "FauxRequest", or fake a request that
            // MediaWiki would otherwise get naturally by a client browser to
            // do whatever it has to do. Let's put together the params.
            $title = $crOrigTitle;
            // a. We know our title, so we can instantiate a "Title" and
            // "Article" object. We don't actually plug this into the
            // FauxRequest, but they're required for the writing process,
            // and they contain important information on the article in
            // question that's being edited.
            $crEditTitle = Title::newFromText($crOrigTitle);
            // First, construct "Title". "Article" relies on the former object being set.
            $crEditArticle = new Article($crEditTitle, 0);
            // Then, construct "Article". This is where most of the article's information is.
            $wpStarttime = wfTimestampNow();
            // POST var "wpStarttime" stores when the edit was started.
            $wpEdittime = $crEditArticle->getTimestamp();
            // POST var "wpEdittime" stores when the article was ''last edited''. This is used to check against edit conflicts, and also why we needed to construct "Article" so early. "Article" contains the article's last edittime.
            $wpTextbox1 = "#REDIRECT [[{$crRedirectTitle}]]\r\n";
            // POST var "wpTextbox1" stores the content that's actually going to be written. This is where we write the #REDIRECT [[Article]] stuff. We plug in $crRedirectTitle here.
            $wpSave = 1;
            $wpMinoredit = 1;
            // TODO: Decide on this; should this really be marked and hardcoded as a minor edit, or not? Or should we provide an option? --Digi 11/4/07
            $wpEditToken = htmlspecialchars($wgUser->editToken());
            // 3. Put together the params that we'll use in "FauxRequest" into a single array.
            $crRequestParams = array('title' => $title, 'wpStarttime' => $wpStarttime, 'wpEdittime' => $wpEdittime, 'wpTextbox1' => $wpTextbox1, 'wpSave' => $wpSave, 'wpMinoredit' => $wpMinoredit, 'wpEditToken' => $wpEditToken);
            // 4. Construct "FauxRequest"! Using a FauxRequest object allows
            // for a transparent interface of generated request params that
            // aren't retrieved from the client itself (i.e. $_REQUEST).
            // It's a very useful tool.
            $crRequest = new FauxRequest($crRequestParams, true);
            // 5. Construct "EditPage", which contains routines to write all
            // the data. This is where all the magic happens.
            $crEdit = new EditPage($crEditArticle);
            // We plug in the "Article" object here so EditPage can center on the article that we need to edit.
            // a. We have to plug in the correct information that we just
            // generated. While we fed EditPage with the correct "Article"
            // object, it doesn't have the correct "Title" object.
            // The "Title" object actually points to Special:CreateRedirect,
            // which don't do us any good. Instead, explicitly plug in the
            // correct objects; the objects "Article" and "Title" that we
            // generated earlier. This will center EditPage on the correct article.
            $crEdit->mArticle = $crEditArticle;
            $crEdit->mTitle = $crEditTitle;
            // b. Then import the "form data" (or the FauxRequest object that
            // we just constructed). EditPage now has all the information we
            // generated.
            $crEdit->importFormData($crRequest);
            $permErrors = $crEditTitle->getUserPermissionsErrors('edit', $wgUser);
            // Can this title be created?
            if (!$crEditTitle->exists()) {
                $permErrors = array_merge($permErrors, wfArrayDiff2($crEditTitle->getUserPermissionsErrors('create', $wgUser), $permErrors));
            }
            if ($permErrors) {
                wfDebug(__METHOD__ . ": User can't edit\n");
                $wgOut->addWikiText($crEdit->formatPermissionsErrorMessage($permErrors, 'edit'));
                wfProfileOut(__METHOD__);
                return;
            }
            $resultDetails = false;
            $status = $crEdit->internalAttemptSave($resultDetails, $wgUser->isAllowed('bot') && $wgRequest->getBool('bot', true));
            $value = $status->value;
            if ($value == EditPage::AS_SUCCESS_UPDATE || $value == EditPage::AS_SUCCESS_NEW_ARTICLE) {
                $wgOut->wrapWikiMsg("<div class=\"mw-createredirect-done\">\n\$1</div>", array('createredirect-redirect-done', $crOrigTitle, $crRedirectTitle));
            }
            switch ($value) {
                case EditPage::AS_SPAM_ERROR:
                    $crEdit->spamPageWithContent($resultDetails['spam']);
                    return;
                case EditPage::AS_BLOCKED_PAGE_FOR_USER:
                    $crEdit->blockedPage();
                    return;
                case EditPage::AS_READ_ONLY_PAGE_ANON:
                    $crEdit->userNotLoggedInPage();
                    return;
                case EditPage::AS_READ_ONLY_PAGE_LOGGED:
                case EditPage::AS_READ_ONLY_PAGE:
                    $wgOut->readOnlyPage();
                    return;
                case EditPage::AS_RATE_LIMITED:
                    $wgOut->rateLimited();
                    break;
//.........这里部分代码省略.........
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:101,代码来源:CreateRedirect.body.php

示例14: execute


//.........这里部分代码省略.........
             $watch = false;
         }
         if ($watch) {
             $reqArr['wpWatchthis'] = '';
         }
         $req = new FauxRequest($reqArr, true);
         $ep->importFormData($req);
         // Run hooks
         // Handle CAPTCHA parameters
         global $wgRequest;
         if (!is_null($params['captchaid'])) {
             $wgRequest->setVal('wpCaptchaId', $params['captchaid']);
         }
         if (!is_null($params['captchaword'])) {
             $wgRequest->setVal('wpCaptchaWord', $params['captchaword']);
         }
         $r = array();
         if (!wfRunHooks('APIEditBeforeSave', array($ep, $ep->textbox1, &$r))) {
             if (count($r)) {
                 $r['result'] = "Failure";
                 $this->getResult()->addValue(null, $this->getModuleName(), $r);
                 return;
             } else {
                 $this->dieUsageMsg(array('hookaborted'));
             }
         }
         // Do the actual save
         $oldRevId = $articleObj->getRevIdFetched();
         $result = null;
         // Fake $wgRequest for some hooks inside EditPage
         // FIXME: This interface SUCKS
         $oldRequest = $wgRequest;
         $wgRequest = $req;
         $retval = $ep->internalAttemptSave($result, $wgUser->isAllowed('bot') && $params['bot']);
         $wgRequest = $oldRequest;
         switch ($retval) {
             case EditPage::AS_HOOK_ERROR:
             case EditPage::AS_HOOK_ERROR_EXPECTED:
                 $this->dieUsageMsg(array('hookaborted'));
             case EditPage::AS_IMAGE_REDIRECT_ANON:
                 $this->dieUsageMsg(array('noimageredirect-anon'));
             case EditPage::AS_IMAGE_REDIRECT_LOGGED:
                 $this->dieUsageMsg(array('noimageredirect-logged'));
             case EditPage::AS_SPAM_ERROR:
                 $this->dieUsageMsg(array('spamdetected', $result['spam']));
             case EditPage::AS_FILTERING:
                 $this->dieUsageMsg(array('filtered'));
             case EditPage::AS_BLOCKED_PAGE_FOR_USER:
                 $this->dieUsageMsg(array('blockedtext'));
             case EditPage::AS_MAX_ARTICLE_SIZE_EXCEEDED:
             case EditPage::AS_CONTENT_TOO_BIG:
                 global $wgMaxArticleSize;
                 $this->dieUsageMsg(array('contenttoobig', $wgMaxArticleSize));
             case EditPage::AS_READ_ONLY_PAGE_ANON:
                 $this->dieUsageMsg(array('noedit-anon'));
             case EditPage::AS_READ_ONLY_PAGE_LOGGED:
                 $this->dieUsageMsg(array('noedit'));
             case EditPage::AS_READ_ONLY_PAGE:
                 $this->dieReadOnly();
             case EditPage::AS_RATE_LIMITED:
                 $this->dieUsageMsg(array('actionthrottledtext'));
             case EditPage::AS_ARTICLE_WAS_DELETED:
                 $this->dieUsageMsg(array('wasdeleted'));
             case EditPage::AS_NO_CREATE_PERMISSION:
                 $this->dieUsageMsg(array('nocreate-loggedin'));
             case EditPage::AS_BLANK_ARTICLE:
开发者ID:schwarer2006,项目名称:wikia,代码行数:67,代码来源:WOM_SetObjectModel.php

示例15: createArticle

 /**
  * Create new article
  *
  * When successful returns title object of created article. If not, returns EditPage error code
  */
 protected function createArticle($title, $content, $summary)
 {
     global $wgUser;
     wfProfileIn(__METHOD__);
     self::log(__METHOD__, "creating article '{$title}'");
     //self::log(__METHOD__, array($title, $content, $summary));
     $ret = false;
     // title object for new article
     $newTitle = Title::newFromText($title);
     if (!empty($newTitle) && !empty($wgUser) && $newTitle->userCan('edit') && !$wgUser->isBlocked()) {
         $article = new Article($newTitle);
         $editPage = new EditPage($article);
         $editPage->edittime = $article->getTimestamp();
         $editPage->textbox1 = $content;
         $editPage->summary = $summary;
         $editPage->recreate = true;
         $result = null;
         $bot = $wgUser->isAllowed('bot');
         // do edit
         $status = $editPage->internalAttemptSave($result, $bot);
         $ret = $status->value;
         // creating new article
         if ($ret == EditPage::AS_SUCCESS_NEW_ARTICLE) {
             // edit successful
             $newTitle->invalidateCache();
             Article::onArticleEdit($newTitle);
             self::log(__METHOD__, 'success!');
             $ret = $newTitle;
         } elseif ($ret == EditPage::AS_SPAM_ERROR) {
             self::log(__METHOD__, 'spam found!');
         } else {
             self::log(__METHOD__, 'edit aborted');
         }
     } else {
         self::log(__METHOD__, 'user not allowed to edit');
         $ret = EditPage::AS_USER_CANNOT_EDIT;
     }
     if (is_numeric($ret)) {
         self::log(__METHOD__, "failed with error code #{$ret}");
     }
     wfProfileOut(__METHOD__);
     return $ret;
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:48,代码来源:RecipesTemplate.class.php


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