46 const RIGOR_QUICK =
'quick';
49 const RIGOR_FULL =
'full';
52 const RIGOR_SECURE =
'secure';
136 $rigor = self::RIGOR_SECURE,
142 foreach ( $errors
as $index => $error ) {
143 $errKey = is_array( $error ) ? $error[0] : $error;
145 if ( in_array( $errKey, $ignoreErrors ) ) {
146 unset( $errors[$index] );
148 if ( $errKey instanceof
MessageSpecifier && in_array( $errKey->getKey(), $ignoreErrors ) ) {
149 unset( $errors[$index] );
168 $blocked =
$user->isHidden();
171 $page = Title::newFromLinkTarget( $page );
174 $block =
$user->getBlock( $fromReplica );
178 if ( $page->equals(
$user->getTalkPage() ) ) {
179 $blocked = $block->appliesToUsertalk( $page );
181 $blocked = $block->appliesToTitle( $page );
187 $allowUsertalk =
$user->isAllowUsertalk();
189 Hooks::run(
'UserIsBlockedFrom', [
$user, $page, &$blocked, &$allowUsertalk ] );
215 $rigor = self::RIGOR_SECURE,
218 if ( !in_array( $rigor, [ self::RIGOR_QUICK, self::RIGOR_FULL, self::RIGOR_SECURE ] ) ) {
219 throw new Exception(
"Invalid rigor parameter '$rigor'." );
222 # Read has special handling
223 if ( $action ==
'read' ) {
225 'checkPermissionHooks',
226 'checkReadPermissions',
229 # Don't call checkSpecialsAndNSPermissions, checkSiteConfigPermissions
230 # or checkUserConfigPermissions here as it will lead to duplicate
231 # error messages. This is okay to do since anywhere that checks for
232 # create will also check for edit, and those checks are called for edit.
233 } elseif ( $action ==
'create' ) {
235 'checkQuickPermissions',
236 'checkPermissionHooks',
237 'checkPageRestrictions',
238 'checkCascadingSourcesRestrictions',
239 'checkActionPermissions',
244 'checkQuickPermissions',
245 'checkPermissionHooks',
246 'checkSpecialsAndNSPermissions',
247 'checkSiteConfigPermissions',
248 'checkUserConfigPermissions',
249 'checkPageRestrictions',
250 'checkCascadingSourcesRestrictions',
251 'checkActionPermissions',
257 foreach ( $checks
as $method ) {
258 $errors = $this->$method( $action,
$user, $errors, $rigor, $short, $page );
260 if ( $short && $errors !== [] ) {
295 $page = Title::newFromLinkTarget( $page );
298 if ( !Hooks::run(
'userCan', [ &$page, &
$user, $action, &
$result ] ) ) {
299 return $result ? [] : [ [
'badaccess-group0' ] ];
302 if ( !Hooks::run(
'getUserPermissionsErrors', [ &$page, &
$user, $action, &
$result ] ) ) {
307 $rigor !== self::RIGOR_QUICK
308 && !( $short && count( $errors ) > 0 )
309 && !Hooks::run(
'getUserPermissionsErrorsExpensive', [ &$page, &
$user, $action, &
$result ] )
331 $errors = array_merge( $errors,
$result );
338 } elseif (
$result ===
false ) {
340 $errors[] = [
'badaccess-group0' ];
372 $page = Title::newFromLinkTarget( $page );
374 $whitelisted =
false;
376 # Shortcut for public wikis, allows skipping quite a bit of code
378 } elseif (
$user->isAllowed(
'read' ) ) {
379 # If the user is allowed to read pages, he is allowed to read all pages
385 # Always grant access to the login page.
386 # Even anons need to be able to log in.
388 } elseif ( is_array( $this->whitelistRead ) && count( $this->whitelistRead ) ) {
389 # Time to check the whitelist
390 # Only do these checks is there's something to check against
391 $name = $page->getPrefixedText();
392 $dbName = $page->getPrefixedDBkey();
395 if ( in_array(
$name, $this->whitelistRead,
true )
396 || in_array( $dbName, $this->whitelistRead,
true ) ) {
399 # Old settings might have the title prefixed with
400 # a colon for main-namespace pages
401 if ( in_array(
':' .
$name, $this->whitelistRead ) ) {
404 } elseif ( $page->isSpecialPage() ) {
405 # If it's a special page, ditch the subpage bit and check again
408 $this->specialPageFactory->resolveAlias(
$name );
411 if ( in_array( $pure, $this->whitelistRead,
true ) ) {
418 if ( !$whitelisted && is_array( $this->whitelistReadRegexp )
419 && !empty( $this->whitelistReadRegexp ) ) {
420 $name = $page->getPrefixedText();
422 foreach ( $this->whitelistReadRegexp
as $listItem ) {
423 if ( preg_match( $listItem,
$name ) ) {
430 if ( !$whitelisted ) {
431 # If the title is not whitelisted, give extensions a chance to do so...
432 Hooks::run(
'TitleReadWhitelist', [ $page,
$user, &$whitelisted ] );
433 if ( !$whitelisted ) {
452 return [
'badaccess-group0' ];
471 $this->specialPageFactory->resolveAlias( $page->
getDBkey() );
472 if (
$name == $thisName ) {
506 if ( $rigor === self::RIGOR_QUICK || in_array( $action, [
'createaccount',
'unblock' ] ) ) {
511 if ( $action ===
'read' && !$this->blockDisablesLogin ) {
515 if ( $this->emailConfirmToEdit
516 && !
$user->isEmailConfirmed()
517 && $action ===
'edit'
519 $errors[] = [
'confirmedittext' ];
522 $useReplica = ( $rigor !== self::RIGOR_SECURE );
523 $block =
$user->getBlock( $useReplica );
527 if ( !$block || $block->appliesToRight( $action ) ===
false ) {
548 if ( $actionObj && $actionObj->getRestriction() !== $action ) {
555 if ( !$actionObj || $actionObj->requiresUnblock() ) {
592 $page = Title::newFromLinkTarget( $page );
594 if ( !Hooks::run(
'TitleQuickPermissions',
595 [ $page,
$user, $action, &$errors, ( $rigor !== self::RIGOR_QUICK ), $short ] )
600 $isSubPage = MWNamespace::hasSubpages( $page->
getNamespace() ) ?
603 if ( $action ==
'create' ) {
605 ( MWNamespace::isTalk( $page->
getNamespace() ) && !
$user->isAllowed(
'createtalk' ) ) ||
606 ( !MWNamespace::isTalk( $page->
getNamespace() ) && !
$user->isAllowed(
'createpage' ) )
608 $errors[] =
$user->isAnon() ? [
'nocreatetext' ] : [
'nocreate-loggedin' ];
610 } elseif ( $action ==
'move' ) {
611 if ( !
$user->isAllowed(
'move-rootuserpages' )
614 $errors[] = [
'cant-move-user-page' ];
619 $errors[] = [
'movenotallowedfile' ];
624 $errors[] = [
'cant-move-category-page' ];
627 if ( !
$user->isAllowed(
'move' ) ) {
631 if (
$user->isAnon() && ( $userCanMove || $autoconfirmedCanMove ) ) {
633 $errors[] = [
'movenologintext' ];
635 $errors[] = [
'movenotallowed' ];
638 } elseif ( $action ==
'move-target' ) {
639 if ( !
$user->isAllowed(
'move' ) ) {
641 $errors[] = [
'movenotallowed' ];
642 } elseif ( !
$user->isAllowed(
'move-rootuserpages' )
645 $errors[] = [
'cant-move-to-user-page' ];
646 } elseif ( !
$user->isAllowed(
'move-categorypages' )
649 $errors[] = [
'cant-move-to-category-page' ];
651 } elseif ( !
$user->isAllowed( $action ) ) {
685 $page = Title::newFromLinkTarget( $page );
686 foreach ( $page->getRestrictions( $action )
as $right ) {
688 if ( $right ==
'sysop' ) {
689 $right =
'editprotected';
692 if ( $right ==
'autoconfirmed' ) {
693 $right =
'editsemiprotected';
695 if ( $right ==
'' ) {
698 if ( !
$user->isAllowed( $right ) ) {
699 $errors[] = [
'protectedpagetext', $right, $action ];
700 } elseif ( $page->areRestrictionsCascading() && !
$user->isAllowed(
'protect' ) ) {
701 $errors[] = [
'protectedpagetext',
'protect', $action ];
733 $page = Title::newFromLinkTarget( $page );
734 if ( $rigor !== self::RIGOR_QUICK && !$page->isUserConfigPage() ) {
735 # We /could/ use the protection level on the source page, but it's
736 # fairly ugly as we have to establish a precedence hierarchy for pages
737 # included by multiple cascade-protected pages. So just restrict
738 # it to people with 'protect' permission, as they could remove the
740 list( $cascadingSources, $restrictions ) = $page->getCascadeProtectionSources();
741 # Cascading protection depends on more than this page...
742 # Several cascading protected pages may include this page...
743 # Check each cascading level
744 # This is only for protection restrictions, not for all actions
745 if ( isset( $restrictions[$action] ) ) {
746 foreach ( $restrictions[$action]
as $right ) {
748 if ( $right ==
'sysop' ) {
749 $right =
'editprotected';
752 if ( $right ==
'autoconfirmed' ) {
753 $right =
'editsemiprotected';
755 if ( $right !=
'' && !
$user->isAllowedAll(
'protect', $right ) ) {
757 foreach ( $cascadingSources
as $wikiPage ) {
758 $wikiPages .=
'* [[:' . $wikiPage->getPrefixedText() .
"]]\n";
760 $errors[] = [
'cascadeprotected', count( $cascadingSources ), $wikiPages, $action ];
797 $page = Title::newFromLinkTarget( $page );
799 if ( $action ==
'protect' ) {
802 $errors[] = [
'protect-cantedit' ];
804 } elseif ( $action ==
'create' ) {
805 $title_protection = $page->getTitleProtection();
806 if ( $title_protection ) {
807 if ( $title_protection[
'permission'] ==
''
808 || !
$user->isAllowed( $title_protection[
'permission'] )
814 $title_protection[
'reason']
818 } elseif ( $action ==
'move' ) {
820 if ( !MWNamespace::isMovable( $page->
getNamespace() ) ) {
822 $errors[] = [
'immobile-source-namespace', $page->getNsText() ];
823 } elseif ( !$page->isMovable() ) {
825 $errors[] = [
'immobile-source-page' ];
827 } elseif ( $action ==
'move-target' ) {
828 if ( !MWNamespace::isMovable( $page->
getNamespace() ) ) {
829 $errors[] = [
'immobile-target-namespace', $page->getNsText() ];
830 } elseif ( !$page->isMovable() ) {
831 $errors[] = [
'immobile-target-page' ];
833 } elseif ( $action ==
'delete' ) {
835 if ( !$tempErrors ) {
837 $user, $tempErrors, $rigor,
true, $page );
841 $errors[] = [
'deleteprotected' ];
844 && !$this->
userCan(
'bigdelete', $user, $page ) && $page->isBigDeletion()
848 } elseif ( $action ===
'undelete' ) {
851 $errors[] = [
'undelete-cantedit' ];
853 if ( !$page->exists()
857 $errors[] = [
'undelete-cantcreate' ];
888 $page = Title::newFromLinkTarget( $page );
890 # Only 'createaccount' can be performed on special pages,
891 # which don't actually exist in the DB.
893 $errors[] = [
'ns-specialprotected' ];
896 # Check $wgNamespaceProtection for restricted namespaces
897 if ( $page->isNamespaceProtected(
$user ) ) {
899 wfMessage(
'nstab-main' )->text() : $page->getNsText();
901 [
'protectedinterface', $action ] : [
'namespaceprotected', $ns, $action ];
932 $page = Title::newFromLinkTarget( $page );
934 if ( $action !=
'patrol' ) {
938 if ( $page->isSiteCssConfigPage() && !
$user->isAllowed(
'editsitecss' ) ) {
939 $error = [
'sitecssprotected', $action ];
940 } elseif ( $page->isSiteJsonConfigPage() && !
$user->isAllowed(
'editsitejson' ) ) {
941 $error = [
'sitejsonprotected', $action ];
942 } elseif ( $page->isSiteJsConfigPage() && !
$user->isAllowed(
'editsitejs' ) ) {
943 $error = [
'sitejsprotected', $action ];
944 } elseif ( $page->isRawHtmlMessage() ) {
946 if ( !
$user->isAllowed(
'editsitejs' ) ) {
947 $error = [
'sitejsprotected', $action ];
948 } elseif ( !
$user->isAllowed(
'editsitecss' ) ) {
949 $error = [
'sitecssprotected', $action ];
954 if (
$user->isAllowed(
'editinterface' ) ) {
958 $error = [
'interfaceadmin-info',
wfMessage( $error[0], $error[1] ) ];
992 $page = Title::newFromLinkTarget( $page );
994 # Protect css/json/js subpages of user pages
995 # XXX: this might be better using restrictions
997 if ( $action ===
'patrol' ) {
1001 if ( preg_match(
'/^' . preg_quote(
$user->getName(),
'/' ) .
'\//', $page->
getText() ) ) {
1004 $page->isUserCssConfigPage()
1005 && !
$user->isAllowedAny(
'editmyusercss',
'editusercss' )
1007 $errors[] = [
'mycustomcssprotected', $action ];
1009 $page->isUserJsonConfigPage()
1010 && !
$user->isAllowedAny(
'editmyuserjson',
'edituserjson' )
1012 $errors[] = [
'mycustomjsonprotected', $action ];
1014 $page->isUserJsConfigPage()
1015 && !
$user->isAllowedAny(
'editmyuserjs',
'edituserjs' )
1017 $errors[] = [
'mycustomjsprotected', $action ];
1024 if ( !in_array( $action, [
'delete',
'deleterevision',
'suppressrevision' ],
true ) ) {
1026 $page->isUserCssConfigPage()
1027 && !
$user->isAllowed(
'editusercss' )
1029 $errors[] = [
'customcssprotected', $action ];
1031 $page->isUserJsonConfigPage()
1032 && !
$user->isAllowed(
'edituserjson' )
1034 $errors[] = [
'customjsonprotected', $action ];
1036 $page->isUserJsConfigPage()
1037 && !
$user->isAllowed(
'edituserjs' )
1039 $errors[] = [
'customjsprotected', $action ];
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
$wgDeleteRevisionsLimit
Optional to restrict deletion of pages with higher revision counts to users with the 'bigdelete' perm...
Actions are things which can be done to pages (edit, delete, rollback, etc).
static factory( $action, Page $page, IContextSource $context=null)
Get an appropriate Action subclass for the given action.
static exists( $name)
Check if a given action is recognised, even if it's disabled.
Exception class which takes an HTML error message, and does not produce a backtrace.
This is a utility class with only static functions for dealing with namespaces that encodes all the "...
Factory for handling the special page list and generating SpecialPage objects.
Group all the pieces relevant to the context of a request into one instance.
static getMain()
Get the RequestContext object associated with the main request.
Parent class for all special pages.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
Represents a title within MediaWiki.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
static isEveryoneAllowed( $right)
Check if all users may be assumed to have the given permission.
static groupHasPermission( $group, $role)
Check, if the given group has the given permission.
static whoIs( $id)
Get the username corresponding to a given user ID.
static newFatalPermissionDeniedStatus( $permission)
Factory function for fatal permission-denied errors.
Class representing a MediaWiki article and history.
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
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
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
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImgAuthModifyHeaders':Executed just before a file is streamed to a user via img_auth.php, allowing headers to be modified beforehand. $title:LinkTarget object & $headers:HTTP headers(name=> value, names are case insensitive). Two headers get special handling:If-Modified-Since(value must be a valid HTTP date) and Range(must be of the form "bytes=(\d*-\d*)") will be honored when streaming the file. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUnknownUser':When a user doesn 't exist locally, this hook is called to give extensions an opportunity to auto-create it. If the auto-creation is successful, return false. $name:User name 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED since 1.28! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead 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 unset offset - wrap String Wrap the message in html(usually something like "<div ...>$1</div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
Allows to change the fields on the form that will be generated $name
return true to allow those checks to and false if checking is done & $user
processing should stop and the error should be shown to the user * false
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