);
$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',
];
--- /dev/null
+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.
--- /dev/null
+<?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;
+}
+
+}
--- /dev/null
+<?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;
+}
--- /dev/null
+<?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;
+}
+
+}
--- /dev/null
+<?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;
+}
'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',
'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',
'ResetUserTokens' => __DIR__ . '/maintenance/resetUserTokens.php',
'ResourceFileCache' => __DIR__ . '/includes/cache/ResourceFileCache.php',
'ResourceLoader' => __DIR__ . '/includes/resourceloader/ResourceLoader.php',
+ 'ResourceLoaderCircularDependencyError' => __DIR__ . '/includes/resourceloader/ResourceLoaderCircularDependencyError.php',
'ResourceLoaderClientHtml' => __DIR__ . '/includes/resourceloader/ResourceLoaderClientHtml.php',
'ResourceLoaderContext' => __DIR__ . '/includes/resourceloader/ResourceLoaderContext.php',
'ResourceLoaderFileModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderFileModule.php',
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;
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
);
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 );
}
}
}
- // 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 ];
}
/**
// Commit and close up!
$lbFactory->commitMasterChanges( __METHOD__ );
- $lbFactory->shutdown( LBFactory::SHUTDOWN_NO_CHRONPROT );
+ $lbFactory->shutdown( $lbFactory::SHUTDOWN_NO_CHRONPROT );
wfDebug( "Request ended normally\n" );
}
+++ /dev/null
-<?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 );
- }
-}
'$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'
--- /dev/null
+<?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;
+ }
+}
--- /dev/null
+<?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 );
+ }
+}
--- /dev/null
+<?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 /*...*/ );
+
+}
* Fetch a result row as an associative and numeric array
*
* @param resource $res Raw result
- * @return array
+ * @return array|false
*/
abstract protected function mysqlFetchArray( $res );
/**
* @param mysqli_result $res
- * @return bool
+ * @return array|false
*/
protected function mysqlFetchArray( $res ) {
$array = $res->fetch_array();
--- /dev/null
+<?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
+ */
+
+/**
+ * @internal For use by ResourceLoaderStartUpModule only
+ */
+class ResourceLoaderCircularDependencyError extends Exception {
+}
protected $origin = self::ORIGIN_CORE_SITEWIDE;
- /** @var ResourceLoaderImage[]|null */
+ /** @var ResourceLoaderImage[][]|null */
protected $imageObjects = null;
/** @var array */
protected $images = [];
*
* @param string $blob
* @param array $exclusions
- * @return array $blob
+ * @return object $blob
*/
protected function excludeMessagesFromBlob( $blob, $exclusions ) {
$data = json_decode( $blob, true );
*
* @param array $registryData
* @param string $moduleName
+ * @param string[] $handled Internal parameter for recursion. (Optional)
* @return array
+ * @throws ResourceLoaderCircularDependencyError
*/
- protected static function getImplicitDependencies( array $registryData, $moduleName ) {
+ protected static function getImplicitDependencies(
+ array $registryData,
+ $moduleName,
+ array $handled = []
+ ) {
static $dependencyCache = [];
- // The list of implicit dependencies won't be altered, so we can
- // cache them without having to worry.
+ // No modules will be added or changed server-side after this point,
+ // so we can safely cache parts of the tree for re-use.
if ( !isset( $dependencyCache[$moduleName] ) ) {
if ( !isset( $registryData[$moduleName] ) ) {
- // Dependencies may not exist
- $dependencyCache[$moduleName] = [];
+ // Unknown module names are allowed here, this is only an optimisation.
+ // Checks for illegal and unknown dependencies happen as PHPUnit structure tests,
+ // and also client-side at run-time.
+ $flat = [];
} else {
$data = $registryData[$moduleName];
- $dependencyCache[$moduleName] = $data['dependencies'];
+ $flat = $data['dependencies'];
+ // Prevent recursion
+ $handled[] = $moduleName;
foreach ( $data['dependencies'] as $dependency ) {
- // Recursively get the dependencies of the dependencies
- $dependencyCache[$moduleName] = array_merge(
- $dependencyCache[$moduleName],
- self::getImplicitDependencies( $registryData, $dependency )
- );
+ if ( in_array( $dependency, $handled, true ) ) {
+ // If we encounter a circular dependency, then stop the optimiser and leave the
+ // original dependencies array unmodified. Circular dependencies are not
+ // supported in ResourceLoader. Awareness of them exists here so that we can
+ // optimise the registry when it isn't broken, and otherwise transport the
+ // registry unchanged. The client will handle this further.
+ throw new ResourceLoaderCircularDependencyError();
+ } else {
+ // Recursively add the dependencies of the dependencies
+ $flat = array_merge(
+ $flat,
+ self::getImplicitDependencies( $registryData, $dependency, $handled )
+ );
+ }
}
}
+
+ $dependencyCache[$moduleName] = $flat;
}
return $dependencyCache[$moduleName];
public static function compileUnresolvedDependencies( array &$registryData ) {
foreach ( $registryData as $name => &$data ) {
$dependencies = $data['dependencies'];
- foreach ( $data['dependencies'] as $dependency ) {
- $implicitDependencies = self::getImplicitDependencies( $registryData, $dependency );
- $dependencies = array_diff( $dependencies, $implicitDependencies );
+ try {
+ foreach ( $data['dependencies'] as $dependency ) {
+ $implicitDependencies = self::getImplicitDependencies( $registryData, $dependency );
+ $dependencies = array_diff( $dependencies, $implicitDependencies );
+ }
+ } catch ( ResourceLoaderCircularDependencyError $err ) {
+ // Leave unchanged
+ $dependencies = $data['dependencies'];
}
+
// Rebuild keys
$data['dependencies'] = array_values( $dependencies );
}
* List all files in the stash.
*
* @throws UploadStashNotLoggedInException
- * @return array
+ * @return array|false
*/
public function listFiles() {
if ( !$this->isLoggedIn ) {
use MediaWiki\Auth\AuthenticationResponse;
use MediaWiki\MediaWikiServices;
use MediaWiki\Session\BotPasswordSessionProvider;
-use Wikimedia\Rdbms\IMaintainableDatabase;
+use Wikimedia\Rdbms\IDatabase;
/**
* Utility class for bot passwords
/**
* Get a database connection for the bot passwords database
* @param int $db Index of the connection to get, e.g. DB_MASTER or DB_REPLICA.
- * @return IMaintainableDatabase
+ * @return IDatabase
*/
public static function getDB( $db ) {
global $wgBotPasswordsCluster, $wgBotPasswordsDatabase;
+++ /dev/null
-<?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;
- }
-}
+++ /dev/null
-<?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 /*...*/ );
-
-}
"c",
"{blankVer}"
]
+] );',
+ ] ],
+ [ [
+ // Regression test for T223402.
+ 'msg' => 'Optimise the dependency tree (indirect circular dependency)',
+ 'modules' => [
+ 'top' => new ResourceLoaderTestModule( [ 'dependencies' => [ 'middle1', 'util' ] ] ),
+ 'middle1' => new ResourceLoaderTestModule( [ 'dependencies' => [ 'middle2', 'util' ] ] ),
+ 'middle2' => new ResourceLoaderTestModule( [ 'dependencies' => [ 'bottom' ] ] ),
+ 'bottom' => new ResourceLoaderTestModule( [ 'dependencies' => [ 'top' ] ] ),
+ 'util' => new ResourceLoaderTestModule( [ 'dependencies' => [] ] ),
+ ],
+ 'out' => '
+mw.loader.addSource( {
+ "local": "/w/load.php"
+} );
+mw.loader.register( [
+ [
+ "top",
+ "{blankVer}",
+ [
+ 1,
+ 4
+ ]
+ ],
+ [
+ "middle1",
+ "{blankVer}",
+ [
+ 2,
+ 4
+ ]
+ ],
+ [
+ "middle2",
+ "{blankVer}",
+ [
+ 3
+ ]
+ ],
+ [
+ "bottom",
+ "{blankVer}",
+ [
+ 0
+ ]
+ ],
+ [
+ "util",
+ "{blankVer}"
+ ]
+] );',
+ ] ],
+ [ [
+ // Regression test for T223402.
+ 'msg' => 'Optimise the dependency tree (direct circular dependency)',
+ 'modules' => [
+ 'top' => new ResourceLoaderTestModule( [ 'dependencies' => [ 'util', 'top' ] ] ),
+ 'util' => new ResourceLoaderTestModule( [ 'dependencies' => [] ] ),
+ ],
+ 'out' => '
+mw.loader.addSource( {
+ "local": "/w/load.php"
+} );
+mw.loader.register( [
+ [
+ "top",
+ "{blankVer}",
+ [
+ 1,
+ 0
+ ]
+ ],
+ [
+ "util",
+ "{blankVer}"
+ ]
] );',
] ],
[ [