本文整理汇总了PHP中SFUtils::getFormTagComponents方法的典型用法代码示例。如果您正苦于以下问题:PHP SFUtils::getFormTagComponents方法的具体用法?PHP SFUtils::getFormTagComponents怎么用?PHP SFUtils::getFormTagComponents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SFUtils
的用法示例。
在下文中一共展示了SFUtils::getFormTagComponents方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: formHTML
//.........这里部分代码省略.........
$wgOut->addWikiText( $wgOut->formatPermissionsErrorMessage( $permissionErrors, 'edit' ) );
$wgOut->addHTML( "\n<hr />\n" );
}
$oldParser = $wgParser;
$wgParser = unserialize( serialize( $oldParser ) ); // deep clone of parser
$wgParser->Options( ParserOptions::newFromUser( $wgUser ) );
$wgParser->Title( $this->mPageTitle );
$wgParser->clearState();
$form_def = SFFormUtils::getFormDefinition( $wgParser, $form_def, $form_id );
// Turn form definition file into an array of sections, one for each
// template definition (plus the first section)
$form_def_sections = array();
$start_position = 0;
$section_start = 0;
$free_text_was_included = false;
$free_text_preload_page = null;
$free_text_components = array();
$all_values_for_template = array();
// Unencode any HTML-encoded representations of curly brackets and
// pipes - this is a hack to allow for forms to include templates
// that themselves contain form elements - the escaping was needed
// to make sure that those elements don't get parsed too early.
$form_def = str_replace( array( '{', '|', '}' ), array( '{', '|', '}' ), $form_def );
// And another hack - replace the 'free text' standard input with
// a field declaration to get it to be handled as a field.
$form_def = str_replace( 'standard input|free text', 'field|<freetext>', $form_def );
while ( $brackets_loc = strpos( $form_def, "{{{", $start_position ) ) {
$brackets_end_loc = strpos( $form_def, "}}}", $brackets_loc );
$bracketed_string = substr( $form_def, $brackets_loc + 3, $brackets_end_loc - ( $brackets_loc + 3 ) );
$tag_components = SFUtils::getFormTagComponents( $bracketed_string );
$tag_title = trim( $tag_components[0] );
if ( $tag_title == 'for template' || $tag_title == 'end template' ) {
// Create a section for everything up to here
$section = substr( $form_def, $section_start, $brackets_loc - $section_start );
$form_def_sections[] = $section;
$section_start = $brackets_loc;
}
$start_position = $brackets_loc + 1;
} // end while
$form_def_sections[] = trim( substr( $form_def, $section_start ) );
// Cycle through the form definition file, and possibly an
// existing article as well, finding template and field
// declarations and replacing them with form elements, either
// blank or pre-populated, as appropriate.
$all_fields = array();
$data_text = "";
$template_name = "";
$allow_multiple = false;
$instance_num = 0;
$all_instances_printed = false;
$strict_parsing = false;
// Placeholder name in the form
$curPlaceholder = null;
// Used to store the HTML code of the multiple template, to reinsert it into the right spot
// This array will keep track of all the replaced @<name>@ strings
$placeholderFields = array();
for ( $section_num = 0; $section_num < count( $form_def_sections ); $section_num++ ) {
$start_position = 0;
$template_text = "";
示例2: printForm
private function printForm(&$parameters, WebRequest &$request)
{
global $wgOut, $sfgFormPrinter;
// Prepare parameters for SFFormPrinter::formHTML
// there is no ONE target page
$targetTitle = null;
// formDefinition
$formName = $request->getText('form');
// if query string did not contain these variables, try the URL
if ($formName === '') {
$queryparts = explode('/', $parameters);
$formName = isset($queryparts[0]) ? $queryparts[0] : null;
// if the form name wasn't in the URL either, throw an error
if (is_null($formName) || $formName === '') {
throw new SPSException(SPSUtils::buildMessage('spserror-noformname'));
}
}
$formTitle = Title::makeTitleSafe(SF_NS_FORM, $formName);
if (!$formTitle->exists()) {
throw new SPSException(SPSUtils::buildMessage('spserror-formunknown', $formName));
}
$formArticle = new Article($formTitle);
$formDefinition = StringUtils::delimiterReplace('<noinclude>', '</noinclude>', '', $formArticle->getContent());
// formSubmitted
$formSubmitted = false;
// pageContents
$pageContents = null;
// get 'preload' query value, if it exists
if ($request->getCheck('preload')) {
$pageContents = SFFormUtils::getPreloadedText($request->getVal('preload'));
} else {
// let other extensions preload the page, if they want
wfRunHooks('sfEditFormPreloadText', array(&$pageContents, $targetTitle, $formTitle));
}
// pageIsSource
$pageIsSource = $pageContents != null;
// pageNameFormula
// parse the form to see if it has a 'page name' value set
$matches;
if (preg_match('/{{{info.*page name\\s*=\\s*(.*)}}}/m', $formDefinition, $matches)) {
$pageNameElements = SFUtils::getFormTagComponents($matches[1]);
$pageNameFormula = $pageNameElements[0];
} else {
return 'sf_formedit_badurl';
}
// get the iterator parameters
$iteratorData = $this->buildIteratorParameters($request);
// Call SFFormPrinter::formHTML
list($formText, $javascriptText, $dataText, $formPageTitle, $generatedPageName) = $sfgFormPrinter->formHTML($formDefinition, $formSubmitted, $pageIsSource, $formArticle->getID(), $pageContents, '', $pageNameFormula);
// Set Special page main header;
// override the default title for this page if a title was specified in the form
if ($formPageTitle != null) {
$wgOut->setPageTitle($formPageTitle);
} else {
$wgOut->setPageTitle(SPSUtils::buildMessage('sf_formedit_createtitlenotarget', $formTitle->getText()));
}
$preFormHtml = '';
wfRunHooks('sfHTMLBeforeForm', array(&$targetTitle, &$preFormHtml));
$text = '<form name="createbox" id="sfForm" action="" method="post" class="createbox">' . $preFormHtml . "\n" . SFFormUtils::hiddenFieldHTML('iteratordata', $iteratorData) . $formText;
SFUtils::addJavascriptAndCSS();
if (!empty($javascriptText)) {
$wgOut->addScript(' <script type="text/javascript">' . "\n{$javascriptText}\n" . '</script>' . "\n");
}
$wgOut->addHTML($text);
return null;
}
示例3: printForm
static function printForm(&$form_name, &$target_name, $alt_forms = array(), $redirectOnError = false)
{
global $wgOut, $wgRequest, $wgUser, $sfgFormPrinter;
// initialize some variables
$target_title = null;
$page_name_formula = null;
$form_title = Title::makeTitleSafe(SF_NS_FORM, $form_name);
// If the given form is not a valid title, bail out.
if (!$form_title) {
return 'sf_formedit_badurl';
}
$form_article = new Article($form_title, 0);
$form_definition = $form_article->getContent();
// If the form page is a redirect, use the other form
// instead.
if ($form_title->isRedirect()) {
$form_title = Title::newFromRedirectRecurse($form_definition);
$form_article = new Article($form_title, 0);
$form_definition = $form_article->getContent();
}
$form_definition = StringUtils::delimiterReplace('<noinclude>', '</noinclude>', '', $form_definition);
if (is_null($target_name)) {
$target_name = '';
}
if ($target_name === '') {
// parse the form to see if it has a 'page name' value set
$matches;
if (preg_match('/{{{info.*page name\\s*=\\s*(.*)}}}/m', $form_definition, $matches)) {
$page_name_elements = SFUtils::getFormTagComponents($matches[1]);
$page_name_formula = $page_name_elements[0];
} elseif (count($alt_forms) == 0) {
return 'sf_formedit_badurl';
}
} else {
$target_title = Title::newFromText($target_name);
if ($target_title && $target_title->exists()) {
if ($wgRequest->getVal('query') == 'true') {
$page_contents = null;
//$page_is_source = false;
} else {
// If page already exists and 'redlink'
// is in the query string, redirect to
// the actual page, just like
// MediaWiki does it.
if ($wgRequest->getBool('redlink')) {
$wgOut->redirect($target_title->getFullURL());
wfProfileOut(__METHOD__);
return;
}
$target_article = new Article($target_title, 0);
$page_contents = $target_article->getContent();
//$page_is_source = true;
}
} else {
$target_name = str_replace('_', ' ', $target_name);
}
}
if (!$form_title || !$form_title->exists()) {
if (count($alt_forms) > 0) {
$text = '<div class="infoMessage">' . wfMsg('sf_formedit_altformsonly') . ' ' . self::printAltFormsList($alt_forms, $form_name) . "</div>\n";
} else {
$text = Html::rawElement('p', array('class' => 'error'), wfMsgExt('sf_formstart_badform', 'parseinline', SFUtils::linkText(SF_NS_FORM, $form_name))) . "\n";
}
} elseif ($target_name === '' && $page_name_formula === '') {
$text = Html::element('p', array('class' => 'error'), wfMsg('sf_formedit_badurl')) . "\n";
} else {
$save_page = $wgRequest->getCheck('wpSave');
$preview_page = $wgRequest->getCheck('wpPreview');
$diff_page = $wgRequest->getCheck('wpDiff');
$form_submitted = $save_page || $preview_page || $diff_page;
// get 'preload' query value, if it exists
if (!$form_submitted) {
if ($wgRequest->getCheck('preload')) {
$page_is_source = true;
$page_contents = SFFormUtils::getPreloadedText($wgRequest->getVal('preload'));
} else {
// let other extensions preload the page, if they want
wfRunHooks('sfEditFormPreloadText', array(&$page_contents, $target_title, $form_title));
$page_is_source = $page_contents != null;
}
} else {
$page_is_source = false;
$page_contents = null;
}
list($form_text, $javascript_text, $data_text, $form_page_title, $generated_page_name) = $sfgFormPrinter->formHTML($form_definition, $form_submitted, $page_is_source, $form_article->getID(), $page_contents, $target_name, $page_name_formula);
// Before we do anything else, set the form header
// title - this needs to be done after formHTML() is
// called, because otherwise it doesn't take hold
// for some reason if the form is disabled.
if (empty($target_title)) {
$s = wfMsg('sf_formedit_createtitlenotarget', $form_title->getText());
} elseif ($target_title->exists()) {
$s = wfMsg('sf_formedit_edittitle', $form_title->getText(), $target_title->getPrefixedText());
} else {
$s = wfMsg('sf_formedit_createtitle', $form_title->getText(), $target_title->getPrefixedText());
}
$wgOut->setPageTitle($s);
if ($form_submitted) {
if (!is_null($page_name_formula) && $page_name_formula !== '') {
$target_name = $generated_page_name;
//.........这里部分代码省略.........
示例4: formHTML
//.........这里部分代码省略.........
} else {
$form_is_disabled = true;
$wgOut->setPageTitle(wfMessage('badaccess')->text());
$wgOut->addWikiText($wgOut->formatPermissionsErrorMessage($permissionErrors, 'edit'));
$wgOut->addHTML("\n<hr />\n");
}
// $oldParser = $wgParser;
// $wgParser = unserialize( serialize( $oldParser ) ); // deep clone of parser
if (!$wgParser->Options()) {
$wgParser->Options(ParserOptions::newFromUser($wgUser));
}
$wgParser->Title($this->mPageTitle);
// This is needed in order to make sure $parser->mLinkHolders
// is set.
$wgParser->clearState();
$form_def = SFFormUtils::getFormDefinition($wgParser, $form_def, $form_id);
// Turn form definition file into an array of sections, one for
// each template definition (plus the first section).
$form_def_sections = array();
$start_position = 0;
$section_start = 0;
$free_text_was_included = false;
// Unencode any HTML-encoded representations of curly brackets and
// pipes - this is a hack to allow for forms to include templates
// that themselves contain form elements - the escaping was needed
// to make sure that those elements don't get parsed too early.
$form_def = str_replace(array('{', '|', '}'), array('{', '|', '}'), $form_def);
// And another hack - replace the 'free text' standard input
// with a field declaration to get it to be handled as a field.
$form_def = str_replace('standard input|free text', 'field|<freetext>', $form_def);
while ($brackets_loc = strpos($form_def, "{{{", $start_position)) {
$brackets_end_loc = strpos($form_def, "}}}", $brackets_loc);
$bracketed_string = substr($form_def, $brackets_loc + 3, $brackets_end_loc - ($brackets_loc + 3));
$tag_components = SFUtils::getFormTagComponents($bracketed_string);
$tag_title = trim($tag_components[0]);
if ($tag_title == 'for template' || $tag_title == 'end template') {
// Create a section for everything up to here
$section = substr($form_def, $section_start, $brackets_loc - $section_start);
$form_def_sections[] = $section;
$section_start = $brackets_loc;
}
$start_position = $brackets_loc + 1;
}
// end while
$form_def_sections[] = trim(substr($form_def, $section_start));
// Cycle through the form definition file, and possibly an
// existing article as well, finding template and field
// declarations and replacing them with form elements, either
// blank or pre-populated, as appropriate.
$tif = null;
// This array will keep track of all the replaced @<name>@ strings
$placeholderFields = array();
for ($section_num = 0; $section_num < count($form_def_sections); $section_num++) {
$start_position = 0;
// the append is there to ensure that the original
// array doesn't get modified; is it necessary?
$section = " " . $form_def_sections[$section_num];
while ($brackets_loc = strpos($section, '{{{', $start_position)) {
$brackets_end_loc = strpos($section, "}}}", $brackets_loc);
$bracketed_string = substr($section, $brackets_loc + 3, $brackets_end_loc - ($brackets_loc + 3));
$tag_components = SFUtils::getFormTagComponents($bracketed_string);
$tag_title = trim($tag_components[0]);
// =====================================================
// for template processing
// =====================================================
if ($tag_title == 'for template') {
示例5: doAction
/**
* Depending on the requested action this method will try to store/preview
* the data in mOptions or retrieve the edit form.
*
* The form and target page will be available in mOptions after execution of
* the method.
*
* Errors and warnings are logged in the API result under the 'errors' key.
* The general request status is maintained in mStatus.
*
* @global $wgRequest
* @global $wgOut
* @global SFFormPrinter $sfgFormPrinter
* @throws MWException
*/
public function doAction()
{
global $wgOut, $wgParser, $wgRequest, $sfgFormPrinter;
// if the wiki is read-only, do not save
if (wfReadOnly()) {
if ($this->mAction === self::ACTION_SAVE) {
throw new MWException(wfMessage('sf_autoedit_readonly', wfReadOnlyReason())->parse());
}
// even if not saving notify client anyway. Might want to dislay a notice
$this->logMessage(wfMessage('sf_autoedit_readonly', wfReadOnlyReason())->parse(), self::NOTICE);
}
// find the title of the form to be used
$formTitle = $this->getFormTitle();
// get the form content
$formContent = StringUtils::delimiterReplace('<noinclude>', '</noinclude>', '', $this->getTextForPage($formTitle));
// signals that the form was submitted
// always true, else we would not be here
$isFormSubmitted = $this->mAction === self::ACTION_SAVE || $this->mAction === self::ACTION_PREVIEW || $this->mAction === self::ACTION_DIFF;
// the article id of the form to be used
$formArticleId = $formTitle->getArticleID();
// the name of the target page; might be empty when using the one-step-process
$targetName = $this->mOptions['target'];
// if the target page was not specified, try finding the page name formula
// (Why is this not done in SFFormPrinter::formHTML?)
if ($targetName === '') {
// Parse the form to see if it has a 'page name' value set.
if (preg_match('/{{{\\s*info.*page name\\s*=\\s*(.*)}}}/msU', $formContent, $matches)) {
$pageNameElements = SFUtils::getFormTagComponents(trim($matches[1]));
$targetNameFormula = $pageNameElements[0];
} else {
throw new MWException(wfMessage('sf_autoedit_notargetspecified')->parse());
}
$targetTitle = null;
} else {
$targetNameFormula = null;
$targetTitle = Title::newFromText($targetName);
}
$preloadContent = '';
// save $wgRequest for later restoration
$oldRequest = $wgRequest;
$pageExists = false;
// preload data if not explicitly excluded and if the preload page exists
if (!isset($this->mOptions['preload']) || $this->mOptions['preload'] !== false) {
if (isset($this->mOptions['preload']) && is_string($this->mOptions['preload'])) {
$preloadTitle = Title::newFromText($this->mOptions['preload']);
} else {
$preloadTitle = Title::newFromText($targetName);
}
if ($preloadTitle !== null && $preloadTitle->exists()) {
// the content of the page that was specified to be used for preloading
$preloadContent = $this->getTextForPage($preloadTitle);
$pageExists = true;
} else {
if (isset($this->mOptions['preload'])) {
$this->logMessage(wfMessage('sf_autoedit_invalidpreloadspecified', $this->mOptions['preload'])->parse(), self::WARNING);
}
}
}
// Allow extensions to set/change the preload text, for new
// pages.
if (!$pageExists) {
Hooks::run('sfEditFormPreloadText', array(&$preloadContent, $targetTitle, $formTitle));
}
// Flag to keep track of formHTML() runs.
$formHtmlHasRun = false;
if ($preloadContent !== '') {
// @HACK - we need to set this for the preload to take
// effect in the form.
$pageExists = true;
// Spoof $wgRequest for SFFormPrinter::formHTML().
if (isset($_SESSION)) {
$wgRequest = new FauxRequest($this->mOptions, true, $_SESSION);
} else {
$wgRequest = new FauxRequest($this->mOptions, true);
}
// Call SFFormPrinter::formHTML() to get at the form
// HTML of the existing page.
list($formHTML, $formJS, $targetContent, $form_page_title, $generatedTargetNameFormula) = $sfgFormPrinter->formHTML($formContent, $isFormSubmitted, $pageExists, $formArticleId, $preloadContent, $targetName, $targetNameFormula);
// Parse the data to be preloaded from the form HTML of
// the existing page.
$data = $this->parseDataFromHTMLFrag($formHTML);
// ...and merge/overwrite it with the new data.
$this->mOptions = SFUtils::array_merge_recursive_distinct($data, $this->mOptions);
}
// We already preloaded stuff for saving/previewing -
//.........这里部分代码省略.........
示例6: doAction
/**
* Depending on the requested action this method will try to store/preview
* the data in mOptions or retrieve the edit form.
*
* The form and target page will be available in mOptions after execution of
* the method.
*
* Errors and warnings are logged in the API result under the 'errors' key.
* The general request status is maintained in mStatus.
*
* @global $wgRequest
* @global $wgOut
* @global $sfgFormPrinter
* @throws MWException
*/
public function doAction()
{
global $wgOut, $wgRequest, $sfgFormPrinter;
// if the wiki is read-only, do not save
if (wfReadOnly()) {
if ($this->mAction === self::ACTION_SAVE) {
throw new MWException(wfMessage('sf_autoedit_readonly', wfReadOnlyReason())->parse());
}
// even if not saving notify client anyway. Might want to dislay a notice
$this->logMessage(wfMessage('sf_autoedit_readonly', wfReadOnlyReason())->parse(), self::NOTICE);
}
// find the title of the form to be used
$formTitle = $this->getFormTitle();
// get the form content
$formContent = StringUtils::delimiterReplace('<noinclude>', '</noinclude>', '', WikiPage::factory($formTitle)->getRawText());
// signals that the form was submitted
// always true, else we would not be here
$isFormSubmitted = $this->mAction === self::ACTION_SAVE || $this->mAction === self::ACTION_PREVIEW;
// the article id of the form to be used
$formArticleId = $formTitle->getArticleID();
// source of the data is a page
$isPageSource = true;
// the name of the target page; might be empty when using the one-step-process
$targetName = $this->mOptions['target'];
// if the target page was not specified, try finding the page name formula
// (Why is this not done in SFFormPrinter::formHTML?)
if ($targetName === '') {
// parse the form to see if it has a 'page name' value set
if (preg_match('/{{{info.*page name\\s*=\\s*(.*)}}}/m', $formContent, $matches)) {
$pageNameElements = SFUtils::getFormTagComponents($matches[1]);
$targetNameFormula = $pageNameElements[0];
} else {
throw new MWException(wfMessage('sf_autoedit_notargetspecified')->parse());
}
$targetTitle = null;
} else {
$targetNameFormula = null;
$targetTitle = Title::newFromText($targetName);
}
$preloadContent = '';
// save $wgRequest for later restoration
$oldRequest = $wgRequest;
// preload data if not explicitly excluded and if the preload page exists
if (!isset($this->mOptions['preload']) || $this->mOptions['preload'] !== false) {
if (!isset($this->mOptions['preload']) || $this->mOptions['preload'] === true) {
$preloadTitle = Title::newFromText($targetName);
} else {
$preloadTitle = Title::newFromText($this->mOptions['preload']);
}
if ($preloadTitle !== null && $preloadTitle->exists()) {
// the content of the page that was specified to be used for preloading
$preloadContent = WikiPage::factory($preloadTitle)->getRawText();
wfRunHooks('sfEditFormPreloadText', array(&$preloadContent, $targetTitle, $formTitle));
$isPageSource = true;
// spoof $wgRequest for SFFormPrinter::formHTML
$wgRequest = new FauxRequest($this->mOptions, true);
// save wgOut for later restoration
$oldOut = $wgOut;
// spoof wgOut; if we took the general $wgOut some JS modules
// might attach themselves twice and thus be called twice
$wgOut = new OutputPage(RequestContext::getMain());
// call SFFormPrinter::formHTML to get at the form html of the existing page
list($formHTML, $formJS, $targetContent, $form_page_title, $generatedTargetNameFormula) = $sfgFormPrinter->formHTML($formContent, $isFormSubmitted, $isPageSource, $formArticleId, $preloadContent, $targetName, $targetNameFormula);
// restore wgOut
$wgOut = $oldOut;
// parse the data to be preloaded from the form html of the
// existing page
$data = $this->parseDataFromHTMLFrag($formHTML);
// and merge/overwrite it with the new data
$this->mOptions = SFUtils::array_merge_recursive_distinct($data, $this->mOptions);
} else {
if (isset($this->mOptions['preload'])) {
$this->logMessage(wfMessage('sf_autoedit_invalidpreloadspecified', $this->mOptions['preload'])->parse(), self::WARNING);
}
}
}
// we already preloaded stuff for saving/previewing, do not do it again
if ($this->mAction === self::ACTION_SAVE || $this->mAction === self::ACTION_PREVIEW) {
$preloadContent = '';
$isPageSource = false;
}
// spoof wgRequest for SFFormPrinter::formHTML
$wgRequest = new FauxRequest($this->mOptions, true);
// get wikitext for submitted data and form
list($formHTML, $formJS, $targetContent, $generatedFormName, $generatedTargetNameFormula) = $sfgFormPrinter->formHTML($formContent, $isFormSubmitted, $isPageSource, $formArticleId, $preloadContent, $targetName, $targetNameFormula);
//.........这里部分代码省略.........