/** * @param $s Status */ private function subscribeToMediaWikiAnnounce(Status $s) { $params = array('email' => $this->getVar('_AdminEmail'), 'language' => 'en', 'digest' => 0); // Mailman doesn't support as many languages as we do, so check to make // sure their selected language is available $myLang = $this->getVar('_UserLang'); if (in_array($myLang, $this->mediaWikiAnnounceLanguages)) { $myLang = $myLang == 'pt-br' ? 'pt_BR' : $myLang; // rewrite to Mailman's pt_BR $params['language'] = $myLang; } if (MWHttpRequest::canMakeRequests()) { $res = MWHttpRequest::factory($this->mediaWikiAnnounceUrl, array('method' => 'POST', 'postData' => $params))->execute(); if (!$res->isOK()) { $s->warning('config-install-subscribe-fail', $res->getMessage()); } } else { $s->warning('config-install-subscribe-notpossible'); } }
/** * @dataProvider provideNonObjectMessages * @covers Status::getStatusArray */ public function testGetStatusArrayWithNonObjectMessages($nonObjMsg) { $status = new Status(); if (!array_key_exists(1, $nonObjMsg)) { $status->warning($nonObjMsg[0]); } else { $status->warning($nonObjMsg[0], $nonObjMsg[1]); } $array = $status->getWarningsArray(); // We use getWarningsArray to access getStatusArray $this->assertEquals(1, count($array)); $this->assertEquals($nonObjMsg, $array[0]); }
/** * @param Status $status * @return Status */ public function setupSearchIndex(&$status) { global $IP; $module = DatabaseSqlite::getFulltextSearchModule(); $fts3tTable = $this->db->checkForEnabledSearch(); if ($fts3tTable && !$module) { $status->warning('config-sqlite-fts3-downgrade'); $this->db->sourceFile("{$IP}/maintenance/sqlite/archives/searchindex-no-fts.sql"); } elseif (!$fts3tTable && $module == 'FTS3') { $this->db->sourceFile("{$IP}/maintenance/sqlite/archives/searchindex-fts3.sql"); } return $status; }
/** * Highlight a code-block using a particular lexer. * * @param string $code Code to highlight. * @param string|null $lang Language name, or null to use plain markup. * @param array $args Associative array of additional arguments. * If it contains a 'line' key, the output will include line numbers. * If it includes a 'highlight' key, the value will be parsed as a * comma-separated list of lines and line-ranges to highlight. * If it contains a 'start' key, the value will be used as the line at which to * start highlighting. * If it contains a 'inline' key, the output will not be wrapped in `<div><pre/></div>`. * @return Status Status object, with HTML representing the highlighted * code as its value. */ protected static function highlight($code, $lang = null, $args = array()) { global $wgPygmentizePath; $status = new Status(); $lexer = self::getLexer($lang); if ($lexer === null && $lang !== null) { $status->warning('syntaxhighlight-error-unknown-language', $lang); } $length = strlen($code); if (strlen($code) > self::HIGHLIGHT_MAX_BYTES) { $status->warning('syntaxhighlight-error-exceeds-size-limit', $length, self::HIGHLIGHT_MAX_BYTES); $lexer = null; } if (wfShellExecDisabled() !== false) { $status->warning('syntaxhighlight-error-pygments-invocation-failure'); wfWarn('MediaWiki determined that it cannot invoke Pygments. ' . 'As a result, SyntaxHighlight_GeSHi will not perform any syntax highlighting. ' . 'See the debug log for details: ' . 'https://www.mediawiki.org/wiki/Manual:$wgDebugLogFile'); $lexer = null; } $inline = isset($args['inline']); if ($lexer === null) { if ($inline) { $status->value = htmlspecialchars(trim($code), ENT_NOQUOTES); } else { $pre = Html::element('pre', array(), $code); $status->value = Html::rawElement('div', array('class' => self::HIGHLIGHT_CSS_CLASS), $pre); } return $status; } $options = array('cssclass' => self::HIGHLIGHT_CSS_CLASS, 'encoding' => 'utf-8'); // Line numbers if (isset($args['line'])) { $options['linenos'] = 'inline'; } if ($lexer === 'php' && strpos($code, '<?php') === false) { $options['startinline'] = 1; } // Highlight specific lines if (isset($args['highlight'])) { $lines = self::parseHighlightLines($args['highlight']); if (count($lines)) { $options['hl_lines'] = implode(' ', $lines); } } // Starting line number if (isset($args['start'])) { $options['linenostart'] = $args['start']; } if ($inline) { $options['nowrap'] = 1; } $cache = wfGetMainCache(); $cacheKey = self::makeCacheKey($code, $lexer, $options); $output = $cache->get($cacheKey); if ($output === false) { $optionPairs = array(); foreach ($options as $k => $v) { $optionPairs[] = "{$k}={$v}"; } $builder = new ProcessBuilder(); $builder->setPrefix($wgPygmentizePath); $process = $builder->add('-l')->add($lexer)->add('-f')->add('html')->add('-O')->add(implode(',', $optionPairs))->getProcess(); $process->setInput($code); $process->run(); if (!$process->isSuccessful()) { $status->warning('syntaxhighlight-error-pygments-invocation-failure'); wfWarn('Failed to invoke Pygments: ' . $process->getErrorOutput()); $status->value = self::highlight($code, null, $args)->getValue(); return $status; } $output = $process->getOutput(); $cache->set($cacheKey, $output); } if ($inline) { $output = trim($output); } $status->value = $output; return $status; }
/** * Actually attempt the history move * * @todo if all versions of page A are moved to B and then a user * tries to do a reverse-merge via the "unmerge" log link, then page * A will still be a redirect (as it was after the original merge), * though it will have the old revisions back from before (as expected). * The user may have to "undo" the redirect manually to finish the "unmerge". * Maybe this should delete redirects at the source page of merges? * * @param User $user * @param string $reason * @return Status status of the history merge */ public function merge(User $user, $reason = '') { $status = new Status(); // Check validity and permissions required for merge $validCheck = $this->isValidMerge(); // Check this first to check for null pages if (!$validCheck->isOK()) { return $validCheck; } $permCheck = $this->checkPermissions($user, $reason); if (!$permCheck->isOK()) { return $permCheck; } $this->dbw->update('revision', array('rev_page' => $this->dest->getArticleID()), array('rev_page' => $this->source->getArticleID(), $this->timeWhere), __METHOD__); // Check if this did anything $this->revisionsMerged = $this->dbw->affectedRows(); if ($this->revisionsMerged < 1) { $status->fatal('mergehistory-fail-no-change'); return $status; } // Make the source page a redirect if no revisions are left $haveRevisions = $this->dbw->selectField('revision', 'rev_timestamp', array('rev_page' => $this->source->getArticleID()), __METHOD__, array('FOR UPDATE')); if (!$haveRevisions) { if ($reason) { $reason = wfMessage('mergehistory-comment', $this->source->getPrefixedText(), $this->dest->getPrefixedText(), $reason)->inContentLanguage()->text(); } else { $reason = wfMessage('mergehistory-autocomment', $this->source->getPrefixedText(), $this->dest->getPrefixedText())->inContentLanguage()->text(); } $contentHandler = ContentHandler::getForTitle($this->source); $redirectContent = $contentHandler->makeRedirectContent($this->dest, wfMessage('mergehistory-redirect-text')->inContentLanguage()->plain()); if ($redirectContent) { $redirectPage = WikiPage::factory($this->source); $redirectRevision = new Revision(array('title' => $this->source, 'page' => $this->source->getArticleID(), 'comment' => $reason, 'content' => $redirectContent)); $redirectRevision->insertOn($this->dbw); $redirectPage->updateRevisionOn($this->dbw, $redirectRevision); // Now, we record the link from the redirect to the new title. // It should have no other outgoing links... $this->dbw->delete('pagelinks', array('pl_from' => $this->dest->getArticleID()), __METHOD__); $this->dbw->insert('pagelinks', array('pl_from' => $this->dest->getArticleID(), 'pl_from_namespace' => $this->dest->getNamespace(), 'pl_namespace' => $this->dest->getNamespace(), 'pl_title' => $this->dest->getDBkey()), __METHOD__); } else { // Warning if we couldn't create the redirect $status->warning('mergehistory-warning-redirect-not-created'); } } else { $this->source->invalidateCache(); // update histories } $this->dest->invalidateCache(); // update histories // Update our logs $logEntry = new ManualLogEntry('merge', 'merge'); $logEntry->setPerformer($user); $logEntry->setComment($reason); $logEntry->setTarget($this->source); $logEntry->setParameters(array('4::dest' => $this->dest->getPrefixedText(), '5::mergepoint' => $this->timestampLimit->getTimestamp(TS_MW))); $logId = $logEntry->insert(); $logEntry->publish($logId); Hooks::run('ArticleMergeComplete', array($this->source, $this->dest)); return $status; }
/** * @covers Status::getErrorsByType */ public function testGetErrorsByType() { $status = new Status(); $warning = new Message('warning111'); $error = new Message('error111'); $status->warning($warning); $status->error($error); $warnings = $status->getErrorsByType('warning'); $errors = $status->getErrorsByType('error'); $this->assertCount(1, $warnings); $this->assertCount(1, $errors); $this->assertEquals($warning, $warnings[0]['message']); $this->assertEquals($error, $errors[0]['message']); }