Merge "maintenance/dev: Clean up router.php"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 2 Apr 2019 08:05:26 +0000 (08:05 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 2 Apr 2019 08:05:26 +0000 (08:05 +0000)
20 files changed:
autoload.php
includes/api/ApiImageRotate.php
includes/api/ApiLogin.php
includes/api/ApiQuerySearch.php
includes/api/ApiQueryWatchlist.php
includes/debug/logger/monolog/MwlogHandler.php [new file with mode: 0644]
includes/htmlform/HTMLForm.php
includes/installer/PostgresInstaller.php
includes/libs/rdbms/database/DatabaseMysqlBase.php
includes/preferences/DefaultPreferencesFactory.php
includes/resourceloader/ResourceLoaderSkinModule.php
includes/skins/Skin.php
includes/specials/SpecialDeletedContributions.php
includes/specials/SpecialEditTags.php
includes/specials/SpecialUndelete.php
includes/specials/pagers/ActiveUsersPager.php
includes/specials/pagers/ContribsPager.php
includes/tidy/RemexCompatMunger.php
includes/widget/ExpiryInputWidget.php
includes/widget/search/InterwikiSearchResultWidget.php

index b38c438..95dd2ae 100644 (file)
@@ -900,6 +900,7 @@ $wgAutoloadLocalClasses = [
        'MediaWiki\\Logger\\Monolog\\LegacyHandler' => __DIR__ . '/includes/debug/logger/monolog/LegacyHandler.php',
        'MediaWiki\\Logger\\Monolog\\LineFormatter' => __DIR__ . '/includes/debug/logger/monolog/LineFormatter.php',
        'MediaWiki\\Logger\\Monolog\\LogstashFormatter' => __DIR__ . '/includes/debug/logger/monolog/LogstashFormatter.php',
+       'MediaWiki\\Logger\\Monolog\\MwlogHandler' => __DIR__ . '/includes/debug/logger/monolog/MwlogHandler.php',
        'MediaWiki\\Logger\\Monolog\\SyslogHandler' => __DIR__ . '/includes/debug/logger/monolog/SyslogHandler.php',
        'MediaWiki\\Logger\\Monolog\\WikiProcessor' => __DIR__ . '/includes/debug/logger/monolog/WikiProcessor.php',
        'MediaWiki\\Logger\\NullSpi' => __DIR__ . '/includes/debug/logger/NullSpi.php',
index 21e2694..7045138 100644 (file)
@@ -33,8 +33,6 @@ class ApiImageRotate extends ApiBase {
                $pageSet = $this->getPageSet();
                $pageSet->execute();
 
-               $result = [];
-
                $result = $pageSet->getInvalidTitlesAndRevisions( [
                        'invalidTitles', 'special', 'missingIds', 'missingRevIds', 'interwikiTitles',
                ] );
index 133f0ce..d7b3332 100644 (file)
@@ -107,7 +107,6 @@ class ApiLogin extends ApiBase {
                }
 
                $authRes = false;
-               $context = new DerivativeContext( $this->getContext() );
                $loginType = 'N/A';
 
                // Check login token
index b90dd5d..e6403f3 100644 (file)
@@ -157,7 +157,6 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
                        convertForSearchResult( $matches->termMatches() );
                $titles = [];
                $count = 0;
-               $limit = $params['limit'];
 
                if ( $matches->hasMoreResults() ) {
                        $this->setContinueEnumParameter( 'offset', $params['offset'] + $params['limit'] );
index 236f6e0..cb49622 100644 (file)
@@ -180,7 +180,6 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
                ] );
 
                $ids = [];
-               $count = 0;
                $watchedItemQuery = MediaWikiServices::getInstance()->getWatchedItemQueryService();
                $items = $watchedItemQuery->getWatchedItemsWithRecentChangeInfo( $wlowner, $options, $startFrom );
 
diff --git a/includes/debug/logger/monolog/MwlogHandler.php b/includes/debug/logger/monolog/MwlogHandler.php
new file mode 100644 (file)
index 0000000..e61aada
--- /dev/null
@@ -0,0 +1,102 @@
+<?php
+/**
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+namespace MediaWiki\Logger\Monolog;
+
+use Monolog\Handler\SyslogUdpHandler;
+use Monolog\Logger;
+
+/**
+ * Log handler that will append the record's channel to a fixed 'application
+ * prefix' given at construction time.
+ *
+ * The use case for this handler is to deprecate udp2log with a localhost
+ * syslog endpoint. The application name is then used to reconstruct the
+ * message's channel.
+ *
+ * @since 1.32
+ * @copyright © 2019 Wikimedia Foundation and contributors
+ */
+class MwlogHandler extends SyslogUdpHandler {
+
+       /**
+        * @var string $appprefix
+        */
+       private $appprefix;
+
+       /**
+        * @var string $hostname
+        */
+       private $hostname;
+
+       /**
+        * @param string $appprefix Application prefix to use, channel will be appended.
+        * @param string $host Syslog host
+        * @param int $port Syslog port
+        * @param int $facility Syslog message facility
+        * @param int $level The minimum logging level at which this handler
+        *   will be triggered
+        * @param bool $bubble Whether the messages that are handled can bubble up
+        *   the stack or not
+        */
+       public function __construct(
+               $appprefix,
+               $host,
+               $port = 514,
+               $facility = LOG_USER,
+               $level = Logger::DEBUG,
+               $bubble = true
+       ) {
+               parent::__construct( $host, $port, $facility, $level, $bubble );
+               $this->appprefix = $appprefix;
+               $this->hostname = php_uname( 'n' );
+       }
+
+       protected function syslogHeader( $severity, $app ) {
+               $pri = $severity + $this->facility;
+
+               // Goofy date format courtesy of RFC 3164 :(
+               // RFC 3164 actually specifies that the day of month should be space
+               // padded rather than unpadded but this seems to work with rsyslog and
+               // Logstash.
+               $timestamp = date( 'M j H:i:s' );
+
+               return "<{$pri}>{$timestamp} {$this->hostname} {$app}: ";
+       }
+
+       private function splitMessageIntoLines( $message ): array {
+               if ( is_array( $message ) ) {
+                       $message = implode( "\n", $message );
+               }
+
+               return preg_split( '/$\R?^/m', (string)$message, -1, PREG_SPLIT_NO_EMPTY );
+       }
+
+       protected function write( array $record ) {
+               $lines = $this->splitMessageIntoLines( $record['formatted'] );
+               $header = $this->syslogHeader(
+                       $this->logLevels[$record['level']],
+                       $this->appprefix . $record['channel'] );
+
+               foreach ( $lines as $line ) {
+                       $this->socket->write( $line, $header );
+               }
+       }
+}
index 3c9b23c..e5330b6 100644 (file)
@@ -527,7 +527,6 @@ class HTMLForm extends ContextSource {
        public function tryAuthorizedSubmit() {
                $result = false;
 
-               $identOkay = false;
                if ( $this->mFormIdentifier === null ) {
                        $identOkay = true;
                } else {
index 16b47e2..f3cbbc4 100644 (file)
@@ -125,7 +125,7 @@ class PostgresInstaller extends DatabaseInstaller {
 
                // Check version
                $version = $conn->getServerVersion();
-               $status = static::meetsMinimumRequirement( $conn->getServerVersion() );
+               $status = static::meetsMinimumRequirement( $version );
                if ( !$status->isOK() ) {
                        return $status;
                }
index 7fccd57..36c947f 100644 (file)
@@ -106,7 +106,7 @@ abstract class DatabaseMysqlBase extends Database {
                                $this->$var = $params[$var];
                        }
                }
-               $this->sqlMode = $params['sqlMode'] ?? '';
+               $this->sqlMode = $params['sqlMode'] ?? null;
                $this->utf8Mode = !empty( $params['utf8Mode'] );
                $this->insertSelectIsSafe = isset( $params['insertSelectIsSafe'] )
                        ? (bool)$params['insertSelectIsSafe'] : null;
index a42726f..c45ab4c 100644 (file)
@@ -1052,7 +1052,6 @@ class DefaultPreferencesFactory implements PreferencesFactory {
                # # Watchlist #####################################
                if ( $user->isAllowed( 'editmywatchlist' ) ) {
                        $editWatchlistLinks = '';
-                       $editWatchlistLinksOld = [];
                        $editWatchlistModes = [
                                'edit' => [ 'subpage' => false, 'flags' => [] ],
                                'raw' => [ 'subpage' => 'raw', 'flags' => [] ],
index e0fbeee..6393803 100644 (file)
@@ -91,7 +91,6 @@ class ResourceLoaderSkinModule extends ResourceLoaderFileModule {
        private function getLogoPreloadlinks() {
                $logo = $this->getLogoData( $this->getConfig() );
 
-               $tags = [];
                $logosPerDppx = [];
                $logos = [];
 
index 7ac2927..ac41c46 100644 (file)
@@ -175,7 +175,6 @@ abstract class Skin extends ContextSource {
         */
        public function getDefaultModules() {
                $out = $this->getOutput();
-               $config = $this->getConfig();
                $user = $this->getUser();
 
                // Modules declared in the $modules literal are loaded
@@ -1525,7 +1524,6 @@ abstract class Skin extends ContextSource {
         *   should fall back to the next notice in its sequence
         */
        private function getCachedNotice( $name ) {
-               $needParse = false;
                $config = $this->getConfig();
 
                if ( $name === 'default' ) {
index d405be7..65cf79e 100644 (file)
@@ -44,8 +44,6 @@ class DeletedContributionsPage extends SpecialPage {
                $this->outputHeader();
                $this->checkPermissions();
 
-               $user = $this->getUser();
-
                $out = $this->getOutput();
                $out->setPageTitle( $this->msg( 'deletedcontributions-title' ) );
 
index 6807ed3..5203807 100644 (file)
@@ -209,8 +209,6 @@ class SpecialEditTags extends UnlistedSpecialPage {
         * the user to modify the tags applied to those items.
         */
        protected function showForm() {
-               $userAllowed = true;
-
                $out = $this->getOutput();
                // Messages: tags-edit-revision-selected, tags-edit-logentry-selected
                $out->wrapWikiMsg( "<strong>$1</strong>", [
index c5c68df..51d6fd9 100644 (file)
@@ -504,7 +504,6 @@ class SpecialUndelete extends SpecialPage {
                        ] );
                } else {
                        $sourceView = '';
-                       $previewButton = '';
                }
 
                $buttonFields[] = new OOUI\ButtonInputWidget( [
index 5dbdba0..39da076 100644 (file)
@@ -230,7 +230,6 @@ class ActiveUsersPager extends UsersPager {
                $lang = $this->getLanguage();
 
                $list = [];
-               $user = User::newFromId( $row->user_id );
 
                $ugms = self::getGroupMemberships( intval( $row->user_id ), $this->userGroupCache );
                foreach ( $ugms as $ugm ) {
index 3ffbde5..10fcfc6 100644 (file)
@@ -646,7 +646,6 @@ class ContribsPager extends RangeChronologicalPager {
 
                        $lang = $this->getLanguage();
                        $comment = $lang->getDirMark() . Linker::revComment( $rev, false, true, false );
-                       $date = $lang->userTimeAndDate( $row->rev_timestamp, $user );
                        $d = ChangesList::revDateLink( $rev, $user, $lang, $page );
 
                        # Show user names for /newbies as there may be different users.
index df9bb96..0cc9905 100644 (file)
@@ -287,7 +287,6 @@ class RemexCompatMunger implements TreeHandler {
                        $newParent = $this->serializer->getParentNode( $parent );
                        $parent = $newParent;
                        $parentData = $parent->snData;
-                       $pElement = $parentData->childPElement;
                        $parentData->childPElement = null;
                        $newRef = $refElement->userData;
                } elseif ( $under && $parentData->isSplittable
index be6e676..02f369a 100644 (file)
@@ -30,8 +30,6 @@ class ExpiryInputWidget extends Widget {
         * @param array $options Configuration options
         */
        public function __construct( Widget $relativeInput, array $options = [] ) {
-               $config = \RequestContext::getMain()->getConfig();
-
                parent::__construct( $options );
 
                $this->required = $options['required'] ?? false;
index 4eead5e..095c30a 100644 (file)
@@ -30,7 +30,6 @@ class InterwikiSearchResultWidget implements SearchResultWidget {
         */
        public function render( SearchResult $result, $terms, $position ) {
                $title = $result->getTitle();
-               $iwPrefix = $result->getTitle()->getInterwiki();
                $titleSnippet = $result->getTitleSnippet();
                $snippet = $result->getTextSnippet( $terms );