/** * Handles autoedit Ajax call from #autoedit parser function and from save * and continue button. * * @param String $optionsString the options/data string * @param String $prefillFromExisting String set to 'true' to retain existing form values (unset by save and continue) * @return String */ static function handleAutoEdit( $optionsString = null, $prefillFromExisting = 'true' ) { global $wgParser; $handler = new self( null, 'sfautoedit' ); $handler->isApiQuery( false ); $options = $handler->setOptionsString( $optionsString ); // get oktext (or use default) if ( array_key_exists( 'ok text', $options ) ) { $oktext = $options['ok text']; } else { $oktext = wfMsg( 'sf_autoedit_success' ); } // get errortext (or use default) if ( array_key_exists( 'error text', $options ) ) { $errortext = $options['error text']; } else { $errortext = '$1'; } // process data // result will be true or an error message $result = $handler->storeSemanticData( $prefillFromExisting === 'true' ); // wrap result in ok/error message if ( $result === true ) { $options = $handler->getOptions(); $result = wfMsgReplaceArgs( $oktext, array( $options['target'], $options['form'] ) ); } else { $result->setResponseCode( '400 Bad Request' ); $result = wfMsgReplaceArgs( $errortext, array( $result ) ); } // initialize parser $title = Title::newFromText( 'DummyTitle' ); if ( !StubObject::isRealObject( $wgParser ) ) { $wgParser->_unstub(); } $parseroptions = $wgParser->getOptions(); if ( $parseroptions == null ) { $parseroptions = new ParserOptions(); $wgParser->Options( $parseroptions ); } $parseroptions->enableLimitReport( false ); $result = new AjaxResponse( $wgParser->parse( $result, $title, $parseroptions )->getText() ); $result->setContentType( 'text/html' ); return $result; }
function getMessage($messageCode) { $messageParameters = func_get_args(); array_shift($messageParameters); $message = \wfMsgGetKey($messageCode, true, $this->languageCode); $message = \wfMsgReplaceArgs($message, $messageParameters); return $message; }
/** * Get a message from i18n * * @param $key String: message name * @param $fallback String: default message if the message cache can't be * called by the exception * The function also has other parameters that are arguments for the message * @return String message with arguments replaced */ function msg($key, $fallback) { $args = array_slice(func_get_args(), 2); if ($this->useMessageCache()) { return wfMsgNoTrans($key, $args); } else { return wfMsgReplaceArgs($fallback, $args); } }
static function intFunction($parser, $part1 = '') { if (strval($part1) !== '') { $args = array_slice(func_get_args(), 2); $message = wfMsgGetKey($part1, true, false, false); $message = wfMsgReplaceArgs($message, $args); $message = $parser->replaceVariables($message); // like $wgMessageCache->transform() return $message; } else { return array('found' => false); } }
public static function plural($data, $params, $parser) { list($from, $to) = self::getRange(@$params['n']); $args = explode('|', $data); $lang = self::languageObject($params); $format = isset($params['format']) ? $params['format'] : '%s'; $format = str_replace('\\n', "\n", $format); $s = ''; for ($i = $from; $i <= $to; $i++) { $t = $lang->convertPlural($i, $args); $fmtn = $lang->formatNum($i); $s .= str_replace(array('%d', '%s'), array($i, wfMsgReplaceArgs($t, array($fmtn))), $format); } return $s; }
/** * Run the job * @return boolean success */ function run() { global $wgUser, $wgCommandLineMode; $oldUser = $wgUser; $wgUser = User::newFromId($this->params['user']); unset($this->params['user']); $this->params['form'] = $this->title->getText(); $handler = new SFAutoeditAPI(null, 'sfautoedit'); $handler->isApiQuery(false); $handler->setOptions($this->params); $result = $handler->storeSemanticData(false); // wrap result in ok/error message if ($result === true) { $options = $handler->getOptions(); $result = wfMsg('sf_autoedit_success', $options['target'], $options['form']); } else { $result = wfMsgReplaceArgs('$1', array($result)); } $this->params = array('result' => $result, 'user' => $wgUser->getName()); wfDebugLog('sps', 'Page Creation Job: ' . $result); $wgUser = $oldUser; }
/** * Return the error message related to a certain array * @param array $error Element of a getUserPermissionsErrors()-style array * @return array('code' => code, 'info' => info) */ public function parseMsg($error) { $error = (array) $error; // It seems strings sometimes make their way in here $key = array_shift($error); // Check whether the error array was nested // array( array( <code>, <params> ), array( <another_code>, <params> ) ) if (is_array($key)) { $error = $key; $key = array_shift($error); } if ($key instanceof IApiMessage) { return array('code' => $key->getApiCode(), 'info' => $key->inLanguage('en')->useDatabase(false)->text(), 'data' => $key->getApiData()); } if (isset(self::$messageMap[$key])) { return array('code' => wfMsgReplaceArgs(self::$messageMap[$key]['code'], $error), 'info' => wfMsgReplaceArgs(self::$messageMap[$key]['info'], $error)); } // If the key isn't present, throw an "unknown error" return $this->parseMsg(array('unknownerror', $key)); }
/** * Returns message in the requested format after parsing wikitext to html * This is meant to be equivalent to wfMsgExt() with parse, parsemag and * escape as available options but using the DPL local parser instead of * the global one (bugfix). */ function msgExt($key, $options) { $args = func_get_args(); array_shift($args); array_shift($args); if (!is_array($options)) { $options = array($options); } $string = wfMsgNoTrans($key); $string = wfMsgReplaceArgs($string, $args); if (in_array('parse', $options)) { $this->mParserOptions->setInterfaceMessage(true); $string = $this->mParser->recursiveTagParse($string); $this->mParserOptions->setInterfaceMessage(false); // $string = $parserOutput->getText(); } elseif (in_array('parsemag', $options)) { $parser = new Parser(); $parserOptions = new ParserOptions(); $parserOptions->setInterfaceMessage(true); $parser->startExternalParse($this->mParserTitle, $parserOptions, OT_MSG); $string = $parser->transformMsg($string, $parserOptions); } if (in_array('escape', $options)) { $string = htmlspecialchars($string); } return $string; }
/** * @param string $key * @param string $fallback Unescaped alternative error text in case the * message cache cannot be used. Can contain parameters as in regular * messages, that should be passed as additional parameters. * @return string Unprocessed plain error text with parameters replaced */ function msg($key, $fallback) { $args = array_slice(func_get_args(), 2); if ($this->useMessageCache()) { return wfMessage($key, $args)->useDatabase(false)->text(); } else { return wfMsgReplaceArgs($fallback, $args); } }
/** * Returns message in the requested format * @param string $key Key of the message * @param array $options Processing rules: * <i>parse<i>: parses wikitext to html * <i>parseinline<i>: parses wikitext to html and removes the surrounding p's added by parser or tidy * <i>escape<i>: filters message trough htmlspecialchars * <i>replaceafter<i>: parameters are substituted after parsing or escaping */ function wfMsgExt($key, $options) { global $wgOut, $wgMsgParserOptions, $wgParser; $args = func_get_args(); array_shift($args); array_shift($args); if (!is_array($options)) { $options = array($options); } $string = wfMsgGetKey($key, true, false, false); if (!in_array('replaceafter', $options)) { $string = wfMsgReplaceArgs($string, $args); } if (in_array('parse', $options)) { $string = $wgOut->parse($string, true, true); } elseif (in_array('parseinline', $options)) { $string = $wgOut->parse($string, true, true); $m = array(); if (preg_match("~^<p>(.*)\n?</p>\$~", $string, $m)) { $string = $m[1]; } } elseif (in_array('parsemag', $options)) { global $wgTitle; $parser = new Parser(); $parserOptions = new ParserOptions(); $parserOptions->setInterfaceMessage(true); $parser->startExternalParse($wgTitle, $parserOptions, OT_MSG); $string = $parser->transformMsg($string, $parserOptions); } if (in_array('escape', $options)) { $string = htmlspecialchars($string); } if (in_array('replaceafter', $options)) { $string = wfMsgReplaceArgs($string, $args); } return $string; }
/** * Returns message in the requested format after parsing wikitext to html * This is meant to be equivalent to wfMsgExt() with parse, parsemag and escape as available options but using the DPL local parser instead of the global one (bugfix). */ function msgExt($key, $options) { $args = func_get_args(); array_shift($args); array_shift($args); if (!is_array($options)) { $options = array($options); } $string = wfMsgNoTrans($key); $string = wfMsgReplaceArgs($string, $args); $this->mParserOptions->setInterfaceMessage(true); $string = $this->mParser->recursiveTagParse($string); $this->mParserOptions->setInterfaceMessage(false); if (in_array('escape', $options)) { $string = htmlspecialchars($string); } return $string; }
public function execute() { $params = $this->extractRequestParams(); global $wgLang; $oldLang = null; if (!is_null($params['lang'])) { $oldLang = $wgLang; // Keep $wgLang for restore later $wgLang = Language::factory($params['lang']); } $prop = array_flip((array) $params['prop']); // Determine which messages should we print if (in_array('*', $params['messages'])) { $message_names = array_keys(Language::getMessagesFor('en')); sort($message_names); $messages_target = $message_names; } else { $messages_target = $params['messages']; } // Filter messages if (isset($params['filter'])) { $messages_filtered = array(); foreach ($messages_target as $message) { // !== is used because filter can be at the beginning of the string if (strpos($message, $params['filter']) !== false) { $messages_filtered[] = $message; } } $messages_target = $messages_filtered; } // Get all requested messages and print the result $skip = !is_null($params['from']); $useto = !is_null($params['to']); $result = $this->getResult(); foreach ($messages_target as $message) { // Skip all messages up to $params['from'] if ($skip && $message === $params['from']) { $skip = false; } if ($useto && $message > $params['to']) { break; } if (!$skip) { $a = array('name' => $message); $args = null; if (isset($params['args']) && count($params['args']) != 0) { $args = $params['args']; } // Check if the parser is enabled: if ($params['enableparser']) { $msg = wfMsgExt($message, array('parsemag'), $args); } elseif ($args) { $msgString = wfMsgGetKey($message, true, false, false); $msg = wfMsgReplaceArgs($msgString, $args); } else { $msg = wfMsgGetKey($message, true, false, false); } if (wfEmptyMsg($message, $msg)) { $a['missing'] = ''; } else { ApiResult::setContent($a, $msg); if (isset($prop['default'])) { $default = wfMsgGetKey($message, false, false, false); if ($default !== $msg) { if (wfEmptyMsg($message, $default)) { $a['defaultmissing'] = ''; } else { $a['default'] = $default; } } } } $fit = $result->addValue(array('query', $this->getModuleName()), null, $a); if (!$fit) { $this->setContinueEnumParameter('from', $message); break; } } } $result->setIndexedTagName_internal(array('query', $this->getModuleName()), 'message'); if (!is_null($oldLang)) { $wgLang = $oldLang; // Restore $oldLang } }
/** * @return mixed|string */ public function reallyMakeHelpMsg() { $this->setHelp(); // Use parent to make default message for the main module $msg = parent::makeHelpMsg(); $astriks = str_repeat('*** ', 14); $msg .= "\n\n{$astriks} Modules {$astriks}\n\n"; foreach (array_keys($this->mModules) as $moduleName) { $module = new $this->mModules[$moduleName]($this, $moduleName); $msg .= self::makeHelpMsgHeader($module, 'action'); $msg2 = $module->makeHelpMsg(); if ($msg2 !== false) { $msg .= $msg2; } $msg .= "\n"; } $msg .= "\n{$astriks} Permissions {$astriks}\n\n"; foreach (self::$mRights as $right => $rightMsg) { $groups = User::getGroupsWithPermission($right); $msg .= "* " . $right . " *\n " . wfMsgReplaceArgs($rightMsg['msg'], $rightMsg['params']) . "\nGranted to:\n " . str_replace('*', 'all', implode(', ', $groups)) . "\n\n"; } $msg .= "\n{$astriks} Formats {$astriks}\n\n"; foreach (array_keys($this->mFormats) as $formatName) { $module = $this->createPrinterByName($formatName); $msg .= self::makeHelpMsgHeader($module, 'format'); $msg2 = $module->makeHelpMsg(); if ($msg2 !== false) { $msg .= $msg2; } $msg .= "\n"; } $msg .= "\n*** Credits: ***\n " . implode("\n ", $this->getCredits()) . "\n"; return $msg; }
/** * Embeds video of the chosen service * @param Parser $parser Instance of running Parser. * @param String $service Which online service has the video. * @param String $id Identifier of the chosen service * @param String $width Width of video (optional) * @param String $desc description to show (optional) * @param String $align alignment of the video (optional) * @return String Encoded representation of input params (to be processed later) */ public static function parserFunction_ev($parser, $service = null, $id = null, $width = null, $align = null, $desc = null) { global $wgScriptPath; // Initialize things once if (!self::$initialized) { self::VerifyWidthMinAndMax(); self::$initialized = true; } // Get the name of the host if ($service === null || $id === null) { return self::errMissingParams($service, $id); } $service = trim($service); $id = trim($id); $desc = $parser->recursiveTagParse($desc); $entry = self::getServiceEntry($service); if (!$entry) { return self::errBadService($service); } if (!self::sanitizeWidth($entry, $width)) { return self::errBadWidth($width); } $height = self::getHeight($entry, $width); $hasalign = $align !== null || $align == 'auto'; if ($hasalign) { $align = trim($align); if (!self::validateAlignment($align)) { return self::errBadAlignment($align); } $desc = self::getDescriptionMarkup($desc); } // If the service has an ID pattern specified, verify the id number if (!self::verifyID($entry, $id)) { return self::errBadID($service, $id); } $url = null; // If service is Yandex -> use own parser if ($service == 'yandex' || $service == 'yandexvideo') { $url = self::getYandex($id); $url = htmlspecialchars_decode($url); } // if the service has it's own custom extern declaration, use that instead if (array_key_exists('extern', $entry) && ($clause = $entry['extern']) != NULL) { if ($service == 'screen9') { $clause = self::parseScreen9Id($id, $width, $height); if ($clause == null) { return self::errBadScreen9Id(); } } else { $clause = wfMsgReplaceArgs($clause, array($wgScriptPath, $id, $width, $height, $url)); } if ($hasalign) { $clause = self::generateAlignExternClause($clause, $align, $desc, $width, $height); } return array($clause, 'noparse' => true, 'isHTML' => true); } // Build URL and output embedded flash object $url = wfMsgReplaceArgs($entry['url'], array($id, $width, $height)); $clause = ""; // If service is RuTube -> use own parser if ($service == 'rutube') { $url = self::getRuTube($id); } if ($hasalign) { $clause = self::generateAlignClause($url, $width, $height, $align, $desc); } else { $clause = self::generateNormalClause($url, $width, $height); } return array($clause, 'noparse' => true, 'isHTML' => true); }
/** * Return the error message related to a certain array * @param $error array Element of a getUserPermissionsErrors()-style array * @return array('code' => code, 'info' => info) */ public function parseMsg($error) { $key = array_shift($error); if (isset(self::$messageMap[$key])) { return array('code' => wfMsgReplaceArgs(self::$messageMap[$key]['code'], $error), 'info' => wfMsgReplaceArgs(self::$messageMap[$key]['info'], $error)); } // If the key isn't present, throw an "unknown error" return $this->parseMsg(array('unknownerror', $key)); }
/** * Really get a message * @return $key String: key to get. * @return $args * @return $useDB Boolean * @return String: the requested message. */ function wfMsgReal($key, $args, $useDB = true, $forContent = false, $transform = true) { $fname = 'wfMsgReal'; $message = wfMsgGetKey($key, $useDB, $forContent, $transform); $message = wfMsgReplaceArgs($message, $args); return $message; }
/** * Callback function to output a block */ function formatRow($block) { global $wgUser, $wgLang; wfProfileIn(__METHOD__); static $sk = null, $msg = null; if (is_null($sk)) { $sk = $wgUser->getSkin(); } if (is_null($msg)) { $msg = array(); $keys = array('infiniteblock', 'expiringblock', 'contribslink', 'unblocklink', 'anononlyblock', 'createaccountblock'); foreach ($keys as $key) { $msg[$key] = wfMsgHtml($key); } $msg['blocklistline'] = wfMsg('blocklistline'); $msg['contribslink'] = wfMsg('contribslink'); } # Prepare links to the blocker's user and talk pages $blocker_name = $block->getByName(); $blocker = $sk->MakeLinkObj(Title::makeTitle(NS_USER, $blocker_name), $blocker_name); $blocker .= ' (' . $sk->makeLinkObj(Title::makeTitle(NS_USER_TALK, $blocker_name), $wgLang->getNsText(NS_TALK)) . ')'; # Prepare links to the block target's user and contribs. pages (as applicable, don't do it for autoblocks) if ($block->mAuto) { $target = $block->getRedactedName(); # Hide the IP addresses of auto-blocks; privacy } else { $target = $sk->makeLinkObj(Title::makeTitle(NS_USER, $block->mAddress), $block->mAddress); $target .= ' (' . $sk->makeKnownLinkObj(Title::makeTitle(NS_SPECIAL, 'Contributions'), $msg['contribslink'], 'target=' . urlencode($block->mAddress)) . ')'; } $formattedTime = $wgLang->timeanddate($block->mTimestamp, true); $properties = array(); if ($block->mExpiry === "" || $block->mExpiry === Block::infinity()) { $properties[] = $msg['infiniteblock']; } else { $properties[] = wfMsgReplaceArgs($msg['expiringblock'], array($wgLang->timeanddate($block->mExpiry, true))); } if ($block->mAnonOnly) { $properties[] = $msg['anononlyblock']; } if ($block->mCreateAccount) { $properties[] = $msg['createaccountblock']; } $properties = implode(', ', $properties); $line = wfMsgReplaceArgs($msg['blocklistline'], array($formattedTime, $blocker, $target, $properties)); $s = "<li>{$line}"; if ($wgUser->isAllowed('block')) { $titleObj = Title::makeTitle(NS_SPECIAL, "Ipblocklist"); $s .= ' (' . $sk->makeKnownLinkObj($titleObj, $msg['unblocklink'], 'action=unblock&id=' . urlencode($block->mId)) . ')'; } $s .= $sk->commentBlock($block->mReason); $s .= "</li>\n"; wfProfileOut(__METHOD__); return $s; }
private static function doRollback() { global $wgRequest, $wgOut, $wgContLang; $wgOut->setArticleBodyOnly(true); $response = ""; $aid = intVal($wgRequest->getVal('aid')); $oldid = intVal($wgRequest->getVal('old')); $from = $wgRequest->getVal('from'); $from = preg_replace('/[_-]/', ' ', $from); $t = Title::newFromId($aid); if ($t && $t->exists()) { $r = Revision::newFromId($oldid); if ($r) { if ($from == '') { // no public user name $summary = wfMessage('rcp-revertpage-nouser'); } else { $summary = wfMessage('rcp-revertpage'); } // Allow the custom summary to use the same args as the default message $args = array($r->getUserText(), $from, $oldid); if ($summary instanceof Message) { $summary = $summary->params($args)->inContentLanguage()->text(); } else { $summary = wfMsgReplaceArgs($summary, $args); } // Trim spaces on user supplied text $summary = trim($summary); // Truncate for whole multibyte characters. $summary = $wgContLang->truncate($summary, 255); $a = new Article($t); $newRev = Revision::newFromTitle($t); $old = Linker::revUserTools(Revision::newFromId($oldid)); $new = Linker::revUserTools($newRev); $revision = 'r' . htmlspecialchars($wgContLang->formatNum($oldid, true)); $revlink = Linker::link($t, $revision, array(), array('oldid' => $oldid, 'diff' => 'prev')); $response = WfMessage('rcp-rollback-success')->rawParams($new, $old, $revlink); $status = $a->doEditContent($r->getContent(), $summary); if (!$status->isOK()) { $response = $status->getErrorsArray(); } // raise error, when the edit is an edit without a new version if (empty($status->value['revision'])) { $resultDetails = array('current' => $current); $query = array('oldid' => $oldid, 'diff' => 'prev'); $response = WfMessage('rcp-alreadyrolled')->params(array(htmlspecialchars($t->getPrefixedText()), htmlspecialchars($from), htmlspecialchars($newRev->getUserText())))->inContentLanguage()->parse(); } } } $wgOut->addHtml($response); }
/** * Callback function to output a block */ function addRow($block, $tag) { global $wgOut, $wgUser, $wgLang; if ($this->ip != '') { if ($block->mAuto) { if (stristr($block->mId, $this->ip) == false) { return; } } else { if (stristr($block->mAddress, $this->ip) == false) { return; } } } // Loading blocks is fast; displaying them is slow. // Quick hack for paging. $this->counter++; if ($this->counter <= $this->offset) { return; } if ($this->counter - $this->offset > $this->limit) { return; } $fname = 'IPUnblockForm-addRow'; wfProfileIn($fname); static $sk = null, $msg = null; if (is_null($sk)) { $sk = $wgUser->getSkin(); } if (is_null($msg)) { $msg = array(); foreach (array('infiniteblock', 'expiringblock', 'contribslink', 'unblocklink') as $key) { $msg[$key] = wfMsgHtml($key); } $msg['blocklistline'] = wfMsg('blocklistline'); $msg['contribslink'] = wfMsg('contribslink'); } # Prepare links to the blocker's user and talk pages $blocker_name = $block->getByName(); $blocker = $sk->MakeLinkObj(Title::makeTitle(NS_USER, $blocker_name), $blocker_name); $blocker .= ' (' . $sk->makeLinkObj(Title::makeTitle(NS_USER_TALK, $blocker_name), $wgLang->getNsText(NS_TALK)) . ')'; # Prepare links to the block target's user and contribs. pages (as applicable, don't do it for autoblocks) if ($block->mAuto) { $target = '#' . $block->mId; # Hide the IP addresses of auto-blocks; privacy } else { $target = $sk->makeLinkObj(Title::makeTitle(NS_USER, $block->mAddress), $block->mAddress); $target .= ' (' . $sk->makeKnownLinkObj(Title::makeTitle(NS_SPECIAL, 'Contributions'), $msg['contribslink'], 'target=' . urlencode($block->mAddress)) . ')'; } # Prep the address for the unblock link, masking autoblocks as before $addr = $block->mAuto ? '#' . $block->mId : $block->mAddress; $formattedTime = $wgLang->timeanddate($block->mTimestamp, true); if ($block->mExpiry === "") { $formattedExpiry = $msg['infiniteblock']; } else { $formattedExpiry = wfMsgReplaceArgs($msg['expiringblock'], array($wgLang->timeanddate($block->mExpiry, true))); } $line = wfMsgReplaceArgs($msg['blocklistline'], array($formattedTime, $blocker, $target, $formattedExpiry)); $wgOut->addHTML("<li>{$line}"); if ($wgUser->isAllowed('block')) { $titleObj = Title::makeTitle(NS_SPECIAL, "Ipblocklist"); $wgOut->addHTML(' (' . $sk->makeKnownLinkObj($titleObj, $msg['unblocklink'], 'action=unblock&ip=' . urlencode($addr)) . ')'); } $wgOut->addHTML($sk->commentBlock($block->mReason)); $wgOut->addHTML("</li>\n"); wfProfileOut($fname); }
/** * @param string $key * @param string $fallback Unescaped alternative error text in case the * message cache cannot be used. Can contain parameters as in regular * messages, that should be passed as additional parameters. * @return string Unprocessed plain error text with parameters replaced */ function msg($key, $fallback) { global $wgLang; $args = array_slice(func_get_args(), 2); if ($this->useMessageCache()) { $message = $wgLang->getMessage($key); } else { $message = $fallback; } return wfMsgReplaceArgs($message, $args); }
/** * Return the error message related to a certain array * @param array $error Element of a getUserPermissionsErrors()-style array * @return array('code' => code, 'info' => info) */ public function parseMsg($error) { $error = (array) $error; // It seems strings sometimes make their way in here $key = array_shift($error); // Check whether the error array was nested // array( array( <code>, <params> ), array( <another_code>, <params> ) ) if (is_array($key)) { $error = $key; $key = array_shift($error); } if (isset(self::$messageMap[$key])) { return array('code' => wfMsgReplaceArgs(self::$messageMap[$key]['code'], $error), 'info' => wfMsgReplaceArgs(self::$messageMap[$key]['info'], $error)); } // If the key isn't present, throw an "unknown error" return $this->parseMsg(array('unknownerror', $key)); }
/** * Backend implementation of doRollback(), please refer there for parameter * and return value documentation * * NOTE: This function does NOT check ANY permissions, it just commits the * rollback to the DB Therefore, you should only call this function direct- * ly if you want to use custom permissions checks. If you don't, use * doRollback() instead. */ public function commitRollback($fromP, $summary, $bot, &$resultDetails) { global $wgUseRCPatrol, $wgUser, $wgLang; $dbw = wfGetDB(DB_MASTER); if (wfReadOnly()) { return array(array('readonlytext')); } # Get the last editor $current = Revision::newFromTitle($this->mTitle); if (is_null($current)) { # Something wrong... no page? return array(array('notanarticle')); } $from = str_replace('_', ' ', $fromP); if ($from != $current->getUserText()) { $resultDetails = array('current' => $current); return array(array('alreadyrolled', htmlspecialchars($this->mTitle->getPrefixedText()), htmlspecialchars($fromP), htmlspecialchars($current->getUserText()))); } # Get the last edit not by this guy $user = intval($current->getUser()); $user_text = $dbw->addQuotes($current->getUserText()); $s = $dbw->selectRow('revision', array('rev_id', 'rev_timestamp', 'rev_deleted'), array('rev_page' => $current->getPage(), "rev_user != {$user} OR rev_user_text != {$user_text}"), __METHOD__, array('USE INDEX' => 'page_timestamp', 'ORDER BY' => 'rev_timestamp DESC')); if ($s === false) { # No one else ever edited this page return array(array('cantrollback')); } else { if ($s->rev_deleted & REVISION::DELETED_TEXT || $s->rev_deleted & REVISION::DELETED_USER) { # Only admins can see this text return array(array('notvisiblerev')); } } $set = array(); if ($bot && $wgUser->isAllowed('markbotedits')) { # Mark all reverted edits as bot $set['rc_bot'] = 1; } if ($wgUseRCPatrol) { # Mark all reverted edits as patrolled $set['rc_patrolled'] = 1; } if ($set) { $dbw->update('recentchanges', $set, array('rc_cur_id' => $current->getPage(), 'rc_user_text' => $current->getUserText(), "rc_timestamp > '{$s->rev_timestamp}'"), __METHOD__); } # Generate the edit summary if necessary $target = Revision::newFromId($s->rev_id); if (empty($summary)) { $summary = wfMsgForContent('revertpage'); } # Allow the custom summary to use the same args as the default message $args = array($target->getUserText(), $from, $s->rev_id, $wgLang->timeanddate(wfTimestamp(TS_MW, $s->rev_timestamp), true), $current->getId(), $wgLang->timeanddate($current->getTimestamp())); $summary = wfMsgReplaceArgs($summary, $args); # Save $flags = EDIT_UPDATE; if ($wgUser->isAllowed('minoredit')) { $flags |= EDIT_MINOR; } if ($bot && ($wgUser->isAllowed('markbotedits') || $wgUser->isAllowed('bot'))) { $flags |= EDIT_FORCE_BOT; } # Actually store the edit $status = $this->doEdit($target->getText(), $summary, $flags, $target->getId()); if (!empty($status->value['revision'])) { $revId = $status->value['revision']->getId(); } else { $revId = false; } wfRunHooks('ArticleRollbackComplete', array($this, $wgUser, $target, $current)); $resultDetails = array('summary' => $summary, 'current' => $current, 'target' => $target, 'newid' => $revId); return array(); }
/** * Returns message in the requested format * * @deprecated since 1.18 * * @param string $key Key of the message * @param array $options Processing rules. * Can take the following options: * parse: parses wikitext to HTML * parseinline: parses wikitext to HTML and removes the surrounding * p's added by parser or tidy * escape: filters message through htmlspecialchars * escapenoentities: same, but allows entity references like   through * replaceafter: parameters are substituted after parsing or escaping * parsemag: transform the message using magic phrases * content: fetch message for content language instead of interface * Also can accept a single associative argument, of the form 'language' => 'xx': * language: Language object or language code to fetch message for * (overridden by content). * Behavior for conflicting options (e.g., parse+parseinline) is undefined. * * @return string */ function wfMsgExt($key, $options) { wfDeprecated(__METHOD__, '1.21'); $args = func_get_args(); array_shift($args); array_shift($args); $options = (array) $options; $validOptions = array('parse', 'parseinline', 'escape', 'escapenoentities', 'replaceafter', 'parsemag', 'content'); foreach ($options as $arrayKey => $option) { if (!preg_match('/^[0-9]+|language$/', $arrayKey)) { // An unknown index, neither numeric nor "language" wfWarn("wfMsgExt called with incorrect parameter key {$arrayKey}", 1, E_USER_WARNING); } elseif (preg_match('/^[0-9]+$/', $arrayKey) && !in_array($option, $validOptions)) { // A numeric index with unknown value wfWarn("wfMsgExt called with incorrect parameter {$option}", 1, E_USER_WARNING); } } if (in_array('content', $options, true)) { $forContent = true; $langCode = true; $langCodeObj = null; } elseif (array_key_exists('language', $options)) { $forContent = false; $langCode = wfGetLangObj($options['language']); $langCodeObj = $langCode; } else { $forContent = false; $langCode = false; $langCodeObj = null; } $string = wfMsgGetKey($key, true, $langCode, false); if (!in_array('replaceafter', $options, true)) { $string = wfMsgReplaceArgs($string, $args); } $messageCache = MessageCache::singleton(); $parseInline = in_array('parseinline', $options, true); if (in_array('parse', $options, true) || $parseInline) { $string = $messageCache->parse($string, null, true, !$forContent, $langCodeObj); if ($string instanceof ParserOutput) { $string = $string->getText(); } if ($parseInline) { $string = Parser::stripOuterParagraph($string); } } elseif (in_array('parsemag', $options, true)) { $string = $messageCache->transform($string, !$forContent, $langCodeObj); } if (in_array('escape', $options, true)) { $string = htmlspecialchars($string); } elseif (in_array('escapenoentities', $options, true)) { $string = Sanitizer::escapeHtmlAllowEntities($string); } if (in_array('replaceafter', $options, true)) { $string = wfMsgReplaceArgs($string, $args); } return $string; }
/** * Returns message in the requested format * @param $key String: key of the message * @param $options Array: processing rules. Can take the following options: * <i>parse</i>: parses wikitext to HTML * <i>parseinline</i>: parses wikitext to HTML and removes the surrounding * p's added by parser or tidy * <i>escape</i>: filters message through htmlspecialchars * <i>escapenoentities</i>: same, but allows entity references like   through * <i>replaceafter</i>: parameters are substituted after parsing or escaping * <i>parsemag</i>: transform the message using magic phrases * <i>content</i>: fetch message for content language instead of interface * Also can accept a single associative argument, of the form 'language' => 'xx': * <i>language</i>: Language object or language code to fetch message for * (overriden by <i>content</i>). * Behavior for conflicting options (e.g., parse+parseinline) is undefined. * * @return String */ function wfMsgExt($key, $options) { $args = func_get_args(); array_shift($args); array_shift($args); $options = (array) $options; foreach ($options as $arrayKey => $option) { if (!preg_match('/^[0-9]+|language$/', $arrayKey)) { # An unknown index, neither numeric nor "language" wfWarn("wfMsgExt called with incorrect parameter key {$arrayKey}", 1, E_USER_WARNING); } elseif (preg_match('/^[0-9]+$/', $arrayKey) && !in_array($option, array('parse', 'parseinline', 'escape', 'escapenoentities', 'replaceafter', 'parsemag', 'content'))) { # A numeric index with unknown value wfWarn("wfMsgExt called with incorrect parameter {$option}", 1, E_USER_WARNING); } } if (in_array('content', $options, true)) { $forContent = true; $langCode = true; $langCodeObj = null; } elseif (array_key_exists('language', $options)) { $forContent = false; $langCode = wfGetLangObj($options['language']); $langCodeObj = $langCode; } else { $forContent = false; $langCode = false; $langCodeObj = null; } $string = wfMsgGetKey($key, true, $langCode, false); if (!in_array('replaceafter', $options, true)) { $string = wfMsgReplaceArgs($string, $args); } $messageCache = MessageCache::singleton(); if (in_array('parse', $options, true)) { $string = $messageCache->parse($string, null, true, !$forContent, $langCodeObj)->getText(); } elseif (in_array('parseinline', $options, true)) { $string = $messageCache->parse($string, null, true, !$forContent, $langCodeObj)->getText(); $m = array(); if (preg_match('/^<p>(.*)\\n?<\\/p>\\n?$/sU', $string, $m)) { $string = $m[1]; } } elseif (in_array('parsemag', $options, true)) { $string = $messageCache->transform($string, !$forContent, $langCodeObj); } if (in_array('escape', $options, true)) { $string = htmlspecialchars($string); } elseif (in_array('escapenoentities', $options, true)) { $string = Sanitizer::escapeHtmlAllowEntities($string); } if (in_array('replaceafter', $options, true)) { $string = wfMsgReplaceArgs($string, $args); } return $string; }
/** * Backend implementation of doRollback(), please refer there for parameter * and return value documentation * * NOTE: This function does NOT check ANY permissions, it just commits the * rollback to the DB. Therefore, you should only call this function direct- * ly if you want to use custom permissions checks. If you don't, use * doRollback() instead. * @param string $fromP Name of the user whose edits to rollback. * @param string $summary Custom summary. Set to default summary if empty. * @param bool $bot If true, mark all reverted edits as bot. * * @param array $resultDetails Contains result-specific array of additional values * @param User $guser The user performing the rollback * @param array|null $tags Change tags to apply to the rollback * Callers are responsible for permission checks * (with ChangeTags::canAddTagsAccompanyingChange) * * @return array */ public function commitRollback($fromP, $summary, $bot, &$resultDetails, User $guser, $tags = null) { global $wgUseRCPatrol, $wgContLang; $dbw = wfGetDB(DB_MASTER); if (wfReadOnly()) { return [['readonlytext']]; } // Get the last editor $current = $this->getRevision(); if (is_null($current)) { // Something wrong... no page? return [['notanarticle']]; } $from = str_replace('_', ' ', $fromP); // User name given should match up with the top revision. // If the user was deleted then $from should be empty. if ($from != $current->getUserText()) { $resultDetails = ['current' => $current]; return [['alreadyrolled', htmlspecialchars($this->mTitle->getPrefixedText()), htmlspecialchars($fromP), htmlspecialchars($current->getUserText())]]; } // Get the last edit not by this person... // Note: these may not be public values $user = intval($current->getUser(Revision::RAW)); $user_text = $dbw->addQuotes($current->getUserText(Revision::RAW)); $s = $dbw->selectRow('revision', ['rev_id', 'rev_timestamp', 'rev_deleted'], ['rev_page' => $current->getPage(), "rev_user != {$user} OR rev_user_text != {$user_text}"], __METHOD__, ['USE INDEX' => 'page_timestamp', 'ORDER BY' => 'rev_timestamp DESC']); if ($s === false) { // No one else ever edited this page return [['cantrollback']]; } elseif ($s->rev_deleted & Revision::DELETED_TEXT || $s->rev_deleted & Revision::DELETED_USER) { // Only admins can see this text return [['notvisiblerev']]; } // Generate the edit summary if necessary $target = Revision::newFromId($s->rev_id, Revision::READ_LATEST); if (empty($summary)) { if ($from == '') { // no public user name $summary = wfMessage('revertpage-nouser'); } else { $summary = wfMessage('revertpage'); } } // Allow the custom summary to use the same args as the default message $args = [$target->getUserText(), $from, $s->rev_id, $wgContLang->timeanddate(wfTimestamp(TS_MW, $s->rev_timestamp)), $current->getId(), $wgContLang->timeanddate($current->getTimestamp())]; if ($summary instanceof Message) { $summary = $summary->params($args)->inContentLanguage()->text(); } else { $summary = wfMsgReplaceArgs($summary, $args); } // Trim spaces on user supplied text $summary = trim($summary); // Truncate for whole multibyte characters. $summary = $wgContLang->truncate($summary, 255); // Save $flags = EDIT_UPDATE | EDIT_INTERNAL; if ($guser->isAllowed('minoredit')) { $flags |= EDIT_MINOR; } if ($bot && $guser->isAllowedAny('markbotedits', 'bot')) { $flags |= EDIT_FORCE_BOT; } $targetContent = $target->getContent(); $changingContentModel = $targetContent->getModel() !== $current->getContentModel(); // Actually store the edit $status = $this->doEditContent($targetContent, $summary, $flags, $target->getId(), $guser, null, $tags); // Set patrolling and bot flag on the edits, which gets rollbacked. // This is done even on edit failure to have patrolling in that case (bug 62157). $set = []; if ($bot && $guser->isAllowed('markbotedits')) { // Mark all reverted edits as bot $set['rc_bot'] = 1; } if ($wgUseRCPatrol) { // Mark all reverted edits as patrolled $set['rc_patrolled'] = 1; } if (count($set)) { $dbw->update('recentchanges', $set, ['rc_cur_id' => $current->getPage(), 'rc_user_text' => $current->getUserText(), 'rc_timestamp > ' . $dbw->addQuotes($s->rev_timestamp)], __METHOD__); } if (!$status->isOK()) { return $status->getErrorsArray(); } // raise error, when the edit is an edit without a new version $statusRev = isset($status->value['revision']) ? $status->value['revision'] : null; if (!$statusRev instanceof Revision) { $resultDetails = ['current' => $current]; return [['alreadyrolled', htmlspecialchars($this->mTitle->getPrefixedText()), htmlspecialchars($fromP), htmlspecialchars($current->getUserText())]]; } if ($changingContentModel) { // If the content model changed during the rollback, // make sure it gets logged to Special:Log/contentmodel $log = new ManualLogEntry('contentmodel', 'change'); $log->setPerformer($guser); $log->setTarget($this->mTitle); $log->setComment($summary); $log->setParameters(['4::oldmodel' => $current->getContentModel(), '5::newmodel' => $targetContent->getModel()]); $logId = $log->insert($dbw); $log->publish($logId); } $revId = $statusRev->getId(); Hooks::run('ArticleRollbackComplete', [$this, $guser, $target, $current]); $resultDetails = ['summary' => $summary, 'current' => $current, 'target' => $target, 'newid' => $revId]; return []; }
function wfMsgReal($key, $args) { $message = wfMsgGetKey($key); $message = wfMsgReplaceArgs($message, $args); return $message; }
/** * Format and return the navigation bar. * @param $limit integer Number of itens being displayed. * @return string HTML-formatted navigation bar. */ public function getNavigationBar( $limit ) { global $wgLang; $limit = $wgLang->formatNum( $limit ); $opts = array( 'parsemag', 'escapenoentities' ); $linkTexts = $disabledTexts = array(); foreach ( self::$linkTextMsgs[$this->mType] as $type => $msg ) { $label = wfMsgExt( $msg, $opts, $limit ); $linkTexts[$type] = wfMsgReplaceArgs( self::$pagingLabels[$type], array( $label ) ); $disabledTexts[$type] = Xml::wrapClass( $linkTexts[$type], 'disabled' ); } $pagingLinks = $this->mPager->getPagingLinks( $linkTexts, $disabledTexts ); // $limitLinks = $this->mPager->getLimitLinks(); // XXX: Not used yet. $ellipsis = wfMsg( 'ellipsis' ); $html = "{$pagingLinks['first']} {$pagingLinks['prev']} {$ellipsis} {$pagingLinks['next']} {$pagingLinks['last']}"; $html = WikilogUtils::wrapDiv( 'wl-pagination', $html ); $dir = $wgLang->getDir(); return Xml::tags( 'div', array( 'class' => 'wl-navbar', 'dir' => $dir ), $html ); }
/** * Return an HTML-escaped version of a message. * Parameter replacements, if any, are done *after* the HTML-escaping, * so parameters may contain HTML (eg links or form controls). Be sure * to pre-escape them if you really do want plaintext, or just wrap * the whole thing in htmlspecialchars(). * * @param string $key * @param string ... parameters * @return string */ function wfMsgHtml($key) { $args = func_get_args(); array_shift($args); return wfMsgReplaceArgs(htmlspecialchars(wfMsgGetKey($key, true)), $args); }
/** * Backend implementation of doRollback(), please refer there for parameter * and return value documentation * * NOTE: This function does NOT check ANY permissions, it just commits the * rollback to the DB. Therefore, you should only call this function direct- * ly if you want to use custom permissions checks. If you don't, use * doRollback() instead. * @param string $fromP Name of the user whose edits to rollback. * @param string $summary Custom summary. Set to default summary if empty. * @param $bot Boolean: If true, mark all reverted edits as bot. * * @param array $resultDetails contains result-specific array of additional values * @param $guser User The user performing the rollback * @return array */ public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User $guser ) { global $wgUseRCPatrol, $wgContLang; $dbw = wfGetDB( DB_MASTER ); if ( wfReadOnly() ) { return array( array( 'readonlytext' ) ); } // Get the last editor $current = $this->getRevision(); if ( is_null( $current ) ) { // Something wrong... no page? return array( array( 'notanarticle' ) ); } $from = str_replace( '_', ' ', $fromP ); // User name given should match up with the top revision. // If the user was deleted then $from should be empty. if ( $from != $current->getUserText() ) { $resultDetails = array( 'current' => $current ); return array( array( 'alreadyrolled', htmlspecialchars( $this->mTitle->getPrefixedText() ), htmlspecialchars( $fromP ), htmlspecialchars( $current->getUserText() ) ) ); } // Get the last edit not by this guy... // Note: these may not be public values $user = intval( $current->getRawUser() ); $user_text = $dbw->addQuotes( $current->getRawUserText() ); $s = $dbw->selectRow( 'revision', array( 'rev_id', 'rev_timestamp', 'rev_deleted' ), array( 'rev_page' => $current->getPage(), "rev_user != {$user} OR rev_user_text != {$user_text}" ), __METHOD__, array( 'USE INDEX' => 'page_timestamp', 'ORDER BY' => 'rev_timestamp DESC' ) ); if ( $s === false ) { // No one else ever edited this page return array( array( 'cantrollback' ) ); } elseif ( $s->rev_deleted & Revision::DELETED_TEXT || $s->rev_deleted & Revision::DELETED_USER ) { // Only admins can see this text return array( array( 'notvisiblerev' ) ); } $set = array(); if ( $bot && $guser->isAllowed( 'markbotedits' ) ) { // Mark all reverted edits as bot $set['rc_bot'] = 1; } if ( $wgUseRCPatrol ) { // Mark all reverted edits as patrolled $set['rc_patrolled'] = 1; } if ( count( $set ) ) { $dbw->update( 'recentchanges', $set, array( /* WHERE */ 'rc_cur_id' => $current->getPage(), 'rc_user_text' => $current->getUserText(), 'rc_timestamp > ' . $dbw->addQuotes( $s->rev_timestamp ), ), __METHOD__ ); } // Generate the edit summary if necessary $target = Revision::newFromId( $s->rev_id ); if ( empty( $summary ) ) { if ( $from == '' ) { // no public user name $summary = wfMessage( 'revertpage-nouser' ); } else { $summary = wfMessage( 'revertpage' ); } } // Allow the custom summary to use the same args as the default message $args = array( $target->getUserText(), $from, $s->rev_id, $wgContLang->timeanddate( wfTimestamp( TS_MW, $s->rev_timestamp ) ), $current->getId(), $wgContLang->timeanddate( $current->getTimestamp() ) ); if ( $summary instanceof Message ) { $summary = $summary->params( $args )->inContentLanguage()->text(); } else { $summary = wfMsgReplaceArgs( $summary, $args ); } // Trim spaces on user supplied text $summary = trim( $summary ); // Truncate for whole multibyte characters. $summary = $wgContLang->truncate( $summary, 255 ); // Save $flags = EDIT_UPDATE; if ( $guser->isAllowed( 'minoredit' ) ) { $flags |= EDIT_MINOR; } if ( $bot && ( $guser->isAllowedAny( 'markbotedits', 'bot' ) ) ) { $flags |= EDIT_FORCE_BOT; } // Actually store the edit $status = $this->doEditContent( $target->getContent(), $summary, $flags, $target->getId(), $guser ); if ( !$status->isOK() ) { return $status->getErrorsArray(); } if ( !empty( $status->value['revision'] ) ) { $revId = $status->value['revision']->getId(); } else { $revId = false; } wfRunHooks( 'ArticleRollbackComplete', array( $this, $guser, $target, $current ) ); $resultDetails = array( 'summary' => $summary, 'current' => $current, 'target' => $target, 'newid' => $revId ); return array(); }
function __construct($msg, $width, $height) { $args = array_slice(func_get_args(), 3); $htmlArgs = array_map('htmlspecialchars', $args); $htmlArgs = array_map('nl2br', $htmlArgs); $this->htmlMsg = wfMsgReplaceArgs(htmlspecialchars(wfMsgGetKey($msg, true)), $htmlArgs); $this->textMsg = wfMsgReal($msg, $args); $this->width = intval($width); $this->height = intval($height); $this->url = false; $this->path = false; }