/** * @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); }
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(); }
/** * 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); } }
/** * 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); }
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); }
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); }
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'); } } }
/** * 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(); }
/** * 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(); }
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(); } }
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(); }
/** * 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'); } }
/** * 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(); }
/** * 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; }
/** * 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(); }
private function showHistory() { # List all stored revisions $revisions = new MergeHistoryPager($this, [], $this->mTargetObj, $this->mDestObj); $haveRevisions = $revisions && $revisions->getNumRows() > 0; $out = $this->getOutput(); $header = '<h2 id="mw-mergehistory">' . $this->msg('mergehistory-list')->escaped() . "</h2>\n"; if ($haveRevisions) { $hiddenFields = ['merge' => true, 'target' => $this->mOpts->getValue('target'), 'dest' => $this->mOpts->getValue('dest')]; $formDescriptor = ['reason' => ['type' => 'text', 'name' => 'reason', 'label-message' => 'mergehistory-reason']]; $mergeText = $this->msg('mergehistory-merge', $this->mTargetObj->getPrefixedText(), $this->mDestObj->getPrefixedText())->parse(); $history = $header . $revisions->getNavigationBar() . '<ul>' . $revisions->getBody() . '</ul>' . $revisions->getNavigationBar(); $form = HTMLForm::factory('ooui', $formDescriptor, $this->getContext())->addHiddenFields($hiddenFields)->setPreText($mergeText)->setFooterText($history)->setSubmitTextMsg('mergehistory-submit')->setMethod('post')->prepareForm()->displayForm(false); } else { $out->addHTML($header); $out->addWikiMsg('mergehistory-empty'); } # Show relevant lines from the merge log: $mergeLogPage = new LogPage('merge'); $out->addHTML('<h2>' . $mergeLogPage->getName()->escaped() . "</h2>\n"); LogEventsList::showLogExtract($out, 'merge', $this->mTargetObj); }
public function execute($par) { $this->setHeaders(); $this->outputHeader(); $config = $this->getConfig(); // Set some variables $this->curonly = true; $this->doExport = false; $request = $this->getRequest(); $this->templates = $request->getCheck('templates'); $this->pageLinkDepth = $this->validateLinkDepth($request->getIntOrNull('pagelink-depth')); $nsindex = ''; $exportall = false; if ($request->getCheck('addcat')) { $page = $request->getText('pages'); $catname = $request->getText('catname'); if ($catname !== '' && $catname !== null && $catname !== false) { $t = Title::makeTitleSafe(NS_MAIN, $catname); if ($t) { /** * @todo FIXME: This can lead to hitting memory limit for very large * categories. Ideally we would do the lookup synchronously * during the export in a single query. */ $catpages = $this->getPagesFromCategory($t); if ($catpages) { if ($page !== '') { $page .= "\n"; } $page .= implode("\n", $catpages); } } } } elseif ($request->getCheck('addns') && $config->get('ExportFromNamespaces')) { $page = $request->getText('pages'); $nsindex = $request->getText('nsindex', ''); if (strval($nsindex) !== '') { /** * Same implementation as above, so same @todo */ $nspages = $this->getPagesFromNamespace($nsindex); if ($nspages) { $page .= "\n" . implode("\n", $nspages); } } } elseif ($request->getCheck('exportall') && $config->get('ExportAllowAll')) { $this->doExport = true; $exportall = true; /* Although $page and $history are not used later on, we nevertheless set them to avoid that PHP notices about using undefined variables foul up our XML output (see call to doExport(...) further down) */ $page = ''; $history = ''; } elseif ($request->wasPosted() && $par == '') { $page = $request->getText('pages'); $this->curonly = $request->getCheck('curonly'); $rawOffset = $request->getVal('offset'); if ($rawOffset) { $offset = wfTimestamp(TS_MW, $rawOffset); } else { $offset = null; } $maxHistory = $config->get('ExportMaxHistory'); $limit = $request->getInt('limit'); $dir = $request->getVal('dir'); $history = array('dir' => 'asc', 'offset' => false, 'limit' => $maxHistory); $historyCheck = $request->getCheck('history'); if ($this->curonly) { $history = WikiExporter::CURRENT; } elseif (!$historyCheck) { if ($limit > 0 && ($maxHistory == 0 || $limit < $maxHistory)) { $history['limit'] = $limit; } if (!is_null($offset)) { $history['offset'] = $offset; } if (strtolower($dir) == 'desc') { $history['dir'] = 'desc'; } } if ($page != '') { $this->doExport = true; } } else { // Default to current-only for GET requests. $page = $request->getText('pages', $par); $historyCheck = $request->getCheck('history'); if ($historyCheck) { $history = WikiExporter::FULL; } else { $history = WikiExporter::CURRENT; } if ($page != '') { $this->doExport = true; } } if (!$config->get('ExportAllowHistory')) { // Override $history = WikiExporter::CURRENT; } $list_authors = $request->getCheck('listauthors'); if (!$this->curonly || !$config->get('ExportAllowListContributors')) { $list_authors = false; } if ($this->doExport) { $this->getOutput()->disable(); // Cancel output buffering and gzipping if set // This should provide safer streaming for pages with history wfResetOutputBuffers(); $request->response()->header("Content-type: application/xml; charset=utf-8"); if ($request->getCheck('wpDownload')) { // Provide a sane filename suggestion $filename = urlencode($config->get('Sitename') . '-' . wfTimestampNow() . '.xml'); $request->response()->header("Content-disposition: attachment;filename={$filename}"); } $this->doExport($page, $history, $list_authors, $exportall); return; } $out = $this->getOutput(); $out->addWikiMsg('exporttext'); if ($page == '') { $categoryName = $request->getText('catname'); } else { $categoryName = ''; } $formDescriptor = array('catname' => array('type' => 'textwithbutton', 'name' => 'catname', 'horizontal-label' => true, 'label-message' => 'export-addcattext', 'default' => $categoryName, 'size' => 40, 'buttontype' => 'submit', 'buttonname' => 'addcat', 'buttondefault' => $this->msg('export-addcat')->text())); if ($config->get('ExportFromNamespaces')) { $formDescriptor += array('nsindex' => array('type' => 'namespaceselectwithbutton', 'default' => $nsindex, 'label-message' => 'export-addnstext', 'horizontal-label' => true, 'name' => 'nsindex', 'id' => 'namespace', 'cssclass' => 'namespaceselector', 'buttontype' => 'submit', 'buttonname' => 'addns', 'buttondefault' => $this->msg('export-addns')->text())); } if ($config->get('ExportAllowAll')) { $formDescriptor += array('exportall' => array('type' => 'check', 'label-message' => 'exportall', 'name' => 'exportall', 'id' => 'exportall', 'default' => $request->wasPosted() ? $request->getCheck('exportall') : false)); } $formDescriptor += array('textarea' => array('class' => 'HTMLTextAreaField', 'name' => 'pages', 'nodata' => true, 'cols' => 40, 'rows' => 10, 'default' => $page)); if ($config->get('ExportAllowHistory')) { $formDescriptor += array('curonly' => array('type' => 'check', 'label-message' => 'exportcuronly', 'name' => 'curonly', 'id' => 'curonly', 'default' => $request->wasPosted() ? $request->getCheck('curonly') : true)); } else { $out->addWikiMsg('exportnohistory'); } $formDescriptor += array('templates' => array('type' => 'check', 'label-message' => 'export-templates', 'name' => 'templates', 'id' => 'wpExportTemplates', 'default' => $request->wasPosted() ? $request->getCheck('templates') : false)); if ($config->get('ExportMaxLinkDepth') || $this->userCanOverrideExportDepth()) { $formDescriptor += array('pagelink-depth' => array('type' => 'text', 'name' => 'pagelink-depth', 'id' => 'pagelink-depth', 'label-message' => 'export-pagelinks', 'default' => '0', 'size' => 20)); } $formDescriptor += array('wpDownload' => array('type' => 'check', 'name' => 'wpDownload', 'id' => 'wpDownload', 'default' => $request->wasPosted() ? $request->getCheck('wpDownload') : true, 'label-message' => 'export-download')); if ($config->get('ExportAllowListContributors')) { $formDescriptor += array('listauthors' => array('type' => 'check', 'label-message' => 'exportlistauthors', 'default' => $request->wasPosted() ? $request->getCheck('listauthors') : false, 'name' => 'listauthors', 'id' => 'listauthors')); } $htmlForm = HTMLForm::factory('div', $formDescriptor, $this->getContext()); $htmlForm->setSubmitTextMsg('export-submit'); $htmlForm->prepareForm()->displayForm(false); $this->addHelpLink('Help:Export'); }
public function sendEmailForm() { $out = $this->getOutput(); $ret = $this->mTargetObj; if (!$ret instanceof User) { if ($this->mTarget != '') { // Messages used here: notargettext, noemailtext, nowikiemailtext $ret = $ret == 'notarget' ? 'emailnotarget' : $ret . 'text'; return Status::newFatal($ret); } return false; } $context = new DerivativeContext($this->getContext()); $context->setTitle($this->getPageTitle()); // Remove subpage $form = HTMLForm::factory('ooui', $this->getFormFields(), $context); // By now we are supposed to be sure that $this->mTarget is a user name $form->addPreText($this->msg('emailpagetext', $this->mTarget)->parse()); $form->setSubmitTextMsg('emailsend'); $form->setSubmitCallback(array(__CLASS__, 'uiSubmit')); $form->setWrapperLegendMsg('email-legend'); $form->loadData(); if (!Hooks::run('EmailUserForm', array(&$form))) { return false; } $result = $form->show(); if ($result === true || $result instanceof Status && $result->isGood()) { $out->setPageTitle($this->msg('emailsent')); $out->addWikiMsg('emailsenttext', $this->mTarget); $out->returnToMain(false, $ret->getUserPage()); } return true; }
/** * Get the HTMLForm to control behavior * @return HTMLForm|null */ protected function getForm() { $form = HTMLForm::factory($this->getDisplayFormat(), $this->getFormFields(), $this->getContext(), $this->getMessagePrefix()); $form->setSubmitCallback(array($this, 'onSubmit')); if ($this->getDisplayFormat() !== 'ooui') { // No legend and wrapper by default in OOUI forms, but can be set manually // from alterForm() $form->setWrapperLegendMsg($this->getMessagePrefix() . '-legend'); } $headerMsg = $this->msg($this->getMessagePrefix() . '-text'); if (!$headerMsg->isDisabled()) { $form->addHeaderText($headerMsg->parseAsBlock()); } // Retain query parameters (uselang etc) $params = array_diff_key($this->getRequest()->getQueryValues(), array('title' => null)); $form->addHiddenField('redirectparams', wfArrayToCgi($params)); $form->addPreText($this->preText()); $form->addPostText($this->postText()); $this->alterForm($form); // Give hooks a chance to alter the form, adding extra fields or text etc Hooks::run('SpecialPageBeforeFormDisplay', array($this->getName(), &$form)); return $form; }
/** * Generate a form to allow users to enter an ISBN * * @param string $isbn */ private function buildForm($isbn) { $formDescriptor = ['isbn' => ['type' => 'text', 'name' => 'isbn', 'label-message' => 'booksources-isbn', 'default' => $isbn, 'autofocus' => true, 'required' => true]]; $context = new DerivativeContext($this->getContext()); $context->setTitle($this->getPageTitle()); HTMLForm::factory('ooui', $formDescriptor, $context)->setWrapperLegendMsg('booksources-search-legend')->setSubmitTextMsg('booksources-search')->setMethod('get')->prepareForm()->displayForm(false); }
/** * @param AuthenticationRequest[] $requests * @param string $action AuthManager action name (one of the AuthManager::ACTION_* constants) * @return HTMLForm */ protected function getAuthForm(array $requests, $action) { $formDescriptor = $this->getAuthFormDescriptor($requests, $action); $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('ooui', $formDescriptor, $context); $form->setAction($this->getFullTitle()->getFullURL($this->getPreservedParams())); $form->addHiddenField($this->getTokenName(), $this->getToken()->toString()); $form->addHiddenField('authAction', $this->authAction); $form->suppressDefaultSubmit(!$this->needsSubmitButton($formDescriptor)); return $form; }
/** * Generate and output the form */ function getPageHeader() { $formDescriptor = ['mime' => ['type' => 'text', 'name' => 'mime', 'label-message' => 'mimetype', 'required' => true, 'default' => $this->mime]]; $form = HTMLForm::factory('ooui', $formDescriptor, $this->getContext())->setWrapperLegendMsg('mimesearch')->setSubmitTextMsg('ilsubmit')->setAction($this->getPageTitle()->getLocalURL())->setMethod('get')->prepareForm()->displayForm(false); }
public function execute($par) { $this->setHeaders(); $this->outputHeader(); $this->filename = $par !== null ? $par : $this->getRequest()->getText('filename'); $this->file = null; $this->hash = ''; $title = Title::newFromText($this->filename, NS_FILE); if ($title && $title->getText() != '') { $this->file = wfFindFile($title); } $out = $this->getOutput(); # Create the input form $formFields = ['filename' => ['type' => 'text', 'name' => 'filename', 'label-message' => 'fileduplicatesearch-filename', 'id' => 'filename', 'size' => 50, 'value' => $this->filename]]; $hiddenFields = ['title' => $this->getPageTitle()->getPrefixedDBkey()]; $htmlForm = HTMLForm::factory('ooui', $formFields, $this->getContext()); $htmlForm->addHiddenFields($hiddenFields); $htmlForm->setAction(wfScript()); $htmlForm->setMethod('get'); $htmlForm->setSubmitProgressive(); $htmlForm->setSubmitTextMsg($this->msg('fileduplicatesearch-submit')); // The form should be visible always, even if it was submitted (e.g. to perform another action). // To bypass the callback validation of HTMLForm, use prepareForm() and displayForm(). $htmlForm->prepareForm()->displayForm(false); if ($this->file) { $this->hash = $this->file->getSha1(); } elseif ($this->filename !== '') { $out->wrapWikiMsg("<p class='mw-fileduplicatesearch-noresults'>\n\$1\n</p>", ['fileduplicatesearch-noresults', wfEscapeWikiText($this->filename)]); } if ($this->hash != '') { # Show a thumbnail of the file $img = $this->file; if ($img) { $thumb = $img->transform(['width' => 120, 'height' => 120]); if ($thumb) { $out->addModuleStyles('mediawiki.special'); $out->addHTML('<div id="mw-fileduplicatesearch-icon">' . $thumb->toHtml(['desc-link' => false]) . '<br />' . $this->msg('fileduplicatesearch-info')->numParams($img->getWidth(), $img->getHeight())->params($this->getLanguage()->formatSize($img->getSize()), $img->getMimeType())->parseAsBlock() . '</div>'); } } $dupes = $this->getDupes(); $numRows = count($dupes); # Show a short summary if ($numRows == 1) { $out->wrapWikiMsg("<p class='mw-fileduplicatesearch-result-1'>\n\$1\n</p>", ['fileduplicatesearch-result-1', wfEscapeWikiText($this->filename)]); } elseif ($numRows) { $out->wrapWikiMsg("<p class='mw-fileduplicatesearch-result-n'>\n\$1\n</p>", ['fileduplicatesearch-result-n', wfEscapeWikiText($this->filename), $this->getLanguage()->formatNum($numRows - 1)]); } $this->doBatchLookups($dupes); $this->showList($dupes); } }
/** * Outputs the HTMLForm used on this page * * @param int $namespace A namespace constant (default NS_MAIN). * @param string $from DbKey we are starting listing at. * @param string $to DbKey we are ending listing at. * @param bool $hideRedirects Dont show redirects (default false) */ protected function outputHTMLForm($namespace = NS_MAIN, $from = '', $to = '', $hideRedirects = false) { $fields = array('from' => array('type' => 'text', 'name' => 'from', 'id' => 'nsfrom', 'size' => 30, 'label-message' => 'allpagesfrom', 'default' => str_replace('_', ' ', $from)), 'to' => array('type' => 'text', 'name' => 'to', 'id' => 'nsto', 'size' => 30, 'label-message' => 'allpagesto', 'default' => str_replace('_', ' ', $to)), 'namespace' => array('type' => 'namespaceselect', 'name' => 'namespace', 'id' => 'namespace', 'label-message' => 'namespace', 'all' => null, 'value' => $namespace), 'hideredirects' => array('type' => 'check', 'name' => 'hideredirects', 'id' => 'hidredirects', 'label-message' => 'allpages-hide-redirects', 'value' => $hideRedirects)); $form = HTMLForm::factory('table', $fields, $this->getContext()); $form->setMethod('get')->setWrapperLegendMsg('allpages')->setSubmitTextMsg('allpagessubmit')->prepareForm()->displayForm(false); }
/** * 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); $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'); } // add pre/post text // header used by ConfirmEdit, CondfirmAccount, Persona, WikimediaIncubator, SemanticSignup // should be above the error message but HTMLForm doesn't support that $form->addHeaderText($fakeTemplate->html('header')); // FIXME the old form used this for error/warning messages which does not play well with // HTMLForm (maybe it could with a subclass?); for now only display it for signups // (where the JS username validation needs it) and alway empty if ($this->isSignup()) { // used by the mediawiki.special.userlogin.signup.js module $statusAreaAttribs = ['id' => 'mw-createacct-status-area']; // $statusAreaAttribs += $msg ? [ 'class' => "{$msgType}box" ] : [ 'style' => 'display: none;' ]; $form->addHeaderText(Html::element('div', $statusAreaAttribs)); } // header used by MobileFrontend $form->addHeaderText($fakeTemplate->html('formheader')); // blank signup footer for site customization if ($this->isSignup() && $this->showExtraInformation()) { // Use signupend-https for HTTPS requests if it's not blank, signupend otherwise $signupendMsg = $this->msg('signupend'); $signupendHttpsMsg = $this->msg('signupend-https'); if (!$signupendMsg->isDisabled()) { $signupendText = $usingHTTPS && !$signupendHttpsMsg->isBlank() ? $signupendHttpsMsg->parse() : $signupendMsg->parse(); $form->addPostText(Html::rawElement('div', ['id' => 'signupend'], $signupendText)); } } // warning header for non-standard workflows (e.g. security reauthentication) if (!$this->isSignup() && $this->getUser()->isLoggedIn()) { $reauthMessage = $this->securityLevel ? 'userlogin-reauth' : 'userlogin-loggedin'; $form->addHeaderText(Html::rawElement('div', ['class' => 'warningbox'], $this->msg($reauthMessage)->params($this->getUser()->getName())->parse())); } if (!$this->isSignup() && $this->showExtraInformation()) { $passwordReset = new PasswordReset($this->getConfig(), AuthManager::singleton()); if ($passwordReset->isAllowed($this->getUser())) { $form->addFooterText(Html::rawElement('div', ['class' => 'mw-ui-vform-field mw-form-related-link-container'], Linker::link(SpecialPage::getTitleFor('PasswordReset'), $this->msg('userlogin-resetpassword-link')->escaped()))); } // Don't show a "create account" link if the user can't. if ($this->showCreateAccountLink()) { // link to the other action $linkTitle = $this->getTitleFor($this->isSignup() ? 'Userlogin' : 'CreateAccount'); $linkq = $this->getReturnToQueryStringFragment(); // Pass any language selection on to the mode switch link if ($wgLoginLanguageSelector && $this->mLanguage) { $linkq .= '&uselang=' . $this->mLanguage; } $createOrLoginHref = $linkTitle->getLocalURL($linkq); if ($this->getUser()->isLoggedIn()) { $createOrLoginHtml = Html::rawElement('div', ['class' => 'mw-ui-vform-field'], Html::element('a', ['id' => 'mw-createaccount-join', 'href' => $createOrLoginHref, 'tabindex' => 100], $this->msg('userlogin-createanother')->escaped())); } else { $createOrLoginHtml = Html::rawElement('div', ['id' => 'mw-createaccount-cta', 'class' => 'mw-ui-vform-field'], $this->msg('userlogin-noaccount')->escaped() . Html::element('a', ['id' => 'mw-createaccount-join', 'href' => $createOrLoginHref, 'class' => 'mw-ui-button', 'tabindex' => 100], $this->msg('userlogin-joinproject')->escaped())); } $form->addFooterText($createOrLoginHtml); } } $form->suppressDefaultSubmit(); $this->authForm = $form; return $form; }
/** * Default action when we don't have a subpage -- just show links to the uploads we have, * Also show a button to clear stashed files * @return bool */ private function showUploads() { // sets the title, etc. $this->setHeaders(); $this->outputHeader(); // create the form, which will also be used to execute a callback to process incoming form data // this design is extremely dubious, but supposedly HTMLForm is our standard now? $context = new DerivativeContext($this->getContext()); $context->setTitle($this->getPageTitle()); // Remove subpage $form = HTMLForm::factory('ooui', ['Clear' => ['type' => 'hidden', 'default' => true, 'name' => 'clear']], $context, 'clearStashedUploads'); $form->setSubmitDestructive(); $form->setSubmitCallback([__CLASS__, 'tryClearStashedUploads']); $form->setSubmitTextMsg('uploadstash-clear'); $form->prepareForm(); $formResult = $form->tryAuthorizedSubmit(); // show the files + form, if there are any, or just say there are none $refreshHtml = Html::element('a', ['href' => $this->getPageTitle()->getLocalURL()], $this->msg('uploadstash-refresh')->text()); $files = $this->stash->listFiles(); if ($files && count($files)) { sort($files); $fileListItemsHtml = ''; $linkRenderer = $this->getLinkRenderer(); foreach ($files as $file) { $itemHtml = $linkRenderer->makeKnownLink($this->getPageTitle("file/{$file}"), $file); try { $fileObj = $this->stash->getFile($file); $thumb = $fileObj->generateThumbName($file, ['width' => 220]); $itemHtml .= $this->msg('word-separator')->escaped() . $this->msg('parentheses')->rawParams($linkRenderer->makeKnownLink($this->getPageTitle("thumb/{$file}/{$thumb}"), $this->msg('uploadstash-thumbnail')->text()))->escaped(); } catch (Exception $e) { } $fileListItemsHtml .= Html::rawElement('li', [], $itemHtml); } $this->getOutput()->addHTML(Html::rawElement('ul', [], $fileListItemsHtml)); $form->displayForm($formResult); $this->getOutput()->addHTML(Html::rawElement('p', [], $refreshHtml)); } else { $this->getOutput()->addHTML(Html::rawElement('p', [], Html::element('span', [], $this->msg('uploadstash-nofiles')->text()) . ' ' . $refreshHtml)); } return true; }
/** * Display form for approving/denying request or process form submission. * * @param GlobalRenameRequest $req Pending request */ protected function doShowProcessForm(GlobalRenameRequest $req) { $this->commonPreamble('globalrenamequeue-request-title', array($req->getName())); $form = HTMLForm::factory('vform', array('rid' => array('default' => $req->getId(), 'name' => 'rid', 'type' => 'hidden'), 'comments' => array('default' => $this->getRequest()->getVal('comments'), 'id' => 'mw-renamequeue-comments', 'label-message' => 'globalrenamequeue-request-comments-label', 'name' => 'comments', 'type' => 'textarea', 'rows' => 5), 'reason' => array('id' => 'mw-renamequeue-reason', 'label-message' => 'globalrenamequeue-request-reason-label', 'name' => 'reason', 'type' => 'text'), 'movepages' => array('id' => 'mw-renamequeue-movepages', 'name' => 'movepages', 'label-message' => 'globalrenamequeue-request-movepages', 'type' => 'check', 'default' => 1), 'suppressredirects' => array('id' => 'mw-renamequeue-suppressredirects', 'name' => 'suppressredirects', 'label-message' => 'globalrenamequeue-request-suppressredirects', 'type' => 'check')), $this->getContext(), 'globalrenamequeue'); $form->suppressDefaultSubmit(); $form->addButton('approve', $this->msg('globalrenamequeue-request-approve-text')->text(), 'mw-renamequeue-approve', array('class' => 'mw-ui-constructive mw-ui-flush-right')); $form->addButton('deny', $this->msg('globalrenamequeue-request-deny-text')->text(), 'mw-renamequeue-deny', array('class' => 'mw-ui-destructive mw-ui-flush-right')); $form->addButton('cancel', $this->msg('globalrenamequeue-request-cancel-text')->text(), 'mw-renamequeue-cancel', array('class' => 'mw-ui-quiet mw-ui-flush-left')); $form->setId('mw-globalrenamequeue-request'); if ($req->userIsGlobal()) { $globalUser = new CentralAuthUser($req->getName()); $homeWiki = $globalUser->getHomeWiki(); $infoMsgKey = 'globalrenamequeue-request-userinfo-global'; } else { $homeWiki = $req->getWiki(); $infoMsgKey = 'globalrenamequeue-request-userinfo-local'; } $headerMsg = $this->msg('globalrenamequeue-request-header', WikiMap::getForeignURL($homeWiki, "User:{$req->getName()}"), $req->getName(), $req->getNewName()); $form->addHeaderText('<span class="plainlinks">' . $headerMsg->parseAsBlock() . '</span>'); $homeWikiWiki = WikiMap::getWiki($homeWiki); $infoMsg = $this->msg($infoMsgKey, $req->getName(), $homeWikiWiki ? $homeWikiWiki->getDisplayName() : $homeWiki, $req->getNewName()); $form->addHeaderText($infoMsg->parseAsBlock()); if (class_exists('CentralAuthSpoofUser')) { $spoofUser = new CentralAuthSpoofUser($req->getNewName()); // @todo move this code somewhere else $specialGblRename = new SpecialGlobalRenameUser(); $specialGblRename->setContext($this->getContext()); $conflicts = $specialGblRename->processAntiSpoofConflicts($req->getName(), $spoofUser->getConflicts()); if ($conflicts) { $form->addHeaderText($this->msg('globalrenamequeue-request-antispoof-conflicts', $this->getLanguage()->commaList($conflicts))->numParams(count($conflicts))->parse()); } } // Show a log entry of previous renames under the requesting user's username $caTitle = Title::makeTitleSafe(NS_SPECIAL, 'CentralAuth/' . $req->getName()); $extract = ''; $extractCount = LogEventsList::showLogExtract($extract, 'gblrename', $caTitle, '', array('showIfEmpty' => false)); if ($extractCount) { $form->addHeaderText(Xml::fieldset($this->msg('globalrenamequeue-request-previous-renames')->numParams($extractCount)->text(), $extract)); } $reason = $req->getReason() ?: $this->msg('globalrenamequeue-request-reason-sul')->parseAsBlock(); $form->addHeaderText($this->msg('globalrenamequeue-request-reason', $reason)->parseAsBlock()); $form->setSubmitCallback(array($this, 'onProcessSubmit')); $out = $this->getOutput(); $out->addModuleStyles(array('mediawiki.ui', 'mediawiki.ui.button', 'mediawiki.ui.input', 'ext.centralauth.globalrenamequeue.styles')); $out->addModules('ext.centralauth.globalrenamequeue'); $status = $form->show(); if ($status instanceof Status && $status->isOk()) { $this->getOutput()->redirect($this->getPageTitle(self::PAGE_PROCESS_REQUEST . "/{$req->getId()}/{$status->value}")->getFullURL()); } }
public function execute($par) { $user = $this->getUser(); if (!$this->userCanExecute($user)) { throw new \PermissionsError('commentadmin'); } $request = $this->getRequest(); $output = $this->getOutput(); $config = $this->getConfig(); $this->setHeaders(); $doExport = false; if ($request->wasPosted()) { $doExport = true; } if ($doExport) { // No default output, we are printing raw data now $this->getOutput()->disable(); // No buffering, otherwise output will consume too much memory wfResetOutputBuffers(); $request->response()->header("Content-type: application/json; charset=utf-8"); // Got headers ready so browser triggers a download $filename = urlencode($config->get('Sitename') . '-' . wfTimestampNow() . '-flowthread.json'); $request->response()->header("Content-disposition: attachment;filename={$filename}"); $request->response()->header("Cache-Control: no-cache"); // Got all data. NOTE that ORDER BY is essential since we are grouping comments $dbr = wfGetDB(DB_SLAVE); $pageid = 0; $counter = 0; $offset = 0; $hasNext = true; echo "["; // We do a limited query, as otherwise buffering will consume too much memory and time while ($hasNext) { $res = $dbr->select('FlowThread', Post::getRequiredColumns(), array(), __METHOD__, array('ORDER BY' => 'flowthread_pageid ASC, flowthread_id ASC', 'OFFSET' => $offset, 'LIMIT' => 1000)); $offset += 1000; $hasNext = false; // Nasty but neccessary stuff to make it fast foreach ($res as $row) { $hasNext = true; $post = Post::newFromDatabaseRow($row); if ($post->pageid != $pageid) { if ($pageid != 0) { echo "\n]},"; } $pageid = $post->pageid; $title = \Title::newFromId($pageid); $title = \FormatJSON::encode($title ? $title->getPrefixedText() : ''); echo "{\"title\":{$title}, \"posts\":[\n"; $first = true; } if ($first) { $first = false; } else { echo ",\n"; } $postJSON = array('id' => $post->id->getHex(), 'userid' => $post->userid, 'username' => $post->username, 'text' => $post->text, 'parentid' => $post->parentid ? $post->parentid->getHex() : null, 'status' => $post->status); echo ' ' . \FormatJSON::encode($postJSON); } } echo "\n]}]"; return; } else { $formDescriptor = array(); $htmlForm = \HTMLForm::factory('div', $formDescriptor, $this->getContext(), 'flowthread_export_form'); $htmlForm->setSubmitTextMsg('flowthreadexport-submit'); $htmlForm->show(); } }