+ /**
+ * Array that maps message keys to error messages. $1 and friends are replaced.
+ */
+ public static $messageMap = array(
+ // This one MUST be present, or dieUsageMsg() will recurse infinitely
+ 'unknownerror' => array('code' => 'unknownerror', 'info' => "Unknown error: ``\$1''"),
+ 'unknownerror-nocode' => array('code' => 'unknownerror', 'info' => 'Unknown error'),
+
+ // Messages from Title::getUserPermissionsErrors()
+ 'ns-specialprotected' => array('code' => 'unsupportednamespace', 'info' => "Pages in the Special namespace can't be edited"),
+ 'protectedinterface' => array('code' => 'protectednamespace-interface', 'info' => "You're not allowed to edit interface messages"),
+ 'namespaceprotected' => array('code' => 'protectednamespace', 'info' => "You're not allowed to edit pages in the ``\$1'' namespace"),
+ 'customcssjsprotected' => array('code' => 'customcssjsprotected', 'info' => "You're not allowed to edit custom CSS and JavaScript pages"),
+ 'cascadeprotected' => array('code' => 'cascadeprotected', 'info' =>"The page you're trying to edit is protected because it's included in a cascade-protected page"),
+ 'protectedpagetext' => array('code' => 'protectedpage', 'info' => "The ``\$1'' right is required to edit this page"),
+ 'protect-cantedit' => array('code' => 'cantedit', 'info' => "You can't protect this page because you can't edit it"),
+ 'badaccess-group0' => array('code' => 'permissiondenied', 'info' => "Permission denied"), // Generic permission denied message
+ 'badaccess-groups' => array('code' => 'permissiondenied', 'info' => "Permission denied"),
+ 'titleprotected' => array('code' => 'protectedtitle', 'info' => "This title has been protected from creation"),
+ 'nocreate-loggedin' => array('code' => 'cantcreate', 'info' => "You don't have permission to create new pages"),
+ 'nocreatetext' => array('code' => 'cantcreate-anon', 'info' => "Anonymous users can't create new pages"),
+ 'movenologintext' => array('code' => 'cantmove-anon', 'info' => "Anonymous users can't move pages"),
+ 'movenotallowed' => array('code' => 'cantmove', 'info' => "You don't have permission to move pages"),
+ 'confirmedittext' => array('code' => 'confirmemail', 'info' => "You must confirm your e-mail address before you can edit"),
+ 'blockedtext' => array('code' => 'blocked', 'info' => "You have been blocked from editing"),
+ 'autoblockedtext' => array('code' => 'autoblocked', 'info' => "Your IP address has been blocked automatically, because it was used by a blocked user"),
+
+ // Miscellaneous interface messages
+ 'actionthrottledtext' => array('code' => 'ratelimited', 'info' => "You've exceeded your rate limit. Please wait some time and try again"),
+ 'alreadyrolled' => array('code' => 'alreadyrolled', 'info' => "The page you tried to rollback was already rolled back"),
+ 'cantrollback' => array('code' => 'onlyauthor', 'info' => "The page you tried to rollback only has one author"),
+ 'readonlytext' => array('code' => 'readonly', 'info' => "The wiki is currently in read-only mode"),
+ 'sessionfailure' => array('code' => 'badtoken', 'info' => "Invalid token"),
+ 'cannotdelete' => array('code' => 'cantdelete', 'info' => "Couldn't delete ``\$1''. Maybe it was deleted already by someone else"),
+ 'notanarticle' => array('code' => 'missingtitle', 'info' => "The page you requested doesn't exist"),
+ 'selfmove' => array('code' => 'selfmove', 'info' => "Can't move a page to itself"),
+ 'immobile_namespace' => array('code' => 'immobilenamespace', 'info' => "You tried to move pages from or to a namespace that is protected from moving"),
+ 'articleexists' => array('code' => 'articleexists', 'info' => "The destination article already exists and is not a redirect to the source article"),
+ 'protectedpage' => array('code' => 'protectedpage', 'info' => "You don't have permission to perform this move"),
+ 'hookaborted' => array('code' => 'hookaborted', 'info' => "The modification you tried to make was aborted by an extension hook"),
+ 'cantmove-titleprotected' => array('code' => 'protectedtitle', 'info' => "The destination article has been protected from creation"),
+ 'imagenocrossnamespace' => array('code' => 'nonfilenamespace', 'info' => "Can't move a file to a non-file namespace"),
+ 'imagetypemismatch' => array('code' => 'filetypemismatch', 'info' => "The new file extension doesn't match its type"),
+ // 'badarticleerror' => shouldn't happen
+ // 'badtitletext' => shouldn't happen
+ 'ip_range_invalid' => array('code' => 'invalidrange', 'info' => "Invalid IP range"),
+ 'range_block_disabled' => array('code' => 'rangedisabled', 'info' => "Blocking IP ranges has been disabled"),
+ 'nosuchusershort' => array('code' => 'nosuchuser', 'info' => "The user you specified doesn't exist"),
+ 'badipaddress' => array('code' => 'invalidip', 'info' => "Invalid IP address specified"),
+ 'ipb_expiry_invalid' => array('code' => 'invalidexpiry', 'info' => "Invalid expiry time"),
+ 'ipb_already_blocked' => array('code' => 'alreadyblocked', 'info' => "The user you tried to block was already blocked"),
+ 'ipb_blocked_as_range' => array('code' => 'blockedasrange', 'info' => "IP address ``\$1'' was blocked as part of range ``\$2''. You can't unblock the IP invidually, but you can unblock the range as a whole."),
+ 'ipb_cant_unblock' => array('code' => 'cantunblock', 'info' => "The block you specified was not found. It may have been unblocked already"),
+ 'mailnologin' => array('code' => 'cantsend', 'info' => "You're not logged in or you don't have a confirmed e-mail address, so you can't send e-mail"),
+ 'usermaildisabled' => array('code' => 'usermaildisabled', 'info' => "User email has been disabled"),
+ 'blockedemailuser' => array('code' => 'blockedfrommail', 'info' => "You have been blocked from sending e-mail"),
+ 'notarget' => array('code' => 'notarget', 'info' => "You have not specified a valid target for this action"),
+ 'noemail' => array('code' => 'noemail', 'info' => "The user has not specified a valid e-mail address, or has chosen not to receive e-mail from other users"),
+ 'rcpatroldisabled' => array('code' => 'patroldisabled', 'info' => "Patrolling is disabled on this wiki"),
+ 'markedaspatrollederror-noautopatrol' => array('code' => 'noautopatrol', 'info' => "You don't have permission to patrol your own changes"),
+ 'delete-toobig' => array('code' => 'bigdelete', 'info' => "You can't delete this page because it has more than \$1 revisions"),
+
+ // API-specific messages
+ 'missingparam' => array('code' => 'no$1', 'info' => "The \$1 parameter must be set"),
+ 'invalidtitle' => array('code' => 'invalidtitle', 'info' => "Bad title ``\$1''"),
+ 'nosuchpageid' => array('code' => 'nosuchpageid', 'info' => "There is no page with ID \$1"),
+ 'invaliduser' => array('code' => 'invaliduser', 'info' => "Invalid username ``\$1''"),
+ 'invalidexpiry' => array('code' => 'invalidexpiry', 'info' => "Invalid expiry time ``\$1''"),
+ 'pastexpiry' => array('code' => 'pastexpiry', 'info' => "Expiry time ``\$1'' is in the past"),
+ 'create-titleexists' => array('code' => 'create-titleexists', 'info' => "Existing titles can't be protected with 'create'"),
+ 'missingtitle-createonly' => array('code' => 'missingtitle-createonly', 'info' => "Missing titles can only be protected with 'create'"),
+ 'cantblock' => array('code' => 'cantblock', 'info' => "You don't have permission to block users"),
+ 'canthide' => array('code' => 'canthide', 'info' => "You don't have permission to hide user names from the block log"),
+ 'cantblock-email' => array('code' => 'cantblock-email', 'info' => "You don't have permission to block users from sending e-mail through the wiki"),
+ 'unblock-notarget' => array('code' => 'notarget', 'info' => "Either the id or the user parameter must be set"),
+ 'unblock-idanduser' => array('code' => 'idanduser', 'info' => "The id and user parameters can't be used together"),
+ 'cantunblock' => array('code' => 'permissiondenied', 'info' => "You don't have permission to unblock users"),
+ 'cannotundelete' => array('code' => 'cantundelete', 'info' => "Couldn't undelete: the requested revisions may not exist, or may have been undeleted already"),
+ 'permdenied-undelete' => array('code' => 'permissiondenied', 'info' => "You don't have permission to restore deleted revisions"),
+ 'createonly-exists' => array('code' => 'articleexists', 'info' => "The article you tried to create has been created already"),
+ 'nocreate-missing' => array('code' => 'missingtitle', 'info' => "The article you tried to edit doesn't exist"),
+ 'nosuchrcid' => array('code' => 'nosuchrcid', 'info' => "There is no change with rcid ``\$1''"),
+ 'cantpurge' => array('code' => 'cantpurge', 'info' => "Only users with the 'purge' right can purge pages via the API"),
+ 'protect-invalidaction' => array('code' => 'protect-invalidaction', 'info' => "Invalid protection type ``\$1''"),
+ 'protect-invalidlevel' => array('code' => 'protect-invalidlevel', 'info' => "Invalid protection level ``\$1''"),
+ 'toofewexpiries' => array('code' => 'toofewexpiries', 'info' => "\$1 expiry timestamps were provided where \$2 were needed"),
+
+
+ // ApiEditPage messages
+ 'noimageredirect-anon' => array('code' => 'noimageredirect-anon', 'info' => "Anonymous users can't create image redirects"),
+ 'noimageredirect-logged' => array('code' => 'noimageredirect', 'info' => "You don't have permission to create image redirects"),
+ 'spamdetected' => array('code' => 'spamdetected', 'info' => "Your edit was refused because it contained a spam fragment: ``\$1''"),
+ 'filtered' => array('code' => 'filtered', 'info' => "The filter callback function refused your edit"),
+ 'contenttoobig' => array('code' => 'contenttoobig', 'info' => "The content you supplied exceeds the article size limit of \$1 bytes"),
+ 'noedit-anon' => array('code' => 'noedit-anon', 'info' => "Anonymous users can't edit pages"),
+ 'noedit' => array('code' => 'noedit', 'info' => "You don't have permission to edit pages"),
+ 'wasdeleted' => array('code' => 'pagedeleted', 'info' => "The page has been deleted since you fetched its timestamp"),
+ 'blankpage' => array('code' => 'emptypage', 'info' => "Creating new, empty pages is not allowed"),
+ 'editconflict' => array('code' => 'editconflict', 'info' => "Edit conflict detected"),
+ 'hashcheckfailed' => array('code' => 'badmd5', 'info' => "The supplied MD5 hash was incorrect"),
+ 'missingtext' => array('code' => 'notext', 'info' => "One of the text, appendtext and prependtext parameters must be set"),
+ 'emptynewsection' => array('code' => 'emptynewsection', 'info' => 'Creating empty new sections is not possible.'),
+ );
+
+ /**
+ * Output the error message related to a certain array
+ * @param array $error Element of a getUserPermissionsErrors()
+ */
+ public function dieUsageMsg($error) {
+ $key = array_shift($error);
+ if(isset(self::$messageMap[$key]))
+ $this->dieUsage(wfMsgReplaceArgs(self::$messageMap[$key]['info'], $error), wfMsgReplaceArgs(self::$messageMap[$key]['code'], $error));
+ // If the key isn't present, throw an "unknown error"
+ $this->dieUsageMsg(array('unknownerror', $key));
+ }
+