/** * @covers ApiRawMessage */ public function testApiRawMessage() { $msg = new RawMessage('foo', array('baz')); $msg->inLanguage('de')->title(Title::newMainPage()); $msg2 = new ApiRawMessage($msg, 'code', array('data')); $this->compareMessages($msg, $msg2); $this->assertEquals('code', $msg2->getApiCode()); $this->assertEquals(array('data'), $msg2->getApiData()); $msg2 = unserialize(serialize($msg2)); $this->compareMessages($msg, $msg2); $this->assertEquals('code', $msg2->getApiCode()); $this->assertEquals(array('data'), $msg2->getApiData()); $msg = new RawMessage('foo', array('baz')); $msg2 = new ApiRawMessage(array('foo', 'baz'), 'code', array('data')); $this->compareMessages($msg, $msg2); $this->assertEquals('code', $msg2->getApiCode()); $this->assertEquals(array('data'), $msg2->getApiData()); $msg = new RawMessage('foo'); $msg2 = new ApiRawMessage('foo', 'code', array('data')); $this->compareMessages($msg, $msg2); $this->assertEquals('code', $msg2->getApiCode()); $this->assertEquals(array('data'), $msg2->getApiData()); $msg2->setApiCode('code', array('data')); $this->assertEquals('code', $msg2->getApiCode()); $this->assertEquals(array('data'), $msg2->getApiData()); $msg2->setApiCode(null); $this->assertEquals('foo', $msg2->getApiCode()); $this->assertEquals(array('data'), $msg2->getApiData()); $msg2->setApiData(array('data2')); $this->assertEquals(array('data2'), $msg2->getApiData()); }
function testDeliciouslyManyParams() { $msg = new RawMessage('$1$2$3$4$5$6$7$8$9$10$11$12'); // One less than above has placeholders $params = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k'); $this->assertEquals('abcdefghijka2', $msg->params($params)->plain(), 'Params > 9 are replaced correctly'); }
public static function saveMessage(array $message, PropelPDO $con = null) { $crit = new Criteria(); $crit->add(self::MESSAGE_ID, $message['id']); $rawmessage = self::doSelectOne($crit); if (is_null($rawmessage)) { $follower = FollowerPeer::createFollower($message['user'], $con); $rawmessage = new RawMessage(); $rawmessage->setMessageId($message['id']); $rawmessage->setCreatedAt($message['created_at']); $rawmessage->setText($message['text']); $rawmessage->setFollower($follower); $rawmessage->save(); return $rawmessage; } else { return null; } }
/** * Get the error list as a Message object * * @param string|string[] $shortContext A short enclosing context message name (or an array of * message names), to be used when there is a single error. * @param string|string[] $longContext A long enclosing context message name (or an array of * message names), for a list. * * @return Message */ public function getMessage($shortContext = false, $longContext = false) { $rawErrors = $this->sv->getErrors(); if (count($rawErrors) == 0) { if ($this->sv->isOK()) { $this->sv->fatal('internalerror_info', __METHOD__ . " called for a good result, this is incorrect\n"); } else { $this->sv->fatal('internalerror_info', __METHOD__ . ": Invalid result object: no error text but not OK\n"); } $rawErrors = $this->sv->getErrors(); // just added a fatal } if (count($rawErrors) == 1) { $s = $this->getErrorMessage($rawErrors[0]); if ($shortContext) { $s = wfMessage($shortContext, $s); } elseif ($longContext) { $wrapper = new RawMessage("* \$1\n"); $wrapper->params($s)->parse(); $s = wfMessage($longContext, $wrapper); } } else { $msgs = $this->getErrorMessageArray($rawErrors); $msgCount = count($msgs); if ($shortContext) { $msgCount++; } $s = new RawMessage('* $' . implode("\n* \$", range(1, $msgCount))); $s->params($msgs)->parse(); if ($longContext) { $s = wfMessage($longContext, $s); } elseif ($shortContext) { $wrapper = new RawMessage("\n\$1\n", $s); $wrapper->parse(); $s = wfMessage($shortContext, $wrapper); } } return $s; }
public static function provideStripOuterParagraph() { // This mimics the most common use case (stripping paragraphs generated by the parser). $message = new RawMessage("Message text."); return array(array("<p>Text.</p>", "Text."), array("<p class='foo'>Text.</p>", "<p class='foo'>Text.</p>"), array("<p>Text.\n</p>\n", "Text."), array("<p>Text.</p><p>More text.</p>", "<p>Text.</p><p>More text.</p>"), array($message->parse(), "Message text.")); }
/** * @covers Message::bitrateParams */ public function testMessageBitrateParams() { $lang = Language::factory('en'); $msg = new RawMessage('$1'); $this->assertEquals($lang->formatBitrate(123456), $msg->inLanguage($lang)->bitrateParams(123456)->plain(), 'bitrateParams is handled correctly'); }
/** * Get the Limit report for page previews * * @since 1.22 * @param ParserOutput $output ParserOutput object from the parse * @return string HTML */ public static function getPreviewLimitReport($output) { if (!$output || !$output->getLimitReportData()) { return ''; } wfProfileIn(__METHOD__); $limitReport = Html::rawElement('div', array('class' => 'mw-limitReportExplanation'), wfMessage('limitreport-title')->parseAsBlock()); // Show/hide animation doesn't work correctly on a table, so wrap it in a div. $limitReport .= Html::openElement('div', array('class' => 'preview-limit-report-wrapper')); $limitReport .= Html::openElement('table', array('class' => 'preview-limit-report wikitable')) . Html::openElement('tbody'); foreach ($output->getLimitReportData() as $key => $value) { if (wfRunHooks('ParserLimitReportFormat', array($key, &$value, &$limitReport, true, true))) { $keyMsg = wfMessage($key); $valueMsg = wfMessage(array("{$key}-value-html", "{$key}-value")); if (!$valueMsg->exists()) { $valueMsg = new RawMessage('$1'); } if (!$keyMsg->isDisabled() && !$valueMsg->isDisabled()) { $limitReport .= Html::openElement('tr') . Html::rawElement('th', null, $keyMsg->parse()) . Html::rawElement('td', null, $valueMsg->params($value)->parse()) . Html::closeElement('tr'); } } } $limitReport .= Html::closeElement('tbody') . Html::closeElement('table') . Html::closeElement('div'); wfProfileOut(__METHOD__); return $limitReport; }
/** * Get the Limit report for page previews * * @since 1.22 * @param ParserOutput $output ParserOutput object from the parse * @return string HTML */ public static function getPreviewLimitReport($output) { if (!$output || !$output->getLimitReportData()) { return ''; } $limitReport = Html::rawElement('div', ['class' => 'mw-limitReportExplanation'], wfMessage('limitreport-title')->parseAsBlock()); // Show/hide animation doesn't work correctly on a table, so wrap it in a div. $limitReport .= Html::openElement('div', ['class' => 'preview-limit-report-wrapper']); $limitReport .= Html::openElement('table', ['class' => 'preview-limit-report wikitable']) . Html::openElement('tbody'); foreach ($output->getLimitReportData()['limitreport'] as $key => $value) { if (Hooks::run('ParserLimitReportFormat', [$key, &$value, &$limitReport, true, true])) { $keyMsg = wfMessage("limitreport-{$key}"); $valueMsg = wfMessage(["limitreport-{$key}-value-html", "limitreport-{$key}-value"]); if (!$valueMsg->exists()) { $valueMsg = new RawMessage('$1'); } if (!$keyMsg->isDisabled() && !$valueMsg->isDisabled()) { // If it's a value/limit array, convert it for $1/$2 if (is_array($value) && isset($value['value'])) { $value = [$value['value'], $value['limit']]; } $limitReport .= Html::openElement('tr') . Html::rawElement('th', null, $keyMsg->parse()) . Html::rawElement('td', null, $valueMsg->params($value)->parse()) . Html::closeElement('tr'); } } } $limitReport .= Html::closeElement('tbody') . Html::closeElement('table') . Html::closeElement('div'); return $limitReport; }
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param RawMessage $value A RawMessage object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(RawMessage $obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getId(); } // if key === null self::$instances[$key] = $obj; } }
/** * FIXME: This should not need database, but Language#formatExpiry does (bug 55912) * @group Database * @todo this should be split up into multiple test methods * @covers Message::numParams * @covers Message::durationParams * @covers Message::expiryParams * @covers Message::timeperiodParams * @covers Message::sizeParams * @covers Message::bitrateParams */ public function testMessageParamTypes() { $lang = Language::factory('en'); $msg = new RawMessage('$1'); $this->assertEquals($lang->formatNum(123456.789), $msg->inLanguage($lang)->numParams(123456.789)->plain(), 'numParams is handled correctly'); $msg = new RawMessage('$1'); $this->assertEquals($lang->formatDuration(1234), $msg->inLanguage($lang)->durationParams(1234)->plain(), 'durationParams is handled correctly'); $msg = new RawMessage('$1'); $this->assertEquals($lang->formatExpiry(wfTimestampNow()), $msg->inLanguage($lang)->expiryParams(wfTimestampNow())->plain(), 'expiryParams is handled correctly'); $msg = new RawMessage('$1'); $this->assertEquals($lang->formatTimePeriod(1234), $msg->inLanguage($lang)->timeperiodParams(1234)->plain(), 'timeperiodParams is handled correctly'); $msg = new RawMessage('$1'); $this->assertEquals($lang->formatSize(123456), $msg->inLanguage($lang)->sizeParams(123456)->plain(), 'sizeParams is handled correctly'); $msg = new RawMessage('$1'); $this->assertEquals($lang->formatBitrate(123456), $msg->inLanguage($lang)->bitrateParams(123456)->plain(), 'bitrateParams is handled correctly'); }
public function unserialize($serialized) { $data = unserialize($serialized); parent::unserialize($data['parent']); $this->apiCode = $data['apiCode']; $this->apiData = $data['apiData']; }
/** * Convert wikitext to HTML * Do not call this function recursively. * * @param string $text text we want to parse * @param $title Title object * @param $options ParserOptions * @param $linestart boolean * @param $clearState boolean * @param int $revid number to pass in {{REVISIONID}} * @return ParserOutput a ParserOutput */ public function parse( $text, Title $title, ParserOptions $options, $linestart = true, $clearState = true, $revid = null ) { /** * First pass--just handle <nowiki> sections, pass the rest off * to internalParse() which does all the real work. */ global $wgUseTidy, $wgAlwaysUseTidy, $wgShowHostnames; $fname = __METHOD__ . '-' . wfGetCaller(); wfProfileIn( __METHOD__ ); wfProfileIn( $fname ); $this->startParse( $title, $options, self::OT_HTML, $clearState ); $this->mInputSize = strlen( $text ); if ( $this->mOptions->getEnableLimitReport() ) { $this->mOutput->resetParseStartTime(); } # Remove the strip marker tag prefix from the input, if present. if ( $clearState ) { $text = str_replace( $this->mUniqPrefix, '', $text ); } $oldRevisionId = $this->mRevisionId; $oldRevisionObject = $this->mRevisionObject; $oldRevisionTimestamp = $this->mRevisionTimestamp; $oldRevisionUser = $this->mRevisionUser; $oldRevisionSize = $this->mRevisionSize; if ( $revid !== null ) { $this->mRevisionId = $revid; $this->mRevisionObject = null; $this->mRevisionTimestamp = null; $this->mRevisionUser = null; $this->mRevisionSize = null; } wfRunHooks( 'ParserBeforeStrip', array( &$this, &$text, &$this->mStripState ) ); # No more strip! wfRunHooks( 'ParserAfterStrip', array( &$this, &$text, &$this->mStripState ) ); $text = $this->internalParse( $text ); wfRunHooks( 'ParserAfterParse', array( &$this, &$text, &$this->mStripState ) ); $text = $this->mStripState->unstripGeneral( $text ); # Clean up special characters, only run once, next-to-last before doBlockLevels $fixtags = array( # french spaces, last one Guillemet-left # only if there is something before the space '/(.) (?=\\?|:|;|!|%|\\302\\273)/' => '\\1 ', # french spaces, Guillemet-right '/(\\302\\253) /' => '\\1 ', '/ (!\s*important)/' => ' \\1', # Beware of CSS magic word !important, bug #11874. ); $text = preg_replace( array_keys( $fixtags ), array_values( $fixtags ), $text ); $text = $this->doBlockLevels( $text, $linestart ); $this->replaceLinkHolders( $text ); /** * The input doesn't get language converted if * a) It's disabled * b) Content isn't converted * c) It's a conversion table * d) it is an interface message (which is in the user language) */ if ( !( $options->getDisableContentConversion() || isset( $this->mDoubleUnderscores['nocontentconvert'] ) ) ) { if ( !$this->mOptions->getInterfaceMessage() ) { # The position of the convert() call should not be changed. it # assumes that the links are all replaced and the only thing left # is the <nowiki> mark. $text = $this->getConverterLanguage()->convert( $text ); } } /** * A converted title will be provided in the output object if title and * content conversion are enabled, the article text does not contain * a conversion-suppressing double-underscore tag, and no * {{DISPLAYTITLE:...}} is present. DISPLAYTITLE takes precedence over * automatic link conversion. */ if ( !( $options->getDisableTitleConversion() || isset( $this->mDoubleUnderscores['nocontentconvert'] ) || isset( $this->mDoubleUnderscores['notitleconvert'] ) || $this->mOutput->getDisplayTitle() !== false ) ) { $convruletitle = $this->getConverterLanguage()->getConvRuleTitle(); if ( $convruletitle ) { $this->mOutput->setTitleText( $convruletitle ); } else { $titleText = $this->getConverterLanguage()->convertTitle( $title ); $this->mOutput->setTitleText( $titleText ); } } $text = $this->mStripState->unstripNoWiki( $text ); wfRunHooks( 'ParserBeforeTidy', array( &$this, &$text ) ); $text = $this->replaceTransparentTags( $text ); $text = $this->mStripState->unstripGeneral( $text ); $text = Sanitizer::normalizeCharReferences( $text ); if ( ( $wgUseTidy && $this->mOptions->getTidy() ) || $wgAlwaysUseTidy ) { $text = MWTidy::tidy( $text ); } else { # attempt to sanitize at least some nesting problems # (bug #2702 and quite a few others) $tidyregs = array( # ''Something [http://www.cool.com cool''] --> # <i>Something</i><a href="http://www.cool.com"..><i>cool></i></a> '/(<([bi])>)(<([bi])>)?([^<]*)(<\/?a[^<]*>)([^<]*)(<\/\\4>)?(<\/\\2>)/' => '\\1\\3\\5\\8\\9\\6\\1\\3\\7\\8\\9', # fix up an anchor inside another anchor, only # at least for a single single nested link (bug 3695) '/(<a[^>]+>)([^<]*)(<a[^>]+>[^<]*)<\/a>(.*)<\/a>/' => '\\1\\2</a>\\3</a>\\1\\4</a>', # fix div inside inline elements- doBlockLevels won't wrap a line which # contains a div, so fix it up here; replace # div with escaped text '/(<([aib]) [^>]+>)([^<]*)(<div([^>]*)>)(.*)(<\/div>)([^<]*)(<\/\\2>)/' => '\\1\\3<div\\5>\\6</div>\\8\\9', # remove empty italic or bold tag pairs, some # introduced by rules above '/<([bi])><\/\\1>/' => '', ); $text = preg_replace( array_keys( $tidyregs ), array_values( $tidyregs ), $text ); } if ( $this->mExpensiveFunctionCount > $this->mOptions->getExpensiveParserFunctionLimit() ) { $this->limitationWarn( 'expensive-parserfunction', $this->mExpensiveFunctionCount, $this->mOptions->getExpensiveParserFunctionLimit() ); } wfRunHooks( 'ParserAfterTidy', array( &$this, &$text ) ); # Information on include size limits, for the benefit of users who try to skirt them if ( $this->mOptions->getEnableLimitReport() ) { $max = $this->mOptions->getMaxIncludeSize(); $cpuTime = $this->mOutput->getTimeSinceStart( 'cpu' ); if ( $cpuTime !== null ) { $this->mOutput->setLimitReportData( 'limitreport-cputime', sprintf( "%.3f", $cpuTime ) ); } $wallTime = $this->mOutput->getTimeSinceStart( 'wall' ); $this->mOutput->setLimitReportData( 'limitreport-walltime', sprintf( "%.3f", $wallTime ) ); $this->mOutput->setLimitReportData( 'limitreport-ppvisitednodes', array( $this->mPPNodeCount, $this->mOptions->getMaxPPNodeCount() ) ); $this->mOutput->setLimitReportData( 'limitreport-ppgeneratednodes', array( $this->mGeneratedPPNodeCount, $this->mOptions->getMaxGeneratedPPNodeCount() ) ); $this->mOutput->setLimitReportData( 'limitreport-postexpandincludesize', array( $this->mIncludeSizes['post-expand'], $max ) ); $this->mOutput->setLimitReportData( 'limitreport-templateargumentsize', array( $this->mIncludeSizes['arg'], $max ) ); $this->mOutput->setLimitReportData( 'limitreport-expansiondepth', array( $this->mHighestExpansionDepth, $this->mOptions->getMaxPPExpandDepth() ) ); $this->mOutput->setLimitReportData( 'limitreport-expensivefunctioncount', array( $this->mExpensiveFunctionCount, $this->mOptions->getExpensiveParserFunctionLimit() ) ); wfRunHooks( 'ParserLimitReportPrepare', array( $this, $this->mOutput ) ); $limitReport = "NewPP limit report\n"; if ( $wgShowHostnames ) { $limitReport .= 'Parsed by ' . wfHostname() . "\n"; } foreach ( $this->mOutput->getLimitReportData() as $key => $value ) { if ( wfRunHooks( 'ParserLimitReportFormat', array( $key, $value, &$limitReport, false, false ) ) ) { $keyMsg = wfMessage( $key )->inLanguage( 'en' )->useDatabase( false ); $valueMsg = wfMessage( array( "$key-value-text", "$key-value" ) ) ->inLanguage( 'en' )->useDatabase( false ); if ( !$valueMsg->exists() ) { $valueMsg = new RawMessage( '$1' ); } if ( !$keyMsg->isDisabled() && !$valueMsg->isDisabled() ) { $valueMsg->params( $value ); $limitReport .= "{$keyMsg->text()}: {$valueMsg->text()}\n"; } } } // Since we're not really outputting HTML, decode the entities and // then re-encode the things that need hiding inside HTML comments. $limitReport = htmlspecialchars_decode( $limitReport ); wfRunHooks( 'ParserLimitReport', array( $this, &$limitReport ) ); // Sanitize for comment. Note '‐' in the replacement is U+2010, // which looks much like the problematic '-'. $limitReport = str_replace( array( '-', '&' ), array( '‐', '&' ), $limitReport ); $text .= "\n<!-- \n$limitReport-->\n"; if ( $this->mGeneratedPPNodeCount > $this->mOptions->getMaxGeneratedPPNodeCount() / 10 ) { wfDebugLog( 'generated-pp-node-count', $this->mGeneratedPPNodeCount . ' ' . $this->mTitle->getPrefixedDBkey() ); } } $this->mOutput->setText( $text ); $this->mRevisionId = $oldRevisionId; $this->mRevisionObject = $oldRevisionObject; $this->mRevisionTimestamp = $oldRevisionTimestamp; $this->mRevisionUser = $oldRevisionUser; $this->mRevisionSize = $oldRevisionSize; $this->mInputSize = false; wfProfileOut( $fname ); wfProfileOut( __METHOD__ ); return $this->mOutput; }
/** * Make a new user account using the loaded data. * @private * @throws PermissionsError|ReadOnlyError * @return Status */ public function addNewAccountInternal() { global $wgAuth, $wgMemc, $wgAccountCreationThrottle, $wgMinimalPasswordLength, $wgEmailConfirmToEdit; // If the user passes an invalid domain, something is fishy if ( !$wgAuth->validDomain( $this->mDomain ) ) { return Status::newFatal( 'wrongpassword' ); } // If we are not allowing users to login locally, we should be checking // to see if the user is actually able to authenticate to the authenti- // cation server before they create an account (otherwise, they can // create a local account and login as any domain user). We only need // to check this for domains that aren't local. if ( 'local' != $this->mDomain && $this->mDomain != '' ) { if ( !$wgAuth->canCreateAccounts() && ( !$wgAuth->userExists( $this->mUsername ) || !$wgAuth->authenticate( $this->mUsername, $this->mPassword ) ) ) { return Status::newFatal( 'wrongpassword' ); } } if ( wfReadOnly() ) { throw new ReadOnlyError; } # Request forgery checks. if ( !self::getCreateaccountToken() ) { self::setCreateaccountToken(); return Status::newFatal( 'nocookiesfornew' ); } # The user didn't pass a createaccount token if ( !$this->mToken ) { return Status::newFatal( 'sessionfailure' ); } # Validate the createaccount token if ( $this->mToken !== self::getCreateaccountToken() ) { return Status::newFatal( 'sessionfailure' ); } # Check permissions $currentUser = $this->getUser(); $creationBlock = $currentUser->isBlockedFromCreateAccount(); if ( !$currentUser->isAllowed( 'createaccount' ) ) { throw new PermissionsError( 'createaccount' ); } elseif ( $creationBlock instanceof Block ) { // Throws an ErrorPageError. $this->userBlockedMessage( $creationBlock ); // This should never be reached. return false; } # Include checks that will include GlobalBlocking (Bug 38333) $permErrors = $this->getTitle()->getUserPermissionsErrors( 'createaccount', $currentUser, true ); if ( count( $permErrors ) ) { throw new PermissionsError( 'createaccount', $permErrors ); } $ip = $this->getRequest()->getIP(); if ( $currentUser->isDnsBlacklisted( $ip, true /* check $wgProxyWhitelist */ ) ) { return Status::newFatal( 'sorbs_create_account_reason' ); } # Now create a dummy user ($u) and check if it is valid $name = trim( $this->mUsername ); $u = User::newFromName( $name, 'creatable' ); if ( !is_object( $u ) ) { return Status::newFatal( 'noname' ); } elseif ( 0 != $u->idForName() ) { return Status::newFatal( 'userexists' ); } if ( $this->mCreateaccountMail ) { # do not force a password for account creation by email # set invalid password, it will be replaced later by a random generated password $this->mPassword = null; } else { if ( $this->mPassword !== $this->mRetype ) { return Status::newFatal( 'badretype' ); } # check for minimal password length $valid = $u->getPasswordValidity( $this->mPassword ); if ( $valid !== true ) { if ( !is_array( $valid ) ) { $valid = array( $valid, $wgMinimalPasswordLength ); } return call_user_func_array( 'Status::newFatal', $valid ); } } # if you need a confirmed email address to edit, then obviously you # need an email address. if ( $wgEmailConfirmToEdit && strval( $this->mEmail ) === '' ) { return Status::newFatal( 'noemailtitle' ); } if ( strval( $this->mEmail ) !== '' && !Sanitizer::validateEmail( $this->mEmail ) ) { return Status::newFatal( 'invalidemailaddress' ); } # Set some additional data so the AbortNewAccount hook can be used for # more than just username validation $u->setEmail( $this->mEmail ); $u->setRealName( $this->mRealName ); $abortError = ''; if ( !wfRunHooks( 'AbortNewAccount', array( $u, &$abortError ) ) ) { // Hook point to add extra creation throttles and blocks wfDebug( "LoginForm::addNewAccountInternal: a hook blocked creation\n" ); $abortError = new RawMessage( $abortError ); $abortError->text(); return Status::newFatal( $abortError ); } // Hook point to check for exempt from account creation throttle if ( !wfRunHooks( 'ExemptFromAccountCreationThrottle', array( $ip ) ) ) { wfDebug( "LoginForm::exemptFromAccountCreationThrottle: a hook allowed account creation w/o throttle\n" ); } else { if ( ( $wgAccountCreationThrottle && $currentUser->isPingLimitable() ) ) { $key = wfMemcKey( 'acctcreate', 'ip', $ip ); $value = $wgMemc->get( $key ); if ( !$value ) { $wgMemc->set( $key, 0, 86400 ); } if ( $value >= $wgAccountCreationThrottle ) { return Status::newFatal( 'acct_creation_throttle_hit', $wgAccountCreationThrottle ); } $wgMemc->incr( $key ); } } if ( !$wgAuth->addUser( $u, $this->mPassword, $this->mEmail, $this->mRealName ) ) { return Status::newFatal( 'externaldberror' ); } self::clearCreateaccountToken(); return $this->initUser( $u, false ); }
public static function from(RawMessage $message) { return new static($message->nickname(), $message->username(), $message->hostname(), $message->serverName(), $message->command(), $message->params()); }
/** * @param RawMessage|string|array $msg * - RawMessage: is cloned * - array: first element is $key, rest are $params to RawMessage::__construct * - string: passed to RawMessage::__construct * @param string|null $code * @param array|null $data * @return ApiMessage */ public function __construct($msg, $code = null, array $data = null) { if ($msg instanceof RawMessage) { foreach (get_class_vars(get_class($this)) as $key => $value) { if (isset($msg->{$key})) { $this->{$key} = $msg->{$key}; } } } elseif (is_array($msg)) { $key = array_shift($msg); parent::__construct($key, $msg); } else { parent::__construct($msg); } $this->apiCode = $code; $this->apiData = (array) $data; }
/** * @covers Message::text * @covers Message::parse * @covers Message::parseAsBlock * @covers Message::toString * @covers Message::transformText * @covers Message::parseText * @dataProvider provideParser */ public function testParser($expect, $format) { $msg = new RawMessage("''&'' <x><!-- x -->"); $this->assertEquals($expect, $msg->inLanguage('en')->{$format}()); }
/** * Process the wikitext for the "?preload=" feature. (bug 5210) * * "<noinclude>", "<includeonly>" etc. are parsed as for template * transclusion, comments, templates, arguments, tags hooks and parser * functions are untouched. * * @param $text String * @param $title Title * @param $options ParserOptions * @param $params Array * @return String */ public function getPreloadText($text, Title $title, ParserOptions $options, $params = array()) { $msg = new RawMessage($text); $text = $msg->params($params)->plain(); # Parser (re)initialisation $this->startParse($title, $options, self::OT_PLAIN, true); $flags = PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES; $dom = $this->preprocessToDom($text, self::PTD_FOR_INCLUSION); $text = $this->getPreprocessor()->newFrame()->expand($dom, $flags); $text = $this->mStripState->unstripBoth($text); return $text; }
/** * @todo Move this to AbstractBlock and use for summary/header/etc. * @param AbstractRevision $revision * @return Message */ protected function getDisallowedErrorMessage(AbstractRevision $revision) { if (in_array($this->action, array('moderate-topic', 'moderate-post'))) { /* * When failing to moderate an already moderated action (like * undo), show the more general "you have insufficient * permissions for this action" message, rather than the * specialized "this topic is <hidden|deleted|suppressed>" msg. */ return $this->context->msg('flow-error-not-allowed'); } $state = $revision->getModerationState(); // display simple message // i18n messages: // flow-error-not-allowed-hide, // flow-error-not-allowed-reply-to-hide-topic // flow-error-not-allowed-delete // flow-error-not-allowed-reply-to-delete-topic // flow-error-not-allowed-suppress // flow-error-not-allowed-reply-to-suppress-topic if ($revision instanceof PostRevision) { $type = $revision->isTopicTitle() ? 'topic' : 'post'; } else { $type = $revision->getRevisionType(); } // Show a snippet of the relevant log entry if available. if (\LogPage::isLogType($state)) { // check if user has sufficient permissions to see log $logPage = new \LogPage($state); if ($this->context->getUser()->isAllowed($logPage->getRestriction())) { // LogEventsList::showLogExtract will write to OutputPage, but we // actually just want that text, to write it ourselves wherever we want, // so let's create an OutputPage object to then get the content from. $rc = new \RequestContext(); $output = $rc->getOutput(); // get log extract $entries = \LogEventsList::showLogExtract($output, array($state), $this->workflow->getArticleTitle()->getPrefixedText(), '', array('lim' => 10, 'showIfEmpty' => false, 'msgKey' => array(array("flow-error-not-allowed-{$this->action}-to-{$state}-{$type}", "flow-error-not-allowed-{$state}-extract")))); // check if there were any log extracts if ($entries) { $message = new \RawMessage('$1'); return $message->rawParams($output->getHTML()); } } } return $this->context->msg(array("flow-error-not-allowed-{$this->action}-to-{$state}-{$type}", "flow-error-not-allowed-{$state}", "flow-error-not-allowed")); }