protected function setup($par) { global $wgRequest, $wgUser, $wgEnableNewpagesUserFilter; // Options $opts = new FormOptions(); $this->opts = $opts; // bind $opts->add('hideliu', false); $opts->add('hidepatrolled', $wgUser->getBoolOption('newpageshidepatrolled')); $opts->add('hidebots', false); $opts->add('hideredirs', true); $opts->add('limit', (int) $wgUser->getOption('rclimit')); $opts->add('offset', ''); $opts->add('namespace', '0'); $opts->add('username', ''); $opts->add('feed', ''); $opts->add('tagfilter', ''); // Set values $opts->fetchValuesFromRequest($wgRequest); if ($par) { $this->parseParams($par); } // Validate $opts->validateIntBounds('limit', 0, 5000); if (!$wgEnableNewpagesUserFilter) { $opts->setValue('username', ''); } // Store some objects $this->skin = $wgUser->getSkin(); }
public function execute($par) { $this->setHeaders(); $this->outputHeader(); $out = $this->getOutput(); $this->addHelpLink('Help:New images'); $opts = new FormOptions(); $opts->add('like', ''); $opts->add('showbots', false); $opts->add('hidepatrolled', false); $opts->add('limit', 50); $opts->add('offset', ''); $opts->fetchValuesFromRequest($this->getRequest()); if ($par !== null) { $opts->setValue(is_numeric($par) ? 'limit' : 'like', $par); } $opts->validateIntBounds('limit', 0, 500); $this->opts = $opts; if (!$this->including()) { $this->setTopText(); $this->buildForm(); } $pager = new NewFilesPager($this->getContext(), $opts); $out->addHTML($pager->getBody()); if (!$this->including()) { $out->addHTML($pager->getNavigationBar()); } }
public function execute($par) { global $wgLogRestrictions; $this->setHeaders(); $this->outputHeader(); $opts = new FormOptions(); $opts->add('type', ''); $opts->add('user', ''); $opts->add('page', ''); $opts->add('pattern', false); // $opts->add( 'year', null, FormOptions::INTNULL ); don't default to zero $opts->add('year', ''); $opts->add('month', null, FormOptions::INTNULL); $opts->add('tagfilter', ''); $opts->add('offset', ''); $opts->add('dir', ''); $opts->add('offender', ''); // Set values $opts->fetchValuesFromRequest($this->getRequest()); if ($par !== null) { $this->parseParams($opts, (string) $par); } # Don't let the user get stuck with a certain date if ($opts->getValue('offset') || $opts->getValue('dir') == 'prev') { $opts->setValue('year', ''); $opts->setValue('month', ''); } // If the user doesn't have the right permission to view the specific // log type, throw a PermissionsError // If the log type is invalid, just show all public logs $type = $opts->getValue('type'); if (!LogPage::isLogType($type)) { $opts->setValue('type', ''); } elseif (isset($wgLogRestrictions[$type]) && !$this->getUser()->isAllowed($wgLogRestrictions[$type])) { throw new PermissionsError($wgLogRestrictions[$type]); } # Handle type-specific inputs $qc = array(); if ($opts->getValue('type') == 'suppress') { $offender = User::newFromName($opts->getValue('offender'), false); if ($offender && $offender->getId() > 0) { $qc = array('ls_field' => 'target_author_id', 'ls_value' => $offender->getId()); } elseif ($offender && IP::isIPAddress($offender->getName())) { $qc = array('ls_field' => 'target_author_ip', 'ls_value' => $offender->getName()); } } # Some log types are only for a 'User:'******'User:username'. This part try # to lookup for a user by that name and eventually fix user input. See bug 1697. wfRunHooks('GetLogTypesOnUser', array(&$this->typeOnUser)); if (in_array($opts->getValue('type'), $this->typeOnUser)) { # ok we have a type of log which expect a user title. $target = Title::newFromText($opts->getValue('page')); if ($target && $target->getNamespace() === NS_MAIN) { # User forgot to add 'User:'******'page', Title::makeTitleSafe(NS_USER, $opts->getValue('page'))); } } $this->show($opts, $qc); }
public function execute($par) { // Shortcut by using $par if ($par) { $this->getOutput()->redirect($this->getTitle()->getLinkURL(array('user' => $par))); return; } $this->setHeaders(); $this->outputHeader(); // Parse options $opt = new \FormOptions(); $opt->add('user', ''); $opt->add('delete', ''); $opt->add('reason', ''); $opt->fetchValuesFromRequest($this->getRequest()); // Parse user $user = $opt->getValue('user'); $userObj = \User::newFromName($user); $userExists = $userObj && $userObj->getId() !== 0; // If current task is delete and user is not allowed $canDoAdmin = $this->getUser()->isAllowed('avataradmin'); if ($opt->getValue('delete')) { if (!$canDoAdmin) { throw new \PermissionsError('avataradmin'); } // Delete avatar if the user exists if ($userExists) { if (Avatars::deleteAvatar($userObj)) { global $wgAvatarLogInRC; $logEntry = new \ManualLogEntry('avatar', 'delete'); $logEntry->setPerformer($this->getUser()); $logEntry->setTarget($userObj->getUserPage()); $logEntry->setComment($opt->getValue('reason')); $logId = $logEntry->insert(); $logEntry->publish($logId, $wgAvatarLogInRC ? 'rcandudp' : 'udp'); } } } $this->getOutput()->addModules(array('mediawiki.userSuggest')); $this->showForm($user); if ($userExists) { $haveAvatar = Avatars::hasAvatar($userObj); if ($haveAvatar) { $html = \Xml::tags('img', array('src' => Avatars::getLinkFor($user, 'original') . '&nocache&ver=' . dechex(time()), 'height' => 400), ''); $html = \Xml::tags('p', array(), $html); $this->getOutput()->addHTML($html); // Add a delete button if ($canDoAdmin) { $this->showDeleteForm($user); } } else { $this->getOutput()->addWikiMsg('viewavatar-noavatar'); } } else { if ($user) { $this->getOutput()->addWikiMsg('viewavatar-nouser'); } } }
/** * Instanciates a FormOptions object to play with. * FormOptions::add() is tested by the class FormOptionsInitializationTest * so we assume the function is well tested already an use it to create * the fixture. */ protected function setUp() { $this->object = new FormOptions(); $this->object->add('string1', 'string one'); $this->object->add('string2', 'string two'); $this->object->add('integer', 0); $this->object->add('intnull', 0, FormOptions::INTNULL); }
function execute($par) { $out = $this->getOutput(); $this->setHeaders(); $this->outputHeader(); $opts = new FormOptions(); $opts->add('target', ''); $opts->add('namespace', '', FormOptions::INTNULL); $opts->add('limit', 50); $opts->add('from', 0); $opts->add('back', 0); $opts->add('hideredirs', false); $opts->add('hidetrans', false); $opts->add('hidelinks', false); $opts->add('hideimages', false); $opts->fetchValuesFromRequest($this->getRequest()); $opts->validateIntBounds('limit', 0, 5000); // Give precedence to subpage syntax if (isset($par)) { $opts->setValue('target', $par); } // Bind to member variable $this->opts = $opts; $this->target = Title::newFromURL($opts->getValue('target')); if (!$this->target) { $out->addHTML($this->whatlinkshereForm()); return; } $this->getSkin()->setRelevantTitle($this->target); $this->selfTitle = $this->getTitle($this->target->getPrefixedDBkey()); $out->setPageTitle(wfMsg('whatlinkshere-title', $this->target->getPrefixedText())); $out->setSubtitle(wfMsg('whatlinkshere-backlink', Linker::link($this->target, $this->target->getPrefixedText(), array(), array('redirect' => 'no')))); $this->showIndirectLinks(0, $this->target, $opts->getValue('limit'), $opts->getValue('from'), $opts->getValue('back')); }
public function setupOptions() { $this->opts = new FormOptions(); $this->opts->add('hidebots', false, FormOptions::BOOL); $this->opts->add('hidesysops', false, FormOptions::BOOL); $this->opts->fetchValuesFromRequest($this->getRequest()); if ($this->opts->getValue('hidebots') == 1) { $this->hideRights[] = 'bot'; } if ($this->opts->getValue('hidesysops') == 1) { $this->hideGroups[] = 'sysop'; } }
public function setupOptions() { $this->opts = new FormOptions(); $this->opts->add('hidebots', false, FormOptions::BOOL); $this->opts->add('hidesysops', false, FormOptions::BOOL); $this->opts->fetchValuesFromRequest($this->getRequest()); $this->groups = array(); if ($this->opts->getValue('hidebots') == 1) { $this->groups['bot'] = true; } if ($this->opts->getValue('hidesysops') == 1) { $this->groups['sysop'] = true; } }
/** * Get options from array, applying callback to extract key and value. * * fromArrayCallback([$a, $b, $c], function($x){ * return [$x->key, $x->value]; * }); **/ public static function fromArrayCallback(array $data, callable $callback) { $ret = new FormOptions(); foreach ($data as $item) { list($value, $text) = $callback($item); $ret->add($value, $text); } return $ret; }
protected function setup($par) { global $wgRequest, $wgUser; // Options $opts = new FormOptions(); $this->opts = $opts; // bind $opts->add('page1', ''); $opts->add('page2', ''); $opts->add('rev1', ''); $opts->add('rev2', ''); $opts->add('action', ''); // Set values $opts->fetchValuesFromRequest($wgRequest); $title1 = Title::newFromText($opts->getValue('page1')); $title2 = Title::newFromText($opts->getValue('page2')); if ($title1 && $title1->exists() && $opts->getValue('rev1') == '') { $pda = new Article($title1); $pdi = $pda->getID(); $pdLastRevision = Revision::loadFromPageId(wfGetDB(DB_SLAVE), $pdi); $opts->setValue('rev1', $pdLastRevision->getId()); } elseif ($opts->getValue('rev1') != '') { $pdrev = Revision::newFromId($opts->getValue('rev1')); if ($pdrev) { $opts->setValue('page1', $pdrev->getTitle()->getPrefixedText()); } } if ($title2 && $title2->exists() && $opts->getValue('rev2') == '') { $pda = new Article($title2); $pdi = $pda->getID(); $pdLastRevision = Revision::loadFromPageId(wfGetDB(DB_SLAVE), $pdi); $opts->setValue('rev2', $pdLastRevision->getId()); } elseif ($opts->getValue('rev2') != '') { $pdrev = Revision::newFromId($opts->getValue('rev2')); if ($pdrev) { $opts->setValue('page2', $pdrev->getTitle()->getPrefixedText()); } } // Store some objects $this->skin = $wgUser->getSkin(); }
/** * 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'); } }
public function execute($par) { global $wgRequest; $this->setHeaders(); $this->outputHeader(); $opts = new FormOptions(); $opts->add('type', ''); $opts->add('user', ''); $opts->add('page', ''); $opts->add('pattern', false); $opts->add('year', null, FormOptions::INTNULL); $opts->add('month', null, FormOptions::INTNULL); $opts->add('tagfilter', ''); $opts->add('offset', ''); $opts->add('dir', ''); $opts->add('offender', ''); // Set values $opts->fetchValuesFromRequest($wgRequest); if ($par) { $this->parseParams($opts, (string) $par); } # Don't let the user get stuck with a certain date if ($opts->getValue('offset') || $opts->getValue('dir') == 'prev') { $opts->setValue('year', ''); $opts->setValue('month', ''); } # Handle type-specific inputs $qc = array(); if ($opts->getValue('type') == 'suppress') { $offender = User::newFromName($opts->getValue('offender'), false); if ($offender && $offender->getId() > 0) { $qc = array('ls_field' => 'target_author_id', 'ls_value' => $offender->getId()); } elseif ($offender && IP::isIPAddress($offender->getName())) { $qc = array('ls_field' => 'target_author_ip', 'ls_value' => $offender->getName()); } } $this->show($opts, $qc); }
function execute($par) { $out = $this->getOutput(); $this->setHeaders(); $this->outputHeader(); $this->addHelpLink('Help:What links here'); $opts = new FormOptions(); $opts->add('target', ''); $opts->add('namespace', '', FormOptions::INTNULL); $opts->add('limit', $this->getConfig()->get('QueryPageDefaultLimit')); $opts->add('from', 0); $opts->add('back', 0); $opts->add('hideredirs', false); $opts->add('hidetrans', false); $opts->add('hidelinks', false); $opts->add('hideimages', false); $opts->add('invert', false); $opts->fetchValuesFromRequest($this->getRequest()); $opts->validateIntBounds('limit', 0, 5000); // Give precedence to subpage syntax if ($par !== null) { $opts->setValue('target', $par); } // Bind to member variable $this->opts = $opts; $this->target = Title::newFromText($opts->getValue('target')); if (!$this->target) { if (!$this->including()) { $out->addHTML($this->whatlinkshereForm()); } return; } $this->getSkin()->setRelevantTitle($this->target); $this->selfTitle = $this->getPageTitle($this->target->getPrefixedDBkey()); $out->setPageTitle($this->msg('whatlinkshere-title', $this->target->getPrefixedText())); $out->addBacklinkSubtitle($this->target); $this->showIndirectLinks(0, $this->target, $opts->getValue('limit'), $opts->getValue('from'), $opts->getValue('back')); }
public function execute($par) { $this->useTransactionalTimeLimit(); $this->checkPermissions(); $this->checkReadOnly(); $this->setHeaders(); $this->outputHeader(); $this->addHelpLink('Help:Merge history'); $opts = new FormOptions(); $opts->add('target', ''); $opts->add('dest', ''); $opts->add('target', ''); $opts->add('mergepoint', ''); $opts->add('reason', ''); $opts->add('merge', false); $opts->fetchValuesFromRequest($this->getRequest()); $target = $opts->getValue('target'); $dest = $opts->getValue('dest'); $targetObj = Title::newFromText($target); $destObj = Title::newFromText($dest); $status = Status::newGood(); $this->mOpts = $opts; $this->mTargetObj = $targetObj; $this->mDestObj = $destObj; if ($opts->getValue('merge') && $targetObj && $destObj && $opts->getValue('mergepoint') !== '') { $this->merge(); return; } if ($target === '' && $dest === '') { $this->showMergeForm(); return; } if (!$targetObj instanceof Title) { $status->merge(Status::newFatal('mergehistory-invalid-source')); } elseif (!$targetObj->exists()) { $status->merge(Status::newFatal('mergehistory-no-source', wfEscapeWikiText($targetObj->getPrefixedText()))); } if (!$destObj instanceof Title) { $status->merge(Status::newFatal('mergehistory-invalid-destination')); } elseif (!$destObj->exists()) { $status->merge(Status::newFatal('mergehistory-no-destination', wfEscapeWikiText($destObj->getPrefixedText()))); } if ($targetObj && $destObj && $targetObj->equals($destObj)) { $status->merge(Status::newFatal('mergehistory-same-destination')); } $this->mStatus = $status; $this->showMergeForm(); if ($status->isOK()) { $this->showHistory(); } }
/** * Returns default options. */ public function getDefaultOptions() { global $wgWikilogNumArticles; $opts = new FormOptions(); $opts->add( 'view', 'summary' ); $opts->add( 'show', 'published' ); $opts->add( 'wikilog', '' ); $opts->add( 'category', '' ); $opts->add( 'author', '' ); $opts->add( 'tag', '' ); $opts->add( 'year', '', FormOptions::INTNULL ); $opts->add( 'month', '', FormOptions::INTNULL ); $opts->add( 'day', '', FormOptions::INTNULL ); $opts->add( 'limit', $wgWikilogNumArticles ); $opts->add( 'template', '' ); return $opts; }
/** * Get a FormOptions object containing the default options * * @return FormOptions */ public function getDefaultOptions() { global $wgUser; $opts = new FormOptions(); $opts->add('days', (int) $wgUser->getOption('rcdays')); $opts->add('limit', (int) $wgUser->getOption('rclimit')); $opts->add('from', ''); $opts->add('hideminor', (bool) $wgUser->getOption('hideminor')); $opts->add('hidebots', true); $opts->add('hideanons', false); $opts->add('hideliu', false); $opts->add('hidepatrolled', false); $opts->add('hidemyself', false); $opts->add('namespace', '', FormOptions::INTNULL); $opts->add('invert', false); $opts->add('categories', ''); $opts->add('categories_any', false); return $opts; }
/** * Get a FormOptions object containing the default options. By default returns some basic options, * you might want to not call parent method and discard them, or to override default values. * * @return FormOptions */ public function getDefaultOptions() { $config = $this->getConfig(); $opts = new FormOptions(); $opts->add('hideminor', false); $opts->add('hidebots', false); $opts->add('hideanons', false); $opts->add('hideliu', false); $opts->add('hidepatrolled', false); $opts->add('hidemyself', false); if ($config->get('RCWatchCategoryMembership')) { $opts->add('hidecategorization', false); } $opts->add('namespace', '', FormOptions::INTNULL); $opts->add('invert', false); $opts->add('associated', false); return $opts; }
/** * Get a FormOptions object containing the default options * * @return FormOptions */ public function getDefaultOptions() { $opts = new FormOptions(); $opts->add('days', $this->getUser()->getIntOption('rcdays')); $opts->add('limit', $this->getUser()->getIntOption('rclimit')); $opts->add('from', ''); $opts->add('hideminor', $this->getUser()->getBoolOption('hideminor')); $opts->add('hidebots', true); $opts->add('hideanons', false); $opts->add('hideliu', false); $opts->add('hidepatrolled', $this->getUser()->getBoolOption('hidepatrolled')); $opts->add('hidemyself', false); $opts->add('namespace', '', FormOptions::INTNULL); $opts->add('invert', false); $opts->add('associated', false); $opts->add('categories', ''); $opts->add('categories_any', false); $opts->add('tagfilter', ''); return $opts; }
public function execute($par) { global $wgOut, $wgRequest; $opts = new FormOptions(); $opts->add('graphit', false); $opts->add('preview', false); $opts->add('language', ''); $opts->add('count', 'edits'); $opts->add('scale', 'days'); $opts->add('days', 30); // now $endday = time(); $opts->add('endday', date('j', $endday)); $opts->add('endmonth', (int) date('n', $endday)); $opts->add('endyear', date('Y', $endday)); // enddate - 30 days $startday = $endday - 2592000; $opts->add('startday', date('j', $startday)); $opts->add('startmonth', (int) date('n', $startday)); $opts->add('startyear', date('Y', $startday)); $opts->add('width', 600); $opts->add('height', 400); $opts->add('group', ''); $opts->add('uselang', ''); $opts->fetchValuesFromRequest($wgRequest); $pars = explode(';', $par); foreach ($pars as $item) { if (strpos($item, '=') === false) { continue; } list($key, $value) = array_map('trim', explode('=', $item, 2)); if (isset($opts[$key])) { $opts[$key] = $value; } } $opts->validateIntBounds('days', 1, 10000); $opts->validateIntBounds('width', 200, 1000); $opts->validateIntBounds('height', 200, 1000); $validScales = array('months', 'weeks', 'days', 'hours'); if (!in_array($opts['scale'], $validScales)) { $opts['scale'] = 'days'; } if ($opts['scale'] === 'hours') { $opts->validateIntBounds('days', 1, 4); } $validCounts = array('edits', 'users', 'registrations'); if (!in_array($opts['count'], $validCounts)) { $opts['count'] = 'edits'; } foreach (array('group', 'language') as $t) { $values = array_map('trim', explode(',', $opts[$t])); $values = array_splice($values, 0, 4); if ($t === 'group') { $values = preg_replace('~^page_~', 'page|', $values); } $opts[$t] = implode(',', $values); } $validRange = $this->checkDates($opts); if ($this->including()) { if ($validRange) { $wgOut->addHTML($this->image($opts)); } } elseif ($opts['graphit']) { if (!class_exists('PHPlot')) { header("HTTP/1.0 500 Multi fail"); echo "PHPlot not found"; } if (!$validRange) { header("HTTP/1.0 500 Multi fail"); echo "Invalid date range"; } if (!$wgRequest->getBool('debug')) { $wgOut->disable(); header('Content-Type: image/png'); header('Cache-Control: private, max-age=3600'); header('Expires: ' . wfTimestamp(TS_RFC2822, time() + 3600)); } $this->draw($opts); } else { if (!$validRange) { $wgOut->addHTML('<p>' . wfMsg('translationstats-invalid-range') . '</p>'); } $this->form($opts); /* check if form has been posted */ if ($validRange && $wgRequest->getVal('preview')) { $this->table($opts); } } }
protected function setup($par) { global $wgEnableNewpagesUserFilter; // Options $opts = new FormOptions(); $this->opts = $opts; // bind $opts->add('hideliu', false); $opts->add('hidepatrolled', $this->getUser()->getBoolOption('newpageshidepatrolled')); $opts->add('hidebots', false); $opts->add('hideredirs', true); $opts->add('limit', $this->getUser()->getIntOption('rclimit')); $opts->add('offset', ''); $opts->add('namespace', '0'); $opts->add('username', ''); $opts->add('feed', ''); $opts->add('tagfilter', ''); $opts->add('invert', false); $this->customFilters = array(); wfRunHooks('SpecialNewPagesFilters', array($this, &$this->customFilters)); foreach ($this->customFilters as $key => $params) { $opts->add($key, $params['default']); } // Set values $opts->fetchValuesFromRequest($this->getRequest()); if ($par) { $this->parseParams($par); } // Validate $opts->validateIntBounds('limit', 0, 5000); if (!$wgEnableNewpagesUserFilter) { $opts->setValue('username', ''); } }
public function execute( $par ) { global $wgOut, $wgRequest; $opts = new FormOptions(); $opts->add( 'graphit', false ); $opts->add( 'preview', false ); $opts->add( 'language', '' ); $opts->add( 'count', 'edits' ); $opts->add( 'scale', 'days' ); $opts->add( 'days', 30 ); $opts->add( 'width', 600 ); $opts->add( 'height', 400 ); $opts->add( 'group', '' ); $opts->add( 'uselang', '' ); $opts->add( 'start', '' ); $opts->fetchValuesFromRequest( $wgRequest ); $pars = explode( ';', $par ); foreach ( $pars as $item ) { if ( strpos( $item, '=' ) === false ) { continue; } list( $key, $value ) = array_map( 'trim', explode( '=', $item, 2 ) ); if ( isset( $opts[$key] ) ) { $opts[$key] = $value; } } $opts->validateIntBounds( 'days', 1, 10000 ); $opts->validateIntBounds( 'width', 200, 1000 ); $opts->validateIntBounds( 'height', 200, 1000 ); if ( $opts['start'] !== '' ) { $opts['start'] = strval( wfTimestamp( TS_MW, $opts['start'] ) ); } $validScales = array( 'months', 'weeks', 'days', 'hours' ); if ( !in_array( $opts['scale'], $validScales ) ) { $opts['scale'] = 'days'; } if ( $opts['scale'] === 'hours' ) { $opts->validateIntBounds( 'days', 1, 4 ); } $validCounts = array( 'edits', 'users', 'registrations' ); if ( !in_array( $opts['count'], $validCounts ) ) { $opts['count'] = 'edits'; } foreach ( array( 'group', 'language' ) as $t ) { $values = array_map( 'trim', explode( ',', $opts[$t] ) ); $values = array_splice( $values, 0, 4 ); if ( $t === 'group' ) { // BC for old syntax which replaced _ to | which was not allowed $values = preg_replace( '~^page_~', 'page-', $values ); } $opts[$t] = implode( ',', $values ); } if ( $this->including() ) { $wgOut->addHTML( $this->image( $opts ) ); } elseif ( $opts['graphit'] ) { if ( !class_exists( 'PHPlot' ) ) { header( "HTTP/1.0 500 Multi fail" ); echo "PHPlot not found"; } if ( !$wgRequest->getBool( 'debug' ) ) { $wgOut->disable(); header( 'Content-Type: image/png' ); header( 'Cache-Control: private, max-age=3600' ); header( 'Expires: ' . wfTimestamp( TS_RFC2822, time() + 3600 ) ); } $this->draw( $opts ); } else { $this->form( $opts ); } }
/** * Get a FormOptions object containing the default options * * @return FormOptions */ public function getDefaultOptions() { $opts = new FormOptions(); $opts->add('days', (int) $this->getUser()->getGlobalPreference('rcdays')); $opts->add('limit', (int) $this->getUser()->getGlobalPreference('rclimit')); $opts->add('from', ''); $opts->add('hideminor', (bool) $this->getUser()->getGlobalPreference('hideminor')); $opts->add('hidebots', true); $opts->add('hideanons', false); $opts->add('hideliu', false); $opts->add('hidepatrolled', (bool) $this->getUser()->getGlobalPreference('hidepatrolled')); $opts->add('hidemyself', false); // Wikia change - begin // still needed? $opts->add('hideenhanced', !$this->getUser()->getGlobalPreference('usenewrc')); // Wikia change - end $opts->add('namespace', '', FormOptions::INTNULL); $opts->add('invert', false); $opts->add('associated', false); $opts->add('categories', ''); $opts->add('categories_any', false); $opts->add('tagfilter', ''); return $opts; }
public function setup() { global $wgRequest; $opts = new FormOptions(); // Bind to the member variable $this->opts = $opts; $opts->add('mode', self::MODE_STATS); $opts->add('image', APCImages::IMG_NONE); $opts->add('clearcache', false); $opts->add('limit', 20); $opts->add('offset', 0); $opts->add('display', ''); $opts->add('delete', ''); $opts->add('sort', 'hits'); $opts->add('sortdir', 0); $opts->add('scope', 'active'); $opts->add('searchi', ''); // MediaWiki captures search, ARGH! $opts->fetchValuesFromRequest($wgRequest); $opts->validateIntBounds('limit', 0, 5000); $opts->validateIntBounds('sortdir', 0, 1); $this->opts->consumeValues(array('display', 'clearcache', 'image')); }
public function testAddIntegers() { $this->object->add('one', 1); $this->object->add('negone', -1); $this->assertEquals(array('negone' => array('default' => -1, 'value' => null, 'consumed' => false, 'type' => FormOptions::INT), 'one' => array('default' => 1, 'value' => null, 'consumed' => false, 'type' => FormOptions::INT)), $this->object->getOptions()); }
public function execute($par) { $user = $this->getUser(); if (!$this->userCanExecute($user)) { throw new \PermissionsError('commentadmin-restricted'); } // Parse request $opt = new \FormOptions(); $opt->add('user', ''); $opt->add('page', ''); $opt->add('filter', 'all'); $opt->add('keyword', ''); $opt->add('offset', '0'); $opt->add('limit', '20'); $opt->add('dir', ''); $opt->fetchValuesFromRequest($this->getRequest()); // Reset filter to all if it cannot be recognized $filter = $opt->getValue('filter'); if (!in_array($filter, $this->getPossibleFilters())) { $filter = 'all'; } $this->filter = $filter; // Set local variable $this->page = $opt->getValue('page'); $this->user = $opt->getValue('user'); $this->keyword = $opt->getValue('keyword'); $this->offset = intval($opt->getValue('offset')); $this->limit = intval($opt->getValue('limit')); $this->revDir = $opt->getValue('dir') === 'prev'; // Limit the max limit if ($this->limit >= 500) { $this->limit = 500; } global $wgScript; $this->setHeaders(); $this->outputHeader(); $output = $this->getOutput(); $output->addModules('mediawiki.userSuggest'); # This is used for user input field $output->addModules('ext.flowthread.manage'); $this->showForm(); $json = array(); $res = $this->queryDatabase(); $count = 0; foreach ($res as $row) { if ($count === $this->limit) { $this->haveMore = true; break; } else { $count++; } $post = Post::newFromDatabaseRow($row); $title = \Title::newFromId($row->flowthread_pageid); $json[] = array('id' => $post->id->getHex(), 'userid' => $post->userid, 'username' => $post->username, 'title' => $title ? $title->getPrefixedText() : null, 'text' => $post->text, 'timestamp' => $post->id->getTimestamp(), 'parentid' => $post->parentid ? $post->parentid->getHex() : '', 'like' => $post->getFavorCount(), 'report' => $post->getReportCount()); } // Pager can only be generated after query $output->addHTML($this->getPager()); $output->addJsConfigVars(array('commentfilter' => $this->filter, 'commentjson' => $json)); if ($this->getUser()->isAllowed('commentadmin')) { $output->addJsConfigVars(array('commentadmin' => '')); } global $wgFlowThreadConfig; $output->addJsConfigVars(array('wgFlowThreadConfig' => array('Avatar' => $wgFlowThreadConfig['Avatar'], 'AnonymousAvatar' => $wgFlowThreadConfig['AnonymousAvatar']))); }
public function execute($par) { global $wgLanguageCode; $this->setHeaders(); $this->checkPermissions(); $server = TTMServer::primary(); if (!$server instanceof SearchableTTMServer) { throw new ErrorPageError('tux-sst-nosolr-title', 'tux-sst-nosolr-body'); } $out = $this->getOutput(); $out->addModuleStyles('jquery.uls.grid'); $out->addModuleStyles('ext.translate.special.searchtranslations.styles'); $out->addModuleStyles('ext.translate.special.translate.styles'); $out->addModules('ext.translate.special.searchtranslations'); $out->addModules('ext.translate.special.searchtranslations.operatorsuggest'); TranslateUtils::addSpecialHelpLink($out, 'Help:Extension:Translate#searching'); $this->opts = $opts = new FormOptions(); $opts->add('query', ''); $opts->add('sourcelanguage', $wgLanguageCode); $opts->add('language', ''); $opts->add('group', ''); $opts->add('grouppath', ''); $opts->add('filter', ''); $opts->add('match', ''); $opts->add('case', ''); $opts->add('limit', $this->limit); $opts->add('offset', 0); $opts->fetchValuesFromRequest($this->getRequest()); $queryString = $opts->getValue('query'); if ($queryString === '') { $this->showEmptySearch(); return; } $params = $opts->getAllValues(); $filter = $opts->getValue('filter'); try { $translationSearch = new CrossLanguageTranslationSearchQuery($params, $server); if (in_array($filter, $translationSearch->getAvailableFilters())) { if ($opts->getValue('language') === '') { $params['language'] = $this->getLanguage()->getCode(); $opts->setValue('language', $params['language']); } $documents = $translationSearch->getDocuments(); $total = $translationSearch->getTotalHits(); $resultset = $translationSearch->getResultSet(); } else { $resultset = $server->search($queryString, $params, $this->hl); $documents = $server->getDocuments($resultset); $total = $server->getTotalHits($resultset); } } catch (TTMServerException $e) { error_log('Translation search server unavailable:' . $e->getMessage()); throw new ErrorPageError('tux-sst-solr-offline-title', 'tux-sst-solr-offline-body'); } // Part 1: facets $facets = $server->getFacets($resultset); $facetHtml = ''; if (count($facets['language']) > 0) { if ($filter !== '') { $facets['language'] = array_merge($facets['language'], array($opts->getValue('language') => $total)); } $facetHtml = Html::element('div', array('class' => 'row facet languages', 'data-facets' => FormatJson::encode($this->getLanguages($facets['language'])), 'data-language' => $opts->getValue('language')), $this->msg('tux-sst-facet-language')); } if (count($facets['group']) > 0) { $facetHtml .= Html::element('div', array('class' => 'row facet groups', 'data-facets' => FormatJson::encode($this->getGroups($facets['group'])), 'data-group' => $opts->getValue('group')), $this->msg('tux-sst-facet-group')); } // Part 2: results $resultsHtml = ''; $title = Title::newFromText($queryString); if ($title && !in_array($filter, $translationSearch->getAvailableFilters())) { $handle = new MessageHandle($title); $code = $handle->getCode(); $language = $opts->getValue('language'); if ($handle->isValid() && $code !== '' && $code !== $language) { $groupId = $handle->getGroup()->getId(); $helpers = new TranslationHelpers($title, $groupId); $document['wiki'] = wfWikiId(); $document['localid'] = $handle->getTitleForBase()->getPrefixedText(); $document['content'] = $helpers->getTranslation(); $document['language'] = $handle->getCode(); array_unshift($documents, $document); $total++; } } foreach ($documents as $document) { $text = $document['content']; $text = TranslateUtils::convertWhiteSpaceToHTML($text); list($pre, $post) = $this->hl; $text = str_replace($pre, '<strong class="tux-search-highlight">', $text); $text = str_replace($post, '</strong>', $text); $title = Title::newFromText($document['localid'] . '/' . $document['language']); if (!$title) { // Should not ever happen but who knows... continue; } $resultAttribs = array('class' => 'row tux-message', 'data-title' => $title->getPrefixedText(), 'data-language' => $document['language']); $handle = new MessageHandle($title); if ($handle->isValid()) { $groupId = $handle->getGroup()->getId(); $helpers = new TranslationHelpers($title, $groupId); $resultAttribs['data-definition'] = $helpers->getDefinition(); $resultAttribs['data-translation'] = $helpers->getTranslation(); $resultAttribs['data-group'] = $groupId; $uri = $title->getLocalUrl(array('action' => 'edit')); $link = Html::element('a', array('href' => $uri), $this->msg('tux-sst-edit')->text()); } else { $url = wfParseUrl($document['uri']); $domain = $url['host']; $link = Html::element('a', array('href' => $document['uri']), $this->msg('tux-sst-view-foreign', $domain)->text()); } $access = Html::rawElement('div', array('class' => 'row tux-edit tux-message-item'), $link); $titleText = $title->getPrefixedText(); $titleAttribs = array('class' => 'row tux-title', 'dir' => 'ltr'); $textAttribs = array('class' => 'row tux-text', 'lang' => wfBCP47($document['language']), 'dir' => Language::factory($document['language'])->getDir()); $resultsHtml = $resultsHtml . Html::openElement('div', $resultAttribs) . Html::rawElement('div', $textAttribs, $text) . Html::element('div', $titleAttribs, $titleText) . $access . Html::closeElement('div'); } $resultsHtml .= Html::rawElement('hr', array('class' => 'tux-pagination-line')); $prev = $next = ''; $offset = $this->opts->getValue('offset'); $params = $this->opts->getChangedValues(); if ($total - $offset > $this->limit) { $newParams = array('offset' => $offset + $this->limit) + $params; $attribs = array('class' => 'mw-ui-button pager-next', 'href' => $this->getPageTitle()->getLocalUrl($newParams)); $next = Html::element('a', $attribs, $this->msg('tux-sst-next')->text()); } if ($offset) { $newParams = array('offset' => max(0, $offset - $this->limit)) + $params; $attribs = array('class' => 'mw-ui-button pager-prev', 'href' => $this->getPageTitle()->getLocalUrl($newParams)); $prev = Html::element('a', $attribs, $this->msg('tux-sst-prev')->text()); } $resultsHtml .= Html::rawElement('div', array('class' => 'tux-pagination-links'), "{$prev} {$next}"); $search = $this->getSearchInput($queryString); $count = $this->msg('tux-sst-count')->numParams($total); $this->showSearch($search, $count, $facetHtml, $resultsHtml, $total); }
/** * Get a FormOptions object containing the default options. By default returns some basic options, * you might want to not call parent method and discard them, or to override default values. * * @return FormOptions */ public function getDefaultOptions() { $opts = new FormOptions(); $opts->add('hideminor', false); $opts->add('hidebots', false); $opts->add('hideanons', false); $opts->add('hideliu', false); $opts->add('hidepatrolled', false); $opts->add('hidemyself', false); $opts->add('namespace', '', FormOptions::INTNULL); $opts->add('invert', false); $opts->add('associated', false); return $opts; }