MediaWiki  1.29.2
ApiSetPageLanguage.php
Go to the documentation of this file.
1 <?php
34 class ApiSetPageLanguage extends ApiBase {
35  // Check if change language feature is enabled
36  protected function getDescriptionMessage() {
37  if ( !$this->getConfig()->get( 'PageLanguageUseDB' ) ) {
38  return 'apihelp-setpagelanguage-description-disabled';
39  }
40  return parent::getDescriptionMessage();
41  }
42 
50  public function execute() {
51  // Check if change language feature is enabled
52  if ( !$this->getConfig()->get( 'PageLanguageUseDB' ) ) {
53  $this->dieWithError( 'apierror-pagelang-disabled' );
54  }
55 
56  // Check if the user has permissions
57  $this->checkUserRightsAny( 'pagelang' );
58 
60 
61  $params = $this->extractRequestParams();
62 
63  $pageObj = $this->getTitleOrPageId( $params, 'fromdbmaster' );
64  if ( !$pageObj->exists() ) {
65  $this->dieWithError( 'apierror-missingtitle' );
66  }
67 
68  $titleObj = $pageObj->getTitle();
69  $user = $this->getUser();
70 
71  // Check that the user is allowed to edit the page
72  $this->checkTitleUserPermissions( $titleObj, 'edit' );
73 
74  // If change tagging was requested, check that the user is allowed to tag,
75  // and the tags are valid
76  if ( count( $params['tags'] ) ) {
78  if ( !$tagStatus->isOK() ) {
79  $this->dieStatus( $tagStatus );
80  }
81  }
82 
84  $this,
85  $titleObj,
86  $params['lang'],
87  $params['reason'] === null ? '' : $params['reason'],
88  $params['tags'] ?: []
89  );
90 
91  if ( !$status->isOK() ) {
92  $this->dieStatus( $status );
93  }
94 
95  $r = [
96  'title' => $titleObj->getPrefixedText(),
97  'oldlanguage' => $status->value->oldLanguage,
98  'newlanguage' => $status->value->newLanguage,
99  'logid' => $status->value->logId
100  ];
101  $this->getResult()->addValue( null, $this->getModuleName(), $r );
102  }
103 
104  public function mustBePosted() {
105  return true;
106  }
107 
108  public function isWriteMode() {
109  return true;
110  }
111 
112  public function getAllowedParams() {
113  return [
114  'title' => null,
115  'pageid' => [
116  ApiBase::PARAM_TYPE => 'integer'
117  ],
118  'lang' => [
119  ApiBase::PARAM_TYPE => array_merge(
120  [ 'default' ],
121  array_keys( Language::fetchLanguageNames( null, 'mwfile' ) )
122  ),
123  ApiBase::PARAM_REQUIRED => true,
124  ],
125  'reason' => null,
126  'tags' => [
127  ApiBase::PARAM_TYPE => 'tags',
128  ApiBase::PARAM_ISMULTI => true,
129  ],
130  ];
131  }
132 
133  public function needsToken() {
134  return 'csrf';
135  }
136 
137  protected function getExamplesMessages() {
138  return [
139  'action=setpagelanguage&title=Main%20Page&lang=eu&token=123ABC'
140  => 'apihelp-setpagelanguage-example-language',
141  'action=setpagelanguage&pageid=123&lang=default&token=123ABC'
142  => 'apihelp-setpagelanguage-example-default',
143  ];
144  }
145 
146  public function getHelpUrls() {
147  return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:SetPageLanguage';
148  }
149 }
ContextSource\getConfig
getConfig()
Get the Config object.
Definition: ContextSource.php:68
ApiBase\PARAM_REQUIRED
const PARAM_REQUIRED
(boolean) Is the parameter required?
Definition: ApiBase.php:115
captcha-old.count
count
Definition: captcha-old.py:225
ApiBase\dieWithError
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
Definition: ApiBase.php:1796
ApiBase\getTitleOrPageId
getTitleOrPageId( $params, $load=false)
Get a WikiPage object from a title or pageid param, if possible.
Definition: ApiBase.php:895
ApiBase\PARAM_TYPE
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
Definition: ApiBase.php:91
ApiBase\getResult
getResult()
Get the result object.
Definition: ApiBase.php:610
$status
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup 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
Definition: hooks.txt:1049
ApiSetPageLanguage\mustBePosted
mustBePosted()
Indicates whether this module must be called with a POST request.
Definition: ApiSetPageLanguage.php:104
$user
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 account $user
Definition: hooks.txt:246
ApiBase\checkUserRightsAny
checkUserRightsAny( $rights, $user=null)
Helper function for permission-denied errors.
Definition: ApiBase.php:1890
$params
$params
Definition: styleTest.css.php:40
ContextSource\getUser
getUser()
Get the User object.
Definition: ContextSource.php:133
php
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
Definition: injection.txt:35
ApiBase
This abstract class implements many basic API functions, and is the base of all API classes.
Definition: ApiBase.php:41
Language\fetchLanguageNames
static fetchLanguageNames( $inLanguage=null, $include='mw')
Get an array of language names, indexed by code.
Definition: Language.php:803
ApiSetPageLanguage\isWriteMode
isWriteMode()
Indicates whether this module requires write mode.
Definition: ApiSetPageLanguage.php:108
ApiSetPageLanguage
API module that facilitates changing the language of a page.
Definition: ApiSetPageLanguage.php:34
ApiSetPageLanguage\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiSetPageLanguage.php:112
ApiBase\extractRequestParams
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:718
ApiSetPageLanguage\execute
execute()
Extracts the title and language from the request parameters and invokes the static SpecialPageLanguag...
Definition: ApiSetPageLanguage.php:50
ApiBase\checkTitleUserPermissions
checkTitleUserPermissions(Title $title, $actions, $user=null)
Helper function for permission-denied errors.
Definition: ApiBase.php:1908
ApiBase\useTransactionalTimeLimit
useTransactionalTimeLimit()
Call wfTransactionalTimeLimit() if this request was POSTed.
Definition: ApiBase.php:2440
ApiSetPageLanguage\getExamplesMessages
getExamplesMessages()
Returns usage examples for this module.
Definition: ApiSetPageLanguage.php:137
ApiSetPageLanguage\needsToken
needsToken()
Returns the token type this module requires in order to execute.
Definition: ApiSetPageLanguage.php:133
ApiSetPageLanguage\getDescriptionMessage
getDescriptionMessage()
Return the description message.
Definition: ApiSetPageLanguage.php:36
SpecialPageLanguage\changePageLanguage
static changePageLanguage(IContextSource $context, Title $title, $newLanguage, $reason, array $tags=[])
Definition: SpecialPageLanguage.php:159
ChangeTags\canAddTagsAccompanyingChange
static canAddTagsAccompanyingChange(array $tags, User $user=null)
Is it OK to allow the user to apply all the specified tags at the same time as they edit/make the cha...
Definition: ChangeTags.php:395
ApiBase\dieStatus
dieStatus(StatusValue $status)
Throw an ApiUsageException based on the Status object.
Definition: ApiBase.php:1861
ApiBase\getModuleName
getModuleName()
Get the name of the module being executed by this instance.
Definition: ApiBase.php:490
ApiBase\PARAM_ISMULTI
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
Definition: ApiBase.php:55
ApiSetPageLanguage\getHelpUrls
getHelpUrls()
Return links to more detailed help pages about the module.
Definition: ApiSetPageLanguage.php:146