本文整理汇总了PHP中HTMLForm::factory方法的典型用法代码示例。如果您正苦于以下问题:PHP HTMLForm::factory方法的具体用法?PHP HTMLForm::factory怎么用?PHP HTMLForm::factory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTMLForm
的用法示例。
在下文中一共展示了HTMLForm::factory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testForm
/**
* @dataProvider provideValidate
*/
public function testForm($text, $value)
{
$form = HTMLForm::factory('ooui', ['restrictions' => ['class' => HTMLRestrictionsField::class]]);
$request = new FauxRequest(['wprestrictions' => $text], true);
$context = new DerivativeContext(RequestContext::getMain());
$context->setRequest($request);
$form->setContext($context);
$form->setTitle(Title::newFromText('Main Page'))->setSubmitCallback(function () {
return true;
})->prepareForm();
$status = $form->trySubmit();
if ($status instanceof StatusValue) {
$this->assertEquals($value !== false, $status->isGood());
} elseif ($value === false) {
$this->assertNotSame(true, $status);
} else {
$this->assertSame(true, $status);
}
if ($value !== false) {
$restrictions = $form->mFieldData['restrictions'];
$this->assertInstanceOf(MWRestrictions::class, $restrictions);
$this->assertEquals($value, $restrictions->toArray()['IPAddresses']);
}
// sanity
$form->getHTML($status);
}
示例2: execute
public function execute($sub)
{
if (!$this->userCanExecute($this->getUser())) {
$this->displayRestrictionError();
return;
}
$out = $this->getOutput();
$out->addModules('ext.SpellingDictionary.viewByLanguage');
$out->setPageTitle($this->msg('title-view-by-language'));
$out->addWikiMsg('view-by-lang-intro');
// Building a language selector
// Display languages in their native name
$languages = Language::fetchLanguageNames(null, 'mwfile');
ksort($languages);
$options = array();
foreach ($languages as $code => $name) {
$options["{$code} - {$name}"] = $code;
}
$formDescriptor = array('language' => array('type' => 'select', 'label-message' => 'sd-admin-select-language', 'required' => true, 'options' => $options, 'section' => 'section-chooselanguage'));
$form = HTMLForm::factory('ooui', $formDescriptor, $this->getContext());
$form->setId('languageSelectionForm');
$form->setMessagePrefix('view-by-lang');
$form->setSubmitText(wfMessage('sd-admin-view-selected-language')->text());
// Callback function
$form->setSubmitCallback(array($this, 'showSpellings'));
$form->show();
}
示例3: showRequestForm
/**
* Show a nice form for the user to request a confirmation mail
*/
function showRequestForm()
{
$user = $this->getUser();
$out = $this->getOutput();
if (!$user->isEmailConfirmed()) {
$descriptor = array();
if ($user->isEmailConfirmationPending()) {
$descriptor += array('pending' => array('type' => 'info', 'raw' => true, 'default' => "<div class=\"error mw-confirmemail-pending\">\n" . $this->msg('confirmemail_pending')->escaped() . "\n</div>"));
}
$out->addWikiMsg('confirmemail_text');
$form = HTMLForm::factory('ooui', $descriptor, $this->getContext());
$form->setMethod('post')->setAction($this->getPageTitle()->getLocalURL())->setSubmitTextMsg('confirmemail_send')->setSubmitCallback(array($this, 'submitSend'));
$retval = $form->show();
if ($retval === true) {
// should never happen, but if so, don't let the user without any message
$out->addWikiMsg('confirmemail_sent');
} elseif ($retval instanceof Status && $retval->isGood()) {
$out->addWikiText($retval->getValue());
}
} else {
// date and time are separate parameters to facilitate localisation.
// $time is kept for backward compat reasons.
// 'emailauthenticated' is also used in SpecialPreferences.php
$lang = $this->getLanguage();
$emailAuthenticated = $user->getEmailAuthenticationTimestamp();
$time = $lang->userTimeAndDate($emailAuthenticated, $user);
$d = $lang->userDate($emailAuthenticated, $user);
$t = $lang->userTime($emailAuthenticated, $user);
$out->addWikiMsg('emailauthenticated', $time, $d, $t);
}
}
示例4: execute
/**
* Main execution point
*
* @param string $par Title fragment
*/
public function execute($par)
{
$this->setHeaders();
$this->outputHeader();
$out = $this->getOutput();
$lang = $this->getLanguage();
$out->setPageTitle($this->msg('ipblocklist'));
$out->addModuleStyles(['mediawiki.special']);
$request = $this->getRequest();
$par = $request->getVal('ip', $par);
$this->target = trim($request->getVal('wpTarget', $par));
$this->options = $request->getArray('wpOptions', []);
$action = $request->getText('action');
if ($action == 'unblock' || $action == 'submit' && $request->wasPosted()) {
# B/C @since 1.18: Unblock interface is now at Special:Unblock
$title = SpecialPage::getTitleFor('Unblock', $this->target);
$out->redirect($title->getFullURL());
return;
}
# setup BlockListPager here to get the actual default Limit
$pager = $this->getBlockListPager();
# Just show the block list
$fields = ['Target' => ['type' => 'user', 'label-message' => 'ipaddressorusername', 'tabindex' => '1', 'size' => '45', 'default' => $this->target], 'Options' => ['type' => 'multiselect', 'options-messages' => ['blocklist-userblocks' => 'userblocks', 'blocklist-tempblocks' => 'tempblocks', 'blocklist-addressblocks' => 'addressblocks', 'blocklist-rangeblocks' => 'rangeblocks'], 'flatlist' => true], 'Limit' => ['type' => 'limitselect', 'label-message' => 'table_pager_limit_label', 'options' => [$lang->formatNum(20) => 20, $lang->formatNum(50) => 50, $lang->formatNum(100) => 100, $lang->formatNum(250) => 250, $lang->formatNum(500) => 500], 'name' => 'limit', 'default' => $pager->getLimit()]];
$context = new DerivativeContext($this->getContext());
$context->setTitle($this->getPageTitle());
// Remove subpage
$form = HTMLForm::factory('ooui', $fields, $context);
$form->setMethod('get')->setWrapperLegendMsg('ipblocklist-legend')->setSubmitTextMsg('ipblocklist-submit')->setSubmitProgressive()->prepareForm()->displayForm(false);
$this->showList($pager);
}
示例5: getPageHeader
function getPageHeader()
{
# Do not show useless input form if special page is cached
if ($this->isCached()) {
return '';
}
$formDescriptor = ['prefix' => ['label-message' => 'allpagesprefix', 'name' => 'prefix', 'id' => 'wiprefix', 'type' => 'text', 'size' => 20, 'default' => $this->prefix]];
$htmlForm = HTMLForm::factory('ooui', $formDescriptor, $this->getContext());
$htmlForm->setWrapperLegend('')->setSubmitTextMsg('withoutinterwiki-submit')->setMethod('get')->prepareForm()->displayForm(false);
}
示例6: buildForm
protected function buildForm()
{
$formDescriptor = ['like' => ['type' => 'text', 'label-message' => 'newimages-label', 'name' => 'like'], 'showbots' => ['type' => 'check', 'label-message' => 'newimages-showbots', 'name' => 'showbots'], 'hidepatrolled' => ['type' => 'check', 'label-message' => 'newimages-hidepatrolled', 'name' => 'hidepatrolled'], 'limit' => ['type' => 'hidden', 'default' => $this->opts->getValue('limit'), 'name' => 'limit'], 'offset' => ['type' => 'hidden', 'default' => $this->opts->getValue('offset'), 'name' => 'offset']];
if ($this->getConfig()->get('MiserMode')) {
unset($formDescriptor['like']);
}
if (!$this->getUser()->useFilePatrol()) {
unset($formDescriptor['hidepatrolled']);
}
$form = HTMLForm::factory('ooui', $formDescriptor, $this->getContext())->setWrapperLegendMsg('newimages-legend')->setSubmitTextMsg('ilsubmit')->setMethod('get')->prepareForm()->displayForm(false);
}
示例7: execute
public function execute($par)
{
$this->setHeaders();
$this->outputHeader();
$out = $this->getOutput();
$out->allowClickjacking();
$request = $this->getRequest();
$target = $request->getVal('target', $par);
$namespace = $request->getIntOrNull('namespace');
$protocols_list = [];
foreach ($this->getConfig()->get('UrlProtocols') as $prot) {
if ($prot !== '//') {
$protocols_list[] = $prot;
}
}
$target2 = $target;
// Get protocol, default is http://
$protocol = 'http://';
$bits = wfParseUrl($target);
if (isset($bits['scheme']) && isset($bits['delimiter'])) {
$protocol = $bits['scheme'] . $bits['delimiter'];
// Make sure wfParseUrl() didn't make some well-intended correction in the
// protocol
if (strcasecmp($protocol, substr($target, 0, strlen($protocol))) === 0) {
$target2 = substr($target, strlen($protocol));
} else {
// If it did, let LinkFilter::makeLikeArray() handle this
$protocol = '';
}
}
$out->addWikiMsg('linksearch-text', '<nowiki>' . $this->getLanguage()->commaList($protocols_list) . '</nowiki>', count($protocols_list));
$fields = ['target' => ['type' => 'text', 'name' => 'target', 'id' => 'target', 'size' => 50, 'label-message' => 'linksearch-pat', 'default' => $target, 'dir' => 'ltr']];
if (!$this->getConfig()->get('MiserMode')) {
$fields += ['namespace' => ['type' => 'namespaceselect', 'name' => 'namespace', 'label-message' => 'linksearch-ns', 'default' => $namespace, 'id' => 'namespace', 'all' => '', 'cssclass' => 'namespaceselector']];
}
$hiddenFields = ['title' => $this->getPageTitle()->getPrefixedDBkey()];
$htmlForm = HTMLForm::factory('ooui', $fields, $this->getContext());
$htmlForm->addHiddenFields($hiddenFields);
$htmlForm->setSubmitTextMsg('linksearch-ok');
$htmlForm->setWrapperLegendMsg('linksearch');
$htmlForm->setAction(wfScript());
$htmlForm->setMethod('get');
$htmlForm->prepareForm()->displayForm(false);
$this->addHelpLink('Help:Linksearch');
if ($target != '') {
$this->setParams(['query' => Parser::normalizeLinkUrl($target2), 'namespace' => $namespace, 'protocol' => $protocol]);
parent::execute($par);
if ($this->mungedQuery === false) {
$out->addWikiMsg('linksearch-error');
}
}
}
示例8: execute
/**
* Show a form for filtering namespace and username
*
* @param string $par
* @return string
*/
public function execute($par)
{
$this->setHeaders();
$this->outputHeader();
# Form (.mw-searchInput enables suggestions)
$form = HTMLForm::factory('ooui', array('Page1' => array('type' => 'title', 'name' => 'page1', 'label-message' => 'compare-page1', 'size' => '40', 'section' => 'page1', 'validation-callback' => array($this, 'checkExistingTitle')), 'Revision1' => array('type' => 'int', 'name' => 'rev1', 'label-message' => 'compare-rev1', 'size' => '8', 'section' => 'page1', 'validation-callback' => array($this, 'checkExistingRevision')), 'Page2' => array('type' => 'title', 'name' => 'page2', 'label-message' => 'compare-page2', 'size' => '40', 'section' => 'page2', 'validation-callback' => array($this, 'checkExistingTitle')), 'Revision2' => array('type' => 'int', 'name' => 'rev2', 'label-message' => 'compare-rev2', 'size' => '8', 'section' => 'page2', 'validation-callback' => array($this, 'checkExistingRevision')), 'Action' => array('type' => 'hidden', 'name' => 'action'), 'Diffonly' => array('type' => 'hidden', 'name' => 'diffonly'), 'Unhide' => array('type' => 'hidden', 'name' => 'unhide')), $this->getContext(), 'compare');
$form->setSubmitTextMsg('compare-submit');
$form->suppressReset();
$form->setMethod('get');
$form->setSubmitCallback(array(__CLASS__, 'showDiff'));
$form->loadData();
$form->displayForm('');
$form->trySubmit();
}
示例9: execute
/**
* Show a form for filtering namespace and username
*
* @param string $par
* @return string
*/
public function execute($par)
{
$this->setHeaders();
$this->outputHeader();
$this->getOutput()->addModuleStyles('mediawiki.special.comparepages.styles');
$form = HTMLForm::factory('ooui', ['Page1' => ['type' => 'title', 'name' => 'page1', 'label-message' => 'compare-page1', 'size' => '40', 'section' => 'page1', 'validation-callback' => [$this, 'checkExistingTitle']], 'Revision1' => ['type' => 'int', 'name' => 'rev1', 'label-message' => 'compare-rev1', 'size' => '8', 'section' => 'page1', 'validation-callback' => [$this, 'checkExistingRevision']], 'Page2' => ['type' => 'title', 'name' => 'page2', 'label-message' => 'compare-page2', 'size' => '40', 'section' => 'page2', 'validation-callback' => [$this, 'checkExistingTitle']], 'Revision2' => ['type' => 'int', 'name' => 'rev2', 'label-message' => 'compare-rev2', 'size' => '8', 'section' => 'page2', 'validation-callback' => [$this, 'checkExistingRevision']], 'Action' => ['type' => 'hidden', 'name' => 'action'], 'Diffonly' => ['type' => 'hidden', 'name' => 'diffonly'], 'Unhide' => ['type' => 'hidden', 'name' => 'unhide']], $this->getContext(), 'compare');
$form->setSubmitTextMsg('compare-submit');
$form->suppressReset();
$form->setMethod('get');
$form->setSubmitCallback([__CLASS__, 'showDiff']);
$form->loadData();
$form->displayForm('');
$form->trySubmit();
}
示例10: execute
public function execute($par)
{
$this->setHeaders();
$this->outputHeader();
$this->getOutput()->addModuleStyles('mediawiki.special.pagesWithProp');
$request = $this->getRequest();
$propname = $request->getVal('propname', $par);
$propnames = $this->getExistingPropNames();
$form = HTMLForm::factory('ooui', ['propname' => ['type' => 'combobox', 'name' => 'propname', 'options' => $propnames, 'default' => $propname, 'label-message' => 'pageswithprop-prop', 'required' => true]], $this->getContext());
$form->setMethod('get');
$form->setSubmitCallback([$this, 'onSubmit']);
$form->setWrapperLegendMsg('pageswithprop-legend');
$form->addHeaderText($this->msg('pageswithprop-text')->parseAsBlock());
$form->setSubmitTextMsg('pageswithprop-submit');
$form->prepareForm();
$form->displayForm(false);
if ($propname !== '' && $propname !== null) {
$form->trySubmit();
}
}
示例11: showWikiForm
function showWikiForm($wiki)
{
$out = $this->getOutput();
$wiki = $this->lookupWikiDetails($wiki);
if (!$wiki) {
$out->addHTML('<div class="errorbox">' . wfMessage('managewiki-missing')->escaped() . '</div>');
return false;
}
if (!$this->getRequest()->wasPosted()) {
$out->addWikiMsg('managewiki-header', $wiki->wiki_dbname);
}
$languages = Language::fetchLanguageNames(null, 'mwfile');
ksort($languages);
$options = array();
foreach ($languages as $code => $name) {
$options["{$code} - {$name}"] = $code;
}
$formDescriptor = array('dbname' => array('label-message' => 'managewiki-label-dbname', 'type' => 'text', 'size' => 20, 'default' => $wiki->wiki_dbname, 'disabled' => true, 'name' => 'mwDBname'), 'sitename' => array('label-message' => 'managewiki-label-sitename', 'type' => 'text', 'size' => 20, 'default' => $wiki->wiki_sitename, 'required' => true, 'name' => 'mwSitename'), 'language' => array('label-message' => 'managewiki-label-language', 'type' => 'select', 'default' => $wiki->wiki_language, 'options' => $options, 'name' => 'mwLanguage'), 'closed' => array('type' => 'check', 'label-message' => 'managewiki-label-closed', 'name' => 'cwClosed', 'default' => $wiki->wiki_closed == 1 ? 1 : 0), 'private' => array('type' => 'check', 'label-message' => 'managewiki-label-private', 'name' => 'cwPrivate', 'disabled' => !$this->getUser()->isAllowed('managewiki-restricted'), 'default' => $wiki->wiki_private == 1 ? 1 : 0), 'reason' => array('label-message' => 'managewiki-label-reason', 'type' => 'text', 'size' => 45, 'required' => true));
$htmlForm = HTMLForm::factory('ooui', $formDescriptor, $this->getContext(), 'changeForm');
$htmlForm->setMethod('post')->setSubmitCallback(array($this, 'onSubmitInput'))->prepareForm()->show();
}
示例12: execute
/**
* Show the special page
*
* @param string $par Parameter passed to the page or null
*/
public function execute($par)
{
$out = $this->getOutput();
$this->setHeaders();
$this->outputHeader();
$opts = new FormOptions();
$opts->add('username', '');
$opts->add('hidebots', false, FormOptions::BOOL);
$opts->add('hidesysops', false, FormOptions::BOOL);
$opts->fetchValuesFromRequest($this->getRequest());
if ($par !== null) {
$opts->setValue('username', $par);
}
// Mention the level of cache staleness...
$cacheText = '';
$dbr = wfGetDB(DB_SLAVE, 'recentchanges');
$rcMax = $dbr->selectField('recentchanges', 'MAX(rc_timestamp)', '', __METHOD__);
if ($rcMax) {
$cTime = $dbr->selectField('querycache_info', 'qci_timestamp', ['qci_type' => 'activeusers'], __METHOD__);
if ($cTime) {
$secondsOld = wfTimestamp(TS_UNIX, $rcMax) - wfTimestamp(TS_UNIX, $cTime);
} else {
$rcMin = $dbr->selectField('recentchanges', 'MIN(rc_timestamp)');
$secondsOld = time() - wfTimestamp(TS_UNIX, $rcMin);
}
if ($secondsOld > 0) {
$cacheTxt = '<br>' . $this->msg('cachedspecial-viewing-cached-ttl')->durationParams($secondsOld);
}
}
$pager = new ActiveUsersPager($this->getContext(), $opts);
$usersBody = $pager->getBody();
$days = $this->getConfig()->get('ActiveUserDays');
$formDescriptor = ['username' => ['type' => 'user', 'name' => 'username', 'label-message' => 'activeusers-from'], 'hidebots' => ['type' => 'check', 'name' => 'hidebots', 'label-message' => 'activeusers-hidebots', 'default' => false], 'hidesysops' => ['type' => 'check', 'name' => 'hidesysops', 'label-message' => 'activeusers-hidesysops', 'default' => false]];
$htmlForm = HTMLForm::factory('ooui', $formDescriptor, $this->getContext())->setIntro($this->msg('activeusers-intro')->numParams($days) . $cacheText)->setWrapperLegendMsg('activeusers')->setSubmitTextMsg('activeusers-submit')->setMethod('get')->prepareForm()->displayForm(false);
if ($usersBody) {
$out->addHTML($pager->getNavigationBar() . Html::rawElement('ul', [], $usersBody) . $pager->getNavigationBar());
} else {
$out->addWikiMsg('activeusers-noresult');
}
}
示例13: execute
/**
* Shows the page to the user.
* @param string $sub: The subpage string argument (if any).
* [[Special:SpellingDictionary/subpage]].
*/
public function execute($sub)
{
$out = $this->getOutput();
$out->setPageTitle($this->msg('title-special'));
// Parses message from .i18n.php as wikitext and adds it to the
// page output.
$out->addWikiMsg('intro-paragraph');
// Building a language selector
// Display languages in their native name
$languages = Language::fetchLanguageNames(null, 'mwfile');
ksort($languages);
$options = array();
foreach ($languages as $code => $name) {
$options["{$code} - {$name}"] = $code;
}
$formDescriptor = array('word' => array('type' => 'text', 'label-message' => 'spell-dict-word', 'required' => true), 'language' => array('type' => 'select', 'label-message' => 'spell-dict-language', 'required' => true, 'options' => $options));
$form = HTMLForm::factory('vform', $formDescriptor, $this->getContext());
$form->setSubmitText(wfMessage('add-word-form-submit')->text());
//Callback function
$form->setSubmitCallback(array('SpecialSpellingDictionary', 'store'));
$form->show();
}
示例14: getAuthForm
/**
* Generates a form from the given request.
* @param AuthenticationRequest[] $requests
* @param string $action AuthManager action name
* @param string|Message $msg
* @param string $msgType
* @return HTMLForm
*/
protected function getAuthForm(array $requests, $action, $msg = '', $msgType = 'error')
{
global $wgSecureLogin, $wgLoginLanguageSelector;
// FIXME merge this with parent
if (isset($this->authForm)) {
return $this->authForm;
}
$usingHTTPS = $this->getRequest()->getProtocol() === 'https';
// get basic form description from the auth logic
$fieldInfo = AuthenticationRequest::mergeFieldInfo($requests);
$fakeTemplate = $this->getFakeTemplate($msg, $msgType);
$this->fakeTemplate = $fakeTemplate;
// FIXME there should be a saner way to pass this to the hook
// this will call onAuthChangeFormFields()
$formDescriptor = static::fieldInfoToFormDescriptor($requests, $fieldInfo, $this->authAction);
$this->postProcessFormDescriptor($formDescriptor, $requests);
$context = $this->getContext();
if ($context->getRequest() !== $this->getRequest()) {
// We have overridden the request, need to make sure the form uses that too.
$context = new DerivativeContext($this->getContext());
$context->setRequest($this->getRequest());
}
$form = HTMLForm::factory('vform', $formDescriptor, $context);
$form->addHiddenField('authAction', $this->authAction);
if ($wgLoginLanguageSelector) {
$form->addHiddenField('uselang', $this->mLanguage);
}
$form->addHiddenField('force', $this->securityLevel);
$form->addHiddenField($this->getTokenName(), $this->getToken()->toString());
if ($wgSecureLogin) {
// If using HTTPS coming from HTTP, then the 'fromhttp' parameter must be preserved
if (!$this->isSignup()) {
$form->addHiddenField('wpForceHttps', (int) $this->mStickHTTPS);
$form->addHiddenField('wpFromhttp', $usingHTTPS);
}
}
// set properties of the form itself
$form->setAction($this->getPageTitle()->getLocalURL($this->getReturnToQueryStringFragment()));
$form->setName('userlogin' . ($this->isSignup() ? '2' : ''));
if ($this->isSignup()) {
$form->setId('userlogin2');
}
$form->suppressDefaultSubmit();
$this->authForm = $form;
return $form;
}
示例15: makeForm
/**
* Generate a form allowing users to enter information
*
* @param string $title Value for context title field
* @param string $input Value for input textbox
* @return string
*/
private function makeForm($title, $input)
{
$fields = ['contexttitle' => ['type' => 'text', 'label' => $this->msg('expand_templates_title')->plain(), 'name' => 'wpContextTitle', 'id' => 'contexttitle', 'size' => 60, 'default' => $title, 'autofocus' => true, 'cssclass' => 'mw-ui-input-inline'], 'input' => ['type' => 'textarea', 'name' => 'wpInput', 'label' => $this->msg('expand_templates_input')->text(), 'rows' => 10, 'default' => $input, 'id' => 'input'], 'removecomments' => ['type' => 'check', 'label' => $this->msg('expand_templates_remove_comments')->text(), 'name' => 'wpRemoveComments', 'id' => 'removecomments', 'default' => $this->removeComments], 'removenowiki' => ['type' => 'check', 'label' => $this->msg('expand_templates_remove_nowiki')->text(), 'name' => 'wpRemoveNowiki', 'id' => 'removenowiki', 'default' => $this->removeNowiki], 'generate_xml' => ['type' => 'check', 'label' => $this->msg('expand_templates_generate_xml')->text(), 'name' => 'wpGenerateXml', 'id' => 'generate_xml', 'default' => $this->generateXML], 'generate_rawhtml' => ['type' => 'check', 'label' => $this->msg('expand_templates_generate_rawhtml')->text(), 'name' => 'wpGenerateRawHtml', 'id' => 'generate_rawhtml', 'default' => $this->generateRawHtml]];
$form = HTMLForm::factory('ooui', $fields, $this->getContext());
$form->setSubmitTextMsg('expand_templates_ok')->setWrapperLegendMsg('expandtemplates')->setHeaderText($this->msg('expand_templates_intro')->parse())->setSubmitCallback([$this, 'onSubmitInput'])->showAlways();
}