217 $this->mMainModule = $mainModule;
218 $this->mModuleName = $moduleName;
219 $this->mModulePrefix = $modulePrefix;
247 abstract public function execute();
288 if ( !is_array( $examples ) ) {
289 $examples = [ $examples ];
290 } elseif ( $examples && ( count( $examples ) & 1 ) == 0 &&
291 array_keys( $examples ) === range( 0, count( $examples ) - 1 ) &&
292 !preg_match(
'/^\s*api\.php\?/', $examples[0] )
297 $examplesCount = count( $examples );
298 for ( $i = 0; $i < $examplesCount; $i += 2 ) {
299 $tmp[$examples[$i + 1]] = $examples[$i];
304 foreach ( $examples
as $k => $v ) {
305 if ( is_numeric( $k ) ) {
310 $msg = self::escapeWikiText( $v );
311 if ( is_array( $msg ) ) {
312 $msg = implode(
' ', $msg );
316 $qs = preg_replace(
'/^\s*api\.php\?/',
'', $qs );
317 $ret[$qs] = $this->
msg(
'api-help-fallback-example', [ $msg ] );
519 return $this->
getMain()->lacksSameOriginSecurity();
548 if (
$path ===
'main' ) {
552 $parts = explode(
'+',
$path );
553 if ( count( $parts ) === 1 ) {
555 $parts = explode(
' ',
$path );
559 for ( $i = 0; $i <
$count; $i++ ) {
561 $manager = $parent->getModuleManager();
562 if ( $manager === null ) {
563 $errorPath = implode(
'+', array_slice( $parts, 0, $i ) );
564 $this->
dieUsage(
"The module \"$errorPath\" has no submodules",
'badmodule' );
566 $module = $manager->getModule( $parts[$i] );
568 if ( $module === null ) {
569 $errorPath = $i ? implode(
'+', array_slice( $parts, 0, $i ) ) : $parent->getModuleName();
571 "The module \"$errorPath\" does not have a submodule \"{$parts[$i]}\"",
591 return $this->
getMain()->getResult();
605 return $this->
getMain()->getErrorFormatter();
613 if ( !isset( $this->mSlaveDB ) ) {
631 return $this->
getMain()->getContinuationManager();
645 $this->
getMain()->setContinuationManager( $manager );
673 return $this->mModulePrefix . $paramName;
687 if ( !isset( $this->mParamCache[$parseLimit] ) ) {
692 foreach (
$params as $paramName => $paramSettings ) {
694 $paramName, $paramSettings, $parseLimit );
697 $this->mParamCache[$parseLimit] = $results;
700 return $this->mParamCache[$parseLimit];
722 $required = func_get_args();
723 array_shift( $required );
726 $intersection = array_intersect( array_keys( array_filter(
$params,
727 [ $this,
'parameterNotEmpty' ] ) ), $required );
729 if ( count( $intersection ) > 1 ) {
731 "The parameters {$p}" . implode(
", {$p}", $intersection ) .
' can not be used together',
733 } elseif ( count( $intersection ) == 0 ) {
735 "One of the parameters {$p}" . implode(
", {$p}", $required ) .
' is required',
748 $required = func_get_args();
749 array_shift( $required );
752 $intersection = array_intersect( array_keys( array_filter(
$params,
753 [ $this,
'parameterNotEmpty' ] ) ), $required );
755 if ( count( $intersection ) > 1 ) {
757 "The parameters {$p}" . implode(
", {$p}", $intersection ) .
' can not be used together',
771 $required = func_get_args();
772 array_shift( $required );
775 $intersection = array_intersect(
776 array_keys( array_filter(
$params, [ $this,
'parameterNotEmpty' ] ) ),
780 if ( count( $intersection ) == 0 ) {
781 $this->
dieUsage(
"At least one of the parameters {$p}" .
782 implode(
", {$p}", $required ) .
' is required',
"{$p}missingparam" );
795 if ( $this->
getConfig()->
get(
'DebugAPI' ) || $this->
getMain()->isInternalMode() ) {
799 $queryValues = $this->
getRequest()->getQueryValues();
802 if ( $prefix !==
'noprefix' ) {
805 if ( array_key_exists( $param, $queryValues ) ) {
806 $badParams[] = $param;
812 'The following parameters were found in the query string, but must be in the POST body: '
813 . join(
', ', $badParams ),
826 return !is_null( $x ) && $x !==
false;
844 if ( isset(
$params[
'title'] ) ) {
846 if ( !$titleObj || $titleObj->isExternal() ) {
849 if ( !$titleObj->canExist() ) {
850 $this->
dieUsage(
"Namespace doesn't allow actual pages",
'pagecannotexist' );
853 if ( $load !==
false ) {
854 $pageObj->loadPageData( $load );
856 } elseif ( isset(
$params[
'pageid'] ) ) {
857 if ( $load ===
false ) {
881 switch ( $watchlist ) {
889 # If the user is already watching, don't bother checking
890 if ( $userWatching ) {
893 # If no user option was passed, use watchdefault and watchcreations
894 if ( is_null( $userOption ) ) {
895 return $this->
getUser()->getBoolOption(
'watchdefault' ) ||
896 $this->
getUser()->getBoolOption(
'watchcreations' ) && !$titleObj->exists();
899 # Watch the article based on the user preference
900 return $this->
getUser()->getBoolOption( $userOption );
903 return $userWatching;
906 return $userWatching;
923 if ( !is_array( $paramSettings ) ) {
924 $default = $paramSettings;
926 $type = gettype( $paramSettings );
931 $default = isset( $paramSettings[self::PARAM_DFLT] )
932 ? $paramSettings[self::PARAM_DFLT]
934 $multi = isset( $paramSettings[self::PARAM_ISMULTI] )
935 ? $paramSettings[self::PARAM_ISMULTI]
937 $type = isset( $paramSettings[self::PARAM_TYPE] )
938 ? $paramSettings[self::PARAM_TYPE]
940 $dupes = isset( $paramSettings[self::PARAM_ALLOW_DUPLICATES] )
941 ? $paramSettings[self::PARAM_ALLOW_DUPLICATES]
943 $deprecated = isset( $paramSettings[self::PARAM_DEPRECATED] )
944 ? $paramSettings[self::PARAM_DEPRECATED]
946 $required = isset( $paramSettings[self::PARAM_REQUIRED] )
947 ? $paramSettings[self::PARAM_REQUIRED]
951 if ( !isset(
$type ) ) {
952 if ( isset( $default ) ) {
953 $type = gettype( $default );
959 if (
$type ==
'password' || !empty( $paramSettings[self::PARAM_SENSITIVE] ) ) {
960 $this->
getMain()->markParamsSensitive( $encParamName );
965 if (
$type ==
'boolean' ) {
966 if ( isset( $default ) && $default !==
false ) {
970 "Boolean param $encParamName's default is set to '$default'. " .
971 'Boolean parameters must default to false.'
976 } elseif (
$type ==
'upload' ) {
977 if ( isset( $default ) ) {
981 "File upload param $encParamName's default is set to " .
982 "'$default'. File upload parameters may not have a default." );
988 if ( !
$value->exists() ) {
992 $value = $this->
getMain()->getRequest()->unsetVal( $encParamName );
995 "File upload param $encParamName is not a file upload; " .
996 'be sure to use multipart/form-data for your POST and include ' .
997 'a filename in the Content-Disposition header.',
998 "badupload_{$encParamName}"
1003 $value = $this->
getMain()->getVal( $encParamName, $default );
1009 if ( isset( $paramSettings[self::PARAM_SUBMODULE_MAP] ) ) {
1010 $type = array_keys( $paramSettings[self::PARAM_SUBMODULE_MAP] );
1017 if ( isset(
$value ) && ( $multi || is_array(
$type ) ) ) {
1029 if ( !is_array(
$type ) ) {
1036 if ( $required &&
$value ===
'' ) {
1037 $this->
dieUsageMsg( [
'missingparam', $paramName ] );
1041 $min = isset( $paramSettings[self::PARAM_MIN] ) ? $paramSettings[self::PARAM_MIN] : null;
1042 $max = isset( $paramSettings[self::PARAM_MAX] ) ? $paramSettings[self::PARAM_MAX] : null;
1043 $enforceLimits = isset( $paramSettings[self::PARAM_RANGE_ENFORCE] )
1044 ? $paramSettings[self::PARAM_RANGE_ENFORCE] :
false;
1046 if ( is_array(
$value ) ) {
1048 if ( !is_null( $min ) || !is_null( $max ) ) {
1050 $this->
validateLimit( $paramName, $v, $min, $max, null, $enforceLimits );
1055 if ( !is_null( $min ) || !is_null( $max ) ) {
1061 if ( !$parseLimit ) {
1065 if ( !isset( $paramSettings[self::PARAM_MAX] )
1066 || !isset( $paramSettings[self::PARAM_MAX2] )
1070 "MAX1 or MAX2 are not defined for the limit $encParamName"
1074 ApiBase::dieDebug( __METHOD__,
"Multi-values not supported for $encParamName" );
1076 $min = isset( $paramSettings[self::PARAM_MIN] ) ? $paramSettings[self::PARAM_MIN] : 0;
1079 ? $paramSettings[self::PARAM_MAX2]
1080 : $paramSettings[self::PARAM_MAX];
1088 $paramSettings[self::PARAM_MAX],
1089 $paramSettings[self::PARAM_MAX2]
1095 ApiBase::dieDebug( __METHOD__,
"Multi-values not supported for $encParamName" );
1099 if ( is_array(
$value ) ) {
1108 if ( is_array(
$value ) ) {
1120 if ( !is_array(
$value ) && !$multi ) {
1124 if ( !$tagsStatus->isGood() ) {
1129 ApiBase::dieDebug( __METHOD__,
"Param $encParamName's type is unknown - $type" );
1134 if ( !$dupes && is_array(
$value ) ) {
1139 if ( $deprecated &&
$value !==
false ) {
1140 $this->
setWarning(
"The $encParamName parameter has been deprecated." );
1142 $feature = $encParamName;
1144 while ( !$m->isMain() ) {
1145 $p = $m->getParent();
1146 $name = $m->getModuleName();
1147 $param = $p->encodeParamName( $p->getModuleManager()->getModuleGroup(
$name ) );
1148 $feature =
"{$param}={$name}&{$feature}";
1153 } elseif ( $required ) {
1154 $this->
dieUsageMsg( [
'missingparam', $paramName ] );
1174 if ( trim(
$value ) ===
'' && $allowMultiple ) {
1180 $valuesList = explode(
'|',
$value, self::LIMIT_SML2 + 1 );
1181 $sizeLimit = count( $valuesList ) > self::LIMIT_SML1 && $this->mMainModule->canApiHighLimits()
1185 if ( self::truncateArray( $valuesList, $sizeLimit ) ) {
1186 $this->
setWarning(
"Too many values supplied for parameter '$valueName': " .
1187 "the limit is $sizeLimit" );
1190 if ( !$allowMultiple && count( $valuesList ) != 1 ) {
1192 if ( in_array(
$value, $allowedValues,
true ) ) {
1196 $possibleValues = is_array( $allowedValues )
1197 ?
"of '" . implode(
"', '", $allowedValues ) .
"'"
1200 "Only one $possibleValues is allowed for parameter '$valueName'",
1201 "multival_$valueName"
1205 if ( is_array( $allowedValues ) ) {
1207 $unknown = array_diff( $valuesList, $allowedValues );
1208 if ( count( $unknown ) ) {
1209 if ( $allowMultiple ) {
1210 $s = count( $unknown ) > 1 ?
's' :
'';
1211 $vals = implode(
', ', $unknown );
1212 $this->
setWarning(
"Unrecognized value$s for parameter '$valueName': $vals" );
1215 "Unrecognized value for parameter '$valueName': {$valuesList[0]}",
1216 "unknown_$valueName"
1221 $valuesList = array_intersect( $valuesList, $allowedValues );
1224 return $allowMultiple ? $valuesList : $valuesList[0];
1238 $enforceLimits =
false
1240 if ( !is_null( $min ) &&
$value < $min ) {
1241 $msg = $this->
encodeParamName( $paramName ) .
" may not be less than $min (set to $value)";
1242 $this->
warnOrDie( $msg, $enforceLimits );
1248 if ( $this->
getMain()->isInternalMode() ) {
1254 if ( !is_null( $max ) &&
$value > $max ) {
1255 if ( !is_null( $botMax ) && $this->
getMain()->canApiHighLimits() ) {
1256 if (
$value > $botMax ) {
1258 " may not be over $botMax (set to $value) for bots or sysops";
1259 $this->
warnOrDie( $msg, $enforceLimits );
1263 $msg = $this->
encodeParamName( $paramName ) .
" may not be over $max (set to $value) for users";
1264 $this->
warnOrDie( $msg, $enforceLimits );
1283 "Passing '$value' for timestamp parameter $encParamName has been deprecated." .
1284 ' If for some reason you need to explicitly specify the current time without' .
1285 ' calculating it client-side, use "now".'
1291 if (
$value ===
'now' ) {
1296 if ( $unixTimestamp ===
false ) {
1298 "Invalid value '$value' for timestamp parameter $encParamName",
1299 "badtimestamp_{$encParamName}"
1318 if ( !isset( $salts[$tokenType] ) ) {
1320 "Module '{$this->getModuleName()}' tried to use token type '$tokenType' " .
1321 'without registering it'
1328 if ( $tokenObj->match( $token ) ) {
1333 if ( $webUiSalt !== null && $this->
getUser()->matchEditToken(
1354 "Invalid value '$value' for user parameter $encParamName",
1355 "baduser_{$encParamName}"
1359 return $title->getText();
1375 protected function setWatch( $watch, $titleObj, $userOption = null ) {
1392 while ( count( $arr ) >
$limit ) {
1407 if ( !is_null(
$params[
'owner'] ) && !is_null(
$params[
'token'] ) ) {
1410 $this->
dieUsage(
'Specified user does not exist',
'bad_wlowner' );
1412 $token =
$user->getOption(
'watchlisttoken' );
1413 if ( $token ==
'' || !hash_equals( $token,
$params[
'token'] ) ) {
1415 'Incorrect watchlist token provided -- please set a correct token in Special:Preferences',
1420 if ( !$this->
getUser()->isLoggedIn() ) {
1421 $this->
dieUsage(
'You must be logged-in to have a watchlist',
'notloggedin' );
1423 if ( !$this->
getUser()->isAllowed(
'viewmywatchlist' ) ) {
1424 $this->
dieUsage(
'You don\'t have permission to view your watchlist',
'permissiondenied' );
1440 if ( is_array( $v ) ) {
1441 return array_map(
'self::escapeWikiText', $v );
1444 '__' =>
'__',
'{' =>
'{',
'}' =>
'}',
1445 '[[Category:' =>
'[[:Category:',
1446 '[[File:' =>
'[[:File:',
'[[Image:' =>
'[[:Image:',
1464 if ( is_string( $msg ) ) {
1466 } elseif ( is_array( $msg ) ) {
1467 $msg = call_user_func_array(
'wfMessage', $msg );
1469 if ( !$msg instanceof
Message ) {
1473 $msg->setContext( $context );
1506 private function warnOrDie( $msg, $enforceLimits =
false ) {
1507 if ( $enforceLimits ) {
1508 $this->
dieUsage( $msg,
'integeroutofrange' );
1526 public function dieUsage( $description, $errorCode, $httpRespCode = 0, $extradata = null ) {
1547 'Your IP address has been blocked automatically, because it was used by a blocked user',
1554 'You have been blocked from editing',
1573 throw new MWException(
'Successful status passed to ApiBase::dieStatus' );
1576 $errors =
$status->getErrorsByType(
'error' );
1579 $errors =
$status->getErrorsByType(
'warning' );
1583 $errors = [ [
'message' =>
'unknownerror-nocode',
'params' => [] ] ];
1588 if ( $errors[0][
'message'] instanceof
Message ) {
1589 $msg = $errors[0][
'message'];
1591 $extraData = $msg->getApiData();
1592 $code = $msg->getApiCode();
1594 $code = $msg->getKey();
1597 $code = $errors[0][
'message'];
1605 return [
$code, $msg->inLanguage(
'en' )->useDatabase(
false )->plain() ];
1627 'unknownerror' => [
'code' =>
'unknownerror',
'info' =>
"Unknown error: \"\$1\"" ],
1628 'unknownerror-nocode' => [
'code' =>
'unknownerror',
'info' =>
'Unknown error' ],
1631 'ns-specialprotected' => [
1632 'code' =>
'unsupportednamespace',
1633 'info' =>
"Pages in the Special namespace can't be edited"
1635 'protectedinterface' => [
1636 'code' =>
'protectednamespace-interface',
1637 'info' =>
"You're not allowed to edit interface messages"
1639 'namespaceprotected' => [
1640 'code' =>
'protectednamespace',
1641 'info' =>
"You're not allowed to edit pages in the \"\$1\" namespace"
1643 'customcssprotected' => [
1644 'code' =>
'customcssprotected',
1645 'info' =>
"You're not allowed to edit custom CSS pages"
1647 'customjsprotected' => [
1648 'code' =>
'customjsprotected',
1649 'info' =>
"You're not allowed to edit custom JavaScript pages"
1651 'cascadeprotected' => [
1652 'code' =>
'cascadeprotected',
1653 'info' =>
"The page you're trying to edit is protected because it's included in a cascade-protected page"
1655 'protectedpagetext' => [
1656 'code' =>
'protectedpage',
1657 'info' =>
"The \"\$1\" right is required to edit this page"
1659 'protect-cantedit' => [
1660 'code' =>
'cantedit',
1661 'info' =>
"You can't protect this page because you can't edit it"
1663 'deleteprotected' => [
1664 'code' =>
'cantedit',
1665 'info' =>
"You can't delete this page because it has been protected"
1667 'badaccess-group0' => [
1668 'code' =>
'permissiondenied',
1669 'info' =>
'Permission denied'
1671 'badaccess-groups' => [
1672 'code' =>
'permissiondenied',
1673 'info' =>
'Permission denied'
1675 'titleprotected' => [
1676 'code' =>
'protectedtitle',
1677 'info' =>
'This title has been protected from creation'
1679 'nocreate-loggedin' => [
1680 'code' =>
'cantcreate',
1681 'info' =>
"You don't have permission to create new pages"
1684 'code' =>
'cantcreate-anon',
1685 'info' =>
"Anonymous users can't create new pages"
1687 'movenologintext' => [
1688 'code' =>
'cantmove-anon',
1689 'info' =>
"Anonymous users can't move pages"
1691 'movenotallowed' => [
1692 'code' =>
'cantmove',
1693 'info' =>
"You don't have permission to move pages"
1695 'confirmedittext' => [
1696 'code' =>
'confirmemail',
1697 'info' =>
'You must confirm your email address before you can edit'
1700 'code' =>
'blocked',
1701 'info' =>
'You have been blocked from editing'
1703 'autoblockedtext' => [
1704 'code' =>
'autoblocked',
1705 'info' =>
'Your IP address has been blocked automatically, because it was used by a blocked user'
1709 'actionthrottledtext' => [
1710 'code' =>
'ratelimited',
1711 'info' =>
"You've exceeded your rate limit. Please wait some time and try again"
1713 'alreadyrolled' => [
1714 'code' =>
'alreadyrolled',
1715 'info' =>
'The page you tried to rollback was already rolled back'
1718 'code' =>
'onlyauthor',
1719 'info' =>
'The page you tried to rollback only has one author'
1722 'code' =>
'readonly',
1723 'info' =>
'The wiki is currently in read-only mode'
1725 'sessionfailure' => [
1726 'code' =>
'badtoken',
1727 'info' =>
'Invalid token' ],
1729 'code' =>
'cantdelete',
1730 'info' =>
"Couldn't delete \"\$1\". Maybe it was deleted already by someone else"
1733 'code' =>
'missingtitle',
1734 'info' =>
"The page you requested doesn't exist"
1736 'selfmove' => [
'code' =>
'selfmove',
'info' =>
"Can't move a page to itself"
1738 'immobile_namespace' => [
1739 'code' =>
'immobilenamespace',
1740 'info' =>
'You tried to move pages from or to a namespace that is protected from moving'
1742 'articleexists' => [
1743 'code' =>
'articleexists',
1744 'info' =>
'The destination article already exists and is not a redirect to the source article'
1746 'protectedpage' => [
1747 'code' =>
'protectedpage',
1748 'info' =>
"You don't have permission to perform this move"
1751 'code' =>
'hookaborted',
1752 'info' =>
'The modification you tried to make was aborted by an extension hook'
1754 'cantmove-titleprotected' => [
1755 'code' =>
'protectedtitle',
1756 'info' =>
'The destination article has been protected from creation'
1758 'imagenocrossnamespace' => [
1759 'code' =>
'nonfilenamespace',
1760 'info' =>
"Can't move a file to a non-file namespace"
1762 'imagetypemismatch' => [
1763 'code' =>
'filetypemismatch',
1764 'info' =>
"The new file extension doesn't match its type"
1768 'ip_range_invalid' => [
'code' =>
'invalidrange',
'info' =>
'Invalid IP range' ],
1769 'range_block_disabled' => [
1770 'code' =>
'rangedisabled',
1771 'info' =>
'Blocking IP ranges has been disabled'
1773 'nosuchusershort' => [
1774 'code' =>
'nosuchuser',
1775 'info' =>
"The user you specified doesn't exist"
1777 'badipaddress' => [
'code' =>
'invalidip',
'info' =>
'Invalid IP address specified' ],
1778 'ipb_expiry_invalid' => [
'code' =>
'invalidexpiry',
'info' =>
'Invalid expiry time' ],
1779 'ipb_already_blocked' => [
1780 'code' =>
'alreadyblocked',
1781 'info' =>
'The user you tried to block was already blocked'
1783 'ipb_blocked_as_range' => [
1784 'code' =>
'blockedasrange',
1785 'info' =>
"IP address \"\$1\" was blocked as part of range \"\$2\". You can't unblock the IP individually, but you can unblock the range as a whole."
1787 'ipb_cant_unblock' => [
1788 'code' =>
'cantunblock',
1789 'info' =>
'The block you specified was not found. It may have been unblocked already'
1792 'code' =>
'cantsend',
1793 'info' =>
'You are not logged in, you do not have a confirmed email address, or you are not allowed to send email to other users, so you cannot send email'
1796 'code' =>
'ipbblocked',
1797 'info' =>
'You cannot block or unblock users while you are yourself blocked'
1799 'ipbnounblockself' => [
1800 'code' =>
'ipbnounblockself',
1801 'info' =>
'You are not allowed to unblock yourself'
1803 'usermaildisabled' => [
1804 'code' =>
'usermaildisabled',
1805 'info' =>
'User email has been disabled'
1807 'blockedemailuser' => [
1808 'code' =>
'blockedfrommail',
1809 'info' =>
'You have been blocked from sending email'
1812 'code' =>
'notarget',
1813 'info' =>
'You have not specified a valid target for this action'
1816 'code' =>
'noemail',
1817 'info' =>
'The user has not specified a valid email address, or has chosen not to receive email from other users'
1819 'rcpatroldisabled' => [
1820 'code' =>
'patroldisabled',
1821 'info' =>
'Patrolling is disabled on this wiki'
1823 'markedaspatrollederror-noautopatrol' => [
1824 'code' =>
'noautopatrol',
1825 'info' =>
"You don't have permission to patrol your own changes"
1827 'delete-toobig' => [
1828 'code' =>
'bigdelete',
1829 'info' =>
"You can't delete this page because it has more than \$1 revisions"
1831 'movenotallowedfile' => [
1832 'code' =>
'cantmovefile',
1833 'info' =>
"You don't have permission to move files"
1835 'userrights-no-interwiki' => [
1836 'code' =>
'nointerwikiuserrights',
1837 'info' =>
"You don't have permission to change user rights on other wikis"
1839 'userrights-nodatabase' => [
1840 'code' =>
'nosuchdatabase',
1841 'info' =>
"Database \"\$1\" does not exist or is not local"
1843 'nouserspecified' => [
'code' =>
'invaliduser',
'info' =>
"Invalid username \"\$1\"" ],
1844 'noname' => [
'code' =>
'invaliduser',
'info' =>
"Invalid username \"\$1\"" ],
1845 'summaryrequired' => [
'code' =>
'summaryrequired',
'info' =>
'Summary required' ],
1846 'import-rootpage-invalid' => [
1847 'code' =>
'import-rootpage-invalid',
1848 'info' =>
'Root page is an invalid title'
1850 'import-rootpage-nosubpage' => [
1851 'code' =>
'import-rootpage-nosubpage',
1852 'info' =>
'Namespace "$1" of the root page does not allow subpages'
1857 'code' =>
'readapidenied',
1858 'info' =>
'You need read permission to use this module'
1860 'writedisabled' => [
1861 'code' =>
'noapiwrite',
1862 'info' =>
"Editing of this wiki through the API is disabled. Make sure the \$wgEnableWriteAPI=true; statement is included in the wiki's LocalSettings.php file"
1864 'writerequired' => [
1865 'code' =>
'writeapidenied',
1866 'info' =>
"You're not allowed to edit this wiki through the API"
1868 'missingparam' => [
'code' =>
'no$1',
'info' =>
"The \$1 parameter must be set" ],
1869 'invalidtitle' => [
'code' =>
'invalidtitle',
'info' =>
"Bad title \"\$1\"" ],
1870 'nosuchpageid' => [
'code' =>
'nosuchpageid',
'info' =>
"There is no page with ID \$1" ],
1871 'nosuchrevid' => [
'code' =>
'nosuchrevid',
'info' =>
"There is no revision with ID \$1" ],
1872 'nosuchuser' => [
'code' =>
'nosuchuser',
'info' =>
"User \"\$1\" doesn't exist" ],
1873 'invaliduser' => [
'code' =>
'invaliduser',
'info' =>
"Invalid username \"\$1\"" ],
1874 'invalidexpiry' => [
'code' =>
'invalidexpiry',
'info' =>
"Invalid expiry time \"\$1\"" ],
1875 'pastexpiry' => [
'code' =>
'pastexpiry',
'info' =>
"Expiry time \"\$1\" is in the past" ],
1876 'create-titleexists' => [
1877 'code' =>
'create-titleexists',
1878 'info' =>
"Existing titles can't be protected with 'create'"
1880 'missingtitle-createonly' => [
1881 'code' =>
'missingtitle-createonly',
1882 'info' =>
"Missing titles can only be protected with 'create'"
1884 'cantblock' => [
'code' =>
'cantblock',
1885 'info' =>
"You don't have permission to block users"
1888 'code' =>
'canthide',
1889 'info' =>
"You don't have permission to hide user names from the block log"
1891 'cantblock-email' => [
1892 'code' =>
'cantblock-email',
1893 'info' =>
"You don't have permission to block users from sending email through the wiki"
1895 'unblock-notarget' => [
1896 'code' =>
'notarget',
1897 'info' =>
'Either the id or the user parameter must be set'
1899 'unblock-idanduser' => [
1900 'code' =>
'idanduser',
1901 'info' =>
"The id and user parameters can't be used together"
1904 'code' =>
'permissiondenied',
1905 'info' =>
"You don't have permission to unblock users"
1907 'cannotundelete' => [
1908 'code' =>
'cantundelete',
1909 'info' =>
"Couldn't undelete: the requested revisions may not exist, or may have been undeleted already"
1911 'permdenied-undelete' => [
1912 'code' =>
'permissiondenied',
1913 'info' =>
"You don't have permission to restore deleted revisions"
1915 'createonly-exists' => [
1916 'code' =>
'articleexists',
1917 'info' =>
'The article you tried to create has been created already'
1919 'nocreate-missing' => [
1920 'code' =>
'missingtitle',
1921 'info' =>
"The article you tried to edit doesn't exist"
1923 'cantchangecontentmodel' => [
1924 'code' =>
'cantchangecontentmodel',
1925 'info' =>
"You don't have permission to change the content model of a page"
1928 'code' =>
'nosuchrcid',
1929 'info' =>
"There is no change with rcid \"\$1\""
1932 'code' =>
'nosuchlogid',
1933 'info' =>
"There is no log entry with ID \"\$1\""
1935 'protect-invalidaction' => [
1936 'code' =>
'protect-invalidaction',
1937 'info' =>
"Invalid protection type \"\$1\""
1939 'protect-invalidlevel' => [
1940 'code' =>
'protect-invalidlevel',
1941 'info' =>
"Invalid protection level \"\$1\""
1943 'toofewexpiries' => [
1944 'code' =>
'toofewexpiries',
1945 'info' =>
"\$1 expiry timestamps were provided where \$2 were needed"
1948 'code' =>
'cantimport',
1949 'info' =>
"You don't have permission to import pages"
1951 'cantimport-upload' => [
1952 'code' =>
'cantimport-upload',
1953 'info' =>
"You don't have permission to import uploaded pages"
1955 'importnofile' => [
'code' =>
'nofile',
'info' =>
"You didn't upload a file" ],
1956 'importuploaderrorsize' => [
1957 'code' =>
'filetoobig',
1958 'info' =>
'The file you uploaded is bigger than the maximum upload size'
1960 'importuploaderrorpartial' => [
1961 'code' =>
'partialupload',
1962 'info' =>
'The file was only partially uploaded'
1964 'importuploaderrortemp' => [
1965 'code' =>
'notempdir',
1966 'info' =>
'The temporary upload directory is missing'
1968 'importcantopen' => [
1969 'code' =>
'cantopenfile',
1970 'info' =>
"Couldn't open the uploaded file"
1972 'import-noarticle' => [
1973 'code' =>
'badinterwiki',
1974 'info' =>
'Invalid interwiki title specified'
1976 'importbadinterwiki' => [
1977 'code' =>
'badinterwiki',
1978 'info' =>
'Invalid interwiki title specified'
1980 'import-unknownerror' => [
1981 'code' =>
'import-unknownerror',
1982 'info' =>
"Unknown error on import: \"\$1\""
1984 'cantoverwrite-sharedfile' => [
1985 'code' =>
'cantoverwrite-sharedfile',
1986 'info' =>
'The target file exists on a shared repository and you do not have permission to override it'
1988 'sharedfile-exists' => [
1989 'code' =>
'fileexists-sharedrepo-perm',
1990 'info' =>
'The target file exists on a shared repository. Use the ignorewarnings parameter to override it.'
1993 'code' =>
'mustbeposted',
1994 'info' =>
"The \$1 module requires a POST request"
1998 'info' =>
'Incorrect parameter - mutually exclusive values may not be supplied'
2000 'specialpage-cantexecute' => [
2001 'code' =>
'specialpage-cantexecute',
2002 'info' =>
"You don't have permission to view the results of this special page"
2004 'invalidoldimage' => [
2005 'code' =>
'invalidoldimage',
2006 'info' =>
'The oldimage parameter has invalid format'
2008 'nodeleteablefile' => [
2009 'code' =>
'nodeleteablefile',
2010 'info' =>
'No such old version of the file'
2012 'fileexists-forbidden' => [
2013 'code' =>
'fileexists-forbidden',
2014 'info' =>
'A file with name "$1" already exists, and cannot be overwritten.'
2016 'fileexists-shared-forbidden' => [
2017 'code' =>
'fileexists-shared-forbidden',
2018 'info' =>
'A file with name "$1" already exists in the shared file repository, and cannot be overwritten.'
2020 'filerevert-badversion' => [
2021 'code' =>
'filerevert-badversion',
2022 'info' =>
'There is no previous local version of this file with the provided timestamp.'
2026 'noimageredirect-anon' => [
2027 'code' =>
'noimageredirect-anon',
2028 'info' =>
"Anonymous users can't create image redirects"
2030 'noimageredirect-logged' => [
2031 'code' =>
'noimageredirect',
2032 'info' =>
"You don't have permission to create image redirects"
2035 'code' =>
'spamdetected',
2036 'info' =>
"Your edit was refused because it contained a spam fragment: \"\$1\""
2038 'contenttoobig' => [
2039 'code' =>
'contenttoobig',
2040 'info' =>
"The content you supplied exceeds the article size limit of \$1 kilobytes"
2042 'noedit-anon' => [
'code' =>
'noedit-anon',
'info' =>
"Anonymous users can't edit pages" ],
2043 'noedit' => [
'code' =>
'noedit',
'info' =>
"You don't have permission to edit pages" ],
2045 'code' =>
'pagedeleted',
2046 'info' =>
'The page has been deleted since you fetched its timestamp'
2049 'code' =>
'emptypage',
2050 'info' =>
'Creating new, empty pages is not allowed'
2052 'editconflict' => [
'code' =>
'editconflict',
'info' =>
'Edit conflict detected' ],
2053 'hashcheckfailed' => [
'code' =>
'badmd5',
'info' =>
'The supplied MD5 hash was incorrect' ],
2056 'info' =>
'One of the text, appendtext, prependtext and undo parameters must be set'
2058 'emptynewsection' => [
2059 'code' =>
'emptynewsection',
2060 'info' =>
'Creating empty new sections is not possible.'
2063 'code' =>
'revwrongpage',
2064 'info' =>
"r\$1 is not a revision of \"\$2\""
2067 'code' =>
'undofailure',
2068 'info' =>
'Undo failed due to conflicting intermediate edits'
2070 'content-not-allowed-here' => [
2071 'code' =>
'contentnotallowedhere',
2072 'info' =>
'Content model "$1" is not allowed at title "$2"'
2076 'edit-hook-aborted' => [
2077 'code' =>
'edit-hook-aborted',
2078 'info' =>
'Your edit was aborted by an ArticleSave hook'
2080 'edit-gone-missing' => [
2081 'code' =>
'edit-gone-missing',
2082 'info' =>
"The page you tried to edit doesn't seem to exist anymore"
2084 'edit-conflict' => [
'code' =>
'editconflict',
'info' =>
'Edit conflict detected' ],
2085 'edit-already-exists' => [
2086 'code' =>
'edit-already-exists',
2087 'info' =>
'It seems the page you tried to create already exist'
2091 'invalid-file-key' => [
'code' =>
'invalid-file-key',
'info' =>
'Not a valid file key' ],
2092 'nouploadmodule' => [
'code' =>
'nouploadmodule',
'info' =>
'No upload module set' ],
2093 'uploaddisabled' => [
2094 'code' =>
'uploaddisabled',
2095 'info' =>
'Uploads are not enabled. Make sure $wgEnableUploads is set to true in LocalSettings.php and the PHP ini setting file_uploads is true'
2097 'copyuploaddisabled' => [
2098 'code' =>
'copyuploaddisabled',
2099 'info' =>
'Uploads by URL is not enabled. Make sure $wgAllowCopyUploads is set to true in LocalSettings.php.'
2101 'copyuploadbaddomain' => [
2102 'code' =>
'copyuploadbaddomain',
2103 'info' =>
'Uploads by URL are not allowed from this domain.'
2105 'copyuploadbadurl' => [
2106 'code' =>
'copyuploadbadurl',
2107 'info' =>
'Upload not allowed from this URL.'
2110 'filename-tooshort' => [
2111 'code' =>
'filename-tooshort',
2112 'info' =>
'The filename is too short'
2114 'filename-toolong' => [
'code' =>
'filename-toolong',
'info' =>
'The filename is too long' ],
2115 'illegal-filename' => [
2116 'code' =>
'illegal-filename',
2117 'info' =>
'The filename is not allowed'
2119 'filetype-missing' => [
2120 'code' =>
'filetype-missing',
2121 'info' =>
'The file is missing an extension'
2124 'mustbeloggedin' => [
'code' =>
'mustbeloggedin',
'info' =>
'You must be logged in to $1.' ]
2134 $parsed = $this->
parseMsg( [
'readonlytext' ] );
2135 $this->
dieUsage( $parsed[
'info'], $parsed[
'code'], 0,
2145 # most of the time we send a 1 element, so we might as well send it as
2146 # a string and make this an array here.
2147 if ( is_string( $error ) ) {
2148 $error = [ $error ];
2150 $parsed = $this->
parseMsg( $error );
2151 $extraData = isset( $parsed[
'data'] ) ? $parsed[
'data'] : null;
2152 $this->
dieUsage( $parsed[
'info'], $parsed[
'code'], 0, $extraData );
2163 if ( $this->
getConfig()->
get(
'DebugAPI' ) !==
true ) {
2167 if ( is_string( $error ) ) {
2168 $error = [ $error ];
2170 $parsed = $this->
parseMsg( $error );
2171 $this->
setWarning(
'$wgDebugAPI: ' . $parsed[
'code'] .
' - ' . $parsed[
'info'] );
2184 'Invalid continue param. You should pass the original value returned by the previous query',
2195 $error = (
array)$error;
2196 $key = array_shift( $error );
2200 if ( is_array(
$key ) ) {
2202 $key = array_shift( $error );
2207 'code' =>
$key->getApiCode(),
2208 'info' =>
$key->inLanguage(
'en' )->useDatabase(
false )->text(),
2209 'data' =>
$key->getApiData()
2213 if ( isset( self::$messageMap[
$key] ) ) {
2221 return $this->
parseMsg( [
'unknownerror', $key ] );
2230 protected static function dieDebug( $method, $message ) {
2231 throw new MWException(
"Internal error in $method: $message" );
2241 $s =
'"' . addslashes( $feature ) .
'"' .
2244 ' "' . addslashes(
$request->getHeader(
'Referer' ) ) .
'"' .
2245 ' "' . addslashes( $this->
getMain()->getUserAgent() ) .
'"';
2262 return "apihelp-{$this->getModulePath()}-description";
2274 Hooks::run(
'APIGetDescription', [ &$this, &$desc ] );
2275 $desc = self::escapeWikiText( $desc );
2276 if ( is_array( $desc ) ) {
2277 $desc = implode(
"\n", $desc );
2287 if ( !$msg->exists() ) {
2288 $msg = $this->
msg(
'api-help-fallback-description', $desc );
2292 Hooks::run(
'APIGetDescriptionMessages', [ $this, &$msgs ] );
2317 'api-help-param-token',
2341 Hooks::run(
'APIGetParamDescription', [ &$this, &$desc ] );
2346 $desc = self::escapeWikiText( $desc );
2350 foreach (
$params as $param => $settings ) {
2351 if ( !is_array( $settings ) ) {
2355 $d = isset( $desc[$param] ) ? $desc[$param] :
'';
2356 if ( is_array( $d ) ) {
2358 $d = array_map(
function (
$line ) {
2359 if ( preg_match(
'/^\s+(\S+)\s+-\s+(.+)$/',
$line, $m ) ) {
2360 $line =
"\n;{$m[1]}:{$m[2]}";
2364 $d = implode(
' ', $d );
2370 $msg = $this->
msg(
"apihelp-{$path}-param-{$param}" );
2371 if ( !$msg->exists() ) {
2372 $msg = $this->
msg(
'api-help-fallback-parameter', $d );
2378 self::dieDebug( __METHOD__,
2379 'Value in ApiBase::PARAM_HELP_MSG is not valid' );
2381 $msgs[$param] = [ $msg ];
2384 if ( !is_array( $settings[ApiBase::PARAM_HELP_MSG_PER_VALUE] ) ) {
2385 self::dieDebug( __METHOD__,
2386 'ApiBase::PARAM_HELP_MSG_PER_VALUE is not valid' );
2389 self::dieDebug( __METHOD__,
2390 'ApiBase::PARAM_HELP_MSG_PER_VALUE may only be used when ' .
2391 'ApiBase::PARAM_TYPE is an array' );
2395 foreach ( $settings[ApiBase::PARAM_TYPE]
as $value ) {
2396 if ( isset( $valueMsgs[$value] ) ) {
2397 $msg = $valueMsgs[
$value];
2399 $msg =
"apihelp-{$path}-paramvalue-{$param}-{$value}";
2406 [ $m->getKey(),
'api-help-param-no-description' ],
2411 self::dieDebug( __METHOD__,
2412 "Value in ApiBase::PARAM_HELP_MSG_PER_VALUE for $value is not valid" );
2418 if ( !is_array( $settings[ApiBase::PARAM_HELP_MSG_APPEND] ) ) {
2419 self::dieDebug( __METHOD__,
2420 'Value for ApiBase::PARAM_HELP_MSG_APPEND is not an array' );
2422 foreach ( $settings[ApiBase::PARAM_HELP_MSG_APPEND]
as $m ) {
2426 $msgs[$param][] = $m;
2428 self::dieDebug( __METHOD__,
2429 'Value in ApiBase::PARAM_HELP_MSG_APPEND is not valid' );
2435 Hooks::run(
'APIGetParamDescriptionMessages', [ $this, &$msgs ] );
2462 $flags[] =
'writerights';
2465 $flags[] =
'mustbeposted';
2485 if ( $this->mModuleSource !==
false ) {
2490 $rClass =
new ReflectionClass( $this );
2491 $path = $rClass->getFileName();
2494 $this->mModuleSource = null;
2500 if ( self::$extensionInfo === null ) {
2501 self::$extensionInfo = [
2502 realpath( __DIR__ ) ?: __DIR__ => [
2504 'name' =>
'MediaWiki',
2505 'license-name' =>
'GPL-2.0+',
2507 realpath(
"$IP/extensions" ) ?:
"$IP/extensions" => null,
2513 'license-name' => null,
2515 foreach ( $this->
getConfig()->
get(
'ExtensionCredits' )
as $group ) {
2516 foreach ( $group
as $ext ) {
2517 if ( !isset( $ext[
'path'] ) || !isset( $ext[
'name'] ) ) {
2522 $extpath = $ext[
'path'];
2523 if ( !is_dir( $extpath ) ) {
2524 $extpath = dirname( $extpath );
2526 self::$extensionInfo[realpath( $extpath ) ?: $extpath] =
2527 array_intersect_key( $ext, $keep );
2531 $extpath = $ext[
'path'];
2532 if ( !is_dir( $extpath ) ) {
2533 $extpath = dirname( $extpath );
2535 self::$extensionInfo[realpath( $extpath ) ?: $extpath] =
2536 array_intersect_key( $ext, $keep );
2543 if ( array_key_exists(
$path, self::$extensionInfo ) ) {
2545 $this->mModuleSource = self::$extensionInfo[
$path];
2551 }
while (
$path !== $oldpath );
2554 $this->mModuleSource = null;
2635 static $lnPrfx =
"\n ";
2639 if ( $msg !==
false ) {
2641 if ( !is_array( $msg ) ) {
2646 $msg = $lnPrfx . implode( $lnPrfx, $msg ) .
"\n";
2651 $msg .=
"\nThis module requires read rights";
2654 $msg .=
"\nThis module requires write rights";
2657 $msg .=
"\nThis module only accepts POST requests";
2667 if ( $paramsMsg !==
false ) {
2668 $msg .=
"Parameters:\n$paramsMsg";
2673 if ( !is_array( $examples ) ) {
2678 $msg .=
'Example' . ( count( $examples ) > 1 ?
's' :
'' ) .
":\n";
2679 foreach ( $examples
as $k => $v ) {
2680 if ( is_numeric( $k ) ) {
2683 if ( is_array( $v ) ) {
2684 $msgExample = implode(
"\n", array_map( [ $this,
'indentExampleText' ], $v ) );
2686 $msgExample =
" $v";
2689 $msg .= wordwrap( $msgExample, 100,
"\n" ) .
"\n $k\n";
2716 if ( $input ===
false ) {
2719 if ( !is_array( $input ) ) {
2720 $input = [ $input ];
2723 if ( count( $input ) > 0 ) {
2725 $msg =
$title . ( count( $input ) > 1 ?
's' :
'' ) .
":\n ";
2729 $msg .= implode( $prefix, $input ) .
"\n";
2749 $paramPrefix =
"\n" . str_repeat(
' ', 24 );
2750 $descWordwrap =
"\n" . str_repeat(
' ', 28 );
2751 foreach (
$params as $paramName => $paramSettings ) {
2752 $desc = isset( $paramsDescription[$paramName] ) ? $paramsDescription[$paramName] :
'';
2753 if ( is_array( $desc ) ) {
2754 $desc = implode( $paramPrefix, $desc );
2758 if ( !is_array( $paramSettings ) ) {
2760 self::PARAM_DFLT => $paramSettings,
2769 if ( is_bool( $dflt ) ) {
2771 } elseif ( is_string( $dflt ) || is_null( $dflt ) ) {
2773 } elseif ( is_int( $dflt ) ) {
2778 if ( isset( $paramSettings[self::PARAM_DEPRECATED] )
2779 && $paramSettings[self::PARAM_DEPRECATED]
2781 $desc =
"DEPRECATED! $desc";
2784 if ( isset( $paramSettings[self::PARAM_REQUIRED] )
2785 && $paramSettings[self::PARAM_REQUIRED]
2787 $desc .= $paramPrefix .
'This parameter is required';
2790 $type = isset( $paramSettings[self::PARAM_TYPE] )
2791 ? $paramSettings[self::PARAM_TYPE]
2793 if ( isset(
$type ) ) {
2794 $hintPipeSeparated =
true;
2795 $multi = isset( $paramSettings[self::PARAM_ISMULTI] )
2796 ? $paramSettings[self::PARAM_ISMULTI]
2799 $prompt =
'Values (separate with \'|\'): ';
2801 $prompt =
'One value: ';
2804 if (
$type ===
'submodule' ) {
2805 if ( isset( $paramSettings[self::PARAM_SUBMODULE_MAP] ) ) {
2806 $type = array_keys( $paramSettings[self::PARAM_SUBMODULE_MAP] );
2812 if ( is_array(
$type ) ) {
2814 $nothingPrompt =
'';
2817 $nothingPrompt =
'Can be empty, or ';
2822 $desc .= $paramPrefix . $nothingPrompt . $prompt;
2823 $choicesstring = implode(
', ', $choices );
2824 $desc .= wordwrap( $choicesstring, 100, $descWordwrap );
2825 $hintPipeSeparated =
false;
2831 $desc .= $paramPrefix . $prompt;
2833 100, $descWordwrap );
2834 $hintPipeSeparated =
false;
2837 $desc .= $paramPrefix .
"No more than {$paramSettings[self::PARAM_MAX]}";
2838 if ( isset( $paramSettings[self::PARAM_MAX2] ) ) {
2839 $desc .=
" ({$paramSettings[self::PARAM_MAX2]} for bots)";
2841 $desc .=
' allowed';
2844 $s = $multi ?
's' :
'';
2845 $hasMin = isset( $paramSettings[self::PARAM_MIN] );
2846 $hasMax = isset( $paramSettings[self::PARAM_MAX] );
2847 if ( $hasMin || $hasMax ) {
2849 $intRangeStr =
"The value$s must be no less than " .
2850 "{$paramSettings[self::PARAM_MIN]}";
2851 } elseif ( !$hasMin ) {
2852 $intRangeStr =
"The value$s must be no more than " .
2853 "{$paramSettings[self::PARAM_MAX]}";
2855 $intRangeStr =
"The value$s must be between " .
2856 "{$paramSettings[self::PARAM_MIN]} and {$paramSettings[self::PARAM_MAX]}";
2859 $desc .= $paramPrefix . $intRangeStr;
2863 $desc .= $paramPrefix .
'Must be posted as a file upload using multipart/form-data';
2869 if ( $hintPipeSeparated ) {
2870 $desc .= $paramPrefix .
"Separate values with '|'";
2873 $isArray = is_array(
$type );
2875 || $isArray && count(
$type ) > self::LIMIT_SML1
2877 $desc .= $paramPrefix .
'Maximum number of values ' .
2878 self::LIMIT_SML1 .
' (' . self::LIMIT_SML2 .
' for bots)';
2883 $default = isset( $paramSettings[self::PARAM_DFLT] ) ? $paramSettings[self::PARAM_DFLT] : null;
2884 if ( !is_null( $default ) && $default !==
false ) {
2885 $desc .= $paramPrefix .
"Default: $default";
2888 $msg .= sprintf(
" %-19s - %s\n", $this->
encodeParamName( $paramName ), $desc );
static newFromName($name, $validate= 'valid')
Static factory method for creation from username.
dieUsageMsgOrDebug($error)
Will only set a warning instead of failing if the global $wgDebugAPI is set to true.
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
setContext(IContextSource $context)
Set the IContextSource object.
const PARAM_VALUE_LINKS
(string[]) When PARAM_TYPE is an array, this may be an array mapping those values to page titles whic...
getFinalParamDescription()
Get final parameter descriptions, after hooks have had a chance to tweak it as needed.
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below...
getErrorFormatter()
Get the error formatter.
const LIMIT_BIG2
Fast query, apihighlimits limit.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Interface for objects which can provide a MediaWiki context on request.
wfGetDB($db, $groups=[], $wiki=false)
Get a Database object.
isReadMode()
Indicates whether this module requires read rights.
the array() calling protocol came about after MediaWiki 1.4rc1.
validateTimestamp($value, $encParamName)
Validate and normalize of parameters of type 'timestamp'.
getResult()
Get the result object.
static $messageMap
Array that maps message keys to error messages.
getWatchlistUser($params)
Gets the user for whom to get the watchlist.
magic word the default is to use $key to get the and $key value or $key value text $key value html to format the value $key
Message subclass that prepends wikitext for API help.
getParameter($paramName, $parseLimit=true)
Get a value for the given parameter.
getDescriptionMessage()
Return the description message.
getModuleProfileName($db=false)
getModuleSourceInfo()
Returns information about the source of this module, if known.
getCustomPrinter()
If the module may only be used with a certain format module, it should override this method to return...
static array $extensionInfo
Maps extension paths to info arrays.
requireMaxOneParameter($params, $required)
Die if more than one of a certain set of parameters is set and not false.
useTransactionalTimeLimit()
Call wfTransactionalTimeLimit() if this request was POSTed.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
getMain()
Get the main module.
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
static escapeWikiText($v)
A subset of wfEscapeWikiText for BC texts.
getType()
Get the type of target for this particular block.
const GET_VALUES_FOR_HELP
getAllowedParams() flag: When set, the result could take longer to generate, but should be more thoro...
const LIMIT_BIG1
Fast query, standard limit.
getDB()
Gets a default slave database connection object.
getResultData()
Get the result data array (read-only)
const PARAM_MAX
(integer) Max value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
setWatch($watch, $titleObj, $userOption=null)
Set a watch (or unwatch) based the based on a watchlist parameter.
const PARAM_REQUIRED
(boolean) Is the parameter required?
getWatchlistValue($watchlist, $titleObj, $userOption=null)
Return true if we're to watch the page, false if not, null if no change.
const PARAM_HELP_MSG_INFO
(array) Specify additional information tags for the parameter.
lacksSameOriginSecurity()
Returns true if the current request breaks the same-origin policy.
extractRequestParams($parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user...
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible true was required This is the default since MediaWiki *some string
getParent()
Get the parent of this module.
requireOnlyOneParameter($params, $required)
Die if none or more than one of a certain set of parameters is set and not false. ...
static makeMessage($msg, IContextSource $context, array $params=null)
Create a Message from a string or array.
it s the revision text itself In either if gzip is the revision text is gzipped $flags
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
Interface for messages with machine-readable data for use by the API.
wfUrlencode($s)
We want some things to be included as literal characters in our title URLs for prettiness, which urlencode encodes by default.
static newFromText($text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
isDeprecated()
Indicates whether this module is deprecated.
when a variable name is used in a it is silently declared as a new local masking the global
getHelpUrls()
Return links to more detailed help pages about the module.
needsToken()
Returns the token type this module requires in order to execute.
getConditionalRequestData($condition)
Returns data for HTTP conditional request mechanisms.
getParameterFromSettings($paramName, $paramSettings, $parseLimit)
Using the settings determine the value for the given parameter.
static getBlockInfo(Block $block)
Get basic info about a given block.
wfTimestamp($outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
getRequest()
Get the WebRequest object.
wfMsgReplaceArgs($message, $args)
Replace message parameter keys on the given formatted output.
const PARAM_HELP_MSG_APPEND
((string|array|Message)[]) Specify additional i18n messages to append to the normal message for this ...
wfDebugLog($logGroup, $text, $dest= 'all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not...
getTitleOrPageId($params, $load=false)
Get a WikiPage object from a title or pageid param, if possible.
msg()
Get a Message object with context set Parameters are the same as wfMessage()
const PARAM_SUBMODULE_PARAM_PREFIX
(string) When PARAM_TYPE is 'submodule', used to indicate the 'g' prefix added by ApiQueryGeneratorBa...
static truncateArray(&$arr, $limit)
Truncate an array to a certain length.
validateToken($token, array $params)
Validate the supplied token.
parameterNotEmpty($x)
Callback function used in requireOnlyOneParameter to check whether required parameters are set...
getErrorFromStatus($status, &$extraData=null)
Get error (as code, string) from a Status object.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context $options
getHelpFlags()
Generates the list of flags for the help screen and for action=paraminfo.
const PARAM_RANGE_ENFORCE
(boolean) For PARAM_TYPE 'integer', enforce PARAM_MIN and PARAM_MAX?
getModulePath()
Get the path to this module.
getContinuationManager()
Get the continuation manager.
getConfig()
Get the Config object.
const LIMIT_SML2
Slow query, apihighlimits limit.
const PARAM_SUBMODULE_MAP
(string[]) When PARAM_TYPE is 'submodule', map parameter values to submodule paths.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock()-offset Set to overwrite offset parameter in $wgRequest set to ''to unsetoffset-wrap String Wrap the message in html(usually something like"<
getContext()
Get the base IContextSource object.
This is the main API class, used for both external and internal processing.
validateUser($value, $encParamName)
Validate and normalize of parameters of type 'user'.
wfDeprecated($function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
isInternal()
Indicates whether this module is "internal" Internal API modules are not (yet) intended for 3rd party...
static makeTitleSafe($ns, $title, $fragment= '', $interwiki= '')
Create a new Title from a namespace index and a DB key.
setContext(IContextSource $context)
Set the language and the title from a context object.
namespace and then decline to actually register it file or subcat img or subcat $title
dynamicParameterDocumentation()
Indicate if the module supports dynamically-determined parameters that cannot be included in self::ge...
getModuleName()
Get the name of the module being executed by this instance.
static dieReadOnly()
Helper function for readonly errors.
static run($event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
const PARAM_MAX2
(integer) Max value allowed for the parameter for users with the apihighlimits right, for PARAM_TYPE 'limit'.
setWarning($warning)
Set warning section for this module.
modifyHelp(array &$help, array $options, array &$tocData)
Called from ApiHelp before the pieces are joined together and returned.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable & $code
dieContinueUsageIf($condition)
Die with the $prefix.
requirePostedParameters($params, $prefix= 'prefix')
Die if any of the specified parameters were found in the query part of the URL rather than the post b...
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter...
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
const PARAM_SENSITIVE
(boolean) Is the parameter sensitive? Note 'password'-type fields are always sensitive regardless of ...
const TS_MW
MediaWiki concatenated string timestamp (YYYYMMDDHHMMSS)
const LIMIT_SML1
Slow query, standard limit.
getModuleManager()
Get the module manager, or null if this module has no sub-modules.
static getTokenTypeSalts()
Get the salts for known token types.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
mustBePosted()
Indicates whether this module must be called with a POST request.
error also a ContextSource you ll probably need to make sure the header is varied on $request
wfReadOnlyReason()
Check if the site is in read-only mode and return the message if so.
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
validateLimit($paramName, &$value, $min, $max, $botMax=null, $enforceLimits=false)
Validate the value against the minimum and user/bot maximum limits.
getDescription()
Returns the description string for this module.
parseMultiValue($valueName, $value, $allowMultiple, $allowedValues)
Return an array of values that were given in a 'a|b|c' notation, after it optionally validates them a...
static getToken(User $user, MediaWiki\Session\Session $session, $salt)
Get a token from a salt.
getFinalDescription()
Get final module description, after hooks have had a chance to tweak it as needed.
requireAtLeastOneParameter($params, $required)
Die if none of a certain set of parameters is set and not false.
makeHelpMsg()
Generates help message for this module, or false if there is no description.
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
__construct(ApiMain $mainModule, $moduleName, $modulePrefix= '')
wfTransactionalTimeLimit()
Set PHP's time limit to the larger of php.ini or $wgTransactionalTimeLimit.
dieUsage($description, $errorCode, $httpRespCode=0, $extradata=null)
Throw a UsageException, which will (if uncaught) call the main module's error handler and die with an...
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context the output can only depend on parameters provided to this hook not on global state indicating whether full HTML should be generated If generation of HTML may be but other information should still be present in the ParserOutput object to manipulate or replace but no entry for that model exists in $wgContentHandlers if desired whether it is OK to use $contentModel on $title Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok inclusive $limit
getExamples()
Returns usage examples for this module.
dieBlocked(Block $block)
Throw a UsageException, which will (if uncaught) call the main module's error handler and die with an...
static newFromID($id, $from= 'fromdb')
Constructor from a page id.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
Extension of RawMessage implementing IApiMessage.
This abstract class implements many basic API functions, and is the base of all API classes...
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
getWebUITokenSalt(array $params)
Fetch the salt used in the Web UI corresponding to this module.
const PARAM_DEPRECATED
(boolean) Is the parameter deprecated (will show a warning)?
array null bool $mModuleSource
getParamDescription()
Returns an array of parameter descriptions.
const TS_UNIX
Unix time - the number of seconds since 1970-01-01 00:00:00 UTC.
getExamplesMessages()
Returns usage examples for this module.
parseMsg($error)
Return the error message related to a certain array.
makeHelpMsgParameters()
Generates the parameter descriptions for this module, to be displayed in the module's help...
const PARAM_MIN
(integer) Lowest value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
static dieDebug($method, $message)
Internal code errors should be reported with this method.
logFeatureUsage($feature)
Write logging information for API features to a debug log, for usage analysis.
static doWatchOrUnwatch($watch, Title $title, User $user)
Watch or unwatch a page.
dieStatus($status)
Throw a UsageException based on the errors in the Status object.
shouldCheckMaxlag()
Indicates if this module needs maxlag to be checked.
static getValidNamespaces()
Returns an array of the namespaces (by integer id) that exist on the wiki.
encodeParamName($paramName)
This method mangles parameter name based on the prefix supplied to the constructor.
setContinuationManager($manager)
Set the continuation manager.
warnOrDie($msg, $enforceLimits=false)
Adds a warning to the output, else dies.
getUser()
Get the User object.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached one of or reset my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type
dieUsageMsg($error)
Output the error message related to a certain array.
const PARAM_ALLOW_DUPLICATES
(boolean) Allow the same value to be set more than once when PARAM_ISMULTI is true?
getModuleFromPath($path)
Get a module from its module path.
This exception will be thrown when dieUsage is called to stop module execution.
getFinalParams($flags=0)
Get final list of parameters, after hooks have had a chance to tweak it as needed.
isMain()
Returns true if this module is the main module ($this === $this->mMainModule), false otherwise...
isWriteMode()
Indicates whether this module requires write mode.
makeHelpArrayToString($prefix, $title, $input)
Allows to change the fields on the form that will be generated $name
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...