本文整理汇总了PHP中EditPage::importFormData方法的典型用法代码示例。如果您正苦于以下问题:PHP EditPage::importFormData方法的具体用法?PHP EditPage::importFormData怎么用?PHP EditPage::importFormData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EditPage
的用法示例。
在下文中一共展示了EditPage::importFormData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: importFormData
function importFormData(&$request)
{
# These fields need to be checked for encoding.
# Also remove trailing whitespace, but don't remove _initial_
# whitespace from the text boxes. This may be significant formatting.
EditPage::importFormData($request);
// create the wikiHow wrapper object
if ($request->wasPosted()) {
$whow = WikihowArticleEditor::newFromRequest($request);
$whow->mIsNew = false;
$this->whow = $whow;
$this->textbox1 = $this->whow->formatWikiText();
}
}
示例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;
}
示例3: execute
//.........这里部分代码省略.........
}
// Show notice when editing user / user talk page of a user that doesn't exist
// or who is blocked
// HACK of course this code is partly duplicated from EditPage.php :(
if ($title->getNamespace() == NS_USER || $title->getNamespace() == NS_USER_TALK) {
$parts = explode('/', $title->getText(), 2);
$targetUsername = $parts[0];
$targetUser = User::newFromName($targetUsername, false);
if (!($targetUser && $targetUser->isLoggedIn()) && !User::isIP($targetUsername)) {
// User does not exist
$notices[] = "<div class=\"mw-userpage-userdoesnotexist error\">\n" . $this->msg('userpage-userdoesnotexist', wfEscapeWikiText($targetUsername)) . "\n</div>";
} elseif ($targetUser->isBlocked()) {
// Show log extract if the user is currently blocked
$notices[] = $this->msg('blocked-notice-logextract', $targetUser->getName())->parseAsBlock() . $this->getLastLogEntry($targetUser->getUserPage(), 'block');
}
}
// Blocked user notice
if ($user->isBlockedFrom($title) && $user->getBlock()->prevents('edit') !== false) {
$notices[] = call_user_func_array(array($this, 'msg'), $user->getBlock()->getPermissionsError($this->getContext()))->parseAsBlock();
}
// Blocked user notice for global blocks
if (class_exists('GlobalBlocking')) {
$error = GlobalBlocking::getUserBlockErrors($user, $this->getRequest()->getIP());
if (count($error)) {
$notices[] = call_user_func_array(array($this, 'msg'), $error)->parseAsBlock();
}
}
// HACK: Build a fake EditPage so we can get checkboxes from it
$article = new Article($title);
// Deliberately omitting ,0 so oldid comes from request
$ep = new EditPage($article);
$req = $this->getRequest();
$req->setVal('format', 'text/x-wiki');
$ep->importFormData($req);
// By reference for some reason (bug 52466)
$tabindex = 0;
$states = array('minor' => false, 'watch' => false);
$checkboxes = $ep->getCheckboxes($tabindex, $states);
// HACK: Find out which red links are on the page
// We do the lookup for the current version. This might not be entirely complete
// if we're loading an oldid, but it'll probably be close enough, and LinkCache
// will automatically request any additional data it needs.
$links = array();
$wikipage = WikiPage::factory($title);
$popts = $wikipage->makeParserOptions('canonical');
$cached = ParserCache::singleton()->get($article, $popts, true);
$links = array('missing' => array(), 'known' => $restoring || !$cached ? array() : 1);
if ($cached) {
foreach ($cached->getLinks() as $namespace => $cachedTitles) {
foreach ($cachedTitles as $cachedTitleText => $exists) {
$cachedTitle = Title::makeTitle($namespace, $cachedTitleText);
if (!$cachedTitle->isKnown()) {
$links['missing'][] = $cachedTitle->getPrefixedText();
} elseif ($links['known'] !== 1) {
$links['known'][] = $cachedTitle->getPrefixedText();
}
}
}
}
// Add information about current page
if (!$title->isKnown()) {
$links['missing'][] = $title->getPrefixedText();
} elseif ($links['known'] !== 1) {
$links['known'][] = $title->getPrefixedText();
}
// On parser cache miss, just don't bother populating red link data
示例4: 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;
}
示例5: execute
//.........这里部分代码省略.........
$section = intval($params['section']);
if ($section == 0 && $params['section'] != '0' && $params['section'] != 'new') {
$this->dieUsage("The section parameter must be set to an integer or 'new'", "invalidsection");
}
$requestArray['wpSection'] = $params['section'];
} else {
$requestArray['wpSection'] = '';
}
$watch = $this->getWatchlistValue($params['watchlist'], $titleObj);
// Deprecated parameters
if ($params['watch']) {
$watch = true;
} elseif ($params['unwatch']) {
$watch = false;
}
if ($watch) {
$requestArray['wpWatchthis'] = '';
}
global $wgTitle, $wgRequest;
$req = new DerivativeRequest($this->getRequest(), $requestArray, true);
// Some functions depend on $wgTitle == $ep->mTitle
// TODO: Make them not or check if they still do
$wgTitle = $titleObj;
$articleContext = new RequestContext();
$articleContext->setRequest($req);
$articleContext->setWikiPage($pageObj);
$articleContext->setUser($this->getUser());
/** @var $articleObject Article */
$articleObject = Article::newFromWikiPage($pageObj, $articleContext);
$ep = new EditPage($articleObject);
// allow editing of non-textual content.
$ep->allowNonTextContent = true;
$ep->setContextTitle($titleObj);
$ep->importFormData($req);
// Run hooks
// Handle APIEditBeforeSave parameters
$r = array();
if (!wfRunHooks('APIEditBeforeSave', array($ep, $ep->textbox1, &$r))) {
if (count($r)) {
$r['result'] = 'Failure';
$apiResult->addValue(null, $this->getModuleName(), $r);
return;
} else {
$this->dieUsageMsg('hookaborted');
}
}
// Do the actual save
$oldRevId = $articleObject->getRevIdFetched();
$result = null;
// Fake $wgRequest for some hooks inside EditPage
// @todo FIXME: This interface SUCKS
$oldRequest = $wgRequest;
$wgRequest = $req;
$status = $ep->internalAttemptSave($result, $user->isAllowed('bot') && $params['bot']);
$wgRequest = $oldRequest;
global $wgMaxArticleSize;
switch ($status->value) {
case EditPage::AS_HOOK_ERROR:
case EditPage::AS_HOOK_ERROR_EXPECTED:
$this->dieUsageMsg('hookaborted');
case EditPage::AS_PARSE_ERROR:
$this->dieUsage($status->getMessage(), 'parseerror');
case EditPage::AS_IMAGE_REDIRECT_ANON:
$this->dieUsageMsg('noimageredirect-anon');
case EditPage::AS_IMAGE_REDIRECT_LOGGED:
$this->dieUsageMsg('noimageredirect-logged');
示例6: printForm
//.........这里部分代码省略.........
while ($target_title->exists()) {
if ($isRandom) {
$title_number = self::makeRandomNumber($randomNumDigits, $randomNumHasPadding);
} elseif ($title_number == "") {
$title_number = 2;
} else {
$title_number = str_pad($title_number + 1, strlen($title_number), '0', STR_PAD_LEFT);
}
$target_title = Title::newFromText(preg_replace('/{num.*}/', $title_number, $target_name));
}
$target_name = $target_title->getPrefixedText();
} else {
$target_title = Title::newFromText($target_name);
}
}
if (is_null($target_title)) {
if ($target_name) {
return array('sf_formstart_badtitle', array($target_name));
} else {
return 'sf_formedit_emptytitle';
}
}
if ($save_page) {
$permErrors = $target_title->getUserPermissionsErrors('edit', $wgUser);
if ($permErrors) {
// just return the first error and let them fix it one by one
return array_shift($permErrors);
}
// Set up all the variables for the
// page save.
$data = array('wpTextbox1' => $data_text, 'wpSummary' => $wgRequest->getVal('wpSummary'), 'wpStarttime' => $wgRequest->getVal('wpStarttime'), 'wpEdittime' => $wgRequest->getVal('wpEdittime'), 'wpEditToken' => $wgUser->isLoggedIn() ? $wgUser->editToken() : EDIT_TOKEN_SUFFIX, 'wpSave' => '', 'action' => 'submit');
if ($wgRequest->getCheck('wpMinoredit')) {
$data['wpMinoredit'] = true;
}
if ($wgRequest->getCheck('wpWatchthis')) {
$data['wpWatchthis'] = true;
}
$request = new FauxRequest($data, true);
// Find existing article if it exists,
// or create a new one.
$article = new Article($target_title, 0);
$editor = new EditPage($article);
$editor->importFormData($request);
// Try to save the page!
$resultDetails = array();
$saveResult = $editor->internalAttemptSave($resultDetails);
// Return value was made an object in MW 1.19
if (is_object($saveResult)) {
$saveResultCode = $saveResult->value;
} else {
$saveResultCode = $saveResult;
}
if (($saveResultCode == EditPage::AS_HOOK_ERROR || $saveResultCode == EditPage::AS_HOOK_ERROR_EXPECTED) && $redirectOnError) {
$wgOut->clearHTML();
$wgOut->setArticleBodyOnly(true);
// Lets other code process additional form-definition syntax
wfRunHooks('sfWritePageData', array($form_name, $target_title, &$data_text));
$text = SFUtils::printRedirectForm($target_title, $data_text, $wgRequest->getVal('wpSummary'), $save_page, $preview_page, $diff_page, $wgRequest->getCheck('wpMinoredit'), $wgRequest->getCheck('wpWatchthis'), $wgRequest->getVal('wpStarttime'), $wgRequest->getVal('wpEdittime'));
} else {
if ($saveResultCode == EditPage::AS_SUCCESS_UPDATE || $saveResultCode == EditPage::AS_SUCCESS_NEW_ARTICLE) {
$wgOut->redirect($target_title->getFullURL());
}
return SFUtils::processEditErrors($saveResultCode);
}
} else {
// Lets other code process additional form-definition syntax
wfRunHooks('sfWritePageData', array($form_name, $target_title, &$data_text));
$text = SFUtils::printRedirectForm($target_title, $data_text, $wgRequest->getVal('wpSummary'), $save_page, $preview_page, $diff_page, $wgRequest->getCheck('wpMinoredit'), $wgRequest->getCheck('wpWatchthis'), $wgRequest->getVal('wpStarttime'), $wgRequest->getVal('wpEdittime'));
// extract its data
}
} else {
// override the default title for this page if
// a title was specified in the form
if ($form_page_title != null) {
if ($target_name === '') {
$wgOut->setPageTitle($form_page_title);
} else {
$wgOut->setPageTitle("{$form_page_title}: {$target_title->getPrefixedText()}");
}
}
$text = "";
if (count($alt_forms) > 0) {
$text .= '<div class="infoMessage">' . wfMsg('sf_formedit_altforms') . ' ';
$text .= self::printAltFormsList($alt_forms, $target_name);
$text .= "</div>\n";
}
$text .= '<form name="createbox" id="sfForm" method="post" class="createbox">';
$pre_form_html = '';
wfRunHooks('sfHTMLBeforeForm', array(&$target_title, &$pre_form_html));
$text .= $pre_form_html;
$text .= $form_text;
}
}
SFUtils::addJavascriptAndCSS();
if (!empty($javascript_text)) {
$wgOut->addScript(' <script type="text/javascript">' . "\n{$javascript_text}\n" . '</script>' . "\n");
}
$wgOut->addHTML($text);
return null;
}
示例7: importFormData
/**
* @todo document
*/
function importFormData(&$request)
{
global $wgLang, $wgUser, $wgStructuredParts;
$fname = 'StructuredEditPage::importFormData';
wfProfileIn($fname);
parent::importFormData($request);
if ($request->wasPosted()) {
# These fields need to be checked for encoding.
# Also remove trailing whitespace, but don't remove _initial_
# whitespace from the text boxes. This may be significant formatting.
$ns = $this->mArticle->mTitle->getNamespace();
if (isset($wgStructuredParts[$ns])) {
foreach ($wgStructuredParts[$ns] as $item) {
$this->{$item['name']} = $this->safeUnicodeInput($request, $item['name']);
#print("attempting to access {$item['name']}<br>\n");
#print("got ".$this->{$item['name']}."\n");
}
}
wfProfileOut($fname);
}
}
示例8: execute
//.........这里部分代码省略.........
$watch = true;
} elseif ($params['unwatch']) {
$this->logFeatureUsage('action=edit&unwatch');
$watch = false;
}
if ($watch) {
$requestArray['wpWatchthis'] = '';
}
// Apply change tags
if (count($params['tags'])) {
if ($user->isAllowed('applychangetags')) {
$requestArray['wpChangeTags'] = implode(',', $params['tags']);
} else {
$this->dieUsage('You don\'t have permission to set change tags.', 'taggingnotallowed');
}
}
// Pass through anything else we might have been given, to support extensions
// This is kind of a hack but it's the best we can do to make extensions work
$requestArray += $this->getRequest()->getValues();
global $wgTitle, $wgRequest;
$req = new DerivativeRequest($this->getRequest(), $requestArray, true);
// Some functions depend on $wgTitle == $ep->mTitle
// TODO: Make them not or check if they still do
$wgTitle = $titleObj;
$articleContext = new RequestContext();
$articleContext->setRequest($req);
$articleContext->setWikiPage($pageObj);
$articleContext->setUser($this->getUser());
/** @var $articleObject Article */
$articleObject = Article::newFromWikiPage($pageObj, $articleContext);
$ep = new EditPage($articleObject);
$ep->setApiEditOverride(true);
$ep->setContextTitle($titleObj);
$ep->importFormData($req);
$content = $ep->textbox1;
// The following is needed to give the hook the full content of the
// new revision rather than just the current section. (Bug 52077)
if (!is_null($params['section']) && $contentHandler->supportsSections() && $titleObj->exists()) {
// If sectiontitle is set, use it, otherwise use the summary as the section title (for
// backwards compatibility with old forms/bots).
if ($ep->sectiontitle !== '') {
$sectionTitle = $ep->sectiontitle;
} else {
$sectionTitle = $ep->summary;
}
$contentObj = $contentHandler->unserializeContent($content, $contentFormat);
$fullContentObj = $articleObject->replaceSectionContent($params['section'], $contentObj, $sectionTitle);
if ($fullContentObj) {
$content = $fullContentObj->serialize($contentFormat);
} else {
// This most likely means we have an edit conflict which means that the edit
// wont succeed anyway.
$this->dieUsageMsg('editconflict');
}
}
// Run hooks
// Handle APIEditBeforeSave parameters
$r = array();
if (!Hooks::run('APIEditBeforeSave', array($ep, $content, &$r))) {
if (count($r)) {
$r['result'] = 'Failure';
$apiResult->addValue(null, $this->getModuleName(), $r);
return;
}
$this->dieUsageMsg('hookaborted');
}
示例9: importFormData
/**
* We need to read the hidden checkboxes to know if the
* visual editor was used or not
*/
function importFormData(&$request)
{
if ($request->wasPosted()) {
# MeanEditor: take note if the visual editor was used or not
$this->noVisualEditor = $request->getVal('wpNoVisualEditor');
$this->userWantsTraditionalEditor = $request->getCheck('wpWantTraditionalEditor');
} else {
$this->noVisualEditor = false;
$this->userWantsTraditionalEditor = false;
}
return parent::importFormData($request);
}
示例10: execute
public function execute($par)
{
global $wgUser, $wgRequest, $wgOut, $wgCommentboxNamespaces;
if (!$wgRequest->wasPosted()) {
$wgOut->redirect(Title::newMainPage()->getFullURL());
return;
}
$this->setHeaders();
$Pagename = $wgRequest->getText('wpPageName');
$Author = $wgRequest->getText('wpAuthor', '');
$Comment = $wgRequest->getText('wpComment', '');
$title = Title::newFromText($Pagename);
if ($title == NULL || !$title->exists()) {
$this->fail('commentbox-error-page-nonexistent');
return;
}
if (!array_key_exists($title->getNamespace(), $wgCommentboxNamespaces) || !$wgCommentboxNamespaces[$title->getNamespace()]) {
$this->fail('commentbox-error-namespace', $title);
return;
}
if ($Comment == '' || $Comment == wfMsgNoTrans('commentbox-prefill')) {
$this->fail('commentbox-error-empty-comment', $title);
return;
}
if (!$title->userCan('edit')) {
$this->displayRestrictionError();
return;
}
// TODO: Integrate with SpamBlacklist etc.
// Currently, no http/https-links are allowed at all
$matches = array();
if (preg_match('@https?://[-.\\w]+@', $Comment, $matches) || preg_match('@https?://[-.\\w]+@', $Author, $matches)) {
$wgOut->setPageTitle(wfMsg('spamprotectiontitle'));
$wgOut->setRobotPolicy('noindex,nofollow');
$wgOut->setArticleRelated(false);
$wgOut->addWikiMsg('spamprotectiontext');
$wgOut->addWikiMsg('spamprotectionmatch', "<nowiki>{$matches[0]}</nowiki>");
$wgOut->returnToMain(false, $title);
return;
}
$article = new Article($title);
$text = $article->getContent();
$subject = '';
if (!preg_match(wfMsgForContentNoTrans('commentbox-regex'), $text)) {
$subject = wfMsgForContent('commentbox-first-comment-heading') . "\n";
}
$sig = $wgUser->isLoggedIn() ? "-- ~~~~" : "-- {$Author} ~~~~~";
// Append <br /> after each newline, except if the user started a new paragraph
$Comment = preg_replace('/(?<!\\n)\\n(?!\\n)/', "<br />\n", $Comment);
$text .= "\n\n" . $subject . $Comment . "\n<br />" . $sig;
$reqArr = array('wpTextbox1' => $text, 'wpSummary' => wfMsgForContent('commentbox-log'), 'wpEditToken' => $wgUser->editToken(), 'wpIgnoreBlankSummary' => '', 'wpStarttime' => wfTimestampNow(), 'wpEdittime' => $article->getTimestamp());
$request = new FauxRequest($reqArr, true);
$ep = new EditPage($article);
$ep->setContextTitle($title);
$ep->importFormData($request);
$details = array();
// Passed by ref
$status = $ep->internalAttemptSave($details);
$retval = $status->value;
switch ($retval) {
case EditPage::AS_SUCCESS_UPDATE:
$wgOut->redirect($title->getFullURL());
break;
case EditPage::AS_SPAM_ERROR:
$ep->spamPageWithContent($details['spam']);
break;
case EditPage::AS_BLOCKED_PAGE_FOR_USER:
$wgOut->blockedPage();
break;
case EditPage::AS_READ_ONLY_PAGE_ANON:
case EditPage::AS_READ_ONLY_PAGE_LOGGED:
$wgOut->permissionRequired('edit');
break;
case EditPage::AS_READ_ONLY_PAGE:
$wgOut->readOnlyPage();
}
}
示例11: importFormData
/**
* Override importFormData to add possibility to prevent save during post request
*/
function importFormData(&$request)
{
parent::importFormData($request);
if ($this->mPreventSave) {
$this->save = false;
}
}
示例12: 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;
//.........这里部分代码省略.........
示例13: execute
//.........这里部分代码省略.........
// Fake wpStartime
if ($params['minor'] || !$params['notminor'] && $wgUser->getOption('minordefault')) {
$reqArr['wpMinoredit'] = '';
}
// Handle watchlist settings
switch ($params['watchlist']) {
case 'watch':
$watch = true;
break;
case 'unwatch':
$watch = false;
break;
case 'preferences':
if ($titleObj->exists()) {
$watch = $wgUser->getOption('watchdefault') || $titleObj->userIsWatching();
} else {
$watch = $wgUser->getOption('watchcreations');
}
break;
case 'nochange':
default:
$watch = $titleObj->userIsWatching();
}
// Deprecated parameters
if ($params['watch']) {
$watch = true;
} elseif ($params['unwatch']) {
$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'));
示例14: setupEditPage
protected function setupEditPage($targetContent)
{
global $wgUser;
// Find existing target article if it exists, or create a new one.
$article = new Article(Title::newFromText($this->mOptions['target']));
$summary = array_key_exists('wpSummary', $this->mOptions) ? $this->mOptions['wpSummary'] : '';
$startTime = array_key_exists('wpStartTime', $this->mOptions) ? $this->mOptions['wpStarttime'] : wfTimestampNow();
$editTime = array_key_exists('wpEdittime', $this->mOptions) ? $this->mOptions['wpEdittime'] : '';
// set up a normal edit page
// we'll feed it our data to simulate a normal edit
$editor = new EditPage($article);
// set up simulated form data
$data = array('wpTextbox1' => $targetContent, 'wpSummary' => $summary, 'wpStarttime' => $startTime, 'wpEdittime' => $editTime, 'wpEditToken' => $wgUser->isLoggedIn() ? $wgUser->editToken() : EDIT_TOKEN_SUFFIX, 'action' => 'submit');
// set up a faux request with the simulated data
$request = new FauxRequest($data, true);
// and import it into the edit page
$editor->importFormData($request);
return $editor;
}
示例15: importFormData
/**
* We need to read the checkbox and the hidden value to know if the
* visual editor was used or not
*/
function importFormData(&$request)
{
global $wgUser;
if ($request->wasPosted()) {
# Reuse values from the previous submission
$this->noVisualEditor = $request->getVal('wpNoVisualEditor');
$this->userWantsTraditionalEditor = $request->getCheck('wpWantTraditionalEditor');
} else {
# Default values
$this->noVisualEditor = false;
$this->userWantsTraditionalEditor = $wgUser->getOption('prefer_traditional_editor');
}
return parent::importFormData($request);
}