Merge "rdbms: mention wait time in LoadBalancer::safeWaitForMasterPos() error logging"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 19 Jun 2019 13:27:07 +0000 (13:27 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 19 Jun 2019 13:27:07 +0000 (13:27 +0000)
23 files changed:
.phan/config.php
.phan/internal_stubs/README [new file with mode: 0644]
.phan/internal_stubs/imagick.phan_php [new file with mode: 0644]
.phan/internal_stubs/pcntl.phan_php [new file with mode: 0644]
.phan/internal_stubs/redis.phan_php [new file with mode: 0644]
.phan/internal_stubs/sockets.phan_php [new file with mode: 0644]
autoload.php
includes/MediaWiki.php
includes/Message.php [deleted file]
includes/OutputPage.php
includes/api/ApiMain.php
includes/language/LanguageCode.php [new file with mode: 0644]
includes/language/Message.php [new file with mode: 0644]
includes/language/MessageLocalizer.php [new file with mode: 0644]
includes/libs/rdbms/loadbalancer/ILoadBalancer.php
includes/libs/rdbms/loadbalancer/LoadBalancer.php
includes/libs/rdbms/loadmonitor/LoadMonitor.php
includes/resourceloader/ResourceLoaderClientHtml.php
includes/resourceloader/ResourceLoaderStartUpModule.php
includes/specials/SpecialJavaScriptTest.php
languages/LanguageCode.php [deleted file]
languages/MessageLocalizer.php [deleted file]
tests/phpunit/includes/resourceloader/ResourceLoaderClientHtmlTest.php

index 3478977..8746ada 100644 (file)
@@ -43,8 +43,12 @@ $cfg['file_list'] = array_merge(
 );
 
 $cfg['autoload_internal_extension_signatures'] = [
+       'imagick' => '.phan/internal_stubs/imagick.phan_php',
        'memcached' => '.phan/internal_stubs/memcached.phan_php',
        'oci8' => '.phan/internal_stubs/oci8.phan_php',
+       'pcntl' => '.phan/internal_stubs/pcntl.phan_php',
+       'redis' => '.phan/internal_stubs/redis.phan_php',
+       'sockets' => '.phan/internal_stubs/sockets.phan_php',
        'sqlsrv' => '.phan/internal_stubs/sqlsrv.phan_php',
        'tideways' => '.phan/internal_stubs/tideways.phan_php',
 ];
diff --git a/.phan/internal_stubs/README b/.phan/internal_stubs/README
new file mode 100644 (file)
index 0000000..c57d596
--- /dev/null
@@ -0,0 +1,5 @@
+See <https://github.com/phan/phan/wiki/How-To-Use-Stubs#generating-stubs> for
+how to generate internal stubs for phan.
+
+The stubs should be generated using the PHP version that is our lowest
+requirement.
diff --git a/.phan/internal_stubs/imagick.phan_php b/.phan/internal_stubs/imagick.phan_php
new file mode 100644 (file)
index 0000000..c4f355b
--- /dev/null
@@ -0,0 +1,1204 @@
+<?php
+// These stubs were generated by the phan stub generator.
+// @phan-stub-for-extension imagick@3.4.3RC2
+
+namespace {
+class Imagick implements \Iterator, \Traversable, \Countable {
+
+    // constants
+    const COLOR_BLACK = 11;
+    const COLOR_BLUE = 12;
+    const COLOR_CYAN = 13;
+    const COLOR_GREEN = 14;
+    const COLOR_RED = 15;
+    const COLOR_YELLOW = 16;
+    const COLOR_MAGENTA = 17;
+    const COLOR_OPACITY = 18;
+    const COLOR_ALPHA = 19;
+    const COLOR_FUZZ = 20;
+    const IMAGICK_EXTNUM = 30403;
+    const IMAGICK_EXTVER = '3.4.3RC2';
+    const QUANTUM_RANGE = 65535;
+    const USE_ZEND_MM = 0;
+    const COMPOSITE_DEFAULT = 40;
+    const COMPOSITE_UNDEFINED = 0;
+    const COMPOSITE_NO = 1;
+    const COMPOSITE_ADD = 2;
+    const COMPOSITE_ATOP = 3;
+    const COMPOSITE_BLEND = 4;
+    const COMPOSITE_BUMPMAP = 5;
+    const COMPOSITE_CLEAR = 7;
+    const COMPOSITE_COLORBURN = 8;
+    const COMPOSITE_COLORDODGE = 9;
+    const COMPOSITE_COLORIZE = 10;
+    const COMPOSITE_COPYBLACK = 11;
+    const COMPOSITE_COPYBLUE = 12;
+    const COMPOSITE_COPY = 13;
+    const COMPOSITE_COPYCYAN = 14;
+    const COMPOSITE_COPYGREEN = 15;
+    const COMPOSITE_COPYMAGENTA = 16;
+    const COMPOSITE_COPYOPACITY = 17;
+    const COMPOSITE_COPYRED = 18;
+    const COMPOSITE_COPYYELLOW = 19;
+    const COMPOSITE_DARKEN = 20;
+    const COMPOSITE_DSTATOP = 21;
+    const COMPOSITE_DST = 22;
+    const COMPOSITE_DSTIN = 23;
+    const COMPOSITE_DSTOUT = 24;
+    const COMPOSITE_DSTOVER = 25;
+    const COMPOSITE_DIFFERENCE = 26;
+    const COMPOSITE_DISPLACE = 27;
+    const COMPOSITE_DISSOLVE = 28;
+    const COMPOSITE_EXCLUSION = 29;
+    const COMPOSITE_HARDLIGHT = 30;
+    const COMPOSITE_HUE = 31;
+    const COMPOSITE_IN = 32;
+    const COMPOSITE_LIGHTEN = 33;
+    const COMPOSITE_LUMINIZE = 35;
+    const COMPOSITE_MINUS = 36;
+    const COMPOSITE_MODULATE = 37;
+    const COMPOSITE_MULTIPLY = 38;
+    const COMPOSITE_OUT = 39;
+    const COMPOSITE_OVER = 40;
+    const COMPOSITE_OVERLAY = 41;
+    const COMPOSITE_PLUS = 42;
+    const COMPOSITE_REPLACE = 43;
+    const COMPOSITE_SATURATE = 44;
+    const COMPOSITE_SCREEN = 45;
+    const COMPOSITE_SOFTLIGHT = 46;
+    const COMPOSITE_SRCATOP = 47;
+    const COMPOSITE_SRC = 48;
+    const COMPOSITE_SRCIN = 49;
+    const COMPOSITE_SRCOUT = 50;
+    const COMPOSITE_SRCOVER = 51;
+    const COMPOSITE_SUBTRACT = 52;
+    const COMPOSITE_THRESHOLD = 53;
+    const COMPOSITE_XOR = 54;
+    const COMPOSITE_CHANGEMASK = 6;
+    const COMPOSITE_LINEARLIGHT = 34;
+    const COMPOSITE_DIVIDE = 55;
+    const COMPOSITE_DISTORT = 56;
+    const COMPOSITE_BLUR = 57;
+    const COMPOSITE_PEGTOPLIGHT = 58;
+    const COMPOSITE_VIVIDLIGHT = 59;
+    const COMPOSITE_PINLIGHT = 60;
+    const COMPOSITE_LINEARDODGE = 61;
+    const COMPOSITE_LINEARBURN = 62;
+    const COMPOSITE_MATHEMATICS = 63;
+    const COMPOSITE_MODULUSADD = 2;
+    const COMPOSITE_MODULUSSUBTRACT = 52;
+    const COMPOSITE_MINUSDST = 36;
+    const COMPOSITE_DIVIDEDST = 55;
+    const COMPOSITE_DIVIDESRC = 64;
+    const COMPOSITE_MINUSSRC = 65;
+    const COMPOSITE_DARKENINTENSITY = 66;
+    const COMPOSITE_LIGHTENINTENSITY = 67;
+    const COMPOSITE_HARDMIX = 68;
+    const MONTAGEMODE_FRAME = 1;
+    const MONTAGEMODE_UNFRAME = 2;
+    const MONTAGEMODE_CONCATENATE = 3;
+    const STYLE_NORMAL = 1;
+    const STYLE_ITALIC = 2;
+    const STYLE_OBLIQUE = 3;
+    const STYLE_ANY = 4;
+    const FILTER_UNDEFINED = 0;
+    const FILTER_POINT = 1;
+    const FILTER_BOX = 2;
+    const FILTER_TRIANGLE = 3;
+    const FILTER_HERMITE = 4;
+    const FILTER_HANNING = 5;
+    const FILTER_HAMMING = 6;
+    const FILTER_BLACKMAN = 7;
+    const FILTER_GAUSSIAN = 8;
+    const FILTER_QUADRATIC = 9;
+    const FILTER_CUBIC = 10;
+    const FILTER_CATROM = 11;
+    const FILTER_MITCHELL = 12;
+    const FILTER_LANCZOS = 22;
+    const FILTER_BESSEL = 13;
+    const FILTER_SINC = 14;
+    const FILTER_KAISER = 16;
+    const FILTER_WELSH = 17;
+    const FILTER_PARZEN = 18;
+    const FILTER_LAGRANGE = 21;
+    const FILTER_SENTINEL = 31;
+    const FILTER_BOHMAN = 19;
+    const FILTER_BARTLETT = 20;
+    const FILTER_JINC = 13;
+    const FILTER_SINCFAST = 15;
+    const FILTER_ROBIDOUX = 26;
+    const FILTER_LANCZOSSHARP = 23;
+    const FILTER_LANCZOS2 = 24;
+    const FILTER_LANCZOS2SHARP = 25;
+    const FILTER_ROBIDOUXSHARP = 27;
+    const FILTER_COSINE = 28;
+    const FILTER_SPLINE = 29;
+    const FILTER_LANCZOSRADIUS = 30;
+    const IMGTYPE_UNDEFINED = 0;
+    const IMGTYPE_BILEVEL = 1;
+    const IMGTYPE_GRAYSCALE = 2;
+    const IMGTYPE_GRAYSCALEMATTE = 3;
+    const IMGTYPE_PALETTE = 4;
+    const IMGTYPE_PALETTEMATTE = 5;
+    const IMGTYPE_TRUECOLOR = 6;
+    const IMGTYPE_TRUECOLORMATTE = 7;
+    const IMGTYPE_COLORSEPARATION = 8;
+    const IMGTYPE_COLORSEPARATIONMATTE = 9;
+    const IMGTYPE_OPTIMIZE = 10;
+    const IMGTYPE_PALETTEBILEVELMATTE = 11;
+    const RESOLUTION_UNDEFINED = 0;
+    const RESOLUTION_PIXELSPERINCH = 1;
+    const RESOLUTION_PIXELSPERCENTIMETER = 2;
+    const COMPRESSION_UNDEFINED = 0;
+    const COMPRESSION_NO = 1;
+    const COMPRESSION_BZIP = 2;
+    const COMPRESSION_FAX = 6;
+    const COMPRESSION_GROUP4 = 7;
+    const COMPRESSION_JPEG = 8;
+    const COMPRESSION_JPEG2000 = 9;
+    const COMPRESSION_LOSSLESSJPEG = 10;
+    const COMPRESSION_LZW = 11;
+    const COMPRESSION_RLE = 12;
+    const COMPRESSION_ZIP = 13;
+    const COMPRESSION_DXT1 = 3;
+    const COMPRESSION_DXT3 = 4;
+    const COMPRESSION_DXT5 = 5;
+    const COMPRESSION_ZIPS = 14;
+    const COMPRESSION_PIZ = 15;
+    const COMPRESSION_PXR24 = 16;
+    const COMPRESSION_B44 = 17;
+    const COMPRESSION_B44A = 18;
+    const COMPRESSION_LZMA = 19;
+    const COMPRESSION_JBIG1 = 20;
+    const COMPRESSION_JBIG2 = 21;
+    const PAINT_POINT = 1;
+    const PAINT_REPLACE = 2;
+    const PAINT_FLOODFILL = 3;
+    const PAINT_FILLTOBORDER = 4;
+    const PAINT_RESET = 5;
+    const GRAVITY_NORTHWEST = 1;
+    const GRAVITY_NORTH = 2;
+    const GRAVITY_NORTHEAST = 3;
+    const GRAVITY_WEST = 4;
+    const GRAVITY_CENTER = 5;
+    const GRAVITY_EAST = 6;
+    const GRAVITY_SOUTHWEST = 7;
+    const GRAVITY_SOUTH = 8;
+    const GRAVITY_SOUTHEAST = 9;
+    const GRAVITY_FORGET = 0;
+    const GRAVITY_STATIC = 10;
+    const STRETCH_NORMAL = 1;
+    const STRETCH_ULTRACONDENSED = 2;
+    const STRETCH_EXTRACONDENSED = 3;
+    const STRETCH_CONDENSED = 4;
+    const STRETCH_SEMICONDENSED = 5;
+    const STRETCH_SEMIEXPANDED = 6;
+    const STRETCH_EXPANDED = 7;
+    const STRETCH_EXTRAEXPANDED = 8;
+    const STRETCH_ULTRAEXPANDED = 9;
+    const STRETCH_ANY = 10;
+    const ALIGN_UNDEFINED = 0;
+    const ALIGN_LEFT = 1;
+    const ALIGN_CENTER = 2;
+    const ALIGN_RIGHT = 3;
+    const DECORATION_NO = 1;
+    const DECORATION_UNDERLINE = 2;
+    const DECORATION_OVERLINE = 3;
+    const DECORATION_LINETROUGH = 4;
+    const DECORATION_LINETHROUGH = 4;
+    const NOISE_UNIFORM = 1;
+    const NOISE_GAUSSIAN = 2;
+    const NOISE_MULTIPLICATIVEGAUSSIAN = 3;
+    const NOISE_IMPULSE = 4;
+    const NOISE_LAPLACIAN = 5;
+    const NOISE_POISSON = 6;
+    const NOISE_RANDOM = 7;
+    const CHANNEL_UNDEFINED = 0;
+    const CHANNEL_RED = 1;
+    const CHANNEL_GRAY = 1;
+    const CHANNEL_CYAN = 1;
+    const CHANNEL_GREEN = 2;
+    const CHANNEL_MAGENTA = 2;
+    const CHANNEL_BLUE = 4;
+    const CHANNEL_YELLOW = 4;
+    const CHANNEL_ALPHA = 8;
+    const CHANNEL_OPACITY = 8;
+    const CHANNEL_MATTE = 8;
+    const CHANNEL_BLACK = 32;
+    const CHANNEL_INDEX = 32;
+    const CHANNEL_ALL = 134217727;
+    const CHANNEL_DEFAULT = 134217719;
+    const CHANNEL_RGBA = 15;
+    const CHANNEL_TRUEALPHA = 64;
+    const CHANNEL_RGBS = 128;
+    const CHANNEL_GRAY_CHANNELS = 128;
+    const CHANNEL_SYNC = 256;
+    const CHANNEL_COMPOSITES = 47;
+    const METRIC_UNDEFINED = 0;
+    const METRIC_ABSOLUTEERRORMETRIC = 1;
+    const METRIC_MEANABSOLUTEERROR = 2;
+    const METRIC_MEANERRORPERPIXELMETRIC = 3;
+    const METRIC_MEANSQUAREERROR = 4;
+    const METRIC_PEAKABSOLUTEERROR = 5;
+    const METRIC_PEAKSIGNALTONOISERATIO = 6;
+    const METRIC_ROOTMEANSQUAREDERROR = 7;
+    const METRIC_NORMALIZEDCROSSCORRELATIONERRORMETRIC = 8;
+    const METRIC_FUZZERROR = 9;
+    const METRIC_PERCEPTUALHASH_ERROR = 255;
+    const PIXEL_CHAR = 1;
+    const PIXEL_DOUBLE = 2;
+    const PIXEL_FLOAT = 3;
+    const PIXEL_INTEGER = 4;
+    const PIXEL_LONG = 5;
+    const PIXEL_QUANTUM = 6;
+    const PIXEL_SHORT = 7;
+    const EVALUATE_UNDEFINED = 0;
+    const EVALUATE_ADD = 1;
+    const EVALUATE_AND = 2;
+    const EVALUATE_DIVIDE = 3;
+    const EVALUATE_LEFTSHIFT = 4;
+    const EVALUATE_MAX = 5;
+    const EVALUATE_MIN = 6;
+    const EVALUATE_MULTIPLY = 7;
+    const EVALUATE_OR = 8;
+    const EVALUATE_RIGHTSHIFT = 9;
+    const EVALUATE_SET = 10;
+    const EVALUATE_SUBTRACT = 11;
+    const EVALUATE_XOR = 12;
+    const EVALUATE_POW = 13;
+    const EVALUATE_LOG = 14;
+    const EVALUATE_THRESHOLD = 15;
+    const EVALUATE_THRESHOLDBLACK = 16;
+    const EVALUATE_THRESHOLDWHITE = 17;
+    const EVALUATE_GAUSSIANNOISE = 18;
+    const EVALUATE_IMPULSENOISE = 19;
+    const EVALUATE_LAPLACIANNOISE = 20;
+    const EVALUATE_MULTIPLICATIVENOISE = 21;
+    const EVALUATE_POISSONNOISE = 22;
+    const EVALUATE_UNIFORMNOISE = 23;
+    const EVALUATE_COSINE = 24;
+    const EVALUATE_SINE = 25;
+    const EVALUATE_ADDMODULUS = 26;
+    const EVALUATE_MEAN = 27;
+    const EVALUATE_ABS = 28;
+    const EVALUATE_EXPONENTIAL = 29;
+    const EVALUATE_MEDIAN = 30;
+    const EVALUATE_SUM = 31;
+    const EVALUATE_ROOT_MEAN_SQUARE = 32;
+    const COLORSPACE_UNDEFINED = 0;
+    const COLORSPACE_RGB = 1;
+    const COLORSPACE_GRAY = 2;
+    const COLORSPACE_TRANSPARENT = 3;
+    const COLORSPACE_OHTA = 4;
+    const COLORSPACE_LAB = 5;
+    const COLORSPACE_XYZ = 6;
+    const COLORSPACE_YCBCR = 7;
+    const COLORSPACE_YCC = 8;
+    const COLORSPACE_YIQ = 9;
+    const COLORSPACE_YPBPR = 10;
+    const COLORSPACE_YUV = 11;
+    const COLORSPACE_CMYK = 12;
+    const COLORSPACE_SRGB = 13;
+    const COLORSPACE_HSB = 14;
+    const COLORSPACE_HSL = 15;
+    const COLORSPACE_HWB = 16;
+    const COLORSPACE_REC601LUMA = 17;
+    const COLORSPACE_REC709LUMA = 19;
+    const COLORSPACE_LOG = 21;
+    const COLORSPACE_CMY = 22;
+    const COLORSPACE_LUV = 23;
+    const COLORSPACE_HCL = 24;
+    const COLORSPACE_LCH = 25;
+    const COLORSPACE_LMS = 26;
+    const COLORSPACE_LCHAB = 27;
+    const COLORSPACE_LCHUV = 28;
+    const COLORSPACE_SCRGB = 29;
+    const COLORSPACE_HSI = 30;
+    const COLORSPACE_HSV = 31;
+    const COLORSPACE_HCLP = 32;
+    const COLORSPACE_YDBDR = 33;
+    const COLORSPACE_REC601YCBCR = 18;
+    const COLORSPACE_REC709YCBCR = 20;
+    const COLORSPACE_XYY = 34;
+    const VIRTUALPIXELMETHOD_UNDEFINED = 0;
+    const VIRTUALPIXELMETHOD_BACKGROUND = 1;
+    const VIRTUALPIXELMETHOD_CONSTANT = 2;
+    const VIRTUALPIXELMETHOD_EDGE = 4;
+    const VIRTUALPIXELMETHOD_MIRROR = 5;
+    const VIRTUALPIXELMETHOD_TILE = 7;
+    const VIRTUALPIXELMETHOD_TRANSPARENT = 8;
+    const VIRTUALPIXELMETHOD_MASK = 9;
+    const VIRTUALPIXELMETHOD_BLACK = 10;
+    const VIRTUALPIXELMETHOD_GRAY = 11;
+    const VIRTUALPIXELMETHOD_WHITE = 12;
+    const VIRTUALPIXELMETHOD_HORIZONTALTILE = 13;
+    const VIRTUALPIXELMETHOD_VERTICALTILE = 14;
+    const VIRTUALPIXELMETHOD_HORIZONTALTILEEDGE = 15;
+    const VIRTUALPIXELMETHOD_VERTICALTILEEDGE = 16;
+    const VIRTUALPIXELMETHOD_CHECKERTILE = 17;
+    const PREVIEW_UNDEFINED = 0;
+    const PREVIEW_ROTATE = 1;
+    const PREVIEW_SHEAR = 2;
+    const PREVIEW_ROLL = 3;
+    const PREVIEW_HUE = 4;
+    const PREVIEW_SATURATION = 5;
+    const PREVIEW_BRIGHTNESS = 6;
+    const PREVIEW_GAMMA = 7;
+    const PREVIEW_SPIFF = 8;
+    const PREVIEW_DULL = 9;
+    const PREVIEW_GRAYSCALE = 10;
+    const PREVIEW_QUANTIZE = 11;
+    const PREVIEW_DESPECKLE = 12;
+    const PREVIEW_REDUCENOISE = 13;
+    const PREVIEW_ADDNOISE = 14;
+    const PREVIEW_SHARPEN = 15;
+    const PREVIEW_BLUR = 16;
+    const PREVIEW_THRESHOLD = 17;
+    const PREVIEW_EDGEDETECT = 18;
+    const PREVIEW_SPREAD = 19;
+    const PREVIEW_SOLARIZE = 20;
+    const PREVIEW_SHADE = 21;
+    const PREVIEW_RAISE = 22;
+    const PREVIEW_SEGMENT = 23;
+    const PREVIEW_SWIRL = 24;
+    const PREVIEW_IMPLODE = 25;
+    const PREVIEW_WAVE = 26;
+    const PREVIEW_OILPAINT = 27;
+    const PREVIEW_CHARCOALDRAWING = 28;
+    const PREVIEW_JPEG = 29;
+    const RENDERINGINTENT_UNDEFINED = 0;
+    const RENDERINGINTENT_SATURATION = 1;
+    const RENDERINGINTENT_PERCEPTUAL = 2;
+    const RENDERINGINTENT_ABSOLUTE = 3;
+    const RENDERINGINTENT_RELATIVE = 4;
+    const INTERLACE_UNDEFINED = 0;
+    const INTERLACE_NO = 1;
+    const INTERLACE_LINE = 2;
+    const INTERLACE_PLANE = 3;
+    const INTERLACE_PARTITION = 4;
+    const INTERLACE_GIF = 5;
+    const INTERLACE_JPEG = 6;
+    const INTERLACE_PNG = 7;
+    const FILLRULE_UNDEFINED = 0;
+    const FILLRULE_EVENODD = 1;
+    const FILLRULE_NONZERO = 2;
+    const PATHUNITS_UNDEFINED = 0;
+    const PATHUNITS_USERSPACE = 1;
+    const PATHUNITS_USERSPACEONUSE = 2;
+    const PATHUNITS_OBJECTBOUNDINGBOX = 3;
+    const LINECAP_UNDEFINED = 0;
+    const LINECAP_BUTT = 1;
+    const LINECAP_ROUND = 2;
+    const LINECAP_SQUARE = 3;
+    const LINEJOIN_UNDEFINED = 0;
+    const LINEJOIN_MITER = 1;
+    const LINEJOIN_ROUND = 2;
+    const LINEJOIN_BEVEL = 3;
+    const RESOURCETYPE_UNDEFINED = 0;
+    const RESOURCETYPE_AREA = 1;
+    const RESOURCETYPE_DISK = 2;
+    const RESOURCETYPE_FILE = 3;
+    const RESOURCETYPE_MAP = 4;
+    const RESOURCETYPE_MEMORY = 5;
+    const RESOURCETYPE_TIME = 7;
+    const RESOURCETYPE_THROTTLE = 8;
+    const RESOURCETYPE_THREAD = 6;
+    const RESOURCETYPE_WIDTH = 9;
+    const RESOURCETYPE_HEIGHT = 10;
+    const DISPOSE_UNRECOGNIZED = 0;
+    const DISPOSE_UNDEFINED = 0;
+    const DISPOSE_NONE = 1;
+    const DISPOSE_BACKGROUND = 2;
+    const DISPOSE_PREVIOUS = 3;
+    const INTERPOLATE_UNDEFINED = 0;
+    const INTERPOLATE_AVERAGE = 1;
+    const INTERPOLATE_BICUBIC = 2;
+    const INTERPOLATE_BILINEAR = 3;
+    const INTERPOLATE_FILTER = 4;
+    const INTERPOLATE_INTEGER = 5;
+    const INTERPOLATE_MESH = 6;
+    const INTERPOLATE_NEARESTNEIGHBOR = 7;
+    const INTERPOLATE_SPLINE = 8;
+    const INTERPOLATE_AVERAGE_9 = 9;
+    const INTERPOLATE_AVERAGE_16 = 10;
+    const INTERPOLATE_BLEND = 11;
+    const INTERPOLATE_BACKGROUND_COLOR = 12;
+    const INTERPOLATE_CATROM = 13;
+    const LAYERMETHOD_UNDEFINED = 0;
+    const LAYERMETHOD_COALESCE = 1;
+    const LAYERMETHOD_COMPAREANY = 2;
+    const LAYERMETHOD_COMPARECLEAR = 3;
+    const LAYERMETHOD_COMPAREOVERLAY = 4;
+    const LAYERMETHOD_DISPOSE = 5;
+    const LAYERMETHOD_OPTIMIZE = 6;
+    const LAYERMETHOD_OPTIMIZEPLUS = 8;
+    const LAYERMETHOD_OPTIMIZETRANS = 9;
+    const LAYERMETHOD_COMPOSITE = 12;
+    const LAYERMETHOD_OPTIMIZEIMAGE = 7;
+    const LAYERMETHOD_REMOVEDUPS = 10;
+    const LAYERMETHOD_REMOVEZERO = 11;
+    const LAYERMETHOD_TRIMBOUNDS = 16;
+    const ORIENTATION_UNDEFINED = 0;
+    const ORIENTATION_TOPLEFT = 1;
+    const ORIENTATION_TOPRIGHT = 2;
+    const ORIENTATION_BOTTOMRIGHT = 3;
+    const ORIENTATION_BOTTOMLEFT = 4;
+    const ORIENTATION_LEFTTOP = 5;
+    const ORIENTATION_RIGHTTOP = 6;
+    const ORIENTATION_RIGHTBOTTOM = 7;
+    const ORIENTATION_LEFTBOTTOM = 8;
+    const DISTORTION_UNDEFINED = 0;
+    const DISTORTION_AFFINE = 1;
+    const DISTORTION_AFFINEPROJECTION = 2;
+    const DISTORTION_ARC = 9;
+    const DISTORTION_BILINEAR = 6;
+    const DISTORTION_PERSPECTIVE = 4;
+    const DISTORTION_PERSPECTIVEPROJECTION = 5;
+    const DISTORTION_SCALEROTATETRANSLATE = 3;
+    const DISTORTION_POLYNOMIAL = 8;
+    const DISTORTION_POLAR = 10;
+    const DISTORTION_DEPOLAR = 11;
+    const DISTORTION_BARREL = 14;
+    const DISTORTION_SHEPARDS = 16;
+    const DISTORTION_SENTINEL = 18;
+    const DISTORTION_BARRELINVERSE = 15;
+    const DISTORTION_BILINEARFORWARD = 6;
+    const DISTORTION_BILINEARREVERSE = 7;
+    const DISTORTION_RESIZE = 17;
+    const DISTORTION_CYLINDER2PLANE = 12;
+    const DISTORTION_PLANE2CYLINDER = 13;
+    const LAYERMETHOD_MERGE = 13;
+    const LAYERMETHOD_FLATTEN = 14;
+    const LAYERMETHOD_MOSAIC = 15;
+    const ALPHACHANNEL_ACTIVATE = 1;
+    const ALPHACHANNEL_RESET = 7;
+    const ALPHACHANNEL_SET = 8;
+    const ALPHACHANNEL_UNDEFINED = 0;
+    const ALPHACHANNEL_COPY = 3;
+    const ALPHACHANNEL_DEACTIVATE = 4;
+    const ALPHACHANNEL_EXTRACT = 5;
+    const ALPHACHANNEL_OPAQUE = 6;
+    const ALPHACHANNEL_SHAPE = 9;
+    const ALPHACHANNEL_TRANSPARENT = 10;
+    const ALPHACHANNEL_ASSOCIATE = 13;
+    const ALPHACHANNEL_DISSOCIATE = 14;
+    const SPARSECOLORMETHOD_UNDEFINED = 0;
+    const SPARSECOLORMETHOD_BARYCENTRIC = 1;
+    const SPARSECOLORMETHOD_BILINEAR = 7;
+    const SPARSECOLORMETHOD_POLYNOMIAL = 8;
+    const SPARSECOLORMETHOD_SPEPARDS = 16;
+    const SPARSECOLORMETHOD_VORONOI = 18;
+    const SPARSECOLORMETHOD_INVERSE = 19;
+    const SPARSECOLORMETHOD_MANHATTAN = 20;
+    const DITHERMETHOD_UNDEFINED = 0;
+    const DITHERMETHOD_NO = 1;
+    const DITHERMETHOD_RIEMERSMA = 2;
+    const DITHERMETHOD_FLOYDSTEINBERG = 3;
+    const FUNCTION_UNDEFINED = 0;
+    const FUNCTION_POLYNOMIAL = 1;
+    const FUNCTION_SINUSOID = 2;
+    const ALPHACHANNEL_BACKGROUND = 2;
+    const FUNCTION_ARCSIN = 3;
+    const FUNCTION_ARCTAN = 4;
+    const ALPHACHANNEL_FLATTEN = 11;
+    const ALPHACHANNEL_REMOVE = 12;
+    const STATISTIC_GRADIENT = 1;
+    const STATISTIC_MAXIMUM = 2;
+    const STATISTIC_MEAN = 3;
+    const STATISTIC_MEDIAN = 4;
+    const STATISTIC_MINIMUM = 5;
+    const STATISTIC_MODE = 6;
+    const STATISTIC_NONPEAK = 7;
+    const STATISTIC_STANDARD_DEVIATION = 8;
+    const STATISTIC_ROOT_MEAN_SQUARE = 9;
+    const MORPHOLOGY_CONVOLVE = 1;
+    const MORPHOLOGY_CORRELATE = 2;
+    const MORPHOLOGY_ERODE = 3;
+    const MORPHOLOGY_DILATE = 4;
+    const MORPHOLOGY_ERODE_INTENSITY = 5;
+    const MORPHOLOGY_DILATE_INTENSITY = 6;
+    const MORPHOLOGY_DISTANCE = 7;
+    const MORPHOLOGY_OPEN = 8;
+    const MORPHOLOGY_CLOSE = 9;
+    const MORPHOLOGY_OPEN_INTENSITY = 10;
+    const MORPHOLOGY_CLOSE_INTENSITY = 11;
+    const MORPHOLOGY_SMOOTH = 12;
+    const MORPHOLOGY_EDGE_IN = 13;
+    const MORPHOLOGY_EDGE_OUT = 14;
+    const MORPHOLOGY_EDGE = 15;
+    const MORPHOLOGY_TOP_HAT = 16;
+    const MORPHOLOGY_BOTTOM_HAT = 17;
+    const MORPHOLOGY_HIT_AND_MISS = 18;
+    const MORPHOLOGY_THINNING = 19;
+    const MORPHOLOGY_THICKEN = 20;
+    const MORPHOLOGY_VORONOI = 21;
+    const MORPHOLOGY_ITERATIVE = 22;
+    const KERNEL_UNITY = 1;
+    const KERNEL_GAUSSIAN = 2;
+    const KERNEL_DIFFERENCE_OF_GAUSSIANS = 3;
+    const KERNEL_LAPLACIAN_OF_GAUSSIANS = 4;
+    const KERNEL_BLUR = 5;
+    const KERNEL_COMET = 6;
+    const KERNEL_LAPLACIAN = 7;
+    const KERNEL_SOBEL = 8;
+    const KERNEL_FREI_CHEN = 9;
+    const KERNEL_ROBERTS = 10;
+    const KERNEL_PREWITT = 11;
+    const KERNEL_COMPASS = 12;
+    const KERNEL_KIRSCH = 13;
+    const KERNEL_DIAMOND = 14;
+    const KERNEL_SQUARE = 15;
+    const KERNEL_RECTANGLE = 16;
+    const KERNEL_OCTAGON = 17;
+    const KERNEL_DISK = 18;
+    const KERNEL_PLUS = 19;
+    const KERNEL_CROSS = 20;
+    const KERNEL_RING = 21;
+    const KERNEL_PEAKS = 22;
+    const KERNEL_EDGES = 23;
+    const KERNEL_CORNERS = 24;
+    const KERNEL_DIAGONALS = 25;
+    const KERNEL_LINE_ENDS = 26;
+    const KERNEL_LINE_JUNCTIONS = 27;
+    const KERNEL_RIDGES = 28;
+    const KERNEL_CONVEX_HULL = 29;
+    const KERNEL_THIN_SE = 30;
+    const KERNEL_SKELETON = 31;
+    const KERNEL_CHEBYSHEV = 32;
+    const KERNEL_MANHATTAN = 33;
+    const KERNEL_OCTAGONAL = 34;
+    const KERNEL_EUCLIDEAN = 35;
+    const KERNEL_USER_DEFINED = 36;
+    const KERNEL_BINOMIAL = 37;
+    const DIRECTION_LEFT_TO_RIGHT = 2;
+    const DIRECTION_RIGHT_TO_LEFT = 1;
+    const NORMALIZE_KERNEL_NONE = 0;
+    const NORMALIZE_KERNEL_VALUE = 8192;
+    const NORMALIZE_KERNEL_CORRELATE = 65536;
+    const NORMALIZE_KERNEL_PERCENT = 4096;
+
+    // methods
+    public function optimizeimagelayers() {}
+    public function compareimagelayers($LAYER) {}
+    public function pingimageblob($imageContents) {}
+    public function pingimagefile($fp) {}
+    public function transposeimage() {}
+    public function transverseimage() {}
+    public function trimimage($fuzz) {}
+    public function waveimage($amplitude, $waveLenght) {}
+    public function vignetteimage($blackPoint, $whitePoint, $x, $y) {}
+    public function uniqueimagecolors() {}
+    public function getimagematte() {}
+    public function setimagematte($enable) {}
+    public function adaptiveresizeimage($columns, $rows, $bestfit = null, $legacy = null) {}
+    public function sketchimage($radius, $sigma, $angle) {}
+    public function shadeimage($gray, $azimuth, $elevation) {}
+    public function getsizeoffset() {}
+    public function setsizeoffset($columns, $rows, $offset) {}
+    public function adaptiveblurimage($radius, $sigma, $CHANNEL = null) {}
+    public function contraststretchimage($blackPoint, $whitePoint, $CHANNEL = null) {}
+    public function adaptivesharpenimage($radius, $sigma, $CHANNEL = null) {}
+    public function randomthresholdimage($low, $high, $CHANNELTYPE = null) {}
+    public function roundcornersimage($xRounding, $yRounding, $strokeWidth = null, $displace = null, $sizeCorrection = null) {}
+    public function roundcorners($xRounding, $yRounding, $strokeWidth = null, $displace = null, $sizeCorrection = null) {}
+    public function setiteratorindex($index) {}
+    public function getiteratorindex() {}
+    public function transformimage($crop, $geometry) {}
+    public function setimageopacity($opacity) {}
+    public function orderedposterizeimage($threshold_map, $CHANNEL = null) {}
+    public function polaroidimage(\ImagickDraw $ImagickDraw, $angle) {}
+    public function getimageproperty($name) {}
+    public function setimageproperty($name, $value) {}
+    public function deleteimageproperty($name) {}
+    public function identifyformat($embedText) {}
+    public function setimageinterpolatemethod($INTERPOLATE) {}
+    public function getimageinterpolatemethod() {}
+    public function linearstretchimage($blackPoint, $whitePoint) {}
+    public function getimagelength() {}
+    public function extentimage($width, $height, $x, $y) {}
+    public function getimageorientation() {}
+    public function setimageorientation($ORIENTATION) {}
+    public function paintfloodfillimage($CHANNEL, $fill, $fuzz, $bordercolor, $x, $y) {}
+    public function clutimage(\Imagick $Imagick, $CHANNELTYPE = null) {}
+    public function getimageproperties($pattern = null, $values = null) {}
+    public function getimageprofiles($pattern = null, $values = null) {}
+    public function distortimage($method, $arguments, $bestfit) {}
+    public function writeimagefile($handle, $format = null) {}
+    public function writeimagesfile($handle, $format = null) {}
+    public function resetimagepage($page) {}
+    public function setimageclipmask(\Imagick $Imagick) {}
+    public function getimageclipmask() {}
+    public function animateimages($server_name) {}
+    public function recolorimage($matrix) {}
+    public function setfont($font) {}
+    public function getfont() {}
+    public function setpointsize($pointsize) {}
+    public function getpointsize() {}
+    public function mergeimagelayers($LAYERMETHOD) {}
+    public function setimagealphachannel($ALPHACHANNELTYPE) {}
+    public function floodfillpaintimage($fill, $fuzz, $bordercolor, $x, $y, $invert, $CHANNEL = null) {}
+    public function opaquepaintimage($target, $fill, $fuzz, $invert, $CHANNEL = null) {}
+    public function transparentpaintimage($target, $alpha, $fuzz, $invert) {}
+    public function liquidrescaleimage($columns, $rows, $delta_x, $rigidity) {}
+    public function encipherimage($passphrase) {}
+    public function decipherimage($passphrase) {}
+    public function setgravity($GRAVITY) {}
+    public function getgravity() {}
+    public function getimagechannelrange($CHANNEL) {}
+    public function getimagealphachannel() {}
+    public function getimagechanneldistortions(\Imagick $Imagick, $METRICTYPE = null, $CHANNEL = null) {}
+    public function setimagegravity($GRAVITY) {}
+    public function getimagegravity() {}
+    public function importimagepixels($x, $y, $width, $height, $map, $storage, $PIXEL) {}
+    public function deskewimage($threshold) {}
+    public function segmentimage($COLORSPACE, $cluster_threshold, $smooth_threshold, $verbose = null) {}
+    public function sparsecolorimage($SPARSE_METHOD, $arguments, $CHANNEL = null) {}
+    public function remapimage(\Imagick $Imagick, $DITHER) {}
+    public function exportimagepixels($x, $y, $width, $height, $map, $STORAGE) {}
+    public function getimagechannelkurtosis($CHANNEL = null) {}
+    public function functionimage($FUNCTION, $arguments) {}
+    public function transformimagecolorspace($COLORSPACE) {}
+    public function haldclutimage(\Imagick $Imagick, $CHANNEL = null) {}
+    public function autolevelimage($CHANNEL = null) {}
+    public function blueshiftimage($factor = null) {}
+    public function getimageartifact($artifact) {}
+    public function setimageartifact($artifact, $value) {}
+    public function deleteimageartifact($artifact) {}
+    public function getcolorspace() {}
+    public function setcolorspace($COLORSPACE) {}
+    public function clampimage($CHANNEL = null) {}
+    public function smushimages($stack, $offset) {}
+    public function __construct($files = null) {}
+    public function __toString() {}
+    public function count($mode = null) {}
+    public function getpixeliterator() {}
+    public function getpixelregioniterator($x, $y, $columns, $rows, $modify) {}
+    public function readimage($filename) {}
+    public function readimages($filenames) {}
+    public function readimageblob($imageContents, $filename = null) {}
+    public function setimageformat($imageFormat) {}
+    public function scaleimage($width, $height, $bestfit = null, $legacy = null) {}
+    public function writeimage($filename = null) {}
+    public function writeimages($filename, $adjoin) {}
+    public function blurimage($radius, $sigma, $CHANNELTYPE = null) {}
+    public function thumbnailimage($width, $height, $bestfit = null, $fill = null, $legacy = null) {}
+    public function cropthumbnailimage($width, $height, $legacy = null) {}
+    public function getimagefilename() {}
+    public function setimagefilename($filename) {}
+    public function getimageformat() {}
+    public function getimagemimetype() {}
+    public function removeimage() {}
+    public function destroy() {}
+    public function clear() {}
+    public function clone() {}
+    public function getimagesize() {}
+    public function getimageblob() {}
+    public function getimagesblob() {}
+    public function setfirstiterator() {}
+    public function setlastiterator() {}
+    public function resetiterator() {}
+    public function previousimage() {}
+    public function nextimage() {}
+    public function haspreviousimage() {}
+    public function hasnextimage() {}
+    public function setimageindex($index) {}
+    public function getimageindex() {}
+    public function commentimage($comment) {}
+    public function cropimage($width, $height, $x, $y) {}
+    public function labelimage($label) {}
+    public function getimagegeometry() {}
+    public function drawimage(\ImagickDraw $ImagickDraw) {}
+    public function setimagecompressionquality($quality) {}
+    public function getimagecompressionquality() {}
+    public function setimagecompression($COMPRESSION) {}
+    public function getimagecompression() {}
+    public function annotateimage(\ImagickDraw $ImagickDraw, $x, $y, $angle, $text) {}
+    public function compositeimage(\Imagick $Imagick, $COMPOSITE, $x, $y, $CHANNELTYPE = null) {}
+    public function modulateimage($brightness, $saturation, $hue) {}
+    public function getimagecolors() {}
+    public function montageimage(\ImagickDraw $ImagickDraw, $tileGeometry, $thumbnailGeometry, $MONTAGEMODE, $frame) {}
+    public function identifyimage($appendRawOutput = null) {}
+    public function thresholdimage($threshold, $CHANNELTYPE = null) {}
+    public function adaptivethresholdimage($width, $height, $offset) {}
+    public function blackthresholdimage($color) {}
+    public function whitethresholdimage($color) {}
+    public function appendimages($stack) {}
+    public function charcoalimage($radius, $sigma) {}
+    public function normalizeimage($CHANNEL = null) {}
+    public function oilpaintimage($radius) {}
+    public function posterizeimage($levels, $dither) {}
+    public function radialblurimage($angle, $CHANNEL = null) {}
+    public function raiseimage($width, $height, $x, $y, $raise) {}
+    public function resampleimage($xResolution, $yResolution, $FILTER, $blur) {}
+    public function resizeimage($x, $y, $filter = null, $blur = null, $bestfit = null, $legacy = null) {}
+    public function rollimage($x, $y) {}
+    public function rotateimage($color, $degrees) {}
+    public function sampleimage($columns, $rows) {}
+    public function solarizeimage($threshold) {}
+    public function shadowimage($opacity, $sigma, $x, $y) {}
+    public function setimageattribute($key, $value) {}
+    public function setimagebackgroundcolor($color) {}
+    public function setimagecompose($COMPOSITE) {}
+    public function setimagedelay($delay) {}
+    public function setimagedepth($depth) {}
+    public function setimagegamma($gamma) {}
+    public function setimageiterations($iterations) {}
+    public function setimagemattecolor($color) {}
+    public function setimagepage($width, $height, $x, $y) {}
+    public function setimageprogressmonitor($filename) {}
+    public function setprogressmonitor($callback) {}
+    public function setimageresolution($xResolution, $yResolution) {}
+    public function setimagescene($scene) {}
+    public function setimagetickspersecond($ticksPerSecond) {}
+    public function setimagetype($IMGTYPE) {}
+    public function setimageunits($RESOLUTION) {}
+    public function sharpenimage($radius, $sigma, $CHANNEL = null) {}
+    public function shaveimage($columns, $rows) {}
+    public function shearimage($color, $xShear, $yShear) {}
+    public function spliceimage($width, $height, $x, $y) {}
+    public function pingimage($filename) {}
+    public function readimagefile($fp) {}
+    public function displayimage($serverName) {}
+    public function displayimages($serverName) {}
+    public function spreadimage($radius) {}
+    public function swirlimage($degrees) {}
+    public function stripimage() {}
+    public static function queryformats($pattern) {}
+    public static function queryfonts($pattern) {}
+    public function queryfontmetrics(\ImagickDraw $ImagickDraw, $text, $multiline = null) {}
+    public function steganoimage(\Imagick $Imagick, $offset) {}
+    public function addnoiseimage($NOISE, $CHANNEL = null) {}
+    public function motionblurimage($radius, $sigma, $angle, $CHANNEL = null) {}
+    public function mosaicimages() {}
+    public function morphimages($frames) {}
+    public function minifyimage() {}
+    public function affinetransformimage(\ImagickDraw $ImagickDraw) {}
+    public function averageimages() {}
+    public function borderimage($color, $width, $height) {}
+    public static function calculatecrop($orig_width, $orig_height, $desired_width, $desired_height, $legacy = null) {}
+    public function chopimage($width, $height, $x, $y) {}
+    public function clipimage() {}
+    public function clippathimage($pathname, $inside) {}
+    public function clipimagepath($pathname, $inside) {}
+    public function coalesceimages() {}
+    public function colorfloodfillimage($fill_color, $fuzz, $border_color, $y, $x) {}
+    public function colorizeimage($colorize_color, $opacity, $legacy = null) {}
+    public function compareimagechannels(\Imagick $Imagick, $CHANNEL, $METRIC) {}
+    public function compareimages(\Imagick $Imagick, $METRIC) {}
+    public function contrastimage($sharpen) {}
+    public function combineimages() {}
+    public function convolveimage($kernel, $CHANNEL = null) {}
+    public function cyclecolormapimage($displace) {}
+    public function deconstructimages() {}
+    public function despeckleimage() {}
+    public function edgeimage($radius) {}
+    public function embossimage($radius, $sigma) {}
+    public function enhanceimage() {}
+    public function equalizeimage() {}
+    public function evaluateimage($EVALUATE, $constant, $CHANNEL = null) {}
+    public function evaluateimages($EVALUATE) {}
+    public function flattenimages() {}
+    public function flipimage() {}
+    public function flopimage() {}
+    public function forwardfouriertransformimage($magnitude) {}
+    public function frameimage($color, $width, $height, $innerBevel, $outerBevel) {}
+    public function fximage($expression, $CHANNEL = null) {}
+    public function gammaimage($gamma, $CHANNEL = null) {}
+    public function gaussianblurimage($radius, $sigma, $CHANNEL = null) {}
+    public function getimageattribute($key) {}
+    public function getimagebackgroundcolor() {}
+    public function getimageblueprimary() {}
+    public function getimagebordercolor() {}
+    public function getimagechanneldepth($CHANNEL) {}
+    public function getimagechanneldistortion(\Imagick $Imagick, $CHANNEL, $METRIC) {}
+    public function getimagechannelextrema($CHANNEL) {}
+    public function getimagechannelmean($CHANNEL) {}
+    public function getimagechannelstatistics() {}
+    public function getimagecolormapcolor($index) {}
+    public function getimagecolorspace() {}
+    public function getimagecompose() {}
+    public function getimagedelay() {}
+    public function getimagedepth() {}
+    public function getimagedistortion(\Imagick $Imagick, $METRIC) {}
+    public function getimageextrema() {}
+    public function getimagedispose() {}
+    public function getimagegamma() {}
+    public function getimagegreenprimary() {}
+    public function getimageheight() {}
+    public function getimagehistogram() {}
+    public function getimageinterlacescheme() {}
+    public function getimageiterations() {}
+    public function getimagemattecolor() {}
+    public function getimagepage() {}
+    public function getimagepixelcolor($x, $y) {}
+    public function getimageprofile($name) {}
+    public function getimageredprimary() {}
+    public function getimagerenderingintent() {}
+    public function getimageresolution() {}
+    public function getimagescene() {}
+    public function getimagesignature() {}
+    public function getimagetickspersecond() {}
+    public function getimagetype() {}
+    public function getimageunits() {}
+    public function getimagevirtualpixelmethod() {}
+    public function getimagewhitepoint() {}
+    public function getimagewidth() {}
+    public function getnumberimages() {}
+    public function getimagetotalinkdensity() {}
+    public function getimageregion($width, $height, $x, $y) {}
+    public function implodeimage($radius) {}
+    public function inversefouriertransformimage($complement, $magnitude) {}
+    public function levelimage($blackPoint, $gamma, $whitePoint, $CHANNEL = null) {}
+    public function magnifyimage() {}
+    public function mapimage(\Imagick $Imagick, $dither) {}
+    public function mattefloodfillimage($alpha, $fuzz, $color, $x, $y) {}
+    public function medianfilterimage($radius) {}
+    public function negateimage($gray, $CHANNEL = null) {}
+    public function paintopaqueimage($target_color, $fill_color, $fuzz, $CHANNEL = null) {}
+    public function painttransparentimage($target_color, $alpha, $fuzz) {}
+    public function previewimages($PREVIEW) {}
+    public function profileimage($name, $profile) {}
+    public function quantizeimage($numColors, $COLORSPACE, $treeDepth, $dither, $measureError) {}
+    public function quantizeimages($numColors, $COLORSPACE, $treeDepth, $dither, $measureError) {}
+    public function reducenoiseimage($radius) {}
+    public function removeimageprofile($name) {}
+    public function separateimagechannel($CHANNEL) {}
+    public function sepiatoneimage($threshold) {}
+    public function setimagebias($bias) {}
+    public function setimagebiasquantum($bias) {}
+    public function setimageblueprimary($x, $y) {}
+    public function setimagebordercolor($color) {}
+    public function setimagechanneldepth($CHANNEL, $depth) {}
+    public function setimagecolormapcolor($index, $color) {}
+    public function setimagecolorspace($COLORSPACE) {}
+    public function setimagedispose($DISPOSETYPE) {}
+    public function setimageextent($columns, $rows) {}
+    public function setimagegreenprimary($x, $y) {}
+    public function setimageinterlacescheme($INTERLACE) {}
+    public function setimageprofile($name, $profile) {}
+    public function setimageredprimary($x, $y) {}
+    public function setimagerenderingintent($RENDERINGINTENT) {}
+    public function setimagevirtualpixelmethod($VIRTUALPIXELMETHOD) {}
+    public function setimagewhitepoint($x, $y) {}
+    public function sigmoidalcontrastimage($sharpen, $contrast, $midpoint, $CHANNEL = null) {}
+    public function stereoimage(\Imagick $Imagick) {}
+    public function textureimage(\Imagick $Imagick) {}
+    public function tintimage($tint_color, $opacity, $legacy = null) {}
+    public function unsharpmaskimage($radius, $sigma, $amount, $threshold, $CHANNEL = null) {}
+    public function getimage() {}
+    public function addimage(\Imagick $Imagick) {}
+    public function setimage(\Imagick $Imagick) {}
+    public function newimage($columns, $rows, $background_color, $format = null) {}
+    public function newpseudoimage($columns, $rows, $pseudoString) {}
+    public function getcompression() {}
+    public function getcompressionquality() {}
+    public static function getcopyright() {}
+    public static function getconfigureoptions($pattern = null) {}
+    public static function getfeatures() {}
+    public function getfilename() {}
+    public function getformat() {}
+    public static function gethomeurl() {}
+    public function getinterlacescheme() {}
+    public function getoption($key) {}
+    public static function getpackagename() {}
+    public function getpage() {}
+    public static function getquantum() {}
+    public static function gethdrienabled() {}
+    public static function getquantumdepth() {}
+    public static function getquantumrange() {}
+    public static function getreleasedate() {}
+    public static function getresource($resource_type) {}
+    public static function getresourcelimit($resource_type) {}
+    public function getsamplingfactors() {}
+    public function getsize() {}
+    public static function getversion() {}
+    public function setbackgroundcolor($color) {}
+    public function setcompression($compression) {}
+    public function setcompressionquality($compressionquality) {}
+    public function setfilename($filename) {}
+    public function setformat($format) {}
+    public function setinterlacescheme($INTERLACE) {}
+    public function setoption($key, $value) {}
+    public function setpage($width, $height, $x, $y) {}
+    public static function setresourcelimit($RESOURCETYPE, $limit) {}
+    public function setresolution($xResolution, $yResolution) {}
+    public function setsamplingfactors($factors) {}
+    public function setsize($columns, $rows) {}
+    public function settype($IMGTYPE) {}
+    public function key() {}
+    public function next() {}
+    public function rewind() {}
+    public function valid() {}
+    public function current() {}
+    public function brightnesscontrastimage($brightness, $contrast, $CHANNEL = null) {}
+    public function colormatriximage($color_matrix) {}
+    public function selectiveblurimage($radius, $sigma, $threshold, $CHANNEL) {}
+    public function rotationalblurimage($angle, $CHANNEL = null) {}
+    public function statisticimage($type, $width, $height, $CHANNEL = null) {}
+    public function subimagematch(\Imagick $Imagick, &$offset = null, &$similarity = null, &$similarity_threshold = null, &$metric = null) {}
+    public function similarityimage(\Imagick $Imagick, &$offset = null, &$similarity = null, &$similarity_threshold = null, &$metric = null) {}
+    public static function setregistry($key, $value) {}
+    public static function getregistry($key) {}
+    public static function listregistry() {}
+    public function morphology($morphologyMethod, $iterations, \ImagickKernel $ImagickKernel, $CHANNEL = null) {}
+    public function filter(\ImagickKernel $ImagickKernel, $CHANNEL = null) {}
+    public function setantialias($antialias) {}
+    public function getantialias() {}
+    public function colordecisionlistimage($antialias) {}
+    public function autogammaimage($CHANNEL) {}
+    public function autoorient() {}
+    public function compositeimagegravity(\Imagick $Imagick, $COMPOSITE, $GRAVITY) {}
+    public function localcontrastimage($radius, $strength) {}
+}
+
+class ImagickDraw {
+
+    // methods
+    public function resetvectorgraphics() {}
+    public function gettextkerning() {}
+    public function settextkerning($kerning) {}
+    public function gettextinterwordspacing() {}
+    public function settextinterwordspacing($spacing) {}
+    public function gettextinterlinespacing() {}
+    public function settextinterlinespacing($spacing) {}
+    public function __construct() {}
+    public function setfillcolor($color) {}
+    public function setfillalpha($alpha) {}
+    public function setresolution($x_resolution, $y_resolution) {}
+    public function setstrokecolor($color) {}
+    public function setstrokealpha($alpha) {}
+    public function setstrokewidth($width) {}
+    public function clear() {}
+    public function circle($ox, $oy, $px, $py) {}
+    public function annotation($x, $y, $text) {}
+    public function settextantialias($antialias) {}
+    public function settextencoding($encoding) {}
+    public function setfont($font) {}
+    public function setfontfamily($fontfamily) {}
+    public function setfontsize($pointsize) {}
+    public function setfontstyle($STYLE) {}
+    public function setfontweight($weight) {}
+    public function getfont() {}
+    public function getfontfamily() {}
+    public function getfontsize() {}
+    public function getfontstyle() {}
+    public function getfontweight() {}
+    public function destroy() {}
+    public function rectangle($x1, $y1, $x2, $y2) {}
+    public function roundrectangle($x1, $y1, $x2, $y2, $rx, $ry) {}
+    public function ellipse($ox, $oy, $px, $py, $start, $end) {}
+    public function skewx($degrees) {}
+    public function skewy($degrees) {}
+    public function translate($x, $y) {}
+    public function line($sx, $sy, $ex, $ey) {}
+    public function arc($sx, $sy, $ex, $ey, $sd, $ed) {}
+    public function matte($x, $y, $METHOD) {}
+    public function polygon($coordinates) {}
+    public function point($x, $y) {}
+    public function gettextdecoration() {}
+    public function gettextencoding() {}
+    public function getfontstretch() {}
+    public function setfontstretch($STRETCH) {}
+    public function setstrokeantialias($antialias) {}
+    public function settextalignment($ALIGN) {}
+    public function settextdecoration($DECORATION) {}
+    public function settextundercolor($color) {}
+    public function setviewbox($sx, $sy, $ex, $ey) {}
+    public function clone() {}
+    public function affine($affineMatrix) {}
+    public function bezier($coordinateArray) {}
+    public function composite($COMPOSE, $x, $y, $width, $height, \Imagick $Imagick) {}
+    public function color($x, $y, $PAINTMETHOD) {}
+    public function comment($comment) {}
+    public function getclippath() {}
+    public function getcliprule() {}
+    public function getclipunits() {}
+    public function getfillcolor() {}
+    public function getfillopacity() {}
+    public function getfillrule() {}
+    public function getgravity() {}
+    public function getstrokeantialias() {}
+    public function getstrokecolor() {}
+    public function getstrokedasharray() {}
+    public function getstrokedashoffset() {}
+    public function getstrokelinecap() {}
+    public function getstrokelinejoin() {}
+    public function getstrokemiterlimit() {}
+    public function getstrokeopacity() {}
+    public function getstrokewidth() {}
+    public function gettextalignment() {}
+    public function gettextantialias() {}
+    public function getvectorgraphics() {}
+    public function gettextundercolor() {}
+    public function pathclose() {}
+    public function pathcurvetoabsolute($x1, $y1, $x2, $y2, $x, $y) {}
+    public function pathcurvetorelative($x1, $y1, $x2, $y2, $x, $y) {}
+    public function pathcurvetoquadraticbezierabsolute($x1, $y1, $x, $y) {}
+    public function pathcurvetoquadraticbezierrelative($x1, $y1, $x, $y) {}
+    public function pathcurvetoquadraticbeziersmoothabsolute($x, $y) {}
+    public function pathcurvetoquadraticbeziersmoothrelative($x, $y) {}
+    public function pathcurvetosmoothabsolute($x1, $y1, $x, $y) {}
+    public function pathcurvetosmoothrelative($x1, $y1, $x, $y) {}
+    public function pathellipticarcabsolute($rx, $ry, $xAxisRotation, $largeArc, $sweep, $x, $y) {}
+    public function pathellipticarcrelative($rx, $ry, $xAxisRotation, $largeArc, $sweep, $x, $y) {}
+    public function pathfinish() {}
+    public function pathlinetoabsolute($x, $y) {}
+    public function pathlinetorelative($x, $y) {}
+    public function pathlinetohorizontalabsolute($y) {}
+    public function pathlinetohorizontalrelative($x) {}
+    public function pathlinetoverticalabsolute($y) {}
+    public function pathlinetoverticalrelative($x) {}
+    public function pathmovetoabsolute($x, $y) {}
+    public function pathmovetorelative($x, $y) {}
+    public function pathstart() {}
+    public function polyline($coordinateArray) {}
+    public function popclippath() {}
+    public function popdefs() {}
+    public function poppattern() {}
+    public function pushclippath($clipMask) {}
+    public function pushdefs() {}
+    public function pushpattern($pattern_id, $x, $y, $width, $height) {}
+    public function render() {}
+    public function rotate($degrees) {}
+    public function scale($x, $y) {}
+    public function setclippath($clipMask) {}
+    public function setcliprule($FILLRULE) {}
+    public function setclipunits($PATHUNITS) {}
+    public function setfillopacity($fillOpacity) {}
+    public function setfillpatternurl($url) {}
+    public function setfillrule($FILLRULE) {}
+    public function setgravity($GRAVITY) {}
+    public function setstrokepatternurl($url) {}
+    public function setstrokedashoffset($offset) {}
+    public function setstrokelinecap($LINECAP) {}
+    public function setstrokelinejoin($LINEJOIN) {}
+    public function setstrokemiterlimit($miterLimit) {}
+    public function setstrokeopacity($strokeOpacity) {}
+    public function setvectorgraphics($xml) {}
+    public function pop() {}
+    public function push() {}
+    public function setstrokedasharray($dashArray) {}
+    public function getopacity() {}
+    public function setopacity($opacity) {}
+    public function getfontresolution() {}
+    public function setfontresolution($x, $y) {}
+    public function getbordercolor() {}
+    public function setbordercolor($bordercolor) {}
+    public function setdensity($density) {}
+    public function getdensity() {}
+    public function gettextdirection() {}
+    public function settextdirection($direction) {}
+}
+
+class ImagickDrawException extends \Exception {
+
+    // properties
+    protected $message;
+    protected $code;
+    protected $file;
+    protected $line;
+}
+
+class ImagickException extends \Exception {
+
+    // properties
+    protected $message;
+    protected $code;
+    protected $file;
+    protected $line;
+}
+
+class ImagickKernel {
+
+    // methods
+    private function __construct() {}
+    public static function frommatrix($array, $array = null) {}
+    public static function frombuiltin($kerneltype, $paramstring) {}
+    public function addkernel(\ImagickKernel $ImagickKernel) {}
+    public function getmatrix() {}
+    public function separate() {}
+    public function scale() {}
+    public function addunitykernel() {}
+}
+
+class ImagickKernelException extends \Exception {
+
+    // properties
+    protected $message;
+    protected $code;
+    protected $file;
+    protected $line;
+}
+
+class ImagickPixel {
+
+    // methods
+    public function gethsl() {}
+    public function sethsl($hue, $saturation, $luminosity) {}
+    public function getcolorvaluequantum($color) {}
+    public function setcolorvaluequantum($color_value) {}
+    public function getindex() {}
+    public function setindex($index) {}
+    public function __construct($color = null) {}
+    public function setcolor($color) {}
+    public function setcolorvalue($color, $value) {}
+    public function getcolorvalue($color) {}
+    public function clear() {}
+    public function destroy() {}
+    public function issimilar($color, $fuzz = null) {}
+    public function ispixelsimilarquantum($color, $fuzz = null) {}
+    public function ispixelsimilar($color, $fuzz = null) {}
+    public function getcolor($normalized = null) {}
+    public function getcolorquantum() {}
+    public function getcolorasstring() {}
+    public function getcolorcount() {}
+    public function setcolorcount($colorCount) {}
+    public function clone() {}
+    public function setcolorfrompixel(\ImagickPixel $srcPixel) {}
+}
+
+class ImagickPixelException extends \Exception {
+
+    // properties
+    protected $message;
+    protected $code;
+    protected $file;
+    protected $line;
+}
+
+class ImagickPixelIterator implements \Iterator, \Traversable {
+
+    // methods
+    public function __construct(\Imagick $Imagick) {}
+    public function newpixeliterator() {}
+    public function newpixelregioniterator() {}
+    public function getiteratorrow() {}
+    public function setiteratorrow($row) {}
+    public function setiteratorfirstrow() {}
+    public function setiteratorlastrow() {}
+    public function getpreviousiteratorrow() {}
+    public function getcurrentiteratorrow() {}
+    public function getnextiteratorrow() {}
+    public function resetiterator() {}
+    public function synciterator() {}
+    public function destroy() {}
+    public function clear() {}
+    public static function getpixeliterator(\Imagick $Imagick) {}
+    public static function getpixelregioniterator(\Imagick $Imagick, $x, $y, $columns, $rows) {}
+    public function key() {}
+    public function next() {}
+    public function rewind() {}
+    public function current() {}
+    public function valid() {}
+}
+
+class ImagickPixelIteratorException extends \Exception {
+
+    // properties
+    protected $message;
+    protected $code;
+    protected $file;
+    protected $line;
+}
+
+}
diff --git a/.phan/internal_stubs/pcntl.phan_php b/.phan/internal_stubs/pcntl.phan_php
new file mode 100644 (file)
index 0000000..392dc30
--- /dev/null
@@ -0,0 +1,139 @@
+<?php
+// These stubs were generated by the phan stub generator.
+// @phan-stub-for-extension pcntl@7.0.33-0+deb9u3
+
+namespace {
+function pcntl_alarm($seconds) {}
+function pcntl_errno() {}
+function pcntl_exec($path, $args = null, $envs = null) {}
+function pcntl_fork() {}
+function pcntl_get_last_error() {}
+function pcntl_getpriority($pid = null, $process_identifier = null) {}
+function pcntl_setpriority($priority, $pid = null, $process_identifier = null) {}
+function pcntl_signal($signo, $handler, $restart_syscalls = null) {}
+function pcntl_signal_dispatch() {}
+function pcntl_sigprocmask($how, $set, &$oldset = null) {}
+function pcntl_sigtimedwait($set, &$info = null, $seconds = null, $nanoseconds = null) {}
+function pcntl_sigwaitinfo($set, &$info = null) {}
+function pcntl_strerror($errno) {}
+function pcntl_wait(&$status, $options = null, &$rusage = null) {}
+function pcntl_waitpid($pid, &$status, $options = null, &$rusage = null) {}
+function pcntl_wexitstatus($status) {}
+function pcntl_wifcontinued($status) {}
+function pcntl_wifexited($status) {}
+function pcntl_wifsignaled($status) {}
+function pcntl_wifstopped($status) {}
+function pcntl_wstopsig($status) {}
+function pcntl_wtermsig($status) {}
+const BUS_ADRALN = 1;
+const BUS_ADRERR = 2;
+const BUS_OBJERR = 3;
+const CLD_CONTINUED = 6;
+const CLD_DUMPED = 3;
+const CLD_EXITED = 1;
+const CLD_KILLED = 2;
+const CLD_STOPPED = 5;
+const CLD_TRAPPED = 4;
+const FPE_FLTDIV = 3;
+const FPE_FLTINV = 7;
+const FPE_FLTOVF = 4;
+const FPE_FLTRES = 6;
+const FPE_FLTSUB = 8;
+const FPE_FLTUND = 7;
+const FPE_INTDIV = 1;
+const FPE_INTOVF = 2;
+const ILL_BADSTK = 8;
+const ILL_COPROC = 7;
+const ILL_ILLADR = 3;
+const ILL_ILLOPC = 1;
+const ILL_ILLOPN = 2;
+const ILL_ILLTRP = 4;
+const ILL_PRVOPC = 5;
+const ILL_PRVREG = 6;
+const PCNTL_E2BIG = 7;
+const PCNTL_EACCES = 13;
+const PCNTL_EAGAIN = 11;
+const PCNTL_ECHILD = 10;
+const PCNTL_EFAULT = 14;
+const PCNTL_EINTR = 4;
+const PCNTL_EINVAL = 22;
+const PCNTL_EIO = 5;
+const PCNTL_EISDIR = 21;
+const PCNTL_ELIBBAD = 80;
+const PCNTL_ELOOP = 40;
+const PCNTL_EMFILE = 24;
+const PCNTL_ENAMETOOLONG = 36;
+const PCNTL_ENFILE = 23;
+const PCNTL_ENOENT = 2;
+const PCNTL_ENOEXEC = 8;
+const PCNTL_ENOMEM = 12;
+const PCNTL_ENOTDIR = 20;
+const PCNTL_EPERM = 1;
+const PCNTL_ESRCH = 3;
+const PCNTL_ETXTBSY = 26;
+const POLL_ERR = 4;
+const POLL_HUP = 6;
+const POLL_IN = 1;
+const POLL_MSG = 3;
+const POLL_OUT = 2;
+const POLL_PRI = 5;
+const PRIO_PGRP = 1;
+const PRIO_PROCESS = 0;
+const PRIO_USER = 2;
+const SEGV_ACCERR = 2;
+const SEGV_MAPERR = 1;
+const SIGABRT = 6;
+const SIGALRM = 14;
+const SIGBABY = 31;
+const SIGBUS = 7;
+const SIGCHLD = 17;
+const SIGCLD = 17;
+const SIGCONT = 18;
+const SIGFPE = 8;
+const SIGHUP = 1;
+const SIGILL = 4;
+const SIGINT = 2;
+const SIGIO = 29;
+const SIGIOT = 6;
+const SIGKILL = 9;
+const SIGPIPE = 13;
+const SIGPOLL = 29;
+const SIGPROF = 27;
+const SIGPWR = 30;
+const SIGQUIT = 3;
+const SIGSEGV = 11;
+const SIGSTKFLT = 16;
+const SIGSTOP = 19;
+const SIGSYS = 31;
+const SIGTERM = 15;
+const SIGTRAP = 5;
+const SIGTSTP = 20;
+const SIGTTIN = 21;
+const SIGTTOU = 22;
+const SIGURG = 23;
+const SIGUSR1 = 10;
+const SIGUSR2 = 12;
+const SIGVTALRM = 26;
+const SIGWINCH = 28;
+const SIGXCPU = 24;
+const SIGXFSZ = 25;
+const SIG_BLOCK = 0;
+const SIG_DFL = 0;
+const SIG_ERR = -1;
+const SIG_IGN = 1;
+const SIG_SETMASK = 2;
+const SIG_UNBLOCK = 1;
+const SI_ASYNCIO = -4;
+const SI_KERNEL = 128;
+const SI_MESGQ = -3;
+const SI_QUEUE = -1;
+const SI_SIGIO = -5;
+const SI_TIMER = -2;
+const SI_TKILL = -6;
+const SI_USER = 0;
+const TRAP_BRKPT = 1;
+const TRAP_TRACE = 2;
+const WCONTINUED = 8;
+const WNOHANG = 1;
+const WUNTRACED = 2;
+}
diff --git a/.phan/internal_stubs/redis.phan_php b/.phan/internal_stubs/redis.phan_php
new file mode 100644 (file)
index 0000000..29efb47
--- /dev/null
@@ -0,0 +1,490 @@
+<?php
+// These stubs were generated by the phan stub generator.
+// @phan-stub-for-extension redis@3.1.1
+
+namespace {
+class Redis {
+
+    // constants
+    const REDIS_NOT_FOUND = 0;
+    const REDIS_STRING = 1;
+    const REDIS_SET = 2;
+    const REDIS_LIST = 3;
+    const REDIS_ZSET = 4;
+    const REDIS_HASH = 5;
+    const PIPELINE = 2;
+    const ATOMIC = 0;
+    const MULTI = 1;
+    const OPT_SERIALIZER = 1;
+    const OPT_PREFIX = 2;
+    const OPT_READ_TIMEOUT = 3;
+    const SERIALIZER_NONE = 0;
+    const SERIALIZER_PHP = 1;
+    const SERIALIZER_IGBINARY = 2;
+    const OPT_SCAN = 4;
+    const SCAN_RETRY = 1;
+    const SCAN_NORETRY = 0;
+    const AFTER = 'after';
+    const BEFORE = 'before';
+
+    // methods
+    public function __construct() {}
+    public function __destruct() {}
+    public function connect() {}
+    public function pconnect() {}
+    public function close() {}
+    public function ping() {}
+    public function echo() {}
+    public function get() {}
+    public function set() {}
+    public function setex() {}
+    public function psetex() {}
+    public function setnx() {}
+    public function getSet() {}
+    public function randomKey() {}
+    public function renameKey() {}
+    public function renameNx() {}
+    public function getMultiple() {}
+    public function exists() {}
+    public function delete() {}
+    public function incr() {}
+    public function incrBy() {}
+    public function incrByFloat() {}
+    public function decr() {}
+    public function decrBy() {}
+    public function type() {}
+    public function append() {}
+    public function getRange() {}
+    public function setRange() {}
+    public function getBit() {}
+    public function setBit() {}
+    public function strlen() {}
+    public function getKeys() {}
+    public function sort() {}
+    public function sortAsc() {}
+    public function sortAscAlpha() {}
+    public function sortDesc() {}
+    public function sortDescAlpha() {}
+    public function lPush() {}
+    public function rPush() {}
+    public function lPushx() {}
+    public function rPushx() {}
+    public function lPop() {}
+    public function rPop() {}
+    public function blPop() {}
+    public function brPop() {}
+    public function lSize() {}
+    public function lRemove() {}
+    public function listTrim() {}
+    public function lGet() {}
+    public function lGetRange() {}
+    public function lSet() {}
+    public function lInsert() {}
+    public function sAdd() {}
+    public function sAddArray() {}
+    public function sSize() {}
+    public function sRemove() {}
+    public function sMove() {}
+    public function sPop() {}
+    public function sRandMember() {}
+    public function sContains() {}
+    public function sMembers() {}
+    public function sInter() {}
+    public function sInterStore() {}
+    public function sUnion() {}
+    public function sUnionStore() {}
+    public function sDiff() {}
+    public function sDiffStore() {}
+    public function setTimeout() {}
+    public function save() {}
+    public function bgSave() {}
+    public function lastSave() {}
+    public function flushDB() {}
+    public function flushAll() {}
+    public function dbSize() {}
+    public function auth() {}
+    public function ttl() {}
+    public function pttl() {}
+    public function persist() {}
+    public function info() {}
+    public function select() {}
+    public function move() {}
+    public function bgrewriteaof() {}
+    public function slaveof() {}
+    public function object() {}
+    public function bitop() {}
+    public function bitcount() {}
+    public function bitpos() {}
+    public function mset() {}
+    public function msetnx() {}
+    public function rpoplpush() {}
+    public function brpoplpush() {}
+    public function zAdd() {}
+    public function zDelete() {}
+    public function zRange() {}
+    public function zRevRange() {}
+    public function zRangeByScore() {}
+    public function zRevRangeByScore() {}
+    public function zRangeByLex() {}
+    public function zRevRangeByLex() {}
+    public function zLexCount() {}
+    public function zRemRangeByLex() {}
+    public function zCount() {}
+    public function zDeleteRangeByScore() {}
+    public function zDeleteRangeByRank() {}
+    public function zCard() {}
+    public function zScore() {}
+    public function zRank() {}
+    public function zRevRank() {}
+    public function zInter() {}
+    public function zUnion() {}
+    public function zIncrBy() {}
+    public function expireAt() {}
+    public function pexpire() {}
+    public function pexpireAt() {}
+    public function hGet() {}
+    public function hSet() {}
+    public function hSetNx() {}
+    public function hDel() {}
+    public function hLen() {}
+    public function hKeys() {}
+    public function hVals() {}
+    public function hGetAll() {}
+    public function hExists() {}
+    public function hIncrBy() {}
+    public function hIncrByFloat() {}
+    public function hMset() {}
+    public function hMget() {}
+    public function multi() {}
+    public function discard() {}
+    public function exec() {}
+    public function pipeline() {}
+    public function watch() {}
+    public function unwatch() {}
+    public function publish() {}
+    public function subscribe() {}
+    public function psubscribe() {}
+    public function unsubscribe() {}
+    public function punsubscribe() {}
+    public function time() {}
+    public function role() {}
+    public function eval() {}
+    public function evalsha() {}
+    public function script() {}
+    public function debug() {}
+    public function dump() {}
+    public function restore() {}
+    public function migrate() {}
+    public function getLastError() {}
+    public function clearLastError() {}
+    public function _prefix() {}
+    public function _serialize() {}
+    public function _unserialize() {}
+    public function client() {}
+    public function command() {}
+    public function scan(&$i_iterator, $str_pattern = null, $i_count = null) {}
+    public function hscan($str_key, &$i_iterator, $str_pattern = null, $i_count = null) {}
+    public function zscan($str_key, &$i_iterator, $str_pattern = null, $i_count = null) {}
+    public function sscan($str_key, &$i_iterator, $str_pattern = null, $i_count = null) {}
+    public function pfadd() {}
+    public function pfcount() {}
+    public function pfmerge() {}
+    public function getOption() {}
+    public function setOption() {}
+    public function config() {}
+    public function slowlog() {}
+    public function rawcommand() {}
+    public function geoadd() {}
+    public function geohash() {}
+    public function geopos() {}
+    public function geodist() {}
+    public function georadius() {}
+    public function georadiusbymember() {}
+    public function getHost() {}
+    public function getPort() {}
+    public function getDBNum() {}
+    public function getTimeout() {}
+    public function getReadTimeout() {}
+    public function getPersistentID() {}
+    public function getAuth() {}
+    public function isConnected() {}
+    public function getMode() {}
+    public function wait() {}
+    public function pubsub() {}
+    public function open() {}
+    public function popen() {}
+    public function lLen() {}
+    public function sGetMembers() {}
+    public function mget() {}
+    public function expire() {}
+    public function zunionstore() {}
+    public function zinterstore() {}
+    public function zRemove() {}
+    public function zRem() {}
+    public function zRemoveRangeByScore() {}
+    public function zRemRangeByScore() {}
+    public function zRemRangeByRank() {}
+    public function zSize() {}
+    public function substr() {}
+    public function rename() {}
+    public function del() {}
+    public function keys() {}
+    public function lrem() {}
+    public function ltrim() {}
+    public function lindex() {}
+    public function lrange() {}
+    public function scard() {}
+    public function srem() {}
+    public function sismember() {}
+    public function zReverseRange() {}
+    public function sendEcho() {}
+    public function evaluate() {}
+    public function evaluateSha() {}
+}
+
+class RedisArray {
+
+    // methods
+    public function __construct() {}
+    public function __call($function_name, $arguments) {}
+    public function _hosts() {}
+    public function _target() {}
+    public function _instance() {}
+    public function _function() {}
+    public function _distributor() {}
+    public function _rehash() {}
+    public function select() {}
+    public function info() {}
+    public function ping() {}
+    public function flushdb() {}
+    public function flushall() {}
+    public function mget() {}
+    public function mset() {}
+    public function del() {}
+    public function getOption() {}
+    public function setOption() {}
+    public function keys() {}
+    public function save() {}
+    public function bgsave() {}
+    public function multi() {}
+    public function exec() {}
+    public function discard() {}
+    public function unwatch() {}
+    public function delete() {}
+    public function getMultiple() {}
+}
+
+class RedisCluster {
+
+    // constants
+    const REDIS_NOT_FOUND = 0;
+    const REDIS_STRING = 1;
+    const REDIS_SET = 2;
+    const REDIS_LIST = 3;
+    const REDIS_ZSET = 4;
+    const REDIS_HASH = 5;
+    const ATOMIC = 0;
+    const MULTI = 1;
+    const OPT_SERIALIZER = 1;
+    const OPT_PREFIX = 2;
+    const OPT_READ_TIMEOUT = 3;
+    const SERIALIZER_NONE = 0;
+    const SERIALIZER_PHP = 1;
+    const SERIALIZER_IGBINARY = 2;
+    const OPT_SCAN = 4;
+    const SCAN_RETRY = 1;
+    const SCAN_NORETRY = 0;
+    const OPT_SLAVE_FAILOVER = 5;
+    const FAILOVER_NONE = 0;
+    const FAILOVER_ERROR = 1;
+    const FAILOVER_DISTRIBUTE = 2;
+    const FAILOVER_DISTRIBUTE_SLAVES = 3;
+    const AFTER = 'after';
+    const BEFORE = 'before';
+
+    // methods
+    public function __construct() {}
+    public function close() {}
+    public function get() {}
+    public function set() {}
+    public function mget() {}
+    public function mset() {}
+    public function msetnx() {}
+    public function del() {}
+    public function setex() {}
+    public function psetex() {}
+    public function setnx() {}
+    public function getset() {}
+    public function exists() {}
+    public function keys() {}
+    public function type() {}
+    public function lpop() {}
+    public function rpop() {}
+    public function lset() {}
+    public function spop() {}
+    public function lpush() {}
+    public function rpush() {}
+    public function blpop() {}
+    public function brpop() {}
+    public function rpushx() {}
+    public function lpushx() {}
+    public function linsert() {}
+    public function lindex() {}
+    public function lrem() {}
+    public function brpoplpush() {}
+    public function rpoplpush() {}
+    public function llen() {}
+    public function scard() {}
+    public function smembers() {}
+    public function sismember() {}
+    public function sadd() {}
+    public function saddarray() {}
+    public function srem() {}
+    public function sunion() {}
+    public function sunionstore() {}
+    public function sinter() {}
+    public function sinterstore() {}
+    public function sdiff() {}
+    public function sdiffstore() {}
+    public function srandmember() {}
+    public function strlen() {}
+    public function persist() {}
+    public function ttl() {}
+    public function pttl() {}
+    public function zcard() {}
+    public function zcount() {}
+    public function zremrangebyscore() {}
+    public function zscore() {}
+    public function zadd() {}
+    public function zincrby() {}
+    public function hlen() {}
+    public function hkeys() {}
+    public function hvals() {}
+    public function hget() {}
+    public function hgetall() {}
+    public function hexists() {}
+    public function hincrby() {}
+    public function hset() {}
+    public function hsetnx() {}
+    public function hmget() {}
+    public function hmset() {}
+    public function hdel() {}
+    public function hincrbyfloat() {}
+    public function dump() {}
+    public function zrank() {}
+    public function zrevrank() {}
+    public function incr() {}
+    public function decr() {}
+    public function incrby() {}
+    public function decrby() {}
+    public function incrbyfloat() {}
+    public function expire() {}
+    public function pexpire() {}
+    public function expireat() {}
+    public function pexpireat() {}
+    public function append() {}
+    public function getbit() {}
+    public function setbit() {}
+    public function bitop() {}
+    public function bitpos() {}
+    public function bitcount() {}
+    public function lget() {}
+    public function getrange() {}
+    public function ltrim() {}
+    public function lrange() {}
+    public function zremrangebyrank() {}
+    public function publish() {}
+    public function rename() {}
+    public function renamenx() {}
+    public function pfcount() {}
+    public function pfadd() {}
+    public function pfmerge() {}
+    public function setrange() {}
+    public function restore() {}
+    public function smove() {}
+    public function zrange() {}
+    public function zrevrange() {}
+    public function zrangebyscore() {}
+    public function zrevrangebyscore() {}
+    public function zrangebylex() {}
+    public function zrevrangebylex() {}
+    public function zlexcount() {}
+    public function zremrangebylex() {}
+    public function zunionstore() {}
+    public function zinterstore() {}
+    public function zrem() {}
+    public function sort() {}
+    public function object() {}
+    public function subscribe() {}
+    public function psubscribe() {}
+    public function unsubscribe() {}
+    public function punsubscribe() {}
+    public function eval() {}
+    public function evalsha() {}
+    public function scan(&$i_iterator, $str_node, $str_pattern = null, $i_count = null) {}
+    public function sscan($str_key, &$i_iterator, $str_pattern = null, $i_count = null) {}
+    public function zscan($str_key, &$i_iterator, $str_pattern = null, $i_count = null) {}
+    public function hscan($str_key, &$i_iterator, $str_pattern = null, $i_count = null) {}
+    public function getmode() {}
+    public function getlasterror() {}
+    public function clearlasterror() {}
+    public function getoption() {}
+    public function setoption() {}
+    public function _prefix() {}
+    public function _serialize() {}
+    public function _unserialize() {}
+    public function _masters() {}
+    public function _redir() {}
+    public function multi() {}
+    public function exec() {}
+    public function discard() {}
+    public function watch() {}
+    public function unwatch() {}
+    public function save() {}
+    public function bgsave() {}
+    public function flushdb() {}
+    public function flushall() {}
+    public function dbsize() {}
+    public function bgrewriteaof() {}
+    public function lastsave() {}
+    public function info() {}
+    public function role() {}
+    public function time() {}
+    public function randomkey() {}
+    public function ping() {}
+    public function echo() {}
+    public function command() {}
+    public function rawcommand() {}
+    public function cluster() {}
+    public function client() {}
+    public function config() {}
+    public function pubsub() {}
+    public function script() {}
+    public function slowlog() {}
+    public function geoadd() {}
+    public function geohash() {}
+    public function geopos() {}
+    public function geodist() {}
+    public function georadius() {}
+    public function georadiusbymember() {}
+}
+
+class RedisClusterException extends \RuntimeException {
+
+    // properties
+    protected $message;
+    protected $code;
+    protected $file;
+    protected $line;
+}
+
+class RedisException extends \RuntimeException {
+
+    // properties
+    protected $message;
+    protected $code;
+    protected $file;
+    protected $line;
+}
+
+}
diff --git a/.phan/internal_stubs/sockets.phan_php b/.phan/internal_stubs/sockets.phan_php
new file mode 100644 (file)
index 0000000..d16f363
--- /dev/null
@@ -0,0 +1,211 @@
+<?php
+// These stubs were generated by the phan stub generator.
+// @phan-stub-for-extension sockets@7.0.33-0+deb9u3
+
+namespace {
+function socket_accept($socket) {}
+function socket_bind($socket, $addr, $port = null) {}
+function socket_clear_error($socket = null) {}
+function socket_close($socket) {}
+function socket_cmsg_space($level, $type) {}
+function socket_connect($socket, $addr, $port = null) {}
+function socket_create($domain, $type, $protocol) {}
+function socket_create_listen($port, $backlog = null) {}
+function socket_create_pair($domain, $type, $protocol, &$fd) {}
+function socket_export_stream($socket) {}
+function socket_get_option($socket, $level, $optname) {}
+function socket_getopt($socket, $level, $optname) {}
+function socket_getpeername($socket, &$addr, &$port = null) {}
+function socket_getsockname($socket, &$addr, &$port = null) {}
+function socket_import_stream($stream) {}
+function socket_last_error($socket = null) {}
+function socket_listen($socket, $backlog = null) {}
+function socket_read($socket, $length, $type = null) {}
+function socket_recv($socket, &$buf, $len, $flags) {}
+function socket_recvfrom($socket, &$buf, $len, $flags, &$name, &$port = null) {}
+function socket_recvmsg($socket, &$msghdr, $flags) {}
+function socket_select(&$read_fds, &$write_fds, &$except_fds, $tv_sec, $tv_usec = null) {}
+function socket_send($socket, $buf, $len, $flags) {}
+function socket_sendmsg($socket, $msghdr, $flags) {}
+function socket_sendto($socket, $buf, $len, $flags, $addr, $port = null) {}
+function socket_set_block($socket) {}
+function socket_set_nonblock($socket) {}
+function socket_set_option($socket, $level, $optname, $optval) {}
+function socket_setopt($socket, $level, $optname, $optval) {}
+function socket_shutdown($socket, $how = null) {}
+function socket_strerror($errno) {}
+function socket_write($socket, $buf, $length = null) {}
+const AF_INET = 2;
+const AF_INET6 = 10;
+const AF_UNIX = 1;
+const IPPROTO_IP = 0;
+const IPPROTO_IPV6 = 41;
+const IPV6_HOPLIMIT = 52;
+const IPV6_MULTICAST_HOPS = 18;
+const IPV6_MULTICAST_IF = 17;
+const IPV6_MULTICAST_LOOP = 19;
+const IPV6_PKTINFO = 50;
+const IPV6_RECVHOPLIMIT = 51;
+const IPV6_RECVPKTINFO = 49;
+const IPV6_RECVTCLASS = 66;
+const IPV6_TCLASS = 67;
+const IPV6_UNICAST_HOPS = 16;
+const IPV6_V6ONLY = 26;
+const IP_MULTICAST_IF = 32;
+const IP_MULTICAST_LOOP = 34;
+const IP_MULTICAST_TTL = 33;
+const MCAST_BLOCK_SOURCE = 43;
+const MCAST_JOIN_GROUP = 42;
+const MCAST_JOIN_SOURCE_GROUP = 46;
+const MCAST_LEAVE_GROUP = 45;
+const MCAST_LEAVE_SOURCE_GROUP = 47;
+const MCAST_UNBLOCK_SOURCE = 44;
+const MSG_CMSG_CLOEXEC = 1073741824;
+const MSG_CONFIRM = 2048;
+const MSG_CTRUNC = 8;
+const MSG_DONTROUTE = 4;
+const MSG_DONTWAIT = 64;
+const MSG_EOF = 512;
+const MSG_EOR = 128;
+const MSG_ERRQUEUE = 8192;
+const MSG_MORE = 32768;
+const MSG_NOSIGNAL = 16384;
+const MSG_OOB = 1;
+const MSG_PEEK = 2;
+const MSG_TRUNC = 32;
+const MSG_WAITALL = 256;
+const MSG_WAITFORONE = 65536;
+const PHP_BINARY_READ = 2;
+const PHP_NORMAL_READ = 1;
+const SCM_CREDENTIALS = 2;
+const SCM_RIGHTS = 1;
+const SOCKET_E2BIG = 7;
+const SOCKET_EACCES = 13;
+const SOCKET_EADDRINUSE = 98;
+const SOCKET_EADDRNOTAVAIL = 99;
+const SOCKET_EADV = 68;
+const SOCKET_EAFNOSUPPORT = 97;
+const SOCKET_EAGAIN = 11;
+const SOCKET_EALREADY = 114;
+const SOCKET_EBADE = 52;
+const SOCKET_EBADF = 9;
+const SOCKET_EBADFD = 77;
+const SOCKET_EBADMSG = 74;
+const SOCKET_EBADR = 53;
+const SOCKET_EBADRQC = 56;
+const SOCKET_EBADSLT = 57;
+const SOCKET_EBUSY = 16;
+const SOCKET_ECHRNG = 44;
+const SOCKET_ECOMM = 70;
+const SOCKET_ECONNABORTED = 103;
+const SOCKET_ECONNREFUSED = 111;
+const SOCKET_ECONNRESET = 104;
+const SOCKET_EDESTADDRREQ = 89;
+const SOCKET_EDQUOT = 122;
+const SOCKET_EEXIST = 17;
+const SOCKET_EFAULT = 14;
+const SOCKET_EHOSTDOWN = 112;
+const SOCKET_EHOSTUNREACH = 113;
+const SOCKET_EIDRM = 43;
+const SOCKET_EINPROGRESS = 115;
+const SOCKET_EINTR = 4;
+const SOCKET_EINVAL = 22;
+const SOCKET_EIO = 5;
+const SOCKET_EISCONN = 106;
+const SOCKET_EISDIR = 21;
+const SOCKET_EISNAM = 120;
+const SOCKET_EL2HLT = 51;
+const SOCKET_EL2NSYNC = 45;
+const SOCKET_EL3HLT = 46;
+const SOCKET_EL3RST = 47;
+const SOCKET_ELNRNG = 48;
+const SOCKET_ELOOP = 40;
+const SOCKET_EMEDIUMTYPE = 124;
+const SOCKET_EMFILE = 24;
+const SOCKET_EMLINK = 31;
+const SOCKET_EMSGSIZE = 90;
+const SOCKET_EMULTIHOP = 72;
+const SOCKET_ENAMETOOLONG = 36;
+const SOCKET_ENETDOWN = 100;
+const SOCKET_ENETRESET = 102;
+const SOCKET_ENETUNREACH = 101;
+const SOCKET_ENFILE = 23;
+const SOCKET_ENOANO = 55;
+const SOCKET_ENOBUFS = 105;
+const SOCKET_ENOCSI = 50;
+const SOCKET_ENODATA = 61;
+const SOCKET_ENODEV = 19;
+const SOCKET_ENOENT = 2;
+const SOCKET_ENOLCK = 37;
+const SOCKET_ENOLINK = 67;
+const SOCKET_ENOMEDIUM = 123;
+const SOCKET_ENOMEM = 12;
+const SOCKET_ENOMSG = 42;
+const SOCKET_ENONET = 64;
+const SOCKET_ENOPROTOOPT = 92;
+const SOCKET_ENOSPC = 28;
+const SOCKET_ENOSR = 63;
+const SOCKET_ENOSTR = 60;
+const SOCKET_ENOSYS = 38;
+const SOCKET_ENOTBLK = 15;
+const SOCKET_ENOTCONN = 107;
+const SOCKET_ENOTDIR = 20;
+const SOCKET_ENOTEMPTY = 39;
+const SOCKET_ENOTSOCK = 88;
+const SOCKET_ENOTTY = 25;
+const SOCKET_ENOTUNIQ = 76;
+const SOCKET_ENXIO = 6;
+const SOCKET_EOPNOTSUPP = 95;
+const SOCKET_EPERM = 1;
+const SOCKET_EPFNOSUPPORT = 96;
+const SOCKET_EPIPE = 32;
+const SOCKET_EPROTO = 71;
+const SOCKET_EPROTONOSUPPORT = 93;
+const SOCKET_EPROTOTYPE = 91;
+const SOCKET_EREMCHG = 78;
+const SOCKET_EREMOTE = 66;
+const SOCKET_EREMOTEIO = 121;
+const SOCKET_ERESTART = 85;
+const SOCKET_EROFS = 30;
+const SOCKET_ESHUTDOWN = 108;
+const SOCKET_ESOCKTNOSUPPORT = 94;
+const SOCKET_ESPIPE = 29;
+const SOCKET_ESRMNT = 69;
+const SOCKET_ESTRPIPE = 86;
+const SOCKET_ETIME = 62;
+const SOCKET_ETIMEDOUT = 110;
+const SOCKET_ETOOMANYREFS = 109;
+const SOCKET_EUNATCH = 49;
+const SOCKET_EUSERS = 87;
+const SOCKET_EWOULDBLOCK = 11;
+const SOCKET_EXDEV = 18;
+const SOCKET_EXFULL = 54;
+const SOCK_DGRAM = 2;
+const SOCK_RAW = 3;
+const SOCK_RDM = 4;
+const SOCK_SEQPACKET = 5;
+const SOCK_STREAM = 1;
+const SOL_SOCKET = 1;
+const SOL_TCP = 6;
+const SOL_UDP = 17;
+const SOMAXCONN = 128;
+const SO_BINDTODEVICE = 25;
+const SO_BROADCAST = 6;
+const SO_DEBUG = 1;
+const SO_DONTROUTE = 5;
+const SO_ERROR = 4;
+const SO_KEEPALIVE = 9;
+const SO_LINGER = 13;
+const SO_OOBINLINE = 10;
+const SO_PASSCRED = 16;
+const SO_RCVBUF = 8;
+const SO_RCVLOWAT = 18;
+const SO_RCVTIMEO = 20;
+const SO_REUSEADDR = 2;
+const SO_REUSEPORT = 15;
+const SO_SNDBUF = 7;
+const SO_SNDLOWAT = 19;
+const SO_SNDTIMEO = 21;
+const SO_TYPE = 3;
+const TCP_NODELAY = 1;
+}
index 43440f0..698dbf2 100644 (file)
@@ -736,7 +736,7 @@ $wgAutoloadLocalClasses = [
        'LanguageAz' => __DIR__ . '/languages/classes/LanguageAz.php',
        'LanguageBe_tarask' => __DIR__ . '/languages/classes/LanguageBe_tarask.php',
        'LanguageBs' => __DIR__ . '/languages/classes/LanguageBs.php',
-       'LanguageCode' => __DIR__ . '/languages/LanguageCode.php',
+       'LanguageCode' => __DIR__ . '/includes/language/LanguageCode.php',
        'LanguageConverter' => __DIR__ . '/languages/LanguageConverter.php',
        'LanguageCrh' => __DIR__ . '/languages/classes/LanguageCrh.php',
        'LanguageCu' => __DIR__ . '/languages/classes/LanguageCu.php',
@@ -976,12 +976,12 @@ $wgAutoloadLocalClasses = [
        'MergeLogFormatter' => __DIR__ . '/includes/logging/MergeLogFormatter.php',
        'MergeMessageFileList' => __DIR__ . '/maintenance/mergeMessageFileList.php',
        'MergeableUpdate' => __DIR__ . '/includes/deferred/MergeableUpdate.php',
-       'Message' => __DIR__ . '/includes/Message.php',
+       'Message' => __DIR__ . '/includes/language/Message.php',
        'MessageBlobStore' => __DIR__ . '/includes/resourceloader/MessageBlobStore.php',
        'MessageCache' => __DIR__ . '/includes/cache/MessageCache.php',
        'MessageCacheUpdate' => __DIR__ . '/includes/deferred/MessageCacheUpdate.php',
        'MessageContent' => __DIR__ . '/includes/content/MessageContent.php',
-       'MessageLocalizer' => __DIR__ . '/languages/MessageLocalizer.php',
+       'MessageLocalizer' => __DIR__ . '/includes/language/MessageLocalizer.php',
        'MessageSpecifier' => __DIR__ . '/includes/libs/MessageSpecifier.php',
        'MigrateActors' => __DIR__ . '/maintenance/includes/MigrateActors.php',
        'MigrateArchiveText' => __DIR__ . '/maintenance/migrateArchiveText.php',
index ca77121..69f23c1 100644 (file)
@@ -23,8 +23,8 @@
 use MediaWiki\Logger\LoggerFactory;
 use Psr\Log\LoggerInterface;
 use MediaWiki\MediaWikiServices;
+use Wikimedia\Rdbms\ILBFactory;
 use Wikimedia\Rdbms\ChronologyProtector;
-use Wikimedia\Rdbms\LBFactory;
 use Wikimedia\Rdbms\DBConnectionError;
 use Liuggio\StatsdClient\Sender\SocketSender;
 
@@ -580,15 +580,15 @@ class MediaWiki {
        public static function preOutputCommit(
                IContextSource $context, callable $postCommitWork = null
        ) {
-               // Either all DBs should commit or none
-               ignore_user_abort( true );
-
                $config = $context->getConfig();
                $request = $context->getRequest();
                $output = $context->getOutput();
                $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
 
-               // Commit all changes
+               // Try to make sure that all RDBMs, session, and other storage updates complete
+               ignore_user_abort( true );
+
+               // Commit all RDBMs changes from the main transaction round
                $lbFactory->commitMasterChanges(
                        __METHOD__,
                        // Abort if any transaction was too big
@@ -596,47 +596,31 @@ class MediaWiki {
                );
                wfDebug( __METHOD__ . ': primary transaction round committed' );
 
-               // Run updates that need to block the user or affect output (this is the last chance)
+               // Run updates that need to block the client or affect output (this is the last chance)
                DeferredUpdates::doUpdates( 'run', DeferredUpdates::PRESEND );
                wfDebug( __METHOD__ . ': pre-send deferred updates completed' );
-               // T214471: persist the session to avoid race conditions on subsequent requests
-               $request->getSession()->save();
-
-               // Should the client return, their request should observe the new ChronologyProtector
-               // DB positions. This request might be on a foreign wiki domain, so synchronously update
-               // the DB positions in all datacenters to be safe. If this output is not a redirect,
-               // then OutputPage::output() will be relatively slow, meaning that running it in
-               // $postCommitWork should help mask the latency of those updates.
-               $flags = $lbFactory::SHUTDOWN_CHRONPROT_SYNC;
-               $strategy = 'cookie+sync';
-
-               $allowHeaders = !( $output->isDisabled() || headers_sent() );
-               if ( $output->getRedirect() && $lbFactory->hasOrMadeRecentMasterChanges( INF ) ) {
-                       // OutputPage::output() will be fast, so $postCommitWork is useless for masking
-                       // the latency of synchronously updating the DB positions in all datacenters.
-                       // Try to make use of the time the client spends following redirects instead.
-                       $domainDistance = self::getUrlDomainDistance( $output->getRedirect() );
-                       if ( $domainDistance === 'local' && $allowHeaders ) {
-                               $flags = $lbFactory::SHUTDOWN_CHRONPROT_ASYNC;
-                               $strategy = 'cookie'; // use same-domain cookie and keep the URL uncluttered
-                       } elseif ( $domainDistance === 'remote' ) {
-                               $flags = $lbFactory::SHUTDOWN_CHRONPROT_ASYNC;
-                               $strategy = 'cookie+url'; // cross-domain cookie might not work
-                       }
-               }
-
+               // Persist the session to avoid race conditions on subsequent requests by the client
+               $request->getSession()->save(); // T214471
+               wfDebug( __METHOD__ . ': session changes committed' );
+
+               // Figure out whether to wait for DB replication now or to use some method that assures
+               // that subsequent requests by the client will use the DB replication positions written
+               // during the shutdown() call below; the later requires working around replication lag
+               // of the store containing DB replication positions (e.g. dynomite, mcrouter).
+               list( $flags, $strategy ) = self::getChronProtStrategy( $lbFactory, $output );
                // Record ChronologyProtector positions for DBs affected in this request at this point
                $cpIndex = null;
                $cpClientId = null;
                $lbFactory->shutdown( $flags, $postCommitWork, $cpIndex, $cpClientId );
                wfDebug( __METHOD__ . ': LBFactory shutdown completed' );
 
+               $allowHeaders = !( $output->isDisabled() || headers_sent() );
                if ( $cpIndex > 0 ) {
                        if ( $allowHeaders ) {
                                $now = time();
                                $expires = $now + ChronologyProtector::POSITION_COOKIE_TTL;
                                $options = [ 'prefix' => '' ];
-                               $value = LBFactory::makeCookieValueFromCPIndex( $cpIndex, $now, $cpClientId );
+                               $value = $lbFactory::makeCookieValueFromCPIndex( $cpIndex, $now, $cpClientId );
                                $request->response()->setCookie( 'cpPosIndex', $value, $expires, $options );
                        }
 
@@ -654,31 +638,66 @@ class MediaWiki {
                        }
                }
 
-               // Set a cookie to tell all CDN edge nodes to "stick" the user to the DC that handles this
-               // POST request (e.g. the "master" data center). Also have the user briefly bypass CDN so
-               // ChronologyProtector works for cacheable URLs.
-               if ( $request->wasPosted() && $lbFactory->hasOrMadeRecentMasterChanges() ) {
-                       $expires = time() + $config->get( 'DataCenterUpdateStickTTL' );
-                       $options = [ 'prefix' => '' ];
-                       $request->response()->setCookie( 'UseDC', 'master', $expires, $options );
-                       $request->response()->setCookie( 'UseCDNCache', 'false', $expires, $options );
-               }
+               if ( $allowHeaders ) {
+                       // Set a cookie to tell all CDN edge nodes to "stick" the user to the DC that
+                       // handles this POST request (e.g. the "master" data center). Also have the user
+                       // briefly bypass CDN so ChronologyProtector works for cacheable URLs.
+                       if ( $request->wasPosted() && $lbFactory->hasOrMadeRecentMasterChanges() ) {
+                               $expires = time() + $config->get( 'DataCenterUpdateStickTTL' );
+                               $options = [ 'prefix' => '' ];
+                               $request->response()->setCookie( 'UseDC', 'master', $expires, $options );
+                               $request->response()->setCookie( 'UseCDNCache', 'false', $expires, $options );
+                       }
+
+                       // Avoid letting a few seconds of replica DB lag cause a month of stale data.
+                       // This logic is also intimately related to the value of $wgCdnReboundPurgeDelay.
+                       if ( $lbFactory->laggedReplicaUsed() ) {
+                               $maxAge = $config->get( 'CdnMaxageLagged' );
+                               $output->lowerCdnMaxage( $maxAge );
+                               $request->response()->header( "X-Database-Lagged: true" );
+                               wfDebugLog( 'replication',
+                                       "Lagged DB used; CDN cache TTL limited to $maxAge seconds" );
+                       }
 
-               // Avoid letting a few seconds of replica DB lag cause a month of stale data. This logic is
-               // also intimately related to the value of $wgCdnReboundPurgeDelay.
-               if ( $lbFactory->laggedReplicaUsed() ) {
-                       $maxAge = $config->get( 'CdnMaxageLagged' );
-                       $output->lowerCdnMaxage( $maxAge );
-                       $request->response()->header( "X-Database-Lagged: true" );
-                       wfDebugLog( 'replication', "Lagged DB used; CDN cache TTL limited to $maxAge seconds" );
+                       // Avoid long-term cache pollution due to message cache rebuild timeouts (T133069)
+                       if ( MessageCache::singleton()->isDisabled() ) {
+                               $maxAge = $config->get( 'CdnMaxageSubstitute' );
+                               $output->lowerCdnMaxage( $maxAge );
+                               $request->response()->header( "X-Response-Substitute: true" );
+                       }
                }
+       }
+
+       /**
+        * @param ILBFactory $lbFactory
+        * @param OutputPage $output
+        * @return array
+        */
+       private static function getChronProtStrategy( ILBFactory $lbFactory, OutputPage $output ) {
+               // Should the client return, their request should observe the new ChronologyProtector
+               // DB positions. This request might be on a foreign wiki domain, so synchronously update
+               // the DB positions in all datacenters to be safe. If this output is not a redirect,
+               // then OutputPage::output() will be relatively slow, meaning that running it in
+               // $postCommitWork should help mask the latency of those updates.
+               $flags = $lbFactory::SHUTDOWN_CHRONPROT_SYNC;
+               $strategy = 'cookie+sync';
 
-               // Avoid long-term cache pollution due to message cache rebuild timeouts (T133069)
-               if ( MessageCache::singleton()->isDisabled() ) {
-                       $maxAge = $config->get( 'CdnMaxageSubstitute' );
-                       $output->lowerCdnMaxage( $maxAge );
-                       $request->response()->header( "X-Response-Substitute: true" );
+               $allowHeaders = !( $output->isDisabled() || headers_sent() );
+               if ( $output->getRedirect() && $lbFactory->hasOrMadeRecentMasterChanges( INF ) ) {
+                       // OutputPage::output() will be fast, so $postCommitWork is useless for masking
+                       // the latency of synchronously updating the DB positions in all datacenters.
+                       // Try to make use of the time the client spends following redirects instead.
+                       $domainDistance = self::getUrlDomainDistance( $output->getRedirect() );
+                       if ( $domainDistance === 'local' && $allowHeaders ) {
+                               $flags = $lbFactory::SHUTDOWN_CHRONPROT_ASYNC;
+                               $strategy = 'cookie'; // use same-domain cookie and keep the URL uncluttered
+                       } elseif ( $domainDistance === 'remote' ) {
+                               $flags = $lbFactory::SHUTDOWN_CHRONPROT_ASYNC;
+                               $strategy = 'cookie+url'; // cross-domain cookie might not work
+                       }
                }
+
+               return [ $flags, $strategy ];
        }
 
        /**
@@ -917,7 +936,7 @@ class MediaWiki {
 
                // Commit and close up!
                $lbFactory->commitMasterChanges( __METHOD__ );
-               $lbFactory->shutdown( LBFactory::SHUTDOWN_NO_CHRONPROT );
+               $lbFactory->shutdown( $lbFactory::SHUTDOWN_NO_CHRONPROT );
 
                wfDebug( "Request ended normally\n" );
        }
diff --git a/includes/Message.php b/includes/Message.php
deleted file mode 100644 (file)
index 0b3113f..0000000
+++ /dev/null
@@ -1,1396 +0,0 @@
-<?php
-/**
- * Fetching and processing of interface messages.
- *
- * 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
- * @author Niklas Laxström
- */
-use MediaWiki\MediaWikiServices;
-
-/**
- * The Message class provides methods which fulfil two basic services:
- *  - fetching interface messages
- *  - processing messages into a variety of formats
- *
- * First implemented with MediaWiki 1.17, the Message class is intended to
- * replace the old wfMsg* functions that over time grew unusable.
- * @see https://www.mediawiki.org/wiki/Manual:Messages_API for equivalences
- * between old and new functions.
- *
- * You should use the wfMessage() global function which acts as a wrapper for
- * the Message class. The wrapper let you pass parameters as arguments.
- *
- * The most basic usage cases would be:
- *
- * @code
- *     // Initialize a Message object using the 'some_key' message key
- *     $message = wfMessage( 'some_key' );
- *
- *     // Using two parameters those values are strings 'value1' and 'value2':
- *     $message = wfMessage( 'some_key',
- *          'value1', 'value2'
- *     );
- * @endcode
- *
- * @section message_global_fn Global function wrapper:
- *
- * Since wfMessage() returns a Message instance, you can chain its call with
- * a method. Some of them return a Message instance too so you can chain them.
- * You will find below several examples of wfMessage() usage.
- *
- * Fetching a message text for interface message:
- *
- * @code
- *    $button = Xml::button(
- *         wfMessage( 'submit' )->text()
- *    );
- * @endcode
- *
- * A Message instance can be passed parameters after it has been constructed,
- * use the params() method to do so:
- *
- * @code
- *     wfMessage( 'welcome-to' )
- *         ->params( $wgSitename )
- *         ->text();
- * @endcode
- *
- * {{GRAMMAR}} and friends work correctly:
- *
- * @code
- *    wfMessage( 'are-friends',
- *        $user, $friend
- *    );
- *    wfMessage( 'bad-message' )
- *         ->rawParams( '<script>...</script>' )
- *         ->escaped();
- * @endcode
- *
- * @section message_language Changing language:
- *
- * Messages can be requested in a different language or in whatever current
- * content language is being used. The methods are:
- *     - Message->inContentLanguage()
- *     - Message->inLanguage()
- *
- * Sometimes the message text ends up in the database, so content language is
- * needed:
- *
- * @code
- *    wfMessage( 'file-log',
- *        $user, $filename
- *    )->inContentLanguage()->text();
- * @endcode
- *
- * Checking whether a message exists:
- *
- * @code
- *    wfMessage( 'mysterious-message' )->exists()
- *    // returns a boolean whether the 'mysterious-message' key exist.
- * @endcode
- *
- * If you want to use a different language:
- *
- * @code
- *    $userLanguage = $user->getOption( 'language' );
- *    wfMessage( 'email-header' )
- *         ->inLanguage( $userLanguage )
- *         ->plain();
- * @endcode
- *
- * @note You can parse the text only in the content or interface languages
- *
- * @section message_compare_old Comparison with old wfMsg* functions:
- *
- * Use full parsing:
- *
- * @code
- *     // old style:
- *     wfMsgExt( 'key', [ 'parseinline' ], 'apple' );
- *     // new style:
- *     wfMessage( 'key', 'apple' )->parse();
- * @endcode
- *
- * Parseinline is used because it is more useful when pre-building HTML.
- * In normal use it is better to use OutputPage::(add|wrap)WikiMsg.
- *
- * Places where HTML cannot be used. {{-transformation is done.
- * @code
- *     // old style:
- *     wfMsgExt( 'key', [ 'parsemag' ], 'apple', 'pear' );
- *     // new style:
- *     wfMessage( 'key', 'apple', 'pear' )->text();
- * @endcode
- *
- * Shortcut for escaping the message too, similar to wfMsgHTML(), but
- * parameters are not replaced after escaping by default.
- * @code
- *     $escaped = wfMessage( 'key' )
- *          ->rawParams( 'apple' )
- *          ->escaped();
- * @endcode
- *
- * @section message_appendix Appendix:
- *
- * @todo
- * - test, can we have tests?
- * - this documentation needs to be extended
- *
- * @see https://www.mediawiki.org/wiki/WfMessage()
- * @see https://www.mediawiki.org/wiki/New_messages_API
- * @see https://www.mediawiki.org/wiki/Localisation
- *
- * @since 1.17
- */
-class Message implements MessageSpecifier, Serializable {
-       /** Use message text as-is */
-       const FORMAT_PLAIN = 'plain';
-       /** Use normal wikitext -> HTML parsing (the result will be wrapped in a block-level HTML tag) */
-       const FORMAT_BLOCK_PARSE = 'block-parse';
-       /** Use normal wikitext -> HTML parsing but strip the block-level wrapper */
-       const FORMAT_PARSE = 'parse';
-       /** Transform {{..}} constructs but don't transform to HTML */
-       const FORMAT_TEXT = 'text';
-       /** Transform {{..}} constructs, HTML-escape the result */
-       const FORMAT_ESCAPED = 'escaped';
-
-       /**
-        * Mapping from Message::listParam() types to Language methods.
-        * @var array
-        */
-       protected static $listTypeMap = [
-               'comma' => 'commaList',
-               'semicolon' => 'semicolonList',
-               'pipe' => 'pipeList',
-               'text' => 'listToText',
-       ];
-
-       /**
-        * In which language to get this message. True, which is the default,
-        * means the current user language, false content language.
-        *
-        * @var bool
-        */
-       protected $interface = true;
-
-       /**
-        * In which language to get this message. Overrides the $interface setting.
-        *
-        * @var Language|bool Explicit language object, or false for user language
-        */
-       protected $language = false;
-
-       /**
-        * @var string The message key. If $keysToTry has more than one element,
-        * this may change to one of the keys to try when fetching the message text.
-        */
-       protected $key;
-
-       /**
-        * @var string[] List of keys to try when fetching the message.
-        */
-       protected $keysToTry;
-
-       /**
-        * @var array List of parameters which will be substituted into the message.
-        */
-       protected $parameters = [];
-
-       /**
-        * @var string
-        * @deprecated
-        */
-       protected $format = 'parse';
-
-       /**
-        * @var bool Whether database can be used.
-        */
-       protected $useDatabase = true;
-
-       /**
-        * @var Title Title object to use as context.
-        */
-       protected $title = null;
-
-       /**
-        * @var Content Content object representing the message.
-        */
-       protected $content = null;
-
-       /**
-        * @var string
-        */
-       protected $message;
-
-       /**
-        * @since 1.17
-        * @param string|string[]|MessageSpecifier $key Message key, or array of
-        * message keys to try and use the first non-empty message for, or a
-        * MessageSpecifier to copy from.
-        * @param array $params Message parameters.
-        * @param Language|null $language [optional] Language to use (defaults to current user language).
-        * @throws InvalidArgumentException
-        */
-       public function __construct( $key, $params = [], Language $language = null ) {
-               if ( $key instanceof MessageSpecifier ) {
-                       if ( $params ) {
-                               throw new InvalidArgumentException(
-                                       '$params must be empty if $key is a MessageSpecifier'
-                               );
-                       }
-                       $params = $key->getParams();
-                       $key = $key->getKey();
-               }
-
-               if ( !is_string( $key ) && !is_array( $key ) ) {
-                       throw new InvalidArgumentException( '$key must be a string or an array' );
-               }
-
-               $this->keysToTry = (array)$key;
-
-               if ( empty( $this->keysToTry ) ) {
-                       throw new InvalidArgumentException( '$key must not be an empty list' );
-               }
-
-               $this->key = reset( $this->keysToTry );
-
-               $this->parameters = array_values( $params );
-               // User language is only resolved in getLanguage(). This helps preserve the
-               // semantic intent of "user language" across serialize() and unserialize().
-               $this->language = $language ?: false;
-       }
-
-       /**
-        * @see Serializable::serialize()
-        * @since 1.26
-        * @return string
-        */
-       public function serialize() {
-               return serialize( [
-                       'interface' => $this->interface,
-                       'language' => $this->language ? $this->language->getCode() : false,
-                       'key' => $this->key,
-                       'keysToTry' => $this->keysToTry,
-                       'parameters' => $this->parameters,
-                       'format' => $this->format,
-                       'useDatabase' => $this->useDatabase,
-                       'titlestr' => $this->title ? $this->title->getFullText() : null,
-               ] );
-       }
-
-       /**
-        * @see Serializable::unserialize()
-        * @since 1.26
-        * @param string $serialized
-        */
-       public function unserialize( $serialized ) {
-               $data = unserialize( $serialized );
-               if ( !is_array( $data ) ) {
-                       throw new InvalidArgumentException( __METHOD__ . ': Invalid serialized data' );
-               }
-
-               $this->interface = $data['interface'];
-               $this->key = $data['key'];
-               $this->keysToTry = $data['keysToTry'];
-               $this->parameters = $data['parameters'];
-               $this->format = $data['format'];
-               $this->useDatabase = $data['useDatabase'];
-               $this->language = $data['language'] ? Language::factory( $data['language'] ) : false;
-
-               if ( isset( $data['titlestr'] ) ) {
-                       $this->title = Title::newFromText( $data['titlestr'] );
-               } elseif ( isset( $data['title'] ) && $data['title'] instanceof Title ) {
-                       // Old serializations from before December 2018
-                       $this->title = $data['title'];
-               } else {
-                       $this->title = null; // Explicit for sanity
-               }
-       }
-
-       /**
-        * @since 1.24
-        *
-        * @return bool True if this is a multi-key message, that is, if the key provided to the
-        * constructor was a fallback list of keys to try.
-        */
-       public function isMultiKey() {
-               return count( $this->keysToTry ) > 1;
-       }
-
-       /**
-        * @since 1.24
-        *
-        * @return string[] The list of keys to try when fetching the message text,
-        * in order of preference.
-        */
-       public function getKeysToTry() {
-               return $this->keysToTry;
-       }
-
-       /**
-        * Returns the message key.
-        *
-        * If a list of multiple possible keys was supplied to the constructor, this method may
-        * return any of these keys. After the message has been fetched, this method will return
-        * the key that was actually used to fetch the message.
-        *
-        * @since 1.21
-        *
-        * @return string
-        */
-       public function getKey() {
-               return $this->key;
-       }
-
-       /**
-        * Returns the message parameters.
-        *
-        * @since 1.21
-        *
-        * @return array
-        */
-       public function getParams() {
-               return $this->parameters;
-       }
-
-       /**
-        * Returns the message format.
-        *
-        * @since 1.21
-        *
-        * @return string
-        * @deprecated since 1.29 formatting is not stateful
-        */
-       public function getFormat() {
-               wfDeprecated( __METHOD__, '1.29' );
-               return $this->format;
-       }
-
-       /**
-        * Returns the Language of the Message.
-        *
-        * @since 1.23
-        *
-        * @return Language
-        */
-       public function getLanguage() {
-               // Defaults to false which means current user language
-               return $this->language ?: RequestContext::getMain()->getLanguage();
-       }
-
-       /**
-        * Factory function that is just wrapper for the real constructor. It is
-        * intended to be used instead of the real constructor, because it allows
-        * chaining method calls, while new objects don't.
-        *
-        * @since 1.17
-        *
-        * @param string|string[]|MessageSpecifier $key
-        * @param mixed $param,... Parameters as strings.
-        *
-        * @return Message
-        */
-       public static function newFromKey( $key /*...*/ ) {
-               $params = func_get_args();
-               array_shift( $params );
-               return new self( $key, $params );
-       }
-
-       /**
-        * Transform a MessageSpecifier or a primitive value used interchangeably with
-        * specifiers (a message key string, or a key + params array) into a proper Message.
-        *
-        * Also accepts a MessageSpecifier inside an array: that's not considered a valid format
-        * but is an easy error to make due to how StatusValue stores messages internally.
-        * Further array elements are ignored in that case.
-        *
-        * @param string|array|MessageSpecifier $value
-        * @return Message
-        * @throws InvalidArgumentException
-        * @since 1.27
-        */
-       public static function newFromSpecifier( $value ) {
-               $params = [];
-               if ( is_array( $value ) ) {
-                       $params = $value;
-                       $value = array_shift( $params );
-               }
-
-               if ( $value instanceof Message ) { // Message, RawMessage, ApiMessage, etc
-                       $message = clone $value;
-               } elseif ( $value instanceof MessageSpecifier ) {
-                       $message = new Message( $value );
-               } elseif ( is_string( $value ) ) {
-                       $message = new Message( $value, $params );
-               } else {
-                       throw new InvalidArgumentException( __METHOD__ . ': invalid argument type '
-                               . gettype( $value ) );
-               }
-
-               return $message;
-       }
-
-       /**
-        * Factory function accepting multiple message keys and returning a message instance
-        * for the first message which is non-empty. If all messages are empty then an
-        * instance of the first message key is returned.
-        *
-        * @since 1.18
-        *
-        * @param string|string[] $keys,... Message keys, or first argument as an array of all the
-        * message keys.
-        *
-        * @return Message
-        */
-       public static function newFallbackSequence( /*...*/ ) {
-               $keys = func_get_args();
-               if ( func_num_args() == 1 ) {
-                       if ( is_array( $keys[0] ) ) {
-                               // Allow an array to be passed as the first argument instead
-                               $keys = array_values( $keys[0] );
-                       } else {
-                               // Optimize a single string to not need special fallback handling
-                               $keys = $keys[0];
-                       }
-               }
-               return new self( $keys );
-       }
-
-       /**
-        * Get a title object for a mediawiki message, where it can be found in the mediawiki namespace.
-        * The title will be for the current language, if the message key is in
-        * $wgForceUIMsgAsContentMsg it will be append with the language code (except content
-        * language), because Message::inContentLanguage will also return in user language.
-        *
-        * @see $wgForceUIMsgAsContentMsg
-        * @return Title
-        * @since 1.26
-        */
-       public function getTitle() {
-               global $wgForceUIMsgAsContentMsg;
-
-               $contLang = MediaWikiServices::getInstance()->getContentLanguage();
-               $lang = $this->getLanguage();
-               $title = $this->key;
-               if (
-                       !$lang->equals( $contLang )
-                       && in_array( $this->key, (array)$wgForceUIMsgAsContentMsg )
-               ) {
-                       $title .= '/' . $lang->getCode();
-               }
-
-               return Title::makeTitle(
-                       NS_MEDIAWIKI, $contLang->ucfirst( strtr( $title, ' ', '_' ) ) );
-       }
-
-       /**
-        * Adds parameters to the parameter list of this message.
-        *
-        * @since 1.17
-        *
-        * @param mixed $args,... Parameters as strings or arrays from
-        *  Message::numParam() and the like, or a single array of parameters.
-        *
-        * @return Message $this
-        */
-       public function params( /*...*/ ) {
-               $args = func_get_args();
-
-               // If $args has only one entry and it's an array, then it's either a
-               // non-varargs call or it happens to be a call with just a single
-               // "special" parameter. Since the "special" parameters don't have any
-               // numeric keys, we'll test that to differentiate the cases.
-               if ( count( $args ) === 1 && isset( $args[0] ) && is_array( $args[0] ) ) {
-                       if ( $args[0] === [] ) {
-                               $args = [];
-                       } else {
-                               foreach ( $args[0] as $key => $value ) {
-                                       if ( is_int( $key ) ) {
-                                               $args = $args[0];
-                                               break;
-                                       }
-                               }
-                       }
-               }
-
-               $this->parameters = array_merge( $this->parameters, array_values( $args ) );
-               return $this;
-       }
-
-       /**
-        * Add parameters that are substituted after parsing or escaping.
-        * In other words the parsing process cannot access the contents
-        * of this type of parameter, and you need to make sure it is
-        * sanitized beforehand.  The parser will see "$n", instead.
-        *
-        * @since 1.17
-        *
-        * @param mixed $params,... Raw parameters as strings, or a single argument that is
-        * an array of raw parameters.
-        *
-        * @return Message $this
-        */
-       public function rawParams( /*...*/ ) {
-               $params = func_get_args();
-               if ( isset( $params[0] ) && is_array( $params[0] ) ) {
-                       $params = $params[0];
-               }
-               foreach ( $params as $param ) {
-                       $this->parameters[] = self::rawParam( $param );
-               }
-               return $this;
-       }
-
-       /**
-        * Add parameters that are numeric and will be passed through
-        * Language::formatNum before substitution
-        *
-        * @since 1.18
-        *
-        * @param mixed $param,... Numeric parameters, or a single argument that is
-        * an array of numeric parameters.
-        *
-        * @return Message $this
-        */
-       public function numParams( /*...*/ ) {
-               $params = func_get_args();
-               if ( isset( $params[0] ) && is_array( $params[0] ) ) {
-                       $params = $params[0];
-               }
-               foreach ( $params as $param ) {
-                       $this->parameters[] = self::numParam( $param );
-               }
-               return $this;
-       }
-
-       /**
-        * Add parameters that are durations of time and will be passed through
-        * Language::formatDuration before substitution
-        *
-        * @since 1.22
-        *
-        * @param int|int[] $param,... Duration parameters, or a single argument that is
-        * an array of duration parameters.
-        *
-        * @return Message $this
-        */
-       public function durationParams( /*...*/ ) {
-               $params = func_get_args();
-               if ( isset( $params[0] ) && is_array( $params[0] ) ) {
-                       $params = $params[0];
-               }
-               foreach ( $params as $param ) {
-                       $this->parameters[] = self::durationParam( $param );
-               }
-               return $this;
-       }
-
-       /**
-        * Add parameters that are expiration times and will be passed through
-        * Language::formatExpiry before substitution
-        *
-        * @since 1.22
-        *
-        * @param string|string[] $param,... Expiry parameters, or a single argument that is
-        * an array of expiry parameters.
-        *
-        * @return Message $this
-        */
-       public function expiryParams( /*...*/ ) {
-               $params = func_get_args();
-               if ( isset( $params[0] ) && is_array( $params[0] ) ) {
-                       $params = $params[0];
-               }
-               foreach ( $params as $param ) {
-                       $this->parameters[] = self::expiryParam( $param );
-               }
-               return $this;
-       }
-
-       /**
-        * Add parameters that are time periods and will be passed through
-        * Language::formatTimePeriod before substitution
-        *
-        * @since 1.22
-        *
-        * @param int|int[] $param,... Time period parameters, or a single argument that is
-        * an array of time period parameters.
-        *
-        * @return Message $this
-        */
-       public function timeperiodParams( /*...*/ ) {
-               $params = func_get_args();
-               if ( isset( $params[0] ) && is_array( $params[0] ) ) {
-                       $params = $params[0];
-               }
-               foreach ( $params as $param ) {
-                       $this->parameters[] = self::timeperiodParam( $param );
-               }
-               return $this;
-       }
-
-       /**
-        * Add parameters that are file sizes and will be passed through
-        * Language::formatSize before substitution
-        *
-        * @since 1.22
-        *
-        * @param int|int[] $param,... Size parameters, or a single argument that is
-        * an array of size parameters.
-        *
-        * @return Message $this
-        */
-       public function sizeParams( /*...*/ ) {
-               $params = func_get_args();
-               if ( isset( $params[0] ) && is_array( $params[0] ) ) {
-                       $params = $params[0];
-               }
-               foreach ( $params as $param ) {
-                       $this->parameters[] = self::sizeParam( $param );
-               }
-               return $this;
-       }
-
-       /**
-        * Add parameters that are bitrates and will be passed through
-        * Language::formatBitrate before substitution
-        *
-        * @since 1.22
-        *
-        * @param int|int[] $param,... Bit rate parameters, or a single argument that is
-        * an array of bit rate parameters.
-        *
-        * @return Message $this
-        */
-       public function bitrateParams( /*...*/ ) {
-               $params = func_get_args();
-               if ( isset( $params[0] ) && is_array( $params[0] ) ) {
-                       $params = $params[0];
-               }
-               foreach ( $params as $param ) {
-                       $this->parameters[] = self::bitrateParam( $param );
-               }
-               return $this;
-       }
-
-       /**
-        * Add parameters that are plaintext and will be passed through without
-        * the content being evaluated.  Plaintext parameters are not valid as
-        * arguments to parser functions. This differs from self::rawParams in
-        * that the Message class handles escaping to match the output format.
-        *
-        * @since 1.25
-        *
-        * @param string|string[] $param,... plaintext parameters, or a single argument that is
-        * an array of plaintext parameters.
-        *
-        * @return Message $this
-        */
-       public function plaintextParams( /*...*/ ) {
-               $params = func_get_args();
-               if ( isset( $params[0] ) && is_array( $params[0] ) ) {
-                       $params = $params[0];
-               }
-               foreach ( $params as $param ) {
-                       $this->parameters[] = self::plaintextParam( $param );
-               }
-               return $this;
-       }
-
-       /**
-        * Set the language and the title from a context object
-        *
-        * @since 1.19
-        *
-        * @param IContextSource $context
-        *
-        * @return Message $this
-        */
-       public function setContext( IContextSource $context ) {
-               $this->inLanguage( $context->getLanguage() );
-               $this->title( $context->getTitle() );
-               $this->interface = true;
-
-               return $this;
-       }
-
-       /**
-        * Request the message in any language that is supported.
-        *
-        * As a side effect interface message status is unconditionally
-        * turned off.
-        *
-        * @since 1.17
-        * @param Language|string $lang Language code or Language object.
-        * @return Message $this
-        * @throws MWException
-        */
-       public function inLanguage( $lang ) {
-               $previousLanguage = $this->language;
-
-               if ( $lang instanceof Language ) {
-                       $this->language = $lang;
-               } elseif ( is_string( $lang ) ) {
-                       if ( !$this->language instanceof Language || $this->language->getCode() != $lang ) {
-                               $this->language = Language::factory( $lang );
-                       }
-               } elseif ( $lang instanceof StubUserLang ) {
-                       $this->language = false;
-               } else {
-                       $type = gettype( $lang );
-                       throw new MWException( __METHOD__ . " must be "
-                               . "passed a String or Language object; $type given"
-                       );
-               }
-
-               if ( $this->language !== $previousLanguage ) {
-                       // The language has changed. Clear the message cache.
-                       $this->message = null;
-               }
-               $this->interface = false;
-               return $this;
-       }
-
-       /**
-        * Request the message in the wiki's content language,
-        * unless it is disabled for this message.
-        *
-        * @since 1.17
-        * @see $wgForceUIMsgAsContentMsg
-        *
-        * @return Message $this
-        */
-       public function inContentLanguage() {
-               global $wgForceUIMsgAsContentMsg;
-               if ( in_array( $this->key, (array)$wgForceUIMsgAsContentMsg ) ) {
-                       return $this;
-               }
-
-               $this->inLanguage( MediaWikiServices::getInstance()->getContentLanguage() );
-               return $this;
-       }
-
-       /**
-        * Allows manipulating the interface message flag directly.
-        * Can be used to restore the flag after setting a language.
-        *
-        * @since 1.20
-        *
-        * @param bool $interface
-        *
-        * @return Message $this
-        */
-       public function setInterfaceMessageFlag( $interface ) {
-               $this->interface = (bool)$interface;
-               return $this;
-       }
-
-       /**
-        * Enable or disable database use.
-        *
-        * @since 1.17
-        *
-        * @param bool $useDatabase
-        *
-        * @return Message $this
-        */
-       public function useDatabase( $useDatabase ) {
-               $this->useDatabase = (bool)$useDatabase;
-               $this->message = null;
-               return $this;
-       }
-
-       /**
-        * Set the Title object to use as context when transforming the message
-        *
-        * @since 1.18
-        *
-        * @param Title $title
-        *
-        * @return Message $this
-        */
-       public function title( $title ) {
-               $this->title = $title;
-               return $this;
-       }
-
-       /**
-        * Returns the message as a Content object.
-        *
-        * @return Content
-        */
-       public function content() {
-               if ( !$this->content ) {
-                       $this->content = new MessageContent( $this );
-               }
-
-               return $this->content;
-       }
-
-       /**
-        * Returns the message parsed from wikitext to HTML.
-        *
-        * @since 1.17
-        *
-        * @param string|null $format One of the FORMAT_* constants. Null means use whatever was used
-        *   the last time (this is for B/C and should be avoided).
-        *
-        * @return string HTML
-        * @suppress SecurityCheck-DoubleEscaped phan false positive
-        */
-       public function toString( $format = null ) {
-               if ( $format === null ) {
-                       $ex = new LogicException( __METHOD__ . ' using implicit format: ' . $this->format );
-                       \MediaWiki\Logger\LoggerFactory::getInstance( 'message-format' )->warning(
-                               $ex->getMessage(), [ 'exception' => $ex, 'format' => $this->format, 'key' => $this->key ] );
-                       $format = $this->format;
-               }
-               $string = $this->fetchMessage();
-
-               if ( $string === false ) {
-                       // Err on the side of safety, ensure that the output
-                       // is always html safe in the event the message key is
-                       // missing, since in that case its highly likely the
-                       // message key is user-controlled.
-                       // '⧼' is used instead of '<' to side-step any
-                       // double-escaping issues.
-                       // (Keep synchronised with mw.Message#toString in JS.)
-                       return '⧼' . htmlspecialchars( $this->key ) . '⧽';
-               }
-
-               # Replace $* with a list of parameters for &uselang=qqx.
-               if ( strpos( $string, '$*' ) !== false ) {
-                       $paramlist = '';
-                       if ( $this->parameters !== [] ) {
-                               $paramlist = ': $' . implode( ', $', range( 1, count( $this->parameters ) ) );
-                       }
-                       $string = str_replace( '$*', $paramlist, $string );
-               }
-
-               # Replace parameters before text parsing
-               $string = $this->replaceParameters( $string, 'before', $format );
-
-               # Maybe transform using the full parser
-               if ( $format === self::FORMAT_PARSE ) {
-                       $string = $this->parseText( $string );
-                       $string = Parser::stripOuterParagraph( $string );
-               } elseif ( $format === self::FORMAT_BLOCK_PARSE ) {
-                       $string = $this->parseText( $string );
-               } elseif ( $format === self::FORMAT_TEXT ) {
-                       $string = $this->transformText( $string );
-               } elseif ( $format === self::FORMAT_ESCAPED ) {
-                       $string = $this->transformText( $string );
-                       $string = htmlspecialchars( $string, ENT_QUOTES, 'UTF-8', false );
-               }
-
-               # Raw parameter replacement
-               $string = $this->replaceParameters( $string, 'after', $format );
-
-               return $string;
-       }
-
-       /**
-        * Magic method implementation of the above (for PHP >= 5.2.0), so we can do, eg:
-        *     $foo = new Message( $key );
-        *     $string = "<abbr>$foo</abbr>";
-        *
-        * @since 1.18
-        *
-        * @return string
-        */
-       public function __toString() {
-               // PHP doesn't allow __toString to throw exceptions and will
-               // trigger a fatal error if it does. So, catch any exceptions.
-
-               try {
-                       return $this->toString( self::FORMAT_PARSE );
-               } catch ( Exception $ex ) {
-                       try {
-                               trigger_error( "Exception caught in " . __METHOD__ . " (message " . $this->key . "): "
-                                       . $ex, E_USER_WARNING );
-                       } catch ( Exception $ex ) {
-                               // Doh! Cause a fatal error after all?
-                       }
-
-                       return '⧼' . htmlspecialchars( $this->key ) . '⧽';
-               }
-       }
-
-       /**
-        * Fully parse the text from wikitext to HTML.
-        *
-        * @since 1.17
-        *
-        * @return string Parsed HTML.
-        */
-       public function parse() {
-               $this->format = self::FORMAT_PARSE;
-               return $this->toString( self::FORMAT_PARSE );
-       }
-
-       /**
-        * Returns the message text. {{-transformation is done.
-        *
-        * @since 1.17
-        *
-        * @return string Unescaped message text.
-        */
-       public function text() {
-               $this->format = self::FORMAT_TEXT;
-               return $this->toString( self::FORMAT_TEXT );
-       }
-
-       /**
-        * Returns the message text as-is, only parameters are substituted.
-        *
-        * @since 1.17
-        *
-        * @return string Unescaped untransformed message text.
-        */
-       public function plain() {
-               $this->format = self::FORMAT_PLAIN;
-               return $this->toString( self::FORMAT_PLAIN );
-       }
-
-       /**
-        * Returns the parsed message text which is always surrounded by a block element.
-        *
-        * @since 1.17
-        *
-        * @return string HTML
-        */
-       public function parseAsBlock() {
-               $this->format = self::FORMAT_BLOCK_PARSE;
-               return $this->toString( self::FORMAT_BLOCK_PARSE );
-       }
-
-       /**
-        * Returns the message text. {{-transformation is done and the result
-        * is escaped excluding any raw parameters.
-        *
-        * @since 1.17
-        *
-        * @return string Escaped message text.
-        */
-       public function escaped() {
-               $this->format = self::FORMAT_ESCAPED;
-               return $this->toString( self::FORMAT_ESCAPED );
-       }
-
-       /**
-        * Check whether a message key has been defined currently.
-        *
-        * @since 1.17
-        *
-        * @return bool
-        */
-       public function exists() {
-               return $this->fetchMessage() !== false;
-       }
-
-       /**
-        * Check whether a message does not exist, or is an empty string
-        *
-        * @since 1.18
-        * @todo FIXME: Merge with isDisabled()?
-        *
-        * @return bool
-        */
-       public function isBlank() {
-               $message = $this->fetchMessage();
-               return $message === false || $message === '';
-       }
-
-       /**
-        * Check whether a message does not exist, is an empty string, or is "-".
-        *
-        * @since 1.18
-        *
-        * @return bool
-        */
-       public function isDisabled() {
-               $message = $this->fetchMessage();
-               return $message === false || $message === '' || $message === '-';
-       }
-
-       /**
-        * @since 1.17
-        *
-        * @param mixed $raw
-        *
-        * @return array Array with a single "raw" key.
-        */
-       public static function rawParam( $raw ) {
-               return [ 'raw' => $raw ];
-       }
-
-       /**
-        * @since 1.18
-        *
-        * @param mixed $num
-        *
-        * @return array Array with a single "num" key.
-        */
-       public static function numParam( $num ) {
-               return [ 'num' => $num ];
-       }
-
-       /**
-        * @since 1.22
-        *
-        * @param int $duration
-        *
-        * @return int[] Array with a single "duration" key.
-        */
-       public static function durationParam( $duration ) {
-               return [ 'duration' => $duration ];
-       }
-
-       /**
-        * @since 1.22
-        *
-        * @param string $expiry
-        *
-        * @return string[] Array with a single "expiry" key.
-        */
-       public static function expiryParam( $expiry ) {
-               return [ 'expiry' => $expiry ];
-       }
-
-       /**
-        * @since 1.22
-        *
-        * @param int $period
-        *
-        * @return int[] Array with a single "period" key.
-        */
-       public static function timeperiodParam( $period ) {
-               return [ 'period' => $period ];
-       }
-
-       /**
-        * @since 1.22
-        *
-        * @param int $size
-        *
-        * @return int[] Array with a single "size" key.
-        */
-       public static function sizeParam( $size ) {
-               return [ 'size' => $size ];
-       }
-
-       /**
-        * @since 1.22
-        *
-        * @param int $bitrate
-        *
-        * @return int[] Array with a single "bitrate" key.
-        */
-       public static function bitrateParam( $bitrate ) {
-               return [ 'bitrate' => $bitrate ];
-       }
-
-       /**
-        * @since 1.25
-        *
-        * @param string $plaintext
-        *
-        * @return string[] Array with a single "plaintext" key.
-        */
-       public static function plaintextParam( $plaintext ) {
-               return [ 'plaintext' => $plaintext ];
-       }
-
-       /**
-        * @since 1.29
-        *
-        * @param array $list
-        * @param string $type 'comma', 'semicolon', 'pipe', 'text'
-        * @return array Array with "list" and "type" keys.
-        */
-       public static function listParam( array $list, $type = 'text' ) {
-               if ( !isset( self::$listTypeMap[$type] ) ) {
-                       throw new InvalidArgumentException(
-                               "Invalid type '$type'. Known types are: " . implode( ', ', array_keys( self::$listTypeMap ) )
-                       );
-               }
-               return [ 'list' => $list, 'type' => $type ];
-       }
-
-       /**
-        * Substitutes any parameters into the message text.
-        *
-        * @since 1.17
-        *
-        * @param string $message The message text.
-        * @param string $type Either "before" or "after".
-        * @param string $format One of the FORMAT_* constants.
-        *
-        * @return string
-        */
-       protected function replaceParameters( $message, $type, $format ) {
-               // A temporary marker for $1 parameters that is only valid
-               // in non-attribute contexts. However if the entire message is escaped
-               // then we don't want to use it because it will be mangled in all contexts
-               // and its unnessary as ->escaped() messages aren't html.
-               $marker = $format === self::FORMAT_ESCAPED ? '$' : '$\'"';
-               $replacementKeys = [];
-               foreach ( $this->parameters as $n => $param ) {
-                       list( $paramType, $value ) = $this->extractParam( $param, $format );
-                       if ( $type === 'before' ) {
-                               if ( $paramType === 'before' ) {
-                                       $replacementKeys['$' . ( $n + 1 )] = $value;
-                               } else /* $paramType === 'after' */ {
-                                       // To protect against XSS from replacing parameters
-                                       // inside html attributes, we convert $1 to $'"1.
-                                       // In the event that one of the parameters ends up
-                                       // in an attribute, either the ' or the " will be
-                                       // escaped, breaking the replacement and avoiding XSS.
-                                       $replacementKeys['$' . ( $n + 1 )] = $marker . ( $n + 1 );
-                               }
-                       } elseif ( $paramType === 'after' ) {
-                               $replacementKeys[$marker . ( $n + 1 )] = $value;
-                       }
-               }
-               return strtr( $message, $replacementKeys );
-       }
-
-       /**
-        * Extracts the parameter type and preprocessed the value if needed.
-        *
-        * @since 1.18
-        *
-        * @param mixed $param Parameter as defined in this class.
-        * @param string $format One of the FORMAT_* constants.
-        *
-        * @return array Array with the parameter type (either "before" or "after") and the value.
-        */
-       protected function extractParam( $param, $format ) {
-               if ( is_array( $param ) ) {
-                       if ( isset( $param['raw'] ) ) {
-                               return [ 'after', $param['raw'] ];
-                       } elseif ( isset( $param['num'] ) ) {
-                               // Replace number params always in before step for now.
-                               // No support for combined raw and num params
-                               return [ 'before', $this->getLanguage()->formatNum( $param['num'] ) ];
-                       } elseif ( isset( $param['duration'] ) ) {
-                               return [ 'before', $this->getLanguage()->formatDuration( $param['duration'] ) ];
-                       } elseif ( isset( $param['expiry'] ) ) {
-                               return [ 'before', $this->getLanguage()->formatExpiry( $param['expiry'] ) ];
-                       } elseif ( isset( $param['period'] ) ) {
-                               return [ 'before', $this->getLanguage()->formatTimePeriod( $param['period'] ) ];
-                       } elseif ( isset( $param['size'] ) ) {
-                               return [ 'before', $this->getLanguage()->formatSize( $param['size'] ) ];
-                       } elseif ( isset( $param['bitrate'] ) ) {
-                               return [ 'before', $this->getLanguage()->formatBitrate( $param['bitrate'] ) ];
-                       } elseif ( isset( $param['plaintext'] ) ) {
-                               return [ 'after', $this->formatPlaintext( $param['plaintext'], $format ) ];
-                       } elseif ( isset( $param['list'] ) ) {
-                               return $this->formatListParam( $param['list'], $param['type'], $format );
-                       } else {
-                               if ( !is_scalar( $param ) ) {
-                                       $param = serialize( $param );
-                               }
-                               \MediaWiki\Logger\LoggerFactory::getInstance( 'Bug58676' )->warning(
-                                       'Invalid parameter for message "{msgkey}": {param}',
-                                       [
-                                               'exception' => new Exception,
-                                               'msgkey' => $this->getKey(),
-                                               'param' => htmlspecialchars( $param ),
-                                       ]
-                               );
-
-                               return [ 'before', '[INVALID]' ];
-                       }
-               } elseif ( $param instanceof Message ) {
-                       // Match language, flags, etc. to the current message.
-                       $msg = clone $param;
-                       if ( $msg->language !== $this->language || $msg->useDatabase !== $this->useDatabase ) {
-                               // Cache depends on these parameters
-                               $msg->message = null;
-                       }
-                       $msg->interface = $this->interface;
-                       $msg->language = $this->language;
-                       $msg->useDatabase = $this->useDatabase;
-                       $msg->title = $this->title;
-
-                       // DWIM
-                       if ( $format === 'block-parse' ) {
-                               $format = 'parse';
-                       }
-                       $msg->format = $format;
-
-                       // Message objects should not be before parameters because
-                       // then they'll get double escaped. If the message needs to be
-                       // escaped, it'll happen right here when we call toString().
-                       return [ 'after', $msg->toString( $format ) ];
-               } else {
-                       return [ 'before', $param ];
-               }
-       }
-
-       /**
-        * Wrapper for what ever method we use to parse wikitext.
-        *
-        * @since 1.17
-        *
-        * @param string $string Wikitext message contents.
-        *
-        * @return string Wikitext parsed into HTML.
-        */
-       protected function parseText( $string ) {
-               $out = MessageCache::singleton()->parse(
-                       $string,
-                       $this->title,
-                       /*linestart*/true,
-                       $this->interface,
-                       $this->getLanguage()
-               );
-
-               return $out instanceof ParserOutput
-                       ? $out->getText( [
-                               'enableSectionEditLinks' => false,
-                               // Wrapping messages in an extra <div> is probably not expected. If
-                               // they're outside the content area they probably shouldn't be
-                               // targeted by CSS that's targeting the parser output, and if
-                               // they're inside they already are from the outer div.
-                               'unwrap' => true,
-                       ] )
-                       : $out;
-       }
-
-       /**
-        * Wrapper for what ever method we use to {{-transform wikitext.
-        *
-        * @since 1.17
-        *
-        * @param string $string Wikitext message contents.
-        *
-        * @return string Wikitext with {{-constructs replaced with their values.
-        */
-       protected function transformText( $string ) {
-               return MessageCache::singleton()->transform(
-                       $string,
-                       $this->interface,
-                       $this->getLanguage(),
-                       $this->title
-               );
-       }
-
-       /**
-        * Wrapper for what ever method we use to get message contents.
-        *
-        * @since 1.17
-        *
-        * @return string
-        * @throws MWException If message key array is empty.
-        */
-       protected function fetchMessage() {
-               if ( $this->message === null ) {
-                       $cache = MessageCache::singleton();
-
-                       foreach ( $this->keysToTry as $key ) {
-                               $message = $cache->get( $key, $this->useDatabase, $this->getLanguage() );
-                               if ( $message !== false && $message !== '' ) {
-                                       break;
-                               }
-                       }
-
-                       // NOTE: The constructor makes sure keysToTry isn't empty,
-                       //       so we know that $key and $message are initialized.
-                       $this->key = $key;
-                       $this->message = $message;
-               }
-               return $this->message;
-       }
-
-       /**
-        * Formats a message parameter wrapped with 'plaintext'. Ensures that
-        * the entire string is displayed unchanged when displayed in the output
-        * format.
-        *
-        * @since 1.25
-        *
-        * @param string $plaintext String to ensure plaintext output of
-        * @param string $format One of the FORMAT_* constants.
-        *
-        * @return string Input plaintext encoded for output to $format
-        */
-       protected function formatPlaintext( $plaintext, $format ) {
-               switch ( $format ) {
-                       case self::FORMAT_TEXT:
-                       case self::FORMAT_PLAIN:
-                               return $plaintext;
-
-                       case self::FORMAT_PARSE:
-                       case self::FORMAT_BLOCK_PARSE:
-                       case self::FORMAT_ESCAPED:
-                       default:
-                               return htmlspecialchars( $plaintext, ENT_QUOTES );
-               }
-       }
-
-       /**
-        * Formats a list of parameters as a concatenated string.
-        * @since 1.29
-        * @param array $params
-        * @param string $listType
-        * @param string $format One of the FORMAT_* constants.
-        * @return array Array with the parameter type (either "before" or "after") and the value.
-        */
-       protected function formatListParam( array $params, $listType, $format ) {
-               if ( !isset( self::$listTypeMap[$listType] ) ) {
-                       $warning = 'Invalid list type for message "' . $this->getKey() . '": '
-                               . htmlspecialchars( $listType )
-                               . ' (params are ' . htmlspecialchars( serialize( $params ) ) . ')';
-                       trigger_error( $warning, E_USER_WARNING );
-                       $e = new Exception;
-                       wfDebugLog( 'Bug58676', $warning . "\n" . $e->getTraceAsString() );
-                       return [ 'before', '[INVALID]' ];
-               }
-               $func = self::$listTypeMap[$listType];
-
-               // Handle an empty list sensibly
-               if ( !$params ) {
-                       return [ 'before', $this->getLanguage()->$func( [] ) ];
-               }
-
-               // First, determine what kinds of list items we have
-               $types = [];
-               $vars = [];
-               $list = [];
-               foreach ( $params as $n => $p ) {
-                       list( $type, $value ) = $this->extractParam( $p, $format );
-                       $types[$type] = true;
-                       $list[] = $value;
-                       $vars[] = '$' . ( $n + 1 );
-               }
-
-               // Easy case: all are 'before' or 'after', so just join the
-               // values and use the same type.
-               if ( count( $types ) === 1 ) {
-                       return [ key( $types ), $this->getLanguage()->$func( $list ) ];
-               }
-
-               // Hard case: We need to process each value per its type, then
-               // return the concatenated values as 'after'. We handle this by turning
-               // the list into a RawMessage and processing that as a parameter.
-               $vars = $this->getLanguage()->$func( $vars );
-               return $this->extractParam( new RawMessage( $vars, $params ), $format );
-       }
-}
index 57cd74a..2023d91 100644 (file)
@@ -3222,7 +3222,7 @@ class OutputPage extends ContextSource {
                                ),
                                [ 'html5shiv' ],
                                ResourceLoaderModule::TYPE_SCRIPTS,
-                               [ 'sync' => true ],
+                               [ 'raw' => '1', 'sync' => '1' ],
                                $this->getCSPNonce()
                        ) .
                        '<![endif]-->';
index b845c57..ed17e07 100644 (file)
@@ -1644,7 +1644,7 @@ class ApiMain extends ApiBase {
                        '$schema' => '/mediawiki/api/request/0.0.1',
                        'meta' => [
                                'request_id' => WebRequest::getRequestId(),
-                               'id' => UIDGenerator::newUUIDv1(),
+                               'id' => UIDGenerator::newUUIDv4(),
                                'dt' => wfTimestamp( TS_ISO_8601 ),
                                'domain' => $this->getConfig()->get( 'ServerName' ),
                                'stream' => 'mediawiki.api-request'
diff --git a/includes/language/LanguageCode.php b/includes/language/LanguageCode.php
new file mode 100644 (file)
index 0000000..7d954d3
--- /dev/null
@@ -0,0 +1,204 @@
+<?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
+ * @ingroup Language
+ */
+
+/**
+ * Methods for dealing with language codes.
+ * @todo Move some of the code-related static methods out of Language into this class
+ *
+ * @since 1.29
+ * @ingroup Language
+ */
+class LanguageCode {
+       /**
+        * Mapping of deprecated language codes that were used in previous
+        * versions of MediaWiki to up-to-date, current language codes.
+        * These may or may not be valid BCP 47 codes; they are included here
+        * because MediaWiki renamed these particular codes at some point.
+        *
+        * @var array Mapping from deprecated MediaWiki-internal language code
+        *   to replacement MediaWiki-internal language code.
+        *
+        * @since 1.30
+        * @see https://meta.wikimedia.org/wiki/Special_language_codes
+        */
+       private static $deprecatedLanguageCodeMapping = [
+               // Note that als is actually a valid ISO 639 code (Tosk Albanian), but it
+               // was previously used in MediaWiki for Alsatian, which comes under gsw
+               'als' => 'gsw', // T25215
+               'bat-smg' => 'sgs', // T27522
+               'be-x-old' => 'be-tarask', // T11823
+               'fiu-vro' => 'vro', // T31186
+               'roa-rup' => 'rup', // T17988
+               'zh-classical' => 'lzh', // T30443
+               'zh-min-nan' => 'nan', // T30442
+               'zh-yue' => 'yue', // T30441
+       ];
+
+       /**
+        * Mapping of non-standard language codes used in MediaWiki to
+        * standardized BCP 47 codes.  These are not deprecated (yet?):
+        * IANA may eventually recognize the subtag, in which case the `-x-`
+        * infix could be removed, or else we could rename the code in
+        * MediaWiki, in which case they'd move up to the above mapping
+        * of deprecated codes.
+        *
+        * As a rule, we preserve all distinctions made by MediaWiki
+        * internally.  For example, `de-formal` becomes `de-x-formal`
+        * instead of just `de` because MediaWiki distinguishes `de-formal`
+        * from `de` (for example, for interface translations).  Similarly,
+        * BCP 47 indicates that `kk-Cyrl` SHOULD not be used because it
+        * "typically does not add information", but in our case MediaWiki
+        * LanguageConverter distinguishes `kk` (render content in a mix of
+        * Kurdish variants) from `kk-Cyrl` (convert content to be uniformly
+        * Cyrillic).  As the BCP 47 requirement is a SHOULD not a MUST,
+        * `kk-Cyrl` is a valid code, although some validators may emit
+        * a warning note.
+        *
+        * @var array Mapping from nonstandard MediaWiki-internal codes to
+        *   BCP 47 codes
+        *
+        * @since 1.32
+        * @see https://meta.wikimedia.org/wiki/Special_language_codes
+        * @see https://phabricator.wikimedia.org/T125073
+        */
+       private static $nonstandardLanguageCodeMapping = [
+               // All codes returned by Language::fetchLanguageNames() validated
+               // against IANA registry at
+               //   https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry
+               // with help of validator at
+               //   http://schneegans.de/lv/
+               'cbk-zam' => 'cbk', // T124657
+               'de-formal' => 'de-x-formal',
+               'eml' => 'egl', // T36217
+               'en-rtl' => 'en-x-rtl',
+               'es-formal' => 'es-x-formal',
+               'hu-formal' => 'hu-x-formal',
+               'map-bms' => 'jv-x-bms', // [[en:Banyumasan_dialect]] T125073
+               'mo' => 'ro-Cyrl-MD', // T125073
+               'nrm' => 'nrf', // [[en:Norman_language]] T25216
+               'nl-informal' => 'nl-x-informal',
+               'roa-tara' => 'nap-x-tara', // [[en:Tarantino_dialect]]
+               'simple' => 'en-simple',
+               'sr-ec' => 'sr-Cyrl', // T117845
+               'sr-el' => 'sr-Latn', // T117845
+
+               // Although these next codes aren't *wrong* per se, including
+               // both the script and the country code helps compatibility with
+               // other BCP 47 users. Note that MW also uses `zh-Hans`/`zh-Hant`,
+               // without a country code, and those should be left alone.
+               // (See $variantfallbacks in LanguageZh.php for Hans/Hant id.)
+               'zh-cn' => 'zh-Hans-CN',
+               'zh-sg' => 'zh-Hans-SG',
+               'zh-my' => 'zh-Hans-MY',
+               'zh-tw' => 'zh-Hant-TW',
+               'zh-hk' => 'zh-Hant-HK',
+               'zh-mo' => 'zh-Hant-MO',
+       ];
+
+       /**
+        * Returns a mapping of deprecated language codes that were used in previous
+        * versions of MediaWiki to up-to-date, current language codes.
+        *
+        * This array is merged into $wgDummyLanguageCodes in Setup.php, along with
+        * the fake language codes 'qqq' and 'qqx', which are used internally by
+        * MediaWiki's localisation system.
+        *
+        * @return string[]
+        *
+        * @since 1.29
+        */
+       public static function getDeprecatedCodeMapping() {
+               return self::$deprecatedLanguageCodeMapping;
+       }
+
+       /**
+        * Returns a mapping of non-standard language codes used by
+        * (current and previous version of) MediaWiki, mapped to standard
+        * BCP 47 names.
+        *
+        * This array is exported to JavaScript to ensure
+        * mediawiki.language.bcp47 stays in sync with LanguageCode::bcp47().
+        *
+        * @return string[]
+        *
+        * @since 1.32
+        */
+       public static function getNonstandardLanguageCodeMapping() {
+               $result = [];
+               foreach ( self::$deprecatedLanguageCodeMapping as $code => $ignore ) {
+                       $result[$code] = self::bcp47( $code );
+               }
+               foreach ( self::$nonstandardLanguageCodeMapping as $code => $ignore ) {
+                       $result[$code] = self::bcp47( $code );
+               }
+               return $result;
+       }
+
+       /**
+        * Replace deprecated language codes that were used in previous
+        * versions of MediaWiki to up-to-date, current language codes.
+        * Other values will returned unchanged.
+        *
+        * @param string $code Old language code
+        * @return string New language code
+        *
+        * @since 1.30
+        */
+       public static function replaceDeprecatedCodes( $code ) {
+               return self::$deprecatedLanguageCodeMapping[$code] ?? $code;
+       }
+
+       /**
+        * Get the normalised IETF language tag
+        * See unit test for examples.
+        * See mediawiki.language.bcp47 for the JavaScript implementation.
+        *
+        * @param string $code The language code.
+        * @return string A language code complying with BCP 47 standards.
+        *
+        * @since 1.31
+        */
+       public static function bcp47( $code ) {
+               $code = self::replaceDeprecatedCodes( strtolower( $code ) );
+               if ( isset( self::$nonstandardLanguageCodeMapping[$code] ) ) {
+                       $code = self::$nonstandardLanguageCodeMapping[$code];
+               }
+               $codeSegment = explode( '-', $code );
+               $codeBCP = [];
+               foreach ( $codeSegment as $segNo => $seg ) {
+                       // when previous segment is x, it is a private segment and should be lc
+                       if ( $segNo > 0 && strtolower( $codeSegment[( $segNo - 1 )] ) == 'x' ) {
+                               $codeBCP[$segNo] = strtolower( $seg );
+                       // ISO 3166 country code
+                       } elseif ( ( strlen( $seg ) == 2 ) && ( $segNo > 0 ) ) {
+                               $codeBCP[$segNo] = strtoupper( $seg );
+                       // ISO 15924 script code
+                       } elseif ( ( strlen( $seg ) == 4 ) && ( $segNo > 0 ) ) {
+                               $codeBCP[$segNo] = ucfirst( strtolower( $seg ) );
+                       // Use lowercase for other cases
+                       } else {
+                               $codeBCP[$segNo] = strtolower( $seg );
+                       }
+               }
+               $langCode = implode( '-', $codeBCP );
+               return $langCode;
+       }
+}
diff --git a/includes/language/Message.php b/includes/language/Message.php
new file mode 100644 (file)
index 0000000..0b3113f
--- /dev/null
@@ -0,0 +1,1396 @@
+<?php
+/**
+ * Fetching and processing of interface messages.
+ *
+ * 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
+ * @author Niklas Laxström
+ */
+use MediaWiki\MediaWikiServices;
+
+/**
+ * The Message class provides methods which fulfil two basic services:
+ *  - fetching interface messages
+ *  - processing messages into a variety of formats
+ *
+ * First implemented with MediaWiki 1.17, the Message class is intended to
+ * replace the old wfMsg* functions that over time grew unusable.
+ * @see https://www.mediawiki.org/wiki/Manual:Messages_API for equivalences
+ * between old and new functions.
+ *
+ * You should use the wfMessage() global function which acts as a wrapper for
+ * the Message class. The wrapper let you pass parameters as arguments.
+ *
+ * The most basic usage cases would be:
+ *
+ * @code
+ *     // Initialize a Message object using the 'some_key' message key
+ *     $message = wfMessage( 'some_key' );
+ *
+ *     // Using two parameters those values are strings 'value1' and 'value2':
+ *     $message = wfMessage( 'some_key',
+ *          'value1', 'value2'
+ *     );
+ * @endcode
+ *
+ * @section message_global_fn Global function wrapper:
+ *
+ * Since wfMessage() returns a Message instance, you can chain its call with
+ * a method. Some of them return a Message instance too so you can chain them.
+ * You will find below several examples of wfMessage() usage.
+ *
+ * Fetching a message text for interface message:
+ *
+ * @code
+ *    $button = Xml::button(
+ *         wfMessage( 'submit' )->text()
+ *    );
+ * @endcode
+ *
+ * A Message instance can be passed parameters after it has been constructed,
+ * use the params() method to do so:
+ *
+ * @code
+ *     wfMessage( 'welcome-to' )
+ *         ->params( $wgSitename )
+ *         ->text();
+ * @endcode
+ *
+ * {{GRAMMAR}} and friends work correctly:
+ *
+ * @code
+ *    wfMessage( 'are-friends',
+ *        $user, $friend
+ *    );
+ *    wfMessage( 'bad-message' )
+ *         ->rawParams( '<script>...</script>' )
+ *         ->escaped();
+ * @endcode
+ *
+ * @section message_language Changing language:
+ *
+ * Messages can be requested in a different language or in whatever current
+ * content language is being used. The methods are:
+ *     - Message->inContentLanguage()
+ *     - Message->inLanguage()
+ *
+ * Sometimes the message text ends up in the database, so content language is
+ * needed:
+ *
+ * @code
+ *    wfMessage( 'file-log',
+ *        $user, $filename
+ *    )->inContentLanguage()->text();
+ * @endcode
+ *
+ * Checking whether a message exists:
+ *
+ * @code
+ *    wfMessage( 'mysterious-message' )->exists()
+ *    // returns a boolean whether the 'mysterious-message' key exist.
+ * @endcode
+ *
+ * If you want to use a different language:
+ *
+ * @code
+ *    $userLanguage = $user->getOption( 'language' );
+ *    wfMessage( 'email-header' )
+ *         ->inLanguage( $userLanguage )
+ *         ->plain();
+ * @endcode
+ *
+ * @note You can parse the text only in the content or interface languages
+ *
+ * @section message_compare_old Comparison with old wfMsg* functions:
+ *
+ * Use full parsing:
+ *
+ * @code
+ *     // old style:
+ *     wfMsgExt( 'key', [ 'parseinline' ], 'apple' );
+ *     // new style:
+ *     wfMessage( 'key', 'apple' )->parse();
+ * @endcode
+ *
+ * Parseinline is used because it is more useful when pre-building HTML.
+ * In normal use it is better to use OutputPage::(add|wrap)WikiMsg.
+ *
+ * Places where HTML cannot be used. {{-transformation is done.
+ * @code
+ *     // old style:
+ *     wfMsgExt( 'key', [ 'parsemag' ], 'apple', 'pear' );
+ *     // new style:
+ *     wfMessage( 'key', 'apple', 'pear' )->text();
+ * @endcode
+ *
+ * Shortcut for escaping the message too, similar to wfMsgHTML(), but
+ * parameters are not replaced after escaping by default.
+ * @code
+ *     $escaped = wfMessage( 'key' )
+ *          ->rawParams( 'apple' )
+ *          ->escaped();
+ * @endcode
+ *
+ * @section message_appendix Appendix:
+ *
+ * @todo
+ * - test, can we have tests?
+ * - this documentation needs to be extended
+ *
+ * @see https://www.mediawiki.org/wiki/WfMessage()
+ * @see https://www.mediawiki.org/wiki/New_messages_API
+ * @see https://www.mediawiki.org/wiki/Localisation
+ *
+ * @since 1.17
+ */
+class Message implements MessageSpecifier, Serializable {
+       /** Use message text as-is */
+       const FORMAT_PLAIN = 'plain';
+       /** Use normal wikitext -> HTML parsing (the result will be wrapped in a block-level HTML tag) */
+       const FORMAT_BLOCK_PARSE = 'block-parse';
+       /** Use normal wikitext -> HTML parsing but strip the block-level wrapper */
+       const FORMAT_PARSE = 'parse';
+       /** Transform {{..}} constructs but don't transform to HTML */
+       const FORMAT_TEXT = 'text';
+       /** Transform {{..}} constructs, HTML-escape the result */
+       const FORMAT_ESCAPED = 'escaped';
+
+       /**
+        * Mapping from Message::listParam() types to Language methods.
+        * @var array
+        */
+       protected static $listTypeMap = [
+               'comma' => 'commaList',
+               'semicolon' => 'semicolonList',
+               'pipe' => 'pipeList',
+               'text' => 'listToText',
+       ];
+
+       /**
+        * In which language to get this message. True, which is the default,
+        * means the current user language, false content language.
+        *
+        * @var bool
+        */
+       protected $interface = true;
+
+       /**
+        * In which language to get this message. Overrides the $interface setting.
+        *
+        * @var Language|bool Explicit language object, or false for user language
+        */
+       protected $language = false;
+
+       /**
+        * @var string The message key. If $keysToTry has more than one element,
+        * this may change to one of the keys to try when fetching the message text.
+        */
+       protected $key;
+
+       /**
+        * @var string[] List of keys to try when fetching the message.
+        */
+       protected $keysToTry;
+
+       /**
+        * @var array List of parameters which will be substituted into the message.
+        */
+       protected $parameters = [];
+
+       /**
+        * @var string
+        * @deprecated
+        */
+       protected $format = 'parse';
+
+       /**
+        * @var bool Whether database can be used.
+        */
+       protected $useDatabase = true;
+
+       /**
+        * @var Title Title object to use as context.
+        */
+       protected $title = null;
+
+       /**
+        * @var Content Content object representing the message.
+        */
+       protected $content = null;
+
+       /**
+        * @var string
+        */
+       protected $message;
+
+       /**
+        * @since 1.17
+        * @param string|string[]|MessageSpecifier $key Message key, or array of
+        * message keys to try and use the first non-empty message for, or a
+        * MessageSpecifier to copy from.
+        * @param array $params Message parameters.
+        * @param Language|null $language [optional] Language to use (defaults to current user language).
+        * @throws InvalidArgumentException
+        */
+       public function __construct( $key, $params = [], Language $language = null ) {
+               if ( $key instanceof MessageSpecifier ) {
+                       if ( $params ) {
+                               throw new InvalidArgumentException(
+                                       '$params must be empty if $key is a MessageSpecifier'
+                               );
+                       }
+                       $params = $key->getParams();
+                       $key = $key->getKey();
+               }
+
+               if ( !is_string( $key ) && !is_array( $key ) ) {
+                       throw new InvalidArgumentException( '$key must be a string or an array' );
+               }
+
+               $this->keysToTry = (array)$key;
+
+               if ( empty( $this->keysToTry ) ) {
+                       throw new InvalidArgumentException( '$key must not be an empty list' );
+               }
+
+               $this->key = reset( $this->keysToTry );
+
+               $this->parameters = array_values( $params );
+               // User language is only resolved in getLanguage(). This helps preserve the
+               // semantic intent of "user language" across serialize() and unserialize().
+               $this->language = $language ?: false;
+       }
+
+       /**
+        * @see Serializable::serialize()
+        * @since 1.26
+        * @return string
+        */
+       public function serialize() {
+               return serialize( [
+                       'interface' => $this->interface,
+                       'language' => $this->language ? $this->language->getCode() : false,
+                       'key' => $this->key,
+                       'keysToTry' => $this->keysToTry,
+                       'parameters' => $this->parameters,
+                       'format' => $this->format,
+                       'useDatabase' => $this->useDatabase,
+                       'titlestr' => $this->title ? $this->title->getFullText() : null,
+               ] );
+       }
+
+       /**
+        * @see Serializable::unserialize()
+        * @since 1.26
+        * @param string $serialized
+        */
+       public function unserialize( $serialized ) {
+               $data = unserialize( $serialized );
+               if ( !is_array( $data ) ) {
+                       throw new InvalidArgumentException( __METHOD__ . ': Invalid serialized data' );
+               }
+
+               $this->interface = $data['interface'];
+               $this->key = $data['key'];
+               $this->keysToTry = $data['keysToTry'];
+               $this->parameters = $data['parameters'];
+               $this->format = $data['format'];
+               $this->useDatabase = $data['useDatabase'];
+               $this->language = $data['language'] ? Language::factory( $data['language'] ) : false;
+
+               if ( isset( $data['titlestr'] ) ) {
+                       $this->title = Title::newFromText( $data['titlestr'] );
+               } elseif ( isset( $data['title'] ) && $data['title'] instanceof Title ) {
+                       // Old serializations from before December 2018
+                       $this->title = $data['title'];
+               } else {
+                       $this->title = null; // Explicit for sanity
+               }
+       }
+
+       /**
+        * @since 1.24
+        *
+        * @return bool True if this is a multi-key message, that is, if the key provided to the
+        * constructor was a fallback list of keys to try.
+        */
+       public function isMultiKey() {
+               return count( $this->keysToTry ) > 1;
+       }
+
+       /**
+        * @since 1.24
+        *
+        * @return string[] The list of keys to try when fetching the message text,
+        * in order of preference.
+        */
+       public function getKeysToTry() {
+               return $this->keysToTry;
+       }
+
+       /**
+        * Returns the message key.
+        *
+        * If a list of multiple possible keys was supplied to the constructor, this method may
+        * return any of these keys. After the message has been fetched, this method will return
+        * the key that was actually used to fetch the message.
+        *
+        * @since 1.21
+        *
+        * @return string
+        */
+       public function getKey() {
+               return $this->key;
+       }
+
+       /**
+        * Returns the message parameters.
+        *
+        * @since 1.21
+        *
+        * @return array
+        */
+       public function getParams() {
+               return $this->parameters;
+       }
+
+       /**
+        * Returns the message format.
+        *
+        * @since 1.21
+        *
+        * @return string
+        * @deprecated since 1.29 formatting is not stateful
+        */
+       public function getFormat() {
+               wfDeprecated( __METHOD__, '1.29' );
+               return $this->format;
+       }
+
+       /**
+        * Returns the Language of the Message.
+        *
+        * @since 1.23
+        *
+        * @return Language
+        */
+       public function getLanguage() {
+               // Defaults to false which means current user language
+               return $this->language ?: RequestContext::getMain()->getLanguage();
+       }
+
+       /**
+        * Factory function that is just wrapper for the real constructor. It is
+        * intended to be used instead of the real constructor, because it allows
+        * chaining method calls, while new objects don't.
+        *
+        * @since 1.17
+        *
+        * @param string|string[]|MessageSpecifier $key
+        * @param mixed $param,... Parameters as strings.
+        *
+        * @return Message
+        */
+       public static function newFromKey( $key /*...*/ ) {
+               $params = func_get_args();
+               array_shift( $params );
+               return new self( $key, $params );
+       }
+
+       /**
+        * Transform a MessageSpecifier or a primitive value used interchangeably with
+        * specifiers (a message key string, or a key + params array) into a proper Message.
+        *
+        * Also accepts a MessageSpecifier inside an array: that's not considered a valid format
+        * but is an easy error to make due to how StatusValue stores messages internally.
+        * Further array elements are ignored in that case.
+        *
+        * @param string|array|MessageSpecifier $value
+        * @return Message
+        * @throws InvalidArgumentException
+        * @since 1.27
+        */
+       public static function newFromSpecifier( $value ) {
+               $params = [];
+               if ( is_array( $value ) ) {
+                       $params = $value;
+                       $value = array_shift( $params );
+               }
+
+               if ( $value instanceof Message ) { // Message, RawMessage, ApiMessage, etc
+                       $message = clone $value;
+               } elseif ( $value instanceof MessageSpecifier ) {
+                       $message = new Message( $value );
+               } elseif ( is_string( $value ) ) {
+                       $message = new Message( $value, $params );
+               } else {
+                       throw new InvalidArgumentException( __METHOD__ . ': invalid argument type '
+                               . gettype( $value ) );
+               }
+
+               return $message;
+       }
+
+       /**
+        * Factory function accepting multiple message keys and returning a message instance
+        * for the first message which is non-empty. If all messages are empty then an
+        * instance of the first message key is returned.
+        *
+        * @since 1.18
+        *
+        * @param string|string[] $keys,... Message keys, or first argument as an array of all the
+        * message keys.
+        *
+        * @return Message
+        */
+       public static function newFallbackSequence( /*...*/ ) {
+               $keys = func_get_args();
+               if ( func_num_args() == 1 ) {
+                       if ( is_array( $keys[0] ) ) {
+                               // Allow an array to be passed as the first argument instead
+                               $keys = array_values( $keys[0] );
+                       } else {
+                               // Optimize a single string to not need special fallback handling
+                               $keys = $keys[0];
+                       }
+               }
+               return new self( $keys );
+       }
+
+       /**
+        * Get a title object for a mediawiki message, where it can be found in the mediawiki namespace.
+        * The title will be for the current language, if the message key is in
+        * $wgForceUIMsgAsContentMsg it will be append with the language code (except content
+        * language), because Message::inContentLanguage will also return in user language.
+        *
+        * @see $wgForceUIMsgAsContentMsg
+        * @return Title
+        * @since 1.26
+        */
+       public function getTitle() {
+               global $wgForceUIMsgAsContentMsg;
+
+               $contLang = MediaWikiServices::getInstance()->getContentLanguage();
+               $lang = $this->getLanguage();
+               $title = $this->key;
+               if (
+                       !$lang->equals( $contLang )
+                       && in_array( $this->key, (array)$wgForceUIMsgAsContentMsg )
+               ) {
+                       $title .= '/' . $lang->getCode();
+               }
+
+               return Title::makeTitle(
+                       NS_MEDIAWIKI, $contLang->ucfirst( strtr( $title, ' ', '_' ) ) );
+       }
+
+       /**
+        * Adds parameters to the parameter list of this message.
+        *
+        * @since 1.17
+        *
+        * @param mixed $args,... Parameters as strings or arrays from
+        *  Message::numParam() and the like, or a single array of parameters.
+        *
+        * @return Message $this
+        */
+       public function params( /*...*/ ) {
+               $args = func_get_args();
+
+               // If $args has only one entry and it's an array, then it's either a
+               // non-varargs call or it happens to be a call with just a single
+               // "special" parameter. Since the "special" parameters don't have any
+               // numeric keys, we'll test that to differentiate the cases.
+               if ( count( $args ) === 1 && isset( $args[0] ) && is_array( $args[0] ) ) {
+                       if ( $args[0] === [] ) {
+                               $args = [];
+                       } else {
+                               foreach ( $args[0] as $key => $value ) {
+                                       if ( is_int( $key ) ) {
+                                               $args = $args[0];
+                                               break;
+                                       }
+                               }
+                       }
+               }
+
+               $this->parameters = array_merge( $this->parameters, array_values( $args ) );
+               return $this;
+       }
+
+       /**
+        * Add parameters that are substituted after parsing or escaping.
+        * In other words the parsing process cannot access the contents
+        * of this type of parameter, and you need to make sure it is
+        * sanitized beforehand.  The parser will see "$n", instead.
+        *
+        * @since 1.17
+        *
+        * @param mixed $params,... Raw parameters as strings, or a single argument that is
+        * an array of raw parameters.
+        *
+        * @return Message $this
+        */
+       public function rawParams( /*...*/ ) {
+               $params = func_get_args();
+               if ( isset( $params[0] ) && is_array( $params[0] ) ) {
+                       $params = $params[0];
+               }
+               foreach ( $params as $param ) {
+                       $this->parameters[] = self::rawParam( $param );
+               }
+               return $this;
+       }
+
+       /**
+        * Add parameters that are numeric and will be passed through
+        * Language::formatNum before substitution
+        *
+        * @since 1.18
+        *
+        * @param mixed $param,... Numeric parameters, or a single argument that is
+        * an array of numeric parameters.
+        *
+        * @return Message $this
+        */
+       public function numParams( /*...*/ ) {
+               $params = func_get_args();
+               if ( isset( $params[0] ) && is_array( $params[0] ) ) {
+                       $params = $params[0];
+               }
+               foreach ( $params as $param ) {
+                       $this->parameters[] = self::numParam( $param );
+               }
+               return $this;
+       }
+
+       /**
+        * Add parameters that are durations of time and will be passed through
+        * Language::formatDuration before substitution
+        *
+        * @since 1.22
+        *
+        * @param int|int[] $param,... Duration parameters, or a single argument that is
+        * an array of duration parameters.
+        *
+        * @return Message $this
+        */
+       public function durationParams( /*...*/ ) {
+               $params = func_get_args();
+               if ( isset( $params[0] ) && is_array( $params[0] ) ) {
+                       $params = $params[0];
+               }
+               foreach ( $params as $param ) {
+                       $this->parameters[] = self::durationParam( $param );
+               }
+               return $this;
+       }
+
+       /**
+        * Add parameters that are expiration times and will be passed through
+        * Language::formatExpiry before substitution
+        *
+        * @since 1.22
+        *
+        * @param string|string[] $param,... Expiry parameters, or a single argument that is
+        * an array of expiry parameters.
+        *
+        * @return Message $this
+        */
+       public function expiryParams( /*...*/ ) {
+               $params = func_get_args();
+               if ( isset( $params[0] ) && is_array( $params[0] ) ) {
+                       $params = $params[0];
+               }
+               foreach ( $params as $param ) {
+                       $this->parameters[] = self::expiryParam( $param );
+               }
+               return $this;
+       }
+
+       /**
+        * Add parameters that are time periods and will be passed through
+        * Language::formatTimePeriod before substitution
+        *
+        * @since 1.22
+        *
+        * @param int|int[] $param,... Time period parameters, or a single argument that is
+        * an array of time period parameters.
+        *
+        * @return Message $this
+        */
+       public function timeperiodParams( /*...*/ ) {
+               $params = func_get_args();
+               if ( isset( $params[0] ) && is_array( $params[0] ) ) {
+                       $params = $params[0];
+               }
+               foreach ( $params as $param ) {
+                       $this->parameters[] = self::timeperiodParam( $param );
+               }
+               return $this;
+       }
+
+       /**
+        * Add parameters that are file sizes and will be passed through
+        * Language::formatSize before substitution
+        *
+        * @since 1.22
+        *
+        * @param int|int[] $param,... Size parameters, or a single argument that is
+        * an array of size parameters.
+        *
+        * @return Message $this
+        */
+       public function sizeParams( /*...*/ ) {
+               $params = func_get_args();
+               if ( isset( $params[0] ) && is_array( $params[0] ) ) {
+                       $params = $params[0];
+               }
+               foreach ( $params as $param ) {
+                       $this->parameters[] = self::sizeParam( $param );
+               }
+               return $this;
+       }
+
+       /**
+        * Add parameters that are bitrates and will be passed through
+        * Language::formatBitrate before substitution
+        *
+        * @since 1.22
+        *
+        * @param int|int[] $param,... Bit rate parameters, or a single argument that is
+        * an array of bit rate parameters.
+        *
+        * @return Message $this
+        */
+       public function bitrateParams( /*...*/ ) {
+               $params = func_get_args();
+               if ( isset( $params[0] ) && is_array( $params[0] ) ) {
+                       $params = $params[0];
+               }
+               foreach ( $params as $param ) {
+                       $this->parameters[] = self::bitrateParam( $param );
+               }
+               return $this;
+       }
+
+       /**
+        * Add parameters that are plaintext and will be passed through without
+        * the content being evaluated.  Plaintext parameters are not valid as
+        * arguments to parser functions. This differs from self::rawParams in
+        * that the Message class handles escaping to match the output format.
+        *
+        * @since 1.25
+        *
+        * @param string|string[] $param,... plaintext parameters, or a single argument that is
+        * an array of plaintext parameters.
+        *
+        * @return Message $this
+        */
+       public function plaintextParams( /*...*/ ) {
+               $params = func_get_args();
+               if ( isset( $params[0] ) && is_array( $params[0] ) ) {
+                       $params = $params[0];
+               }
+               foreach ( $params as $param ) {
+                       $this->parameters[] = self::plaintextParam( $param );
+               }
+               return $this;
+       }
+
+       /**
+        * Set the language and the title from a context object
+        *
+        * @since 1.19
+        *
+        * @param IContextSource $context
+        *
+        * @return Message $this
+        */
+       public function setContext( IContextSource $context ) {
+               $this->inLanguage( $context->getLanguage() );
+               $this->title( $context->getTitle() );
+               $this->interface = true;
+
+               return $this;
+       }
+
+       /**
+        * Request the message in any language that is supported.
+        *
+        * As a side effect interface message status is unconditionally
+        * turned off.
+        *
+        * @since 1.17
+        * @param Language|string $lang Language code or Language object.
+        * @return Message $this
+        * @throws MWException
+        */
+       public function inLanguage( $lang ) {
+               $previousLanguage = $this->language;
+
+               if ( $lang instanceof Language ) {
+                       $this->language = $lang;
+               } elseif ( is_string( $lang ) ) {
+                       if ( !$this->language instanceof Language || $this->language->getCode() != $lang ) {
+                               $this->language = Language::factory( $lang );
+                       }
+               } elseif ( $lang instanceof StubUserLang ) {
+                       $this->language = false;
+               } else {
+                       $type = gettype( $lang );
+                       throw new MWException( __METHOD__ . " must be "
+                               . "passed a String or Language object; $type given"
+                       );
+               }
+
+               if ( $this->language !== $previousLanguage ) {
+                       // The language has changed. Clear the message cache.
+                       $this->message = null;
+               }
+               $this->interface = false;
+               return $this;
+       }
+
+       /**
+        * Request the message in the wiki's content language,
+        * unless it is disabled for this message.
+        *
+        * @since 1.17
+        * @see $wgForceUIMsgAsContentMsg
+        *
+        * @return Message $this
+        */
+       public function inContentLanguage() {
+               global $wgForceUIMsgAsContentMsg;
+               if ( in_array( $this->key, (array)$wgForceUIMsgAsContentMsg ) ) {
+                       return $this;
+               }
+
+               $this->inLanguage( MediaWikiServices::getInstance()->getContentLanguage() );
+               return $this;
+       }
+
+       /**
+        * Allows manipulating the interface message flag directly.
+        * Can be used to restore the flag after setting a language.
+        *
+        * @since 1.20
+        *
+        * @param bool $interface
+        *
+        * @return Message $this
+        */
+       public function setInterfaceMessageFlag( $interface ) {
+               $this->interface = (bool)$interface;
+               return $this;
+       }
+
+       /**
+        * Enable or disable database use.
+        *
+        * @since 1.17
+        *
+        * @param bool $useDatabase
+        *
+        * @return Message $this
+        */
+       public function useDatabase( $useDatabase ) {
+               $this->useDatabase = (bool)$useDatabase;
+               $this->message = null;
+               return $this;
+       }
+
+       /**
+        * Set the Title object to use as context when transforming the message
+        *
+        * @since 1.18
+        *
+        * @param Title $title
+        *
+        * @return Message $this
+        */
+       public function title( $title ) {
+               $this->title = $title;
+               return $this;
+       }
+
+       /**
+        * Returns the message as a Content object.
+        *
+        * @return Content
+        */
+       public function content() {
+               if ( !$this->content ) {
+                       $this->content = new MessageContent( $this );
+               }
+
+               return $this->content;
+       }
+
+       /**
+        * Returns the message parsed from wikitext to HTML.
+        *
+        * @since 1.17
+        *
+        * @param string|null $format One of the FORMAT_* constants. Null means use whatever was used
+        *   the last time (this is for B/C and should be avoided).
+        *
+        * @return string HTML
+        * @suppress SecurityCheck-DoubleEscaped phan false positive
+        */
+       public function toString( $format = null ) {
+               if ( $format === null ) {
+                       $ex = new LogicException( __METHOD__ . ' using implicit format: ' . $this->format );
+                       \MediaWiki\Logger\LoggerFactory::getInstance( 'message-format' )->warning(
+                               $ex->getMessage(), [ 'exception' => $ex, 'format' => $this->format, 'key' => $this->key ] );
+                       $format = $this->format;
+               }
+               $string = $this->fetchMessage();
+
+               if ( $string === false ) {
+                       // Err on the side of safety, ensure that the output
+                       // is always html safe in the event the message key is
+                       // missing, since in that case its highly likely the
+                       // message key is user-controlled.
+                       // '⧼' is used instead of '<' to side-step any
+                       // double-escaping issues.
+                       // (Keep synchronised with mw.Message#toString in JS.)
+                       return '⧼' . htmlspecialchars( $this->key ) . '⧽';
+               }
+
+               # Replace $* with a list of parameters for &uselang=qqx.
+               if ( strpos( $string, '$*' ) !== false ) {
+                       $paramlist = '';
+                       if ( $this->parameters !== [] ) {
+                               $paramlist = ': $' . implode( ', $', range( 1, count( $this->parameters ) ) );
+                       }
+                       $string = str_replace( '$*', $paramlist, $string );
+               }
+
+               # Replace parameters before text parsing
+               $string = $this->replaceParameters( $string, 'before', $format );
+
+               # Maybe transform using the full parser
+               if ( $format === self::FORMAT_PARSE ) {
+                       $string = $this->parseText( $string );
+                       $string = Parser::stripOuterParagraph( $string );
+               } elseif ( $format === self::FORMAT_BLOCK_PARSE ) {
+                       $string = $this->parseText( $string );
+               } elseif ( $format === self::FORMAT_TEXT ) {
+                       $string = $this->transformText( $string );
+               } elseif ( $format === self::FORMAT_ESCAPED ) {
+                       $string = $this->transformText( $string );
+                       $string = htmlspecialchars( $string, ENT_QUOTES, 'UTF-8', false );
+               }
+
+               # Raw parameter replacement
+               $string = $this->replaceParameters( $string, 'after', $format );
+
+               return $string;
+       }
+
+       /**
+        * Magic method implementation of the above (for PHP >= 5.2.0), so we can do, eg:
+        *     $foo = new Message( $key );
+        *     $string = "<abbr>$foo</abbr>";
+        *
+        * @since 1.18
+        *
+        * @return string
+        */
+       public function __toString() {
+               // PHP doesn't allow __toString to throw exceptions and will
+               // trigger a fatal error if it does. So, catch any exceptions.
+
+               try {
+                       return $this->toString( self::FORMAT_PARSE );
+               } catch ( Exception $ex ) {
+                       try {
+                               trigger_error( "Exception caught in " . __METHOD__ . " (message " . $this->key . "): "
+                                       . $ex, E_USER_WARNING );
+                       } catch ( Exception $ex ) {
+                               // Doh! Cause a fatal error after all?
+                       }
+
+                       return '⧼' . htmlspecialchars( $this->key ) . '⧽';
+               }
+       }
+
+       /**
+        * Fully parse the text from wikitext to HTML.
+        *
+        * @since 1.17
+        *
+        * @return string Parsed HTML.
+        */
+       public function parse() {
+               $this->format = self::FORMAT_PARSE;
+               return $this->toString( self::FORMAT_PARSE );
+       }
+
+       /**
+        * Returns the message text. {{-transformation is done.
+        *
+        * @since 1.17
+        *
+        * @return string Unescaped message text.
+        */
+       public function text() {
+               $this->format = self::FORMAT_TEXT;
+               return $this->toString( self::FORMAT_TEXT );
+       }
+
+       /**
+        * Returns the message text as-is, only parameters are substituted.
+        *
+        * @since 1.17
+        *
+        * @return string Unescaped untransformed message text.
+        */
+       public function plain() {
+               $this->format = self::FORMAT_PLAIN;
+               return $this->toString( self::FORMAT_PLAIN );
+       }
+
+       /**
+        * Returns the parsed message text which is always surrounded by a block element.
+        *
+        * @since 1.17
+        *
+        * @return string HTML
+        */
+       public function parseAsBlock() {
+               $this->format = self::FORMAT_BLOCK_PARSE;
+               return $this->toString( self::FORMAT_BLOCK_PARSE );
+       }
+
+       /**
+        * Returns the message text. {{-transformation is done and the result
+        * is escaped excluding any raw parameters.
+        *
+        * @since 1.17
+        *
+        * @return string Escaped message text.
+        */
+       public function escaped() {
+               $this->format = self::FORMAT_ESCAPED;
+               return $this->toString( self::FORMAT_ESCAPED );
+       }
+
+       /**
+        * Check whether a message key has been defined currently.
+        *
+        * @since 1.17
+        *
+        * @return bool
+        */
+       public function exists() {
+               return $this->fetchMessage() !== false;
+       }
+
+       /**
+        * Check whether a message does not exist, or is an empty string
+        *
+        * @since 1.18
+        * @todo FIXME: Merge with isDisabled()?
+        *
+        * @return bool
+        */
+       public function isBlank() {
+               $message = $this->fetchMessage();
+               return $message === false || $message === '';
+       }
+
+       /**
+        * Check whether a message does not exist, is an empty string, or is "-".
+        *
+        * @since 1.18
+        *
+        * @return bool
+        */
+       public function isDisabled() {
+               $message = $this->fetchMessage();
+               return $message === false || $message === '' || $message === '-';
+       }
+
+       /**
+        * @since 1.17
+        *
+        * @param mixed $raw
+        *
+        * @return array Array with a single "raw" key.
+        */
+       public static function rawParam( $raw ) {
+               return [ 'raw' => $raw ];
+       }
+
+       /**
+        * @since 1.18
+        *
+        * @param mixed $num
+        *
+        * @return array Array with a single "num" key.
+        */
+       public static function numParam( $num ) {
+               return [ 'num' => $num ];
+       }
+
+       /**
+        * @since 1.22
+        *
+        * @param int $duration
+        *
+        * @return int[] Array with a single "duration" key.
+        */
+       public static function durationParam( $duration ) {
+               return [ 'duration' => $duration ];
+       }
+
+       /**
+        * @since 1.22
+        *
+        * @param string $expiry
+        *
+        * @return string[] Array with a single "expiry" key.
+        */
+       public static function expiryParam( $expiry ) {
+               return [ 'expiry' => $expiry ];
+       }
+
+       /**
+        * @since 1.22
+        *
+        * @param int $period
+        *
+        * @return int[] Array with a single "period" key.
+        */
+       public static function timeperiodParam( $period ) {
+               return [ 'period' => $period ];
+       }
+
+       /**
+        * @since 1.22
+        *
+        * @param int $size
+        *
+        * @return int[] Array with a single "size" key.
+        */
+       public static function sizeParam( $size ) {
+               return [ 'size' => $size ];
+       }
+
+       /**
+        * @since 1.22
+        *
+        * @param int $bitrate
+        *
+        * @return int[] Array with a single "bitrate" key.
+        */
+       public static function bitrateParam( $bitrate ) {
+               return [ 'bitrate' => $bitrate ];
+       }
+
+       /**
+        * @since 1.25
+        *
+        * @param string $plaintext
+        *
+        * @return string[] Array with a single "plaintext" key.
+        */
+       public static function plaintextParam( $plaintext ) {
+               return [ 'plaintext' => $plaintext ];
+       }
+
+       /**
+        * @since 1.29
+        *
+        * @param array $list
+        * @param string $type 'comma', 'semicolon', 'pipe', 'text'
+        * @return array Array with "list" and "type" keys.
+        */
+       public static function listParam( array $list, $type = 'text' ) {
+               if ( !isset( self::$listTypeMap[$type] ) ) {
+                       throw new InvalidArgumentException(
+                               "Invalid type '$type'. Known types are: " . implode( ', ', array_keys( self::$listTypeMap ) )
+                       );
+               }
+               return [ 'list' => $list, 'type' => $type ];
+       }
+
+       /**
+        * Substitutes any parameters into the message text.
+        *
+        * @since 1.17
+        *
+        * @param string $message The message text.
+        * @param string $type Either "before" or "after".
+        * @param string $format One of the FORMAT_* constants.
+        *
+        * @return string
+        */
+       protected function replaceParameters( $message, $type, $format ) {
+               // A temporary marker for $1 parameters that is only valid
+               // in non-attribute contexts. However if the entire message is escaped
+               // then we don't want to use it because it will be mangled in all contexts
+               // and its unnessary as ->escaped() messages aren't html.
+               $marker = $format === self::FORMAT_ESCAPED ? '$' : '$\'"';
+               $replacementKeys = [];
+               foreach ( $this->parameters as $n => $param ) {
+                       list( $paramType, $value ) = $this->extractParam( $param, $format );
+                       if ( $type === 'before' ) {
+                               if ( $paramType === 'before' ) {
+                                       $replacementKeys['$' . ( $n + 1 )] = $value;
+                               } else /* $paramType === 'after' */ {
+                                       // To protect against XSS from replacing parameters
+                                       // inside html attributes, we convert $1 to $'"1.
+                                       // In the event that one of the parameters ends up
+                                       // in an attribute, either the ' or the " will be
+                                       // escaped, breaking the replacement and avoiding XSS.
+                                       $replacementKeys['$' . ( $n + 1 )] = $marker . ( $n + 1 );
+                               }
+                       } elseif ( $paramType === 'after' ) {
+                               $replacementKeys[$marker . ( $n + 1 )] = $value;
+                       }
+               }
+               return strtr( $message, $replacementKeys );
+       }
+
+       /**
+        * Extracts the parameter type and preprocessed the value if needed.
+        *
+        * @since 1.18
+        *
+        * @param mixed $param Parameter as defined in this class.
+        * @param string $format One of the FORMAT_* constants.
+        *
+        * @return array Array with the parameter type (either "before" or "after") and the value.
+        */
+       protected function extractParam( $param, $format ) {
+               if ( is_array( $param ) ) {
+                       if ( isset( $param['raw'] ) ) {
+                               return [ 'after', $param['raw'] ];
+                       } elseif ( isset( $param['num'] ) ) {
+                               // Replace number params always in before step for now.
+                               // No support for combined raw and num params
+                               return [ 'before', $this->getLanguage()->formatNum( $param['num'] ) ];
+                       } elseif ( isset( $param['duration'] ) ) {
+                               return [ 'before', $this->getLanguage()->formatDuration( $param['duration'] ) ];
+                       } elseif ( isset( $param['expiry'] ) ) {
+                               return [ 'before', $this->getLanguage()->formatExpiry( $param['expiry'] ) ];
+                       } elseif ( isset( $param['period'] ) ) {
+                               return [ 'before', $this->getLanguage()->formatTimePeriod( $param['period'] ) ];
+                       } elseif ( isset( $param['size'] ) ) {
+                               return [ 'before', $this->getLanguage()->formatSize( $param['size'] ) ];
+                       } elseif ( isset( $param['bitrate'] ) ) {
+                               return [ 'before', $this->getLanguage()->formatBitrate( $param['bitrate'] ) ];
+                       } elseif ( isset( $param['plaintext'] ) ) {
+                               return [ 'after', $this->formatPlaintext( $param['plaintext'], $format ) ];
+                       } elseif ( isset( $param['list'] ) ) {
+                               return $this->formatListParam( $param['list'], $param['type'], $format );
+                       } else {
+                               if ( !is_scalar( $param ) ) {
+                                       $param = serialize( $param );
+                               }
+                               \MediaWiki\Logger\LoggerFactory::getInstance( 'Bug58676' )->warning(
+                                       'Invalid parameter for message "{msgkey}": {param}',
+                                       [
+                                               'exception' => new Exception,
+                                               'msgkey' => $this->getKey(),
+                                               'param' => htmlspecialchars( $param ),
+                                       ]
+                               );
+
+                               return [ 'before', '[INVALID]' ];
+                       }
+               } elseif ( $param instanceof Message ) {
+                       // Match language, flags, etc. to the current message.
+                       $msg = clone $param;
+                       if ( $msg->language !== $this->language || $msg->useDatabase !== $this->useDatabase ) {
+                               // Cache depends on these parameters
+                               $msg->message = null;
+                       }
+                       $msg->interface = $this->interface;
+                       $msg->language = $this->language;
+                       $msg->useDatabase = $this->useDatabase;
+                       $msg->title = $this->title;
+
+                       // DWIM
+                       if ( $format === 'block-parse' ) {
+                               $format = 'parse';
+                       }
+                       $msg->format = $format;
+
+                       // Message objects should not be before parameters because
+                       // then they'll get double escaped. If the message needs to be
+                       // escaped, it'll happen right here when we call toString().
+                       return [ 'after', $msg->toString( $format ) ];
+               } else {
+                       return [ 'before', $param ];
+               }
+       }
+
+       /**
+        * Wrapper for what ever method we use to parse wikitext.
+        *
+        * @since 1.17
+        *
+        * @param string $string Wikitext message contents.
+        *
+        * @return string Wikitext parsed into HTML.
+        */
+       protected function parseText( $string ) {
+               $out = MessageCache::singleton()->parse(
+                       $string,
+                       $this->title,
+                       /*linestart*/true,
+                       $this->interface,
+                       $this->getLanguage()
+               );
+
+               return $out instanceof ParserOutput
+                       ? $out->getText( [
+                               'enableSectionEditLinks' => false,
+                               // Wrapping messages in an extra <div> is probably not expected. If
+                               // they're outside the content area they probably shouldn't be
+                               // targeted by CSS that's targeting the parser output, and if
+                               // they're inside they already are from the outer div.
+                               'unwrap' => true,
+                       ] )
+                       : $out;
+       }
+
+       /**
+        * Wrapper for what ever method we use to {{-transform wikitext.
+        *
+        * @since 1.17
+        *
+        * @param string $string Wikitext message contents.
+        *
+        * @return string Wikitext with {{-constructs replaced with their values.
+        */
+       protected function transformText( $string ) {
+               return MessageCache::singleton()->transform(
+                       $string,
+                       $this->interface,
+                       $this->getLanguage(),
+                       $this->title
+               );
+       }
+
+       /**
+        * Wrapper for what ever method we use to get message contents.
+        *
+        * @since 1.17
+        *
+        * @return string
+        * @throws MWException If message key array is empty.
+        */
+       protected function fetchMessage() {
+               if ( $this->message === null ) {
+                       $cache = MessageCache::singleton();
+
+                       foreach ( $this->keysToTry as $key ) {
+                               $message = $cache->get( $key, $this->useDatabase, $this->getLanguage() );
+                               if ( $message !== false && $message !== '' ) {
+                                       break;
+                               }
+                       }
+
+                       // NOTE: The constructor makes sure keysToTry isn't empty,
+                       //       so we know that $key and $message are initialized.
+                       $this->key = $key;
+                       $this->message = $message;
+               }
+               return $this->message;
+       }
+
+       /**
+        * Formats a message parameter wrapped with 'plaintext'. Ensures that
+        * the entire string is displayed unchanged when displayed in the output
+        * format.
+        *
+        * @since 1.25
+        *
+        * @param string $plaintext String to ensure plaintext output of
+        * @param string $format One of the FORMAT_* constants.
+        *
+        * @return string Input plaintext encoded for output to $format
+        */
+       protected function formatPlaintext( $plaintext, $format ) {
+               switch ( $format ) {
+                       case self::FORMAT_TEXT:
+                       case self::FORMAT_PLAIN:
+                               return $plaintext;
+
+                       case self::FORMAT_PARSE:
+                       case self::FORMAT_BLOCK_PARSE:
+                       case self::FORMAT_ESCAPED:
+                       default:
+                               return htmlspecialchars( $plaintext, ENT_QUOTES );
+               }
+       }
+
+       /**
+        * Formats a list of parameters as a concatenated string.
+        * @since 1.29
+        * @param array $params
+        * @param string $listType
+        * @param string $format One of the FORMAT_* constants.
+        * @return array Array with the parameter type (either "before" or "after") and the value.
+        */
+       protected function formatListParam( array $params, $listType, $format ) {
+               if ( !isset( self::$listTypeMap[$listType] ) ) {
+                       $warning = 'Invalid list type for message "' . $this->getKey() . '": '
+                               . htmlspecialchars( $listType )
+                               . ' (params are ' . htmlspecialchars( serialize( $params ) ) . ')';
+                       trigger_error( $warning, E_USER_WARNING );
+                       $e = new Exception;
+                       wfDebugLog( 'Bug58676', $warning . "\n" . $e->getTraceAsString() );
+                       return [ 'before', '[INVALID]' ];
+               }
+               $func = self::$listTypeMap[$listType];
+
+               // Handle an empty list sensibly
+               if ( !$params ) {
+                       return [ 'before', $this->getLanguage()->$func( [] ) ];
+               }
+
+               // First, determine what kinds of list items we have
+               $types = [];
+               $vars = [];
+               $list = [];
+               foreach ( $params as $n => $p ) {
+                       list( $type, $value ) = $this->extractParam( $p, $format );
+                       $types[$type] = true;
+                       $list[] = $value;
+                       $vars[] = '$' . ( $n + 1 );
+               }
+
+               // Easy case: all are 'before' or 'after', so just join the
+               // values and use the same type.
+               if ( count( $types ) === 1 ) {
+                       return [ key( $types ), $this->getLanguage()->$func( $list ) ];
+               }
+
+               // Hard case: We need to process each value per its type, then
+               // return the concatenated values as 'after'. We handle this by turning
+               // the list into a RawMessage and processing that as a parameter.
+               $vars = $this->getLanguage()->$func( $vars );
+               return $this->extractParam( new RawMessage( $vars, $params ), $format );
+       }
+}
diff --git a/includes/language/MessageLocalizer.php b/includes/language/MessageLocalizer.php
new file mode 100644 (file)
index 0000000..9a1796b
--- /dev/null
@@ -0,0 +1,43 @@
+<?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
+ * @ingroup Language
+ */
+
+/**
+ * Interface for localizing messages in MediaWiki
+ *
+ * @since 1.30
+ * @ingroup Language
+ */
+interface MessageLocalizer {
+
+       /**
+        * This is the method for getting translated interface messages.
+        *
+        * @see https://www.mediawiki.org/wiki/Manual:Messages_API
+        * @see Message::__construct
+        *
+        * @param string|string[]|MessageSpecifier $key Message key, or array of keys,
+        *   or a MessageSpecifier.
+        * @param mixed $params,... Normal message parameters
+        * @return Message
+        */
+       public function msg( $key /*...*/ );
+
+}
index 0258878..a2202b6 100644 (file)
@@ -86,6 +86,8 @@ interface ILoadBalancer {
 
        /** @var int DB handle should have DBO_TRX disabled and the caller will leave it as such */
        const CONN_TRX_AUTOCOMMIT = 1;
+       /** @var int Return null on connection failure instead of throwing an exception */
+       const CONN_SILENCE_ERRORS = 2;
 
        /** @var string Manager of ILoadBalancer instances is running post-commit callbacks */
        const STAGE_POSTCOMMIT_CALLBACKS = 'stage-postcommit-callbacks';
@@ -148,10 +150,13 @@ interface ILoadBalancer {
        /**
         * Get the index of the reader connection, which may be a replica DB
         *
-        * This takes into account load ratios and lag times. It should
-        * always return a consistent index during a given invocation.
+        * This takes into account load ratios and lag times. It should return a consistent
+        * index during the life time of the load balancer. This initially checks replica DBs
+        * for connectivity to avoid returning an unusable server. This means that connections
+        * might be attempted by calling this method (usally one at the most but possibly more).
+        * Subsequent calls with the same $group will not need to make new connection attempts
+        * since the acquired connection for each group is preserved.
         *
-        * Side effect: opens connections to databases
         * @param string|bool $group Query group, or false for the generic group
         * @param string|bool $domain Domain ID, or false for the current domain
         * @throws DBError
@@ -224,8 +229,8 @@ interface ILoadBalancer {
         *
         * @note This method throws DBAccessError if ILoadBalancer::disable() was called
         *
-        * @throws DBError
-        * @return Database
+        * @throws DBError If any error occurs that prevents the yielding of a (live) IDatabase
+        * @return IDatabase|bool This returns false on failure if CONN_SILENCE_ERRORS is set
         */
        public function getConnection( $i, $groups = [], $domain = false, $flags = 0 );
 
@@ -300,31 +305,6 @@ interface ILoadBalancer {
         */
        public function getMaintenanceConnectionRef( $i, $groups = [], $domain = false, $flags = 0 );
 
-       /**
-        * Open a connection to the server given by the specified index
-        *
-        * The index must be an actual index into the array. If a connection to the server is
-        * already open and not considered an "in use" foreign connection, this simply returns it.
-        *
-        * Avoid using CONN_TRX_AUTOCOMMIT for databases with ATTR_DB_LEVEL_LOCKING (e.g. sqlite)
-        * in order to avoid deadlocks. ILoadBalancer::getServerAttributes() can be used to check
-        * such flags beforehand.
-        *
-        * If the caller uses $domain or sets CONN_TRX_AUTOCOMMIT in $flags, then it must
-        * also call ILoadBalancer::reuseConnection() on the handle when finished using it.
-        * In all other cases, this is not necessary, though not harmful either.
-        * Avoid the use of begin() or startAtomic() on any such connections.
-        *
-        * @note This method throws DBAccessError if ILoadBalancer::disable() was called
-        *
-        * @param int $i Server index (does not support DB_MASTER/DB_REPLICA)
-        * @param string|bool $domain Domain ID, or false for the current domain
-        * @param int $flags Bitfield of CONN_* class constants (e.g. CONN_TRX_AUTOCOMMIT)
-        * @return Database|bool Returns false on errors
-        * @throws DBAccessError
-        */
-       public function openConnection( $i, $domain = false, $flags = 0 );
-
        /**
         * @return int
         */
index 4787edc..62f4582 100644 (file)
@@ -107,7 +107,7 @@ class LoadBalancer implements ILoadBalancer {
        private $genericReadIndex = -1;
        /** @var int[] The group replica DB indexes keyed by group */
        private $readIndexByGroup = [];
-       /** @var bool|DBMasterPos False if not set */
+       /** @var bool|DBMasterPos Replication sync position or false if not set */
        private $waitForPos;
        /** @var bool Whether the generic reader fell back to a lagged replica DB */
        private $laggedReplicaMode = false;
@@ -270,6 +270,49 @@ class LoadBalancer implements ILoadBalancer {
        }
 
        /**
+        * @param int $flags
+        * @return bool
+        */
+       private function sanitizeConnectionFlags( $flags ) {
+               if ( ( $flags & self::CONN_TRX_AUTOCOMMIT ) === self::CONN_TRX_AUTOCOMMIT ) {
+                       // Assuming all servers are of the same type (or similar), which is overwhelmingly
+                       // the case, use the master server information to get the attributes. The information
+                       // for $i cannot be used since it might be DB_REPLICA, which might require connection
+                       // attempts in order to be resolved into a real server index.
+                       $attributes = $this->getServerAttributes( $this->getWriterIndex() );
+                       if ( $attributes[Database::ATTR_DB_LEVEL_LOCKING] ) {
+                               // Callers sometimes want to (a) escape REPEATABLE-READ stateness without locking
+                               // rows (e.g. FOR UPDATE) or (b) make small commits during a larger transactions
+                               // to reduce lock contention. None of these apply for sqlite and using separate
+                               // connections just causes self-deadlocks.
+                               $flags &= ~self::CONN_TRX_AUTOCOMMIT;
+                               $this->connLogger->info( __METHOD__ .
+                                       ': ignoring CONN_TRX_AUTOCOMMIT to avoid deadlocks.' );
+                       }
+               }
+
+               return $flags;
+       }
+
+       /**
+        * @param IDatabase $conn
+        * @param int $flags
+        * @throws DBUnexpectedError
+        */
+       private function enforceConnectionFlags( IDatabase $conn, $flags ) {
+               if ( ( $flags & self::CONN_TRX_AUTOCOMMIT ) == self::CONN_TRX_AUTOCOMMIT ) {
+                       if ( $conn->trxLevel() ) { // sanity
+                               throw new DBUnexpectedError(
+                                       $conn,
+                                       'Handle requested with CONN_TRX_AUTOCOMMIT yet it has a transaction'
+                               );
+                       }
+
+                       $conn->clearFlag( $conn::DBO_TRX ); // auto-commit mode
+               }
+       }
+
+               /**
         * Get a LoadMonitor instance
         *
         * @return ILoadMonitor
@@ -354,7 +397,7 @@ class LoadBalancer implements ILoadBalancer {
         * @param int $i
         * @param array $groups
         * @param string|bool $domain
-        * @return int
+        * @return int The index of a specific server (replica DBs are checked for connectivity)
         */
        private function getConnectionIndex( $i, $groups, $domain ) {
                // Check one "group" per default: the generic pool
@@ -364,9 +407,9 @@ class LoadBalancer implements ILoadBalancer {
                        ? $defaultGroups
                        : (array)$groups;
 
-               if ( $i == self::DB_MASTER ) {
+               if ( $i === self::DB_MASTER ) {
                        $i = $this->getWriterIndex();
-               } elseif ( $i == self::DB_REPLICA ) {
+               } elseif ( $i === self::DB_REPLICA ) {
                        # Try to find an available server in any the query groups (in order)
                        foreach ( $groups as $group ) {
                                $groupIndex = $this->getReaderIndex( $group, $domain );
@@ -378,7 +421,7 @@ class LoadBalancer implements ILoadBalancer {
                }
 
                # Operation-based index
-               if ( $i == self::DB_REPLICA ) {
+               if ( $i === self::DB_REPLICA ) {
                        $this->lastError = 'Unknown error'; // reset error string
                        # Try the general server pool if $groups are unavailable.
                        $i = ( $groups === [ false ] )
@@ -389,7 +432,7 @@ class LoadBalancer implements ILoadBalancer {
                                $this->lastError = 'No working replica DB server: ' . $this->lastError;
                                // Throw an exception
                                $this->reportConnectionError();
-                               return null; // not reached
+                               return null; // unreachable due to exception
                        }
                }
 
@@ -427,6 +470,7 @@ class LoadBalancer implements ILoadBalancer {
                $this->getLoadMonitor()->scaleLoads( $loads, $domain );
 
                // Pick a server to use, accounting for weights, load, lag, and "waitForPos"
+               $this->lazyLoadReplicationPositions(); // optimizes server candidate selection
                list( $i, $laggedReplicaMode ) = $this->pickReaderIndex( $loads, $domain );
                if ( $i === false ) {
                        // DB connection unsuccessful
@@ -510,6 +554,7 @@ class LoadBalancer implements ILoadBalancer {
                        } else {
                                $i = false;
                                if ( $this->waitForPos && $this->waitForPos->asOfTime() ) {
+                                       $this->replLogger->debug( __METHOD__ . ": replication positions detected" );
                                        // "chronologyCallback" sets "waitForPos" for session consistency.
                                        // This triggers doWait() after connect, so it's especially good to
                                        // avoid lagged servers so as to avoid excessive delay in that method.
@@ -542,7 +587,7 @@ class LoadBalancer implements ILoadBalancer {
                        $serverName = $this->getServerName( $i );
                        $this->connLogger->debug( __METHOD__ . ": Using reader #$i: $serverName..." );
 
-                       $conn = $this->openConnection( $i, $domain );
+                       $conn = $this->getConnection( $i, [], $domain, self::CONN_SILENCE_ERRORS );
                        if ( !$conn ) {
                                $this->connLogger->warning( __METHOD__ . ": Failed connecting to $i/$domain" );
                                unset( $currentLoads[$i] ); // avoid this server next iteration
@@ -714,20 +759,20 @@ class LoadBalancer implements ILoadBalancer {
                                );
 
                                return false;
-                       } else {
-                               $conn = $this->openConnection( $index, self::DOMAIN_ANY );
-                               if ( !$conn ) {
-                                       $this->replLogger->warning(
-                                               __METHOD__ . ': failed to connect to {dbserver}',
-                                               [ 'dbserver' => $server ]
-                                       );
+                       }
+                       // Open a temporary new connection in order to wait for replication
+                       $conn = $this->getConnection( $index, [], self::DOMAIN_ANY, self::CONN_SILENCE_ERRORS );
+                       if ( !$conn ) {
+                               $this->replLogger->warning(
+                                       __METHOD__ . ': failed to connect to {dbserver}',
+                                       [ 'dbserver' => $server ]
+                               );
 
-                                       return false;
-                               }
-                               // Avoid connection spam in waitForAll() when connections
-                               // are made just for the sake of doing this lag check.
-                               $close = true;
+                               return false;
                        }
+                       // Avoid connection spam in waitForAll() when connections
+                       // are made just for the sake of doing this lag check.
+                       $close = true;
                }
 
                $this->replLogger->info(
@@ -773,39 +818,32 @@ class LoadBalancer implements ILoadBalancer {
        }
 
        public function getConnection( $i, $groups = [], $domain = false, $flags = 0 ) {
-               if ( $i === null || $i === false ) {
+               if ( !is_int( $i ) ) {
                        throw new InvalidArgumentException( "Cannot connect without a server index" );
+               } elseif ( $groups && $i > 0 ) {
+                       throw new InvalidArgumentException( "Got query groups with server index #$i" );
                }
 
                $domain = $this->resolveDomainID( $domain );
+               $flags = $this->sanitizeConnectionFlags( $flags );
                $masterOnly = ( $i == self::DB_MASTER || $i == $this->getWriterIndex() );
 
-               if ( ( $flags & self::CONN_TRX_AUTOCOMMIT ) === self::CONN_TRX_AUTOCOMMIT ) {
-                       // Assuming all servers are of the same type (or similar), which is overwhelmingly
-                       // the case, use the master server information to get the attributes. The information
-                       // for $i cannot be used since it might be DB_REPLICA, which might require connection
-                       // attempts in order to be resolved into a real server index.
-                       $attributes = $this->getServerAttributes( $this->getWriterIndex() );
-                       if ( $attributes[Database::ATTR_DB_LEVEL_LOCKING] ) {
-                               // Callers sometimes want to (a) escape REPEATABLE-READ stateness without locking
-                               // rows (e.g. FOR UPDATE) or (b) make small commits during a larger transactions
-                               // to reduce lock contention. None of these apply for sqlite and using separate
-                               // connections just causes self-deadlocks.
-                               $flags &= ~self::CONN_TRX_AUTOCOMMIT;
-                               $this->connLogger->info( __METHOD__ .
-                                       ': ignoring CONN_TRX_AUTOCOMMIT to avoid deadlocks.' );
-                       }
-               }
-
                // Number of connections made before getting the server index and handle
                $priorConnectionsMade = $this->connsOpened;
-               // Decide which server to use (might trigger new connections)
+
+               // Choose a server if $i is DB_MASTER/DB_REPLICA (might trigger new connections)
                $serverIndex = $this->getConnectionIndex( $i, $groups, $domain );
                // Get an open connection to that server (might trigger a new connection)
-               $conn = $this->openConnection( $serverIndex, $domain, $flags );
-               if ( !$conn ) {
-                       $this->reportConnectionError();
-                       return null; // unreachable due to exception
+               $conn = $this->localDomain->equals( $domain )
+                       ? $this->getLocalConnection( $serverIndex, $flags )
+                       : $this->getForeignConnection( $serverIndex, $domain, $flags );
+               // Throw an error or bail out if the connection attempt failed
+               if ( !( $conn instanceof IDatabase ) ) {
+                       if ( ( $flags & self::CONN_SILENCE_ERRORS ) != self::CONN_SILENCE_ERRORS ) {
+                               $this->reportConnectionError();
+                       }
+
+                       return false;
                }
 
                // Profile any new connections caused by this method
@@ -815,6 +853,15 @@ class LoadBalancer implements ILoadBalancer {
                        $this->trxProfiler->recordConnection( $host, $dbname, $masterOnly );
                }
 
+               if ( !$conn->isOpen() ) {
+                       // Connection was made but later unrecoverably lost for some reason.
+                       // Do not return a handle that will just throw exceptions on use,
+                       // but let the calling code (e.g. getReaderIndex) try another server.
+                       $this->errorConnection = $conn;
+                       return false;
+               }
+
+               $this->enforceConnectionFlags( $conn, $flags );
                if ( $serverIndex == $this->getWriterIndex() ) {
                        // If the load balancer is read-only, perhaps due to replication lag, then master
                        // DB handles will reflect that. Note that Database::assertIsWritableMaster() takes
@@ -917,43 +964,15 @@ class LoadBalancer implements ILoadBalancer {
                        : self::DB_REPLICA;
        }
 
+       /**
+        * @param int $i
+        * @param bool $domain
+        * @param int $flags
+        * @return Database|bool Live database handle or false on failure
+        * @deprecated Since 1.34 Use getConnection() instead
+        */
        public function openConnection( $i, $domain = false, $flags = 0 ) {
-               $domain = $this->resolveDomainID( $domain );
-
-               if ( !$this->connectionAttempted && $this->chronologyCallback ) {
-                       // Load any "waitFor" positions before connecting so that doWait() is triggered
-                       $this->connLogger->debug( __METHOD__ . ': calling initLB() before first connection.' );
-                       $this->connectionAttempted = true;
-                       ( $this->chronologyCallback )( $this );
-               }
-
-               $conn = $this->localDomain->equals( $domain )
-                       ? $this->openLocalConnection( $i, $flags )
-                       : $this->openForeignConnection( $i, $domain, $flags );
-
-               if ( $conn instanceof IDatabase && !$conn->isOpen() ) {
-                       // Connection was made but later unrecoverably lost for some reason.
-                       // Do not return a handle that will just throw exceptions on use,
-                       // but let the calling code (e.g. getReaderIndex) try another server.
-                       $this->errorConnection = $conn;
-                       $conn = false;
-               }
-
-               if (
-                       $conn instanceof IDatabase &&
-                       ( ( $flags & self::CONN_TRX_AUTOCOMMIT ) == self::CONN_TRX_AUTOCOMMIT )
-               ) {
-                       if ( $conn->trxLevel() ) { // sanity
-                               throw new DBUnexpectedError(
-                                       $conn,
-                                       'Handle requested with CONN_TRX_AUTOCOMMIT yet it has a transaction'
-                               );
-                       }
-
-                       $conn->clearFlag( $conn::DBO_TRX ); // auto-commit mode
-               }
-
-               return $conn;
+               return $this->getConnection( $i, [], $domain, $flags | self::CONN_SILENCE_ERRORS );
        }
 
        /**
@@ -968,7 +987,7 @@ class LoadBalancer implements ILoadBalancer {
         * @param int $flags Class CONN_* constant bitfield
         * @return Database
         */
-       private function openLocalConnection( $i, $flags = 0 ) {
+       private function getLocalConnection( $i, $flags = 0 ) {
                // Connection handles required to be in auto-commit mode use a separate connection
                // pool since the main pool is effected by implicit and explicit transaction rounds
                $autoCommit = ( ( $flags & self::CONN_TRX_AUTOCOMMIT ) == self::CONN_TRX_AUTOCOMMIT );
@@ -1033,7 +1052,7 @@ class LoadBalancer implements ILoadBalancer {
         * @return Database|bool Returns false on connection error
         * @throws DBError When database selection fails
         */
-       private function openForeignConnection( $i, $domain, $flags = 0 ) {
+       private function getForeignConnection( $i, $domain, $flags = 0 ) {
                $domainInstance = DatabaseDomain::newFromId( $domain );
                // Connection handles required to be in auto-commit mode use a separate connection
                // pool since the main pool is effected by implicit and explicit transaction rounds
@@ -1235,9 +1254,22 @@ class LoadBalancer implements ILoadBalancer {
                        }
                }
 
+               $this->lazyLoadReplicationPositions(); // session consistency
+
                return $db;
        }
 
+       /**
+        * Make sure that any "waitForPos" positions are loaded and available to doWait()
+        */
+       private function lazyLoadReplicationPositions() {
+               if ( !$this->connectionAttempted && $this->chronologyCallback ) {
+                       $this->connectionAttempted = true;
+                       ( $this->chronologyCallback )( $this ); // generally calls waitFor()
+                       $this->connLogger->debug( __METHOD__ . ': executed chronology callback.' );
+               }
+       }
+
        /**
         * @throws DBConnectionError
         */
@@ -1944,11 +1976,12 @@ class LoadBalancer implements ILoadBalancer {
 
                if ( !$pos ) {
                        // Get the current master position, opening a connection if needed
-                       $masterConn = $this->getAnyOpenConnection( $this->getWriterIndex() );
+                       $index = $this->getWriterIndex();
+                       $masterConn = $this->getAnyOpenConnection( $index );
                        if ( $masterConn ) {
                                $pos = $masterConn->getMasterPos();
                        } else {
-                               $masterConn = $this->openConnection( $this->getWriterIndex(), self::DOMAIN_ANY );
+                               $masterConn = $this->getConnection( $index, [], self::DOMAIN_ANY, self::CONN_SILENCE_ERRORS );
                                if ( !$masterConn ) {
                                        throw new DBReplicationWaitError(
                                                null,
index 180baed..aa1e9b2 100644 (file)
@@ -154,12 +154,12 @@ class LoadMonitor implements ILoadMonitor {
 
                        # Handles with open transactions are avoided since they might be subject
                        # to REPEATABLE-READ snapshots, which could affect the lag estimate query.
-                       $flags = ILoadBalancer::CONN_TRX_AUTOCOMMIT;
+                       $flags = ILoadBalancer::CONN_TRX_AUTOCOMMIT | ILoadBalancer::CONN_SILENCE_ERRORS;
                        $conn = $this->parent->getAnyOpenConnection( $i, $flags );
                        if ( $conn ) {
                                $close = false; // already open
                        } else {
-                               $conn = $this->parent->openConnection( $i, ILoadBalancer::DOMAIN_ANY, $flags );
+                               $conn = $this->parent->getConnection( $i, [], ILoadBalancer::DOMAIN_ANY, $flags );
                                $close = true; // new connection
                        }
 
index 6061fb5..7f2f85f 100644 (file)
@@ -303,7 +303,7 @@ JAVASCRIPT;
 
                // Async scripts. Once the startup is loaded, inline RLQ scripts will run.
                // Pass-through a custom 'target' from OutputPage (T143066).
-               $startupQuery = [];
+               $startupQuery = [ 'raw' => '1' ];
                foreach ( [ 'target', 'safemode' ] as $param ) {
                        if ( $this->options[$param] !== null ) {
                                $startupQuery[$param] = (string)$this->options[$param];
index 4ce4498..b90b618 100644 (file)
@@ -352,6 +352,7 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
         * @private For internal use by SpecialJavaScriptTest
         * @since 1.32
         * @return array
+        * @codeCoverageIgnore
         */
        public function getBaseModulesInternal() {
                return $this->getBaseModules();
@@ -452,11 +453,4 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
                // and hash it to determine the version (as used by E-Tag HTTP response header).
                return true;
        }
-
-       /**
-        * @return string
-        */
-       public function getGroup() {
-               return 'startup';
-       }
 }
index c984af8..3e9676c 100644 (file)
@@ -174,7 +174,7 @@ JAVASCRIPT
                // load before qunit/export.
                $scripts = $out->makeResourceLoaderLink( 'jquery.qunit',
                        ResourceLoaderModule::TYPE_SCRIPTS,
-                       [ 'raw' => true, 'sync' => true ]
+                       [ 'raw' => '1', 'sync' => '1' ]
                );
 
                $head = implode( "\n", [ $styles, $scripts ] );
diff --git a/languages/LanguageCode.php b/languages/LanguageCode.php
deleted file mode 100644 (file)
index 7d954d3..0000000
+++ /dev/null
@@ -1,204 +0,0 @@
-<?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
- * @ingroup Language
- */
-
-/**
- * Methods for dealing with language codes.
- * @todo Move some of the code-related static methods out of Language into this class
- *
- * @since 1.29
- * @ingroup Language
- */
-class LanguageCode {
-       /**
-        * Mapping of deprecated language codes that were used in previous
-        * versions of MediaWiki to up-to-date, current language codes.
-        * These may or may not be valid BCP 47 codes; they are included here
-        * because MediaWiki renamed these particular codes at some point.
-        *
-        * @var array Mapping from deprecated MediaWiki-internal language code
-        *   to replacement MediaWiki-internal language code.
-        *
-        * @since 1.30
-        * @see https://meta.wikimedia.org/wiki/Special_language_codes
-        */
-       private static $deprecatedLanguageCodeMapping = [
-               // Note that als is actually a valid ISO 639 code (Tosk Albanian), but it
-               // was previously used in MediaWiki for Alsatian, which comes under gsw
-               'als' => 'gsw', // T25215
-               'bat-smg' => 'sgs', // T27522
-               'be-x-old' => 'be-tarask', // T11823
-               'fiu-vro' => 'vro', // T31186
-               'roa-rup' => 'rup', // T17988
-               'zh-classical' => 'lzh', // T30443
-               'zh-min-nan' => 'nan', // T30442
-               'zh-yue' => 'yue', // T30441
-       ];
-
-       /**
-        * Mapping of non-standard language codes used in MediaWiki to
-        * standardized BCP 47 codes.  These are not deprecated (yet?):
-        * IANA may eventually recognize the subtag, in which case the `-x-`
-        * infix could be removed, or else we could rename the code in
-        * MediaWiki, in which case they'd move up to the above mapping
-        * of deprecated codes.
-        *
-        * As a rule, we preserve all distinctions made by MediaWiki
-        * internally.  For example, `de-formal` becomes `de-x-formal`
-        * instead of just `de` because MediaWiki distinguishes `de-formal`
-        * from `de` (for example, for interface translations).  Similarly,
-        * BCP 47 indicates that `kk-Cyrl` SHOULD not be used because it
-        * "typically does not add information", but in our case MediaWiki
-        * LanguageConverter distinguishes `kk` (render content in a mix of
-        * Kurdish variants) from `kk-Cyrl` (convert content to be uniformly
-        * Cyrillic).  As the BCP 47 requirement is a SHOULD not a MUST,
-        * `kk-Cyrl` is a valid code, although some validators may emit
-        * a warning note.
-        *
-        * @var array Mapping from nonstandard MediaWiki-internal codes to
-        *   BCP 47 codes
-        *
-        * @since 1.32
-        * @see https://meta.wikimedia.org/wiki/Special_language_codes
-        * @see https://phabricator.wikimedia.org/T125073
-        */
-       private static $nonstandardLanguageCodeMapping = [
-               // All codes returned by Language::fetchLanguageNames() validated
-               // against IANA registry at
-               //   https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry
-               // with help of validator at
-               //   http://schneegans.de/lv/
-               'cbk-zam' => 'cbk', // T124657
-               'de-formal' => 'de-x-formal',
-               'eml' => 'egl', // T36217
-               'en-rtl' => 'en-x-rtl',
-               'es-formal' => 'es-x-formal',
-               'hu-formal' => 'hu-x-formal',
-               'map-bms' => 'jv-x-bms', // [[en:Banyumasan_dialect]] T125073
-               'mo' => 'ro-Cyrl-MD', // T125073
-               'nrm' => 'nrf', // [[en:Norman_language]] T25216
-               'nl-informal' => 'nl-x-informal',
-               'roa-tara' => 'nap-x-tara', // [[en:Tarantino_dialect]]
-               'simple' => 'en-simple',
-               'sr-ec' => 'sr-Cyrl', // T117845
-               'sr-el' => 'sr-Latn', // T117845
-
-               // Although these next codes aren't *wrong* per se, including
-               // both the script and the country code helps compatibility with
-               // other BCP 47 users. Note that MW also uses `zh-Hans`/`zh-Hant`,
-               // without a country code, and those should be left alone.
-               // (See $variantfallbacks in LanguageZh.php for Hans/Hant id.)
-               'zh-cn' => 'zh-Hans-CN',
-               'zh-sg' => 'zh-Hans-SG',
-               'zh-my' => 'zh-Hans-MY',
-               'zh-tw' => 'zh-Hant-TW',
-               'zh-hk' => 'zh-Hant-HK',
-               'zh-mo' => 'zh-Hant-MO',
-       ];
-
-       /**
-        * Returns a mapping of deprecated language codes that were used in previous
-        * versions of MediaWiki to up-to-date, current language codes.
-        *
-        * This array is merged into $wgDummyLanguageCodes in Setup.php, along with
-        * the fake language codes 'qqq' and 'qqx', which are used internally by
-        * MediaWiki's localisation system.
-        *
-        * @return string[]
-        *
-        * @since 1.29
-        */
-       public static function getDeprecatedCodeMapping() {
-               return self::$deprecatedLanguageCodeMapping;
-       }
-
-       /**
-        * Returns a mapping of non-standard language codes used by
-        * (current and previous version of) MediaWiki, mapped to standard
-        * BCP 47 names.
-        *
-        * This array is exported to JavaScript to ensure
-        * mediawiki.language.bcp47 stays in sync with LanguageCode::bcp47().
-        *
-        * @return string[]
-        *
-        * @since 1.32
-        */
-       public static function getNonstandardLanguageCodeMapping() {
-               $result = [];
-               foreach ( self::$deprecatedLanguageCodeMapping as $code => $ignore ) {
-                       $result[$code] = self::bcp47( $code );
-               }
-               foreach ( self::$nonstandardLanguageCodeMapping as $code => $ignore ) {
-                       $result[$code] = self::bcp47( $code );
-               }
-               return $result;
-       }
-
-       /**
-        * Replace deprecated language codes that were used in previous
-        * versions of MediaWiki to up-to-date, current language codes.
-        * Other values will returned unchanged.
-        *
-        * @param string $code Old language code
-        * @return string New language code
-        *
-        * @since 1.30
-        */
-       public static function replaceDeprecatedCodes( $code ) {
-               return self::$deprecatedLanguageCodeMapping[$code] ?? $code;
-       }
-
-       /**
-        * Get the normalised IETF language tag
-        * See unit test for examples.
-        * See mediawiki.language.bcp47 for the JavaScript implementation.
-        *
-        * @param string $code The language code.
-        * @return string A language code complying with BCP 47 standards.
-        *
-        * @since 1.31
-        */
-       public static function bcp47( $code ) {
-               $code = self::replaceDeprecatedCodes( strtolower( $code ) );
-               if ( isset( self::$nonstandardLanguageCodeMapping[$code] ) ) {
-                       $code = self::$nonstandardLanguageCodeMapping[$code];
-               }
-               $codeSegment = explode( '-', $code );
-               $codeBCP = [];
-               foreach ( $codeSegment as $segNo => $seg ) {
-                       // when previous segment is x, it is a private segment and should be lc
-                       if ( $segNo > 0 && strtolower( $codeSegment[( $segNo - 1 )] ) == 'x' ) {
-                               $codeBCP[$segNo] = strtolower( $seg );
-                       // ISO 3166 country code
-                       } elseif ( ( strlen( $seg ) == 2 ) && ( $segNo > 0 ) ) {
-                               $codeBCP[$segNo] = strtoupper( $seg );
-                       // ISO 15924 script code
-                       } elseif ( ( strlen( $seg ) == 4 ) && ( $segNo > 0 ) ) {
-                               $codeBCP[$segNo] = ucfirst( strtolower( $seg ) );
-                       // Use lowercase for other cases
-                       } else {
-                               $codeBCP[$segNo] = strtolower( $seg );
-                       }
-               }
-               $langCode = implode( '-', $codeBCP );
-               return $langCode;
-       }
-}
diff --git a/languages/MessageLocalizer.php b/languages/MessageLocalizer.php
deleted file mode 100644 (file)
index 9a1796b..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-<?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
- * @ingroup Language
- */
-
-/**
- * Interface for localizing messages in MediaWiki
- *
- * @since 1.30
- * @ingroup Language
- */
-interface MessageLocalizer {
-
-       /**
-        * This is the method for getting translated interface messages.
-        *
-        * @see https://www.mediawiki.org/wiki/Manual:Messages_API
-        * @see Message::__construct
-        *
-        * @param string|string[]|MessageSpecifier $key Message key, or array of keys,
-        *   or a MessageSpecifier.
-        * @param mixed $params,... Normal message parameters
-        * @return Message
-        */
-       public function msg( $key /*...*/ );
-
-}
index 03a3e24..408a0a2 100644 (file)
@@ -118,7 +118,7 @@ Deprecation message.' ]
                        . '});</script>' . "\n"
                        . '<link rel="stylesheet" href="/w/load.php?lang=nl&amp;modules=test.styles.deprecated%2Cpure&amp;only=styles"/>' . "\n"
                        . '<style>.private{}</style>' . "\n"
-                       . '<script async="" src="/w/load.php?lang=nl&amp;modules=startup&amp;only=scripts"></script>';
+                       . '<script async="" src="/w/load.php?lang=nl&amp;modules=startup&amp;only=scripts&amp;raw=1"></script>';
                // phpcs:enable
                $expected = self::expandVariables( $expected );
 
@@ -136,7 +136,7 @@ Deprecation message.' ]
 
                // phpcs:disable Generic.Files.LineLength
                $expected = '<script>document.documentElement.className=document.documentElement.className.replace(/(^|\s)client-nojs(\s|$)/,"$1client-js$2");</script>' . "\n"
-                       . '<script async="" src="/w/load.php?lang=nl&amp;modules=startup&amp;only=scripts&amp;target=example"></script>';
+                       . '<script async="" src="/w/load.php?lang=nl&amp;modules=startup&amp;only=scripts&amp;raw=1&amp;target=example"></script>';
                // phpcs:enable
 
                $this->assertSame( $expected, (string)$client->getHeadHtml() );
@@ -153,7 +153,7 @@ Deprecation message.' ]
 
                // phpcs:disable Generic.Files.LineLength
                $expected = '<script>document.documentElement.className=document.documentElement.className.replace(/(^|\s)client-nojs(\s|$)/,"$1client-js$2");</script>' . "\n"
-                       . '<script async="" src="/w/load.php?lang=nl&amp;modules=startup&amp;only=scripts&amp;safemode=1"></script>';
+                       . '<script async="" src="/w/load.php?lang=nl&amp;modules=startup&amp;only=scripts&amp;raw=1&amp;safemode=1"></script>';
                // phpcs:enable
 
                $this->assertSame( $expected, (string)$client->getHeadHtml() );
@@ -170,7 +170,7 @@ Deprecation message.' ]
 
                // phpcs:disable Generic.Files.LineLength
                $expected = '<script>document.documentElement.className=document.documentElement.className.replace(/(^|\s)client-nojs(\s|$)/,"$1client-js$2");</script>' . "\n"
-                       . '<script async="" src="/w/load.php?lang=nl&amp;modules=startup&amp;only=scripts"></script>';
+                       . '<script async="" src="/w/load.php?lang=nl&amp;modules=startup&amp;only=scripts&amp;raw=1"></script>';
                // phpcs:enable
 
                $this->assertSame( $expected, (string)$client->getHeadHtml() );
@@ -224,18 +224,18 @@ Deprecation message.' ]
                        ],
                        [
                                'context' => [],
-                               // Eg. startup module
-                               'modules' => [ 'test.scripts.raw' ],
+                               'modules' => [ 'test.scripts' ],
                                'only' => ResourceLoaderModule::TYPE_SCRIPTS,
-                               'extra' => [],
-                               'output' => '<script async="" src="/w/load.php?lang=nl&amp;modules=test.scripts.raw&amp;only=scripts"></script>',
+                               // Eg. startup module
+                               'extra' => [ 'raw' => '1' ],
+                               'output' => '<script async="" src="/w/load.php?lang=nl&amp;modules=test.scripts&amp;only=scripts&amp;raw=1"></script>',
                        ],
                        [
                                'context' => [],
-                               'modules' => [ 'test.scripts.raw' ],
+                               'modules' => [ 'test.scripts' ],
                                'only' => ResourceLoaderModule::TYPE_SCRIPTS,
-                               'extra' => [ 'sync' => '1' ],
-                               'output' => '<script src="/w/load.php?lang=nl&amp;modules=test.scripts.raw&amp;only=scripts&amp;sync=1"></script>',
+                               'extra' => [ 'raw' => '1', 'sync' => '1' ],
+                               'output' => '<script src="/w/load.php?lang=nl&amp;modules=test.scripts&amp;only=scripts&amp;raw=1&amp;sync=1"></script>',
                        ],
                        [
                                'context' => [],
@@ -418,7 +418,6 @@ Deprecation message.' ]
                        'test.scripts' => [],
                        'test.scripts.user' => [ 'group' => 'user' ],
                        'test.scripts.user.empty' => [ 'group' => 'user', 'isKnownEmpty' => true ],
-                       'test.scripts.raw' => [ 'isRaw' => true ],
                        'test.scripts.shouldembed' => [ 'shouldEmbed' => true ],
 
                        'test.ordering.a' => [ 'shouldEmbed' => false ],