Page MenuHomePhabricator

Action API returns incomplete error messages for blocks
Closed, ResolvedPublic

Description

Action API returns incomplete error messages for blocks, even when &errorformat=html&errorsuselocal=1 is specified.

As a result, various tools have been forced to add custom code to parse block messages using the action=parse API (at least the mobile editor and the mobile apps).

Note how in the responses below, the protectedpage error includes the full HTML error message, while the blocked error only includes a short message (and machine-readable, but not human-readable, details).

https://en.wikipedia.org/wiki/Special:ApiSandbox#action=query&format=json&errorformat=html&errorsuselocal=1&prop=info&titles=Test&formatversion=2&intestactions=edit&intestactionsdetail=full

{
    "batchcomplete": true,
    "query": {
        "pages": [
            {
                "pageid": 11089416,
                "ns": 0,
                "title": "Test",
                "contentmodel": "wikitext",
                "pagelanguage": "en",
                "pagelanguagehtmlcode": "en",
                "pagelanguagedir": "ltr",
                "touched": "2023-04-24T02:10:52Z",
                "lastrevid": 1143480404,
                "length": 2915,
                "actions": {
                    "edit": [
                        {
                            "code": "protectedpage",
                            "html": "<div class=\"mw-parser-output\">\n<div class=\"mw-parser-output\"><style data-mw-deduplicate=\"TemplateStyles:r1099782930\">.mw-parser-output .pptext-whywhat h2{margin-top:1em;border-bottom:0;font-size:130%;font-weight:bold;padding:0.15em}.mw-parser-output .pptext-submit{list-style:none;display:inline;text-align:center}.mw-parser-output .pptext-whywhat{display:flex;flex-wrap:wrap;column-gap:2em}.mw-parser-output .pptext-whywhat>div{flex:1 1 400px}</style><style data-mw-deduplicate=\"TemplateStyles:r1097275936\">.mw-parser-output .fmbox{clear:both;margin:0.2em 0;width:100%;border:1px solid #a2a9b1;background-color:#f8f9fa;box-sizing:border-box}.mw-parser-output .fmbox-warning{border:1px solid #bb7070;background-color:#ffdbdb}.mw-parser-output .fmbox-editnotice{background-color:transparent}.mw-parser-output .fmbox .mbox-text{border:none;padding:0.25em 0.9em;width:100%}.mw-parser-output .fmbox .mbox-image{border:none;padding:2px 0 2px 0.9em;text-align:center}.mw-parser-output .fmbox .mbox-imageright{border:none;padding:2px 0.9em 2px 0;text-align:center}.mw-parser-output .fmbox .mbox-invalid-type{text-align:center}</style><table id=\"mw-protectedpagetext\" class=\"plainlinks fmbox fmbox-system\" role=\"presentation\" style=\"border-style:none;\"><tbody><tr><td class=\"mbox-text\"><style data-mw-deduplicate=\"TemplateStyles:r1097619167\">.mw-parser-output .ombox{margin:4px 0;border-collapse:collapse;border:1px solid #a2a9b1;background-color:#f8f9fa;box-sizing:border-box}.mw-parser-output .ombox.mbox-small{font-size:88%;line-height:1.25em}.mw-parser-output .ombox-speedy{border:2px solid #b32424;background-color:#fee7e6}.mw-parser-output .ombox-delete{border:2px solid #b32424}.mw-parser-output .ombox-content{border:1px solid #f28500}.mw-parser-output .ombox-style{border:1px solid #fc3}.mw-parser-output .ombox-move{border:1px solid #9932cc}.mw-parser-output .ombox-protection{border:2px solid #a2a9b1}.mw-parser-output .ombox .mbox-text{border:none;padding:0.25em 0.9em;width:100%}.mw-parser-output .ombox .mbox-image{border:none;padding:2px 0 2px 0.9em;text-align:center}.mw-parser-output .ombox .mbox-imageright{border:none;padding:2px 0.9em 2px 0;text-align:center}.mw-parser-output .ombox .mbox-empty-cell{border:none;padding:0;width:1px}.mw-parser-output .ombox .mbox-invalid-type{text-align:center}@media(min-width:720px){.mw-parser-output .ombox{margin:4px 10%}.mw-parser-output .ombox.mbox-small{clear:right;float:right;margin:4px 0 4px 1em;width:238px}}</style><table class=\"plainlinks ombox ombox-protection\" role=\"presentation\"><tbody><tr><td class=\"mbox-image\"><img alt=\"\" src=\"//upload.wikimedia.org/wikipedia/en/thumb/1/1b/Semi-protection-shackle.svg/40px-Semi-protection-shackle.svg.png\" decoding=\"async\" width=\"40\" height=\"40\" srcset=\"//upload.wikimedia.org/wikipedia/en/thumb/1/1b/Semi-protection-shackle.svg/60px-Semi-protection-shackle.svg.png 1.5x, //upload.wikimedia.org/wikipedia/en/thumb/1/1b/Semi-protection-shackle.svg/80px-Semi-protection-shackle.svg.png 2x\" data-file-width=\"512\" data-file-height=\"512\" /></td><td class=\"mbox-text\" style=\"font-weight:bold; font-size:130%;\"><div style=\"text-align: center;\">This page is currently semi-protected so that only <a href=\"/wiki/Wikipedia:User_access_levels#Autoconfirmed\" title=\"Wikipedia:User access levels\">established</a>, <a href=\"/wiki/Wikipedia:Why_create_an_account%3F\" title=\"Wikipedia:Why create an account?\">registered users</a> can edit it.</div></td></tr></tbody></table>\n<div class=\"pptext-whywhat\">\n<div class=\"pptext-why\">\n<h2><span id=\"Why_is_the_page_protected.3F\"></span><span class=\"mw-headline\" id=\"Why_is_the_page_protected?\">Why is the page protected?</span></h2>\n<ul>\n<li>Some titles are <a href=\"/wiki/Wikipedia:Protected_titles\" class=\"mw-redirect\" title=\"Wikipedia:Protected titles\">permanently protected</a> from creation because they are deemed unsuitable for inclusion on Wikipedia, because they are <a href=\"/wiki/Wikipedia:Spam\" title=\"Wikipedia:Spam\">spam</a> or <a href=\"/wiki/Wikipedia:Vandalism\" title=\"Wikipedia:Vandalism\">vandalism</a>, or because they violate the <a href=\"/wiki/Wikipedia:Deletion_policy\" title=\"Wikipedia:Deletion policy\">deletion policy</a>. The reason for this may be recorded in the <a class=\"external text\" href=\"https://en.wikipedia.org/w/index.php?title=Special:Log/delete&amp;page=Special:Badtitle/ApiErrorFormatter::getDummyTitle\">deletion log</a>.</li>\n<li>The reason for protection can be found in the <a class=\"external text\" href=\"https://en.wikipedia.org/w/index.php?title=Special:Log&amp;type=protect&amp;page=ApiErrorFormatter%3A%3AgetDummyTitle\">protection log</a>. If there are no relevant entries in the protection log, the page may have been moved after being protected.\n</li>\n</ul>\n</div>\n<div class=\"pptext-what\">\n<h2><span id=\"What_can_I_do.3F\"></span><span class=\"mw-headline\" id=\"What_can_I_do?\">What can I do?</span></h2>\n<ul>\n<li>If you have a user account, <a href=\"/wiki/Special:UserLogin\" title=\"Special:UserLogin\">log in</a> first. If you do not yet have an account, you may <a class=\"external text\" href=\"https://en.wikipedia.org/w/index.php?title=Special:UserLogin&amp;type=signup&amp;campaign=semiprotectednotice\">create one</a>; after <a href=\"/wiki/Wikipedia:User_access_levels#Autoconfirmed_users\" title=\"Wikipedia:User access levels\">4 days and 10 edits</a>, you will be able to edit semi-protected pages.</li><li>If you believe this page was deleted in violation of the <a href=\"/wiki/Wikipedia:Deletion_policy\" title=\"Wikipedia:Deletion policy\">deletion policy</a>, then you may contact the <a class=\"external text\" href=\"https://en.wikipedia.org/w/index.php?title=Special:Log/delete&amp;page=Special:Badtitle/ApiErrorFormatter::getDummyTitle\">deleting administrator</a> or raise the matter of the deletion at <a href=\"/wiki/Wikipedia:Deletion_review\" title=\"Wikipedia:Deletion review\">deletion review</a>. Be sure to give an explanation as to why you think the page does not violate the deletion policy.</li>\n<li>If the page you are creating is a different topic than the previously deleted page, you may request this page be created. Please ask for help on the <a href=\"/wiki/Wikipedia:Administrators%27_noticeboard\" title=\"Wikipedia:Administrators&#39; noticeboard\">administrators' noticeboard</a> or by <span class=\"plainlinks\"><a class=\"external text\" href=\"https://en.wikipedia.org/wiki/Wikipedia:Requests_for_page_protection/Edit\">opening an edit request</a></span>, making sure to give a full reason why this page should be created. Be sure to specify the exact title (especially by <a href=\"/wiki/Help:Link\" title=\"Help:Link\">linking</a> it) of the page you are trying to create, and if it might be misunderstood (for example, an article with an unusual name), consider explaining briefly what you want to do.</li>\n<li>If you wrote any text, please save it temporarily to your device until you can create this page.</li>\n</ul>\n</div>\n</div></td></tr></tbody></table></div>\n</div>"
                        },
                        {
                            "code": "blocked",
                            "html": "You have been blocked from editing.",
                            "data": {
                                "blockinfo": {
                                    "blockid": null,
                                    "blockedby": "",
                                    "blockedbyid": 0,
                                    "blockreason": "There are multiple blocks against your account and/or IP address",
                                    "blockedtimestamp": "2023-04-24T21:07:01Z",
                                    "blockexpiry": "2028-04-22T18:29:58Z",
                                    "blockpartial": false,
                                    "blocknocreate": true,
                                    "blockanononly": false,
                                    "blockedtimestampformatted": "21:07, 24 April 2023",
                                    "blockexpiryformatted": "18:29, 22 April 2028",
                                    "blockexpiryrelative": "in 4 years"
                                }
                            }
                        }
                    ]
                }
            }
        ]
    }
}

https://en.wikipedia.org/wiki/Special:ApiSandbox#action=edit&format=json&errorformat=html&errorsuselocal=1&title=Test&text=test&token=%2B%5C&formatversion=2

{
    "errors": [
        {
            "code": "protectedpage",
            "html": "<div class=\"mw-parser-output\">\n<div class=\"mw-parser-output\"><style data-mw-deduplicate=\"TemplateStyles:r1099782930\">.mw-parser-output .pptext-whywhat h2{margin-top:1em;border-bottom:0;font-size:130%;font-weight:bold;padding:0.15em}.mw-parser-output .pptext-submit{list-style:none;display:inline;text-align:center}.mw-parser-output .pptext-whywhat{display:flex;flex-wrap:wrap;column-gap:2em}.mw-parser-output .pptext-whywhat>div{flex:1 1 400px}</style><style data-mw-deduplicate=\"TemplateStyles:r1097275936\">.mw-parser-output .fmbox{clear:both;margin:0.2em 0;width:100%;border:1px solid #a2a9b1;background-color:#f8f9fa;box-sizing:border-box}.mw-parser-output .fmbox-warning{border:1px solid #bb7070;background-color:#ffdbdb}.mw-parser-output .fmbox-editnotice{background-color:transparent}.mw-parser-output .fmbox .mbox-text{border:none;padding:0.25em 0.9em;width:100%}.mw-parser-output .fmbox .mbox-image{border:none;padding:2px 0 2px 0.9em;text-align:center}.mw-parser-output .fmbox .mbox-imageright{border:none;padding:2px 0.9em 2px 0;text-align:center}.mw-parser-output .fmbox .mbox-invalid-type{text-align:center}</style><table id=\"mw-protectedpagetext\" class=\"plainlinks fmbox fmbox-system\" role=\"presentation\" style=\"border-style:none;\"><tbody><tr><td class=\"mbox-text\"><style data-mw-deduplicate=\"TemplateStyles:r1097763485\">.mw-parser-output .ambox{border:1px solid #a2a9b1;border-left:10px solid #36c;background-color:#fbfbfb;box-sizing:border-box}.mw-parser-output .ambox+link+.ambox,.mw-parser-output .ambox+link+style+.ambox,.mw-parser-output .ambox+link+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+style+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+link+.ambox{margin-top:-1px}html body.mediawiki .mw-parser-output .ambox.mbox-small-left{margin:4px 1em 4px 0;overflow:hidden;width:238px;border-collapse:collapse;font-size:88%;line-height:1.25em}.mw-parser-output .ambox-speedy{border-left:10px solid #b32424;background-color:#fee7e6}.mw-parser-output .ambox-delete{border-left:10px solid #b32424}.mw-parser-output .ambox-content{border-left:10px solid #f28500}.mw-parser-output .ambox-style{border-left:10px solid #fc3}.mw-parser-output .ambox-move{border-left:10px solid #9932cc}.mw-parser-output .ambox-protection{border-left:10px solid #a2a9b1}.mw-parser-output .ambox .mbox-text{border:none;padding:0.25em 0.5em;width:100%}.mw-parser-output .ambox .mbox-image{border:none;padding:2px 0 2px 0.5em;text-align:center}.mw-parser-output .ambox .mbox-imageright{border:none;padding:2px 0.5em 2px 0;text-align:center}.mw-parser-output .ambox .mbox-empty-cell{border:none;padding:0;width:1px}.mw-parser-output .ambox .mbox-image-div{width:52px}html.client-js body.skin-minerva .mw-parser-output .mbox-text-span{margin-left:23px!important}@media(min-width:720px){.mw-parser-output .ambox{margin:0 10%}}</style><table class=\"plainlinks metadata ambox ambox-protection\" role=\"presentation\"><tbody><tr><td class=\"mbox-image\"><div class=\"mbox-image-div\"><img alt=\"\" src=\"//upload.wikimedia.org/wikipedia/en/thumb/1/1b/Semi-protection-shackle.svg/40px-Semi-protection-shackle.svg.png\" decoding=\"async\" width=\"40\" height=\"40\" srcset=\"//upload.wikimedia.org/wikipedia/en/thumb/1/1b/Semi-protection-shackle.svg/60px-Semi-protection-shackle.svg.png 1.5x, //upload.wikimedia.org/wikipedia/en/thumb/1/1b/Semi-protection-shackle.svg/80px-Semi-protection-shackle.svg.png 2x\" data-file-width=\"512\" data-file-height=\"512\" /></div></td><td class=\"mbox-text\" style=\"font-weight:bold; font-size:130%;\"><div class=\"mbox-text-span\"><div style=\"text-align: center;\">This page is currently semi-protected so that only <a href=\"/wiki/Wikipedia:User_access_levels#Autoconfirmed\" title=\"Wikipedia:User access levels\">established</a>, <a href=\"/wiki/Wikipedia:Why_create_an_account%3F\" title=\"Wikipedia:Why create an account?\">registered users</a> can edit it.</div></div></td></tr></tbody></table>\n<div class=\"pptext-whywhat\">\n<div class=\"pptext-why\">\n<h2><span id=\"Why_is_the_page_protected.3F\"></span><span class=\"mw-headline\" id=\"Why_is_the_page_protected?\">Why is the page protected?</span></h2>\n<ul>\n<li>While most articles can be edited by anyone, <a href=\"/wiki/Wikipedia:Protection_policy#Semi-protection\" title=\"Wikipedia:Protection policy\">semi-protection</a> is sometimes necessary to prevent <a href=\"/wiki/Wikipedia:Vandalism\" title=\"Wikipedia:Vandalism\">vandalism</a> to popular pages.</li>\n<li>The reason for protection can be found in the <a class=\"external text\" href=\"https://en.wikipedia.org/w/index.php?title=Special:Log&amp;type=protect&amp;page=Test\">protection log</a>. If there are no relevant entries in the protection log, the page may have been moved after being protected.\n</li>\n</ul>\n</div>\n<div class=\"pptext-what\">\n<h2><span id=\"What_can_I_do.3F\"></span><span class=\"mw-headline\" id=\"What_can_I_do?\">What can I do?</span></h2>\n<ul>\n<li>If you have a user account, <a href=\"/wiki/Special:UserLogin\" title=\"Special:UserLogin\">log in</a> first. If you do not yet have an account, you may <a class=\"external text\" href=\"https://en.wikipedia.org/w/index.php?title=Special:UserLogin&amp;type=signup&amp;campaign=semiprotectednotice\">create one</a>; after <a href=\"/wiki/Wikipedia:User_access_levels#Autoconfirmed_users\" title=\"Wikipedia:User access levels\">4 days and 10 edits</a>, you will be able to edit semi-protected pages.</li><li><a href=\"/wiki/Talk:Test\" title=\"Talk:Test\">Discuss this page</a> with others.</li>\n<li>For move-protected pages, see <a href=\"/wiki/Wikipedia:Requested_moves\" title=\"Wikipedia:Requested moves\">requested moves</a>.</li>\n<li><a href=\"/wiki/Wikipedia:Requests_for_page_protection#Current_requests_for_reduction_in_protection_level\" title=\"Wikipedia:Requests for page protection\">Request that the page's protection level be reduced</a>.</li>\n<li><a href=\"/wiki/Help:Introduction\" title=\"Help:Introduction\">Find out more about how to get started editing Wikipedia</a>.</li>\n<li>If you have noticed an error or have a suggestion for a simple, non-controversial change, you can submit an edit request by clicking the button below and following the instructions. An <a href=\"/wiki/Wikipedia:User_access_levels#Autoconfirmed_users\" title=\"Wikipedia:User access levels\">established user</a> may then make the change on your behalf. Please check <a href=\"/wiki/Talk:Test\" title=\"Talk:Test\">the talk page</a> first in case the issue is already being discussed.</li>\n<li class=\"pptext-submit\"><div>\n<p><span class=\"plainlinks clickbutton\"><a class=\"external text\" href=\"https://en.wikipedia.org/w/index.php?title=Talk%3ATest&amp;preload=Template%3ASubmit+an+edit+request%2Fpreload&amp;action=edit&amp;section=new&amp;editintro=Template%3AEdit+semi-protected%2Feditintro&amp;preloadtitle=Semi-protected+edit+request+on+24+April+2023&amp;preloadparams%5B%5D=edit+semi-protected&amp;preloadparams%5B%5D=Test\"><span class=\"mw-ui-button mw-ui-progressive\">Submit an edit request</span></a></span>\n</p>\n</div></li>\n<li>If you wrote any text, please save it temporarily to your device until you can edit this page.</li>\n</ul>\n</div>\n</div></td></tr></tbody></table></div><div id=\"editnotice-area\" class=\"editnotice-area mw-parser-output\" style=\"clear: both; width: 100%;\">\n<div class=\"editnotice-link\" style=\"clear: both; float: right; margin: 0px 0.8em; padding: 0; line-height: 1em;\"> <small> <a href=\"/wiki/Template:Editnotices/Page/Test\" title=\"Template:Editnotices/Page/Test\">Page notice</a></small> </div>\n  <div class=\"editnotice-page\" style=\"clear: both; width: 100%;\"> <link rel=\"mw-deduplicated-inline-style\" href=\"mw-data:TemplateStyles:r1097763485\"/><table class=\"plainlinks metadata ambox ambox-content\" role=\"presentation\"><tbody><tr><td class=\"mbox-image\"><div class=\"mbox-image-div\"><img alt=\"\" src=\"//upload.wikimedia.org/wikipedia/commons/thumb/e/e9/Sandbox_Not.svg/50px-Sandbox_Not.svg.png\" decoding=\"async\" width=\"50\" height=\"50\" srcset=\"//upload.wikimedia.org/wikipedia/commons/thumb/e/e9/Sandbox_Not.svg/75px-Sandbox_Not.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/e/e9/Sandbox_Not.svg/100px-Sandbox_Not.svg.png 2x\" data-file-width=\"766\" data-file-height=\"766\" /></div></td><td class=\"mbox-text\"><div class=\"mbox-text-span\"><b>This page is <i>not</i> a <a href=\"/wiki/Wikipedia:About_the_sandbox\" title=\"Wikipedia:About the sandbox\">sandbox</a>.</b><br /><div style=\"font-size:100%\">It should not be used for test editing. To experiment, please use the <a href=\"/wiki/Wikipedia:Sandbox\" title=\"Wikipedia:Sandbox\">Wikipedia sandbox</a>, your <a href=\"/wiki/Special:MyPage/sandbox\" title=\"Special:MyPage/sandbox\">user sandbox</a>,  or the <a href=\"/wiki/Wikipedia:About_the_sandbox#List_of_sandboxes\" title=\"Wikipedia:About the sandbox\">other sandboxes</a>. </div></div></td></tr></tbody></table> </div><div style=\"clear: both;\"></div></div>\n</div>",
            "module": "edit"
        },
        {
            "code": "blocked",
            "html": "You have been blocked from editing.",
            "data": {
                "blockinfo": {
                    "blockid": null,
                    "blockedby": "",
                    "blockedbyid": 0,
                    "blockreason": "There are multiple blocks against your account and/or IP address",
                    "blockedtimestamp": "2023-04-24T21:09:55Z",
                    "blockexpiry": "2028-04-22T18:29:58Z",
                    "blockpartial": false,
                    "blocknocreate": true,
                    "blockanononly": false,
                    "blockedtimestampformatted": "21:09, 24 April 2023",
                    "blockexpiryformatted": "18:29, 22 April 2028",
                    "blockexpiryrelative": "in 4 years"
                }
            },
            "module": "edit"
        }
    ],
    "docref": "See https://en.wikipedia.org/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at &lt;https://lists.wikimedia.org/postorius/lists/mediawiki-api-announce.lists.wikimedia.org/&gt; for notice of API deprecations and breaking changes.",
    "servedby": "mw2405"
}

This seems to be related to ApiBase::$blockMsgMap and the code using it. https://gerrit.wikimedia.org/g/mediawiki/core/+/7c8590396b78e0e580e23aee76a750e85c1f094e/includes/api/ApiBase.php#251