MediaWiki  master
SpecialUserrights.php
Go to the documentation of this file.
1 <?php
29 class UserrightsPage extends SpecialPage {
36  protected $mTarget;
37  /*
38  * @var null|User $mFetchedUser The user object of the target username or null.
39  */
40  protected $mFetchedUser = null;
41  protected $isself = false;
42 
43  public function __construct() {
44  parent::__construct( 'Userrights' );
45  }
46 
47  public function doesWrites() {
48  return true;
49  }
50 
60  public function userCanChangeRights( $targetUser, $checkIfSelf = true ) {
61  $isself = $this->getUser()->equals( $targetUser );
62 
63  $available = $this->changeableGroups();
64  if ( $targetUser->getId() == 0 ) {
65  return false;
66  }
67 
68  return !empty( $available['add'] )
69  || !empty( $available['remove'] )
70  || ( ( $isself || !$checkIfSelf ) &&
71  ( !empty( $available['add-self'] )
72  || !empty( $available['remove-self'] ) ) );
73  }
74 
82  public function execute( $par ) {
83  $user = $this->getUser();
84  $request = $this->getRequest();
85  $session = $request->getSession();
86  $out = $this->getOutput();
87 
88  $out->addModules( [ 'mediawiki.special.userrights' ] );
89 
90  $this->mTarget = $par ?? $request->getVal( 'user' );
91 
92  if ( is_string( $this->mTarget ) ) {
93  $this->mTarget = trim( $this->mTarget );
94  }
95 
96  if ( $this->mTarget !== null && User::getCanonicalName( $this->mTarget ) === $user->getName() ) {
97  $this->isself = true;
98  }
99 
100  $fetchedStatus = $this->fetchUser( $this->mTarget, true );
101  if ( $fetchedStatus->isOK() ) {
102  $this->mFetchedUser = $fetchedStatus->value;
103  if ( $this->mFetchedUser instanceof User ) {
104  // Set the 'relevant user' in the skin, so it displays links like Contributions,
105  // User logs, UserRights, etc.
106  $this->getSkin()->setRelevantUser( $this->mFetchedUser );
107  }
108  }
109 
110  // show a successbox, if the user rights was saved successfully
111  if (
112  $session->get( 'specialUserrightsSaveSuccess' ) &&
113  $this->mFetchedUser !== null
114  ) {
115  // Remove session data for the success message
116  $session->remove( 'specialUserrightsSaveSuccess' );
117 
118  $out->addModuleStyles( 'mediawiki.notification.convertmessagebox.styles' );
119  $out->addHTML(
121  'div',
122  [
123  'class' => 'mw-notify-success successbox',
124  'id' => 'mw-preferences-success',
125  'data-mw-autohide' => 'false',
126  ],
128  'p',
129  [],
130  $this->msg( 'savedrights', $this->mFetchedUser->getName() )->text()
131  )
132  )
133  );
134  }
135 
136  $this->setHeaders();
137  $this->outputHeader();
138 
139  $out->addModuleStyles( 'mediawiki.special' );
140  $this->addHelpLink( 'Help:Assigning permissions' );
141 
142  $this->switchForm();
143 
144  if (
145  $request->wasPosted() &&
146  $request->getCheck( 'saveusergroups' ) &&
147  $this->mTarget !== null &&
148  $user->matchEditToken( $request->getVal( 'wpEditToken' ), $this->mTarget )
149  ) {
150  /*
151  * If the user is blocked and they only have "partial" access
152  * (e.g. they don't have the userrights permission), then don't
153  * allow them to change any user rights.
154  */
155  if ( $user->isBlocked() && !$user->isAllowed( 'userrights' ) ) {
156  throw new UserBlockedError( $user->getBlock() );
157  }
158 
159  $this->checkReadOnly();
160 
161  // save settings
162  if ( !$fetchedStatus->isOK() ) {
163  $this->getOutput()->addWikiTextAsInterface( $fetchedStatus->getWikiText() );
164 
165  return;
166  }
167 
168  $targetUser = $this->mFetchedUser;
169  if ( $targetUser instanceof User ) { // UserRightsProxy doesn't have this method (T63252)
170  $targetUser->clearInstanceCache(); // T40989
171  }
172 
173  if ( $request->getVal( 'conflictcheck-originalgroups' )
174  !== implode( ',', $targetUser->getGroups() )
175  ) {
176  $out->addWikiMsg( 'userrights-conflict' );
177  } else {
178  $status = $this->saveUserGroups(
179  $this->mTarget,
180  $request->getVal( 'user-reason' ),
181  $targetUser
182  );
183 
184  if ( $status->isOK() ) {
185  // Set session data for the success message
186  $session->set( 'specialUserrightsSaveSuccess', 1 );
187 
188  $out->redirect( $this->getSuccessURL() );
189  return;
190  } else {
191  // Print an error message and redisplay the form
192  $out->wrapWikiTextAsInterface( 'error', $status->getWikiText() );
193  }
194  }
195  }
196 
197  // show some more forms
198  if ( $this->mTarget !== null ) {
199  $this->editUserGroupsForm( $this->mTarget );
200  }
201  }
202 
203  function getSuccessURL() {
204  return $this->getPageTitle( $this->mTarget )->getFullURL();
205  }
206 
213  public function canProcessExpiries() {
214  return true;
215  }
216 
226  public static function expiryToTimestamp( $expiry ) {
227  if ( wfIsInfinity( $expiry ) ) {
228  return null;
229  }
230 
231  $unix = strtotime( $expiry );
232 
233  if ( !$unix || $unix === -1 ) {
234  return false;
235  }
236 
237  // @todo FIXME: Non-qualified absolute times are not in users specified timezone
238  // and there isn't notice about it in the ui (see ProtectionForm::getExpiry)
239  return wfTimestamp( TS_MW, $unix );
240  }
241 
251  protected function saveUserGroups( $username, $reason, $user ) {
252  $allgroups = $this->getAllGroups();
253  $addgroup = [];
254  $groupExpiries = []; // associative array of (group name => expiry)
255  $removegroup = [];
256  $existingUGMs = $user->getGroupMemberships();
257 
258  // This could possibly create a highly unlikely race condition if permissions are changed between
259  // when the form is loaded and when the form is saved. Ignoring it for the moment.
260  foreach ( $allgroups as $group ) {
261  // We'll tell it to remove all unchecked groups, and add all checked groups.
262  // Later on, this gets filtered for what can actually be removed
263  if ( $this->getRequest()->getCheck( "wpGroup-$group" ) ) {
264  $addgroup[] = $group;
265 
266  if ( $this->canProcessExpiries() ) {
267  // read the expiry information from the request
268  $expiryDropdown = $this->getRequest()->getVal( "wpExpiry-$group" );
269  if ( $expiryDropdown === 'existing' ) {
270  continue;
271  }
272 
273  if ( $expiryDropdown === 'other' ) {
274  $expiryValue = $this->getRequest()->getVal( "wpExpiry-$group-other" );
275  } else {
276  $expiryValue = $expiryDropdown;
277  }
278 
279  // validate the expiry
280  $groupExpiries[$group] = self::expiryToTimestamp( $expiryValue );
281 
282  if ( $groupExpiries[$group] === false ) {
283  return Status::newFatal( 'userrights-invalid-expiry', $group );
284  }
285 
286  // not allowed to have things expiring in the past
287  if ( $groupExpiries[$group] && $groupExpiries[$group] < wfTimestampNow() ) {
288  return Status::newFatal( 'userrights-expiry-in-past', $group );
289  }
290 
291  // if the user can only add this group (not remove it), the expiry time
292  // cannot be brought forward (T156784)
293  if ( !$this->canRemove( $group ) &&
294  isset( $existingUGMs[$group] ) &&
295  ( $existingUGMs[$group]->getExpiry() ?: 'infinity' ) >
296  ( $groupExpiries[$group] ?: 'infinity' )
297  ) {
298  return Status::newFatal( 'userrights-cannot-shorten-expiry', $group );
299  }
300  }
301  } else {
302  $removegroup[] = $group;
303  }
304  }
305 
306  $this->doSaveUserGroups( $user, $addgroup, $removegroup, $reason, [], $groupExpiries );
307 
308  return Status::newGood();
309  }
310 
324  function doSaveUserGroups( $user, array $add, array $remove, $reason = '',
325  array $tags = [], array $groupExpiries = []
326  ) {
327  // Validate input set...
328  $isself = $user->getName() == $this->getUser()->getName();
329  $groups = $user->getGroups();
330  $ugms = $user->getGroupMemberships();
331  $changeable = $this->changeableGroups();
332  $addable = array_merge( $changeable['add'], $isself ? $changeable['add-self'] : [] );
333  $removable = array_merge( $changeable['remove'], $isself ? $changeable['remove-self'] : [] );
334 
335  $remove = array_unique(
336  array_intersect( (array)$remove, $removable, $groups ) );
337  $add = array_intersect( (array)$add, $addable );
338 
339  // add only groups that are not already present or that need their expiry updated,
340  // UNLESS the user can only add this group (not remove it) and the expiry time
341  // is being brought forward (T156784)
342  $add = array_filter( $add,
343  function ( $group ) use ( $groups, $groupExpiries, $removable, $ugms ) {
344  if ( isset( $groupExpiries[$group] ) &&
345  !in_array( $group, $removable ) &&
346  isset( $ugms[$group] ) &&
347  ( $ugms[$group]->getExpiry() ?: 'infinity' ) >
348  ( $groupExpiries[$group] ?: 'infinity' )
349  ) {
350  return false;
351  }
352  return !in_array( $group, $groups ) || array_key_exists( $group, $groupExpiries );
353  } );
354 
355  Hooks::run( 'ChangeUserGroups', [ $this->getUser(), $user, &$add, &$remove ] );
356 
357  $oldGroups = $groups;
358  $oldUGMs = $user->getGroupMemberships();
359  $newGroups = $oldGroups;
360 
361  // Remove groups, then add new ones/update expiries of existing ones
362  if ( $remove ) {
363  foreach ( $remove as $index => $group ) {
364  if ( !$user->removeGroup( $group ) ) {
365  unset( $remove[$index] );
366  }
367  }
368  $newGroups = array_diff( $newGroups, $remove );
369  }
370  if ( $add ) {
371  foreach ( $add as $index => $group ) {
372  $expiry = $groupExpiries[$group] ?? null;
373  if ( !$user->addGroup( $group, $expiry ) ) {
374  unset( $add[$index] );
375  }
376  }
377  $newGroups = array_merge( $newGroups, $add );
378  }
379  $newGroups = array_unique( $newGroups );
380  $newUGMs = $user->getGroupMemberships();
381 
382  // Ensure that caches are cleared
383  $user->invalidateCache();
384 
385  // update groups in external authentication database
386  Hooks::run( 'UserGroupsChanged', [ $user, $add, $remove, $this->getUser(),
387  $reason, $oldUGMs, $newUGMs ] );
389  'updateExternalDBGroups', [ $user, $add, $remove ]
390  );
391 
392  wfDebug( 'oldGroups: ' . print_r( $oldGroups, true ) . "\n" );
393  wfDebug( 'newGroups: ' . print_r( $newGroups, true ) . "\n" );
394  wfDebug( 'oldUGMs: ' . print_r( $oldUGMs, true ) . "\n" );
395  wfDebug( 'newUGMs: ' . print_r( $newUGMs, true ) . "\n" );
396  // Deprecated in favor of UserGroupsChanged hook
397  Hooks::run( 'UserRights', [ &$user, $add, $remove ], '1.26' );
398 
399  // Only add a log entry if something actually changed
400  if ( $newGroups != $oldGroups || $newUGMs != $oldUGMs ) {
401  $this->addLogEntry( $user, $oldGroups, $newGroups, $reason, $tags, $oldUGMs, $newUGMs );
402  }
403 
404  return [ $add, $remove ];
405  }
406 
414  protected static function serialiseUgmForLog( $ugm ) {
415  if ( !$ugm instanceof UserGroupMembership ) {
416  return null;
417  }
418  return [ 'expiry' => $ugm->getExpiry() ];
419  }
420 
431  protected function addLogEntry( $user, array $oldGroups, array $newGroups, $reason,
432  array $tags, array $oldUGMs, array $newUGMs
433  ) {
434  // make sure $oldUGMs and $newUGMs are in the same order, and serialise
435  // each UGM object to a simplified array
436  $oldUGMs = array_map( function ( $group ) use ( $oldUGMs ) {
437  return isset( $oldUGMs[$group] ) ?
438  self::serialiseUgmForLog( $oldUGMs[$group] ) :
439  null;
440  }, $oldGroups );
441  $newUGMs = array_map( function ( $group ) use ( $newUGMs ) {
442  return isset( $newUGMs[$group] ) ?
443  self::serialiseUgmForLog( $newUGMs[$group] ) :
444  null;
445  }, $newGroups );
446 
447  $logEntry = new ManualLogEntry( 'rights', 'rights' );
448  $logEntry->setPerformer( $this->getUser() );
449  $logEntry->setTarget( $user->getUserPage() );
450  $logEntry->setComment( $reason );
451  $logEntry->setParameters( [
452  '4::oldgroups' => $oldGroups,
453  '5::newgroups' => $newGroups,
454  'oldmetadata' => $oldUGMs,
455  'newmetadata' => $newUGMs,
456  ] );
457  $logid = $logEntry->insert();
458  if ( count( $tags ) ) {
459  $logEntry->setTags( $tags );
460  }
461  $logEntry->publish( $logid );
462  }
463 
469  $status = $this->fetchUser( $username, true );
470  if ( !$status->isOK() ) {
471  $this->getOutput()->addWikiTextAsInterface( $status->getWikiText() );
472 
473  return;
474  } else {
475  $user = $status->value;
476  }
477 
478  $groups = $user->getGroups();
479  $groupMemberships = $user->getGroupMemberships();
480  $this->showEditUserGroupsForm( $user, $groups, $groupMemberships );
481 
482  // This isn't really ideal logging behavior, but let's not hide the
483  // interwiki logs if we're using them as is.
484  $this->showLogFragment( $user, $this->getOutput() );
485  }
486 
496  public function fetchUser( $username, $writing = true ) {
497  $parts = explode( $this->getConfig()->get( 'UserrightsInterwikiDelimiter' ), $username );
498  if ( count( $parts ) < 2 ) {
499  $name = trim( $username );
500  $database = '';
501  } else {
502  list( $name, $database ) = array_map( 'trim', $parts );
503 
504  if ( $database == wfWikiID() ) {
505  $database = '';
506  } else {
507  if ( $writing && !$this->getUser()->isAllowed( 'userrights-interwiki' ) ) {
508  return Status::newFatal( 'userrights-no-interwiki' );
509  }
510  if ( !UserRightsProxy::validDatabase( $database ) ) {
511  return Status::newFatal( 'userrights-nodatabase', $database );
512  }
513  }
514  }
515 
516  if ( $name === '' ) {
517  return Status::newFatal( 'nouserspecified' );
518  }
519 
520  if ( $name[0] == '#' ) {
521  // Numeric ID can be specified...
522  // We'll do a lookup for the name internally.
523  $id = intval( substr( $name, 1 ) );
524 
525  if ( $database == '' ) {
526  $name = User::whoIs( $id );
527  } else {
528  $name = UserRightsProxy::whoIs( $database, $id );
529  }
530 
531  if ( !$name ) {
532  return Status::newFatal( 'noname' );
533  }
534  } else {
536  if ( $name === false ) {
537  // invalid name
538  return Status::newFatal( 'nosuchusershort', $username );
539  }
540  }
541 
542  if ( $database == '' ) {
544  } else {
545  $user = UserRightsProxy::newFromName( $database, $name );
546  }
547 
548  if ( !$user || $user->isAnon() ) {
549  return Status::newFatal( 'nosuchusershort', $username );
550  }
551 
552  return Status::newGood( $user );
553  }
554 
562  public function makeGroupNameList( $ids ) {
563  if ( empty( $ids ) ) {
564  return $this->msg( 'rightsnone' )->inContentLanguage()->text();
565  } else {
566  return implode( ', ', $ids );
567  }
568  }
569 
573  function switchForm() {
574  $this->getOutput()->addModules( 'mediawiki.userSuggest' );
575 
576  $this->getOutput()->addHTML(
578  'form',
579  [
580  'method' => 'get',
581  'action' => wfScript(),
582  'name' => 'uluser',
583  'id' => 'mw-userrights-form1'
584  ]
585  ) .
586  Html::hidden( 'title', $this->getPageTitle()->getPrefixedText() ) .
587  Xml::fieldset( $this->msg( 'userrights-lookup-user' )->text() ) .
589  $this->msg( 'userrights-user-editname' )->text(),
590  'user',
591  'username',
592  30,
593  str_replace( '_', ' ', $this->mTarget ),
594  [
595  'class' => 'mw-autocomplete-user', // used by mediawiki.userSuggest
596  ] + (
597  // Set autofocus on blank input and error input
598  $this->mFetchedUser === null ? [ 'autofocus' => '' ] : []
599  )
600  ) . ' ' .
602  $this->msg( 'editusergroup' )->text()
603  ) .
604  Html::closeElement( 'fieldset' ) .
605  Html::closeElement( 'form' ) . "\n"
606  );
607  }
608 
618  protected function showEditUserGroupsForm( $user, $groups, $groupMemberships ) {
619  $list = $membersList = $tempList = $tempMembersList = [];
620  foreach ( $groupMemberships as $ugm ) {
621  $linkG = UserGroupMembership::getLink( $ugm, $this->getContext(), 'html' );
622  $linkM = UserGroupMembership::getLink( $ugm, $this->getContext(), 'html',
623  $user->getName() );
624  if ( $ugm->getExpiry() ) {
625  $tempList[] = $linkG;
626  $tempMembersList[] = $linkM;
627  } else {
628  $list[] = $linkG;
629  $membersList[] = $linkM;
630 
631  }
632  }
633 
634  $autoList = [];
635  $autoMembersList = [];
636  if ( $user instanceof User ) {
637  foreach ( Autopromote::getAutopromoteGroups( $user ) as $group ) {
638  $autoList[] = UserGroupMembership::getLink( $group, $this->getContext(), 'html' );
639  $autoMembersList[] = UserGroupMembership::getLink( $group, $this->getContext(),
640  'html', $user->getName() );
641  }
642  }
643 
644  $language = $this->getLanguage();
645  $displayedList = $this->msg( 'userrights-groupsmember-type' )
646  ->rawParams(
647  $language->commaList( array_merge( $tempList, $list ) ),
648  $language->commaList( array_merge( $tempMembersList, $membersList ) )
649  )->escaped();
650  $displayedAutolist = $this->msg( 'userrights-groupsmember-type' )
651  ->rawParams(
652  $language->commaList( $autoList ),
653  $language->commaList( $autoMembersList )
654  )->escaped();
655 
656  $grouplist = '';
657  $count = count( $list ) + count( $tempList );
658  if ( $count > 0 ) {
659  $grouplist = $this->msg( 'userrights-groupsmember' )
660  ->numParams( $count )
661  ->params( $user->getName() )
662  ->parse();
663  $grouplist = '<p>' . $grouplist . ' ' . $displayedList . "</p>\n";
664  }
665 
666  $count = count( $autoList );
667  if ( $count > 0 ) {
668  $autogrouplistintro = $this->msg( 'userrights-groupsmember-auto' )
669  ->numParams( $count )
670  ->params( $user->getName() )
671  ->parse();
672  $grouplist .= '<p>' . $autogrouplistintro . ' ' . $displayedAutolist . "</p>\n";
673  }
674 
675  $userToolLinks = Linker::userToolLinks(
676  $user->getId(),
677  $user->getName(),
678  false, /* default for redContribsWhenNoEdits */
679  Linker::TOOL_LINKS_EMAIL /* Add "send e-mail" link */
680  );
681 
682  list( $groupCheckboxes, $canChangeAny ) =
683  $this->groupCheckboxes( $groupMemberships, $user );
684  $this->getOutput()->addHTML(
686  'form',
687  [
688  'method' => 'post',
689  'action' => $this->getPageTitle()->getLocalURL(),
690  'name' => 'editGroup',
691  'id' => 'mw-userrights-form2'
692  ]
693  ) .
694  Html::hidden( 'user', $this->mTarget ) .
695  Html::hidden( 'wpEditToken', $this->getUser()->getEditToken( $this->mTarget ) ) .
696  Html::hidden(
697  'conflictcheck-originalgroups',
698  implode( ',', $user->getGroups() )
699  ) . // Conflict detection
700  Xml::openElement( 'fieldset' ) .
701  Xml::element(
702  'legend',
703  [],
704  $this->msg(
705  $canChangeAny ? 'userrights-editusergroup' : 'userrights-viewusergroup',
706  $user->getName()
707  )->text()
708  ) .
709  $this->msg(
710  $canChangeAny ? 'editinguser' : 'viewinguserrights'
711  )->params( wfEscapeWikiText( $user->getName() ) )
712  ->rawParams( $userToolLinks )->parse()
713  );
714  if ( $canChangeAny ) {
715  $conf = $this->getConfig();
716  $oldCommentSchema = $conf->get( 'CommentTableSchemaMigrationStage' ) === MIGRATION_OLD;
717  $this->getOutput()->addHTML(
718  $this->msg( 'userrights-groups-help', $user->getName() )->parse() .
719  $grouplist .
720  $groupCheckboxes .
721  Xml::openElement( 'table', [ 'id' => 'mw-userrights-table-outer' ] ) .
722  "<tr>
723  <td class='mw-label'>" .
724  Xml::label( $this->msg( 'userrights-reason' )->text(), 'wpReason' ) .
725  "</td>
726  <td class='mw-input'>" .
727  Xml::input( 'user-reason', 60, $this->getRequest()->getVal( 'user-reason', false ), [
728  'id' => 'wpReason',
729  // HTML maxlength uses "UTF-16 code units", which means that characters outside BMP
730  // (e.g. emojis) count for two each. This limit is overridden in JS to instead count
731  // Unicode codepoints (or 255 UTF-8 bytes for old schema).
732  'maxlength' => $oldCommentSchema ? 255 : CommentStore::COMMENT_CHARACTER_LIMIT,
733  ] ) .
734  "</td>
735  </tr>
736  <tr>
737  <td></td>
738  <td class='mw-submit'>" .
739  Xml::submitButton( $this->msg( 'saveusergroups', $user->getName() )->text(),
740  [ 'name' => 'saveusergroups' ] +
741  Linker::tooltipAndAccesskeyAttribs( 'userrights-set' )
742  ) .
743  "</td>
744  </tr>" .
745  Xml::closeElement( 'table' ) . "\n"
746  );
747  } else {
748  $this->getOutput()->addHTML( $grouplist );
749  }
750  $this->getOutput()->addHTML(
751  Xml::closeElement( 'fieldset' ) .
752  Xml::closeElement( 'form' ) . "\n"
753  );
754  }
755 
760  protected static function getAllGroups() {
761  return User::getAllGroups();
762  }
763 
773  private function groupCheckboxes( $usergroups, $user ) {
774  $allgroups = $this->getAllGroups();
775  $ret = '';
776 
777  // Get the list of preset expiry times from the system message
778  $expiryOptionsMsg = $this->msg( 'userrights-expiry-options' )->inContentLanguage();
779  $expiryOptions = $expiryOptionsMsg->isDisabled() ?
780  [] :
781  explode( ',', $expiryOptionsMsg->text() );
782 
783  // Put all column info into an associative array so that extensions can
784  // more easily manage it.
785  $columns = [ 'unchangeable' => [], 'changeable' => [] ];
786 
787  foreach ( $allgroups as $group ) {
788  $set = isset( $usergroups[$group] );
789  // Users who can add the group, but not remove it, can only lengthen
790  // expiries, not shorten them. So they should only see the expiry
791  // dropdown if the group currently has a finite expiry
792  $canOnlyLengthenExpiry = ( $set && $this->canAdd( $group ) &&
793  !$this->canRemove( $group ) && $usergroups[$group]->getExpiry() );
794  // Should the checkbox be disabled?
795  $disabledCheckbox = !(
796  ( $set && $this->canRemove( $group ) ) ||
797  ( !$set && $this->canAdd( $group ) ) );
798  // Should the expiry elements be disabled?
799  $disabledExpiry = $disabledCheckbox && !$canOnlyLengthenExpiry;
800  // Do we need to point out that this action is irreversible?
801  $irreversible = !$disabledCheckbox && (
802  ( $set && !$this->canAdd( $group ) ) ||
803  ( !$set && !$this->canRemove( $group ) ) );
804 
805  $checkbox = [
806  'set' => $set,
807  'disabled' => $disabledCheckbox,
808  'disabled-expiry' => $disabledExpiry,
809  'irreversible' => $irreversible
810  ];
811 
812  if ( $disabledCheckbox && $disabledExpiry ) {
813  $columns['unchangeable'][$group] = $checkbox;
814  } else {
815  $columns['changeable'][$group] = $checkbox;
816  }
817  }
818 
819  // Build the HTML table
820  $ret .= Xml::openElement( 'table', [ 'class' => 'mw-userrights-groups' ] ) .
821  "<tr>\n";
822  foreach ( $columns as $name => $column ) {
823  if ( $column === [] ) {
824  continue;
825  }
826  // Messages: userrights-changeable-col, userrights-unchangeable-col
827  $ret .= Xml::element(
828  'th',
829  null,
830  $this->msg( 'userrights-' . $name . '-col', count( $column ) )->text()
831  );
832  }
833 
834  $ret .= "</tr>\n<tr>\n";
835  foreach ( $columns as $column ) {
836  if ( $column === [] ) {
837  continue;
838  }
839  $ret .= "\t<td style='vertical-align:top;'>\n";
840  foreach ( $column as $group => $checkbox ) {
841  $attr = [ 'class' => 'mw-userrights-groupcheckbox' ];
842  if ( $checkbox['disabled'] ) {
843  $attr['disabled'] = 'disabled';
844  }
845 
846  $member = UserGroupMembership::getGroupMemberName( $group, $user->getName() );
847  if ( $checkbox['irreversible'] ) {
848  $text = $this->msg( 'userrights-irreversible-marker', $member )->text();
849  } elseif ( $checkbox['disabled'] && !$checkbox['disabled-expiry'] ) {
850  $text = $this->msg( 'userrights-no-shorten-expiry-marker', $member )->text();
851  } else {
852  $text = $member;
853  }
854  $checkboxHtml = Xml::checkLabel( $text, "wpGroup-" . $group,
855  "wpGroup-" . $group, $checkbox['set'], $attr );
856 
857  if ( $this->canProcessExpiries() ) {
858  $uiUser = $this->getUser();
859  $uiLanguage = $this->getLanguage();
860 
861  $currentExpiry = isset( $usergroups[$group] ) ?
862  $usergroups[$group]->getExpiry() :
863  null;
864 
865  // If the user can't modify the expiry, print the current expiry below
866  // it in plain text. Otherwise provide UI to set/change the expiry
867  if ( $checkbox['set'] &&
868  ( $checkbox['irreversible'] || $checkbox['disabled-expiry'] )
869  ) {
870  if ( $currentExpiry ) {
871  $expiryFormatted = $uiLanguage->userTimeAndDate( $currentExpiry, $uiUser );
872  $expiryFormattedD = $uiLanguage->userDate( $currentExpiry, $uiUser );
873  $expiryFormattedT = $uiLanguage->userTime( $currentExpiry, $uiUser );
874  $expiryHtml = $this->msg( 'userrights-expiry-current' )->params(
875  $expiryFormatted, $expiryFormattedD, $expiryFormattedT )->text();
876  } else {
877  $expiryHtml = $this->msg( 'userrights-expiry-none' )->text();
878  }
879  // T171345: Add a hidden form element so that other groups can still be manipulated,
880  // otherwise saving errors out with an invalid expiry time for this group.
881  $expiryHtml .= Html::hidden( "wpExpiry-$group",
882  $currentExpiry ? 'existing' : 'infinite' );
883  $expiryHtml .= "<br />\n";
884  } else {
885  $expiryHtml = Xml::element( 'span', null,
886  $this->msg( 'userrights-expiry' )->text() );
887  $expiryHtml .= Xml::openElement( 'span' );
888 
889  // add a form element to set the expiry date
890  $expiryFormOptions = new XmlSelect(
891  "wpExpiry-$group",
892  "mw-input-wpExpiry-$group", // forward compatibility with HTMLForm
893  $currentExpiry ? 'existing' : 'infinite'
894  );
895  if ( $checkbox['disabled-expiry'] ) {
896  $expiryFormOptions->setAttribute( 'disabled', 'disabled' );
897  }
898 
899  if ( $currentExpiry ) {
900  $timestamp = $uiLanguage->userTimeAndDate( $currentExpiry, $uiUser );
901  $d = $uiLanguage->userDate( $currentExpiry, $uiUser );
902  $t = $uiLanguage->userTime( $currentExpiry, $uiUser );
903  $existingExpiryMessage = $this->msg( 'userrights-expiry-existing',
904  $timestamp, $d, $t );
905  $expiryFormOptions->addOption( $existingExpiryMessage->text(), 'existing' );
906  }
907 
908  $expiryFormOptions->addOption(
909  $this->msg( 'userrights-expiry-none' )->text(),
910  'infinite'
911  );
912  $expiryFormOptions->addOption(
913  $this->msg( 'userrights-expiry-othertime' )->text(),
914  'other'
915  );
916  foreach ( $expiryOptions as $option ) {
917  if ( strpos( $option, ":" ) === false ) {
918  $displayText = $value = $option;
919  } else {
920  list( $displayText, $value ) = explode( ":", $option );
921  }
922  $expiryFormOptions->addOption( $displayText, htmlspecialchars( $value ) );
923  }
924 
925  // Add expiry dropdown
926  $expiryHtml .= $expiryFormOptions->getHTML() . '<br />';
927 
928  // Add custom expiry field
929  $attribs = [
930  'id' => "mw-input-wpExpiry-$group-other",
931  'class' => 'mw-userrights-expiryfield',
932  ];
933  if ( $checkbox['disabled-expiry'] ) {
934  $attribs['disabled'] = 'disabled';
935  }
936  $expiryHtml .= Xml::input( "wpExpiry-$group-other", 30, '', $attribs );
937 
938  // If the user group is set but the checkbox is disabled, mimic a
939  // checked checkbox in the form submission
940  if ( $checkbox['set'] && $checkbox['disabled'] ) {
941  $expiryHtml .= Html::hidden( "wpGroup-$group", 1 );
942  }
943 
944  $expiryHtml .= Xml::closeElement( 'span' );
945  }
946 
947  $divAttribs = [
948  'id' => "mw-userrights-nested-wpGroup-$group",
949  'class' => 'mw-userrights-nested',
950  ];
951  $checkboxHtml .= "\t\t\t" . Xml::tags( 'div', $divAttribs, $expiryHtml ) . "\n";
952  }
953  $ret .= "\t\t" . ( ( $checkbox['disabled'] && $checkbox['disabled-expiry'] )
954  ? Xml::tags( 'div', [ 'class' => 'mw-userrights-disabled' ], $checkboxHtml )
955  : Xml::tags( 'div', [], $checkboxHtml )
956  ) . "\n";
957  }
958  $ret .= "\t</td>\n";
959  }
960  $ret .= Xml::closeElement( 'tr' ) . Xml::closeElement( 'table' );
961 
962  return [ $ret, (bool)$columns['changeable'] ];
963  }
964 
969  private function canRemove( $group ) {
970  $groups = $this->changeableGroups();
971 
972  return in_array(
973  $group,
974  $groups['remove'] ) || ( $this->isself && in_array( $group, $groups['remove-self'] )
975  );
976  }
977 
982  private function canAdd( $group ) {
983  $groups = $this->changeableGroups();
984 
985  return in_array(
986  $group,
987  $groups['add'] ) || ( $this->isself && in_array( $group, $groups['add-self'] )
988  );
989  }
990 
1001  function changeableGroups() {
1002  return $this->getUser()->changeableGroups();
1003  }
1004 
1011  protected function showLogFragment( $user, $output ) {
1012  $rightsLogPage = new LogPage( 'rights' );
1013  $output->addHTML( Xml::element( 'h2', null, $rightsLogPage->getName()->text() ) );
1014  LogEventsList::showLogExtract( $output, 'rights', $user->getUserPage() );
1015  }
1016 
1025  public function prefixSearchSubpages( $search, $limit, $offset ) {
1026  $user = User::newFromName( $search );
1027  if ( !$user ) {
1028  // No prefix suggestion for invalid user
1029  return [];
1030  }
1031  // Autocomplete subpage as user list - public to allow caching
1032  return UserNamePrefixSearch::search( 'public', $search, $limit, $offset );
1033  }
1034 
1035  protected function getGroupName() {
1036  return 'users';
1037  }
1038 }
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
editUserGroupsForm( $username)
Edit user groups membership.
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
Definition: deferred.txt:11
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking, formatting, etc.
static expiryToTimestamp( $expiry)
Converts a user group membership expiry string into a timestamp.
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 $out
Definition: hooks.txt:822
static whoIs( $id)
Get the username corresponding to a given user ID.
Definition: User.php:891
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:232
addLogEntry( $user, array $oldGroups, array $newGroups, $reason, array $tags, array $oldUGMs, array $newUGMs)
Add a rights log entry for an action.
getContext()
Gets the context this SpecialPage is executed in.
doSaveUserGroups( $user, array $add, array $remove, $reason='', array $tags=[], array $groupExpiries=[])
Save user groups changes in the database.
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
Definition: hooks.txt:2046
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
execute( $par)
Manage forms to be shown according to posted data.
changeableGroups()
Returns $this->getUser()->changeableGroups()
Status::newGood()` to allow deletion, and then `return false` from the hook function. Ensure you consume the 'ChangeTagAfterDelete' hook to carry out custom deletion actions. $tag:name of the tag $user:user initiating the action & $status:Status object. See above. 'ChangeTagsListActive':Allows you to nominate which of the tags your extension uses are in active use. & $tags:list of all active tags. Append to this array. 'ChangeTagsAfterUpdateTags':Called after tags have been updated with the ChangeTags::updateTags function. Params:$addedTags:tags effectively added in the update $removedTags:tags effectively removed in the update $prevTags:tags that were present prior to the update $rc_id:recentchanges table id $rev_id:revision table id $log_id:logging table id $params:tag params $rc:RecentChange being tagged when the tagging accompanies the action, or null $user:User who performed the tagging when the tagging is subsequent to the action, or null 'ChangeTagsAllowedAdd':Called when checking if a user can add tags to a change. & $allowedTags:List of all the tags the user is allowed to add. Any tags the user wants to add( $addTags) that are not in this array will cause it to fail. You may add or remove tags to this array as required. $addTags:List of tags user intends to add. $user:User who is adding the tags. 'ChangeUserGroups':Called before user groups are changed. $performer:The User who will perform the change $user:The User whose groups will be changed & $add:The groups that will be added & $remove:The groups that will be removed 'Collation::factory':Called if $wgCategoryCollation is an unknown collation. $collationName:Name of the collation in question & $collationObject:Null. Replace with a subclass of the Collation class that implements the collation given in $collationName. 'ConfirmEmailComplete':Called after a user 's email has been confirmed successfully. $user:user(object) whose email is being confirmed 'ContentAlterParserOutput':Modify parser output for a given content object. Called by Content::getParserOutput after parsing has finished. Can be used for changes that depend on the result of the parsing but have to be done before LinksUpdate is called(such as adding tracking categories based on the rendered HTML). $content:The Content to render $title:Title of the page, as context $parserOutput:ParserOutput to manipulate 'ContentGetParserOutput':Customize parser output for a given content object, called by AbstractContent::getParserOutput. May be used to override the normal model-specific rendering of page content. $content:The Content to render $title:Title of the page, as context $revId:The revision ID, as context $options:ParserOptions for rendering. To avoid confusing the parser cache, the output can only depend on parameters provided to this hook function, not on global state. $generateHtml:boolean, indicating whether full HTML should be generated. If false, generation of HTML may be skipped, but other information should still be present in the ParserOutput object. & $output:ParserOutput, to manipulate or replace 'ContentHandlerDefaultModelFor':Called when the default content model is determined for a given title. May be used to assign a different model for that title. $title:the Title in question & $model:the model name. Use with CONTENT_MODEL_XXX constants. 'ContentHandlerForModelID':Called when a ContentHandler is requested for a given content model name, but no entry for that model exists in $wgContentHandlers. Note:if your extension implements additional models via this hook, please use GetContentModels hook to make them known to core. $modeName:the requested content model name & $handler:set this to a ContentHandler object, if desired. 'ContentModelCanBeUsedOn':Called to determine whether that content model can be used on a given page. This is especially useful to prevent some content models to be used in some special location. $contentModel:ID of the content model in question $title:the Title in question. & $ok:Output parameter, 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. 'ContribsPager::getQueryInfo':Before the contributions query is about to run & $pager:Pager object for contributions & $queryInfo:The query for the contribs Pager 'ContribsPager::reallyDoQuery':Called before really executing the query for My Contributions & $data:an array of results of all contribs queries $pager:The ContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'ContributionsLineEnding':Called before a contributions HTML line is finished $page:SpecialPage object for contributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'ContributionsToolLinks':Change tool links above Special:Contributions $id:User identifier $title:User page title & $tools:Array of tool links $specialPage:SpecialPage instance for context and services. Can be either SpecialContributions or DeletedContributionsPage. Extensions should type hint against a generic SpecialPage though. 'ConvertContent':Called by AbstractContent::convert when a conversion to another content model is requested. Handler functions that modify $result should generally return false to disable further attempts at conversion. $content:The Content object to be converted. $toModel:The ID of the content model to convert to. $lossy:boolean indicating whether lossy conversion is allowed. & $result:Output parameter, in case the handler function wants to provide a converted Content object. Note that $result->getContentModel() must return $toModel. 'ContentSecurityPolicyDefaultSource':Modify the allowed CSP load sources. This affects all directives except for the script directive. If you want to add a script source, see ContentSecurityPolicyScriptSource hook. & $defaultSrc:Array of Content-Security-Policy allowed sources $policyConfig:Current configuration for the Content-Security-Policy header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'ContentSecurityPolicyDirectives':Modify the content security policy directives. Use this only if ContentSecurityPolicyDefaultSource and ContentSecurityPolicyScriptSource do not meet your needs. & $directives:Array of CSP directives $policyConfig:Current configuration for the CSP header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'ContentSecurityPolicyScriptSource':Modify the allowed CSP script sources. Note that you also have to use ContentSecurityPolicyDefaultSource if you want non-script sources to be loaded from whatever you add. & $scriptSrc:Array of CSP directives $policyConfig:Current configuration for the CSP header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'CustomEditor':When invoking the page editor Return true to allow the normal editor to be used, or false if implementing a custom editor, e.g. for a special namespace, etc. $article:Article being edited $user:User performing the edit 'DatabaseOraclePostInit':Called after initialising an Oracle database $db:the DatabaseOracle object 'DeletedContribsPager::reallyDoQuery':Called before really executing the query for Special:DeletedContributions Similar to ContribsPager::reallyDoQuery & $data:an array of results of all contribs queries $pager:The DeletedContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'DeletedContributionsLineEnding':Called before a DeletedContributions HTML line is finished. Similar to ContributionsLineEnding $page:SpecialPage object for DeletedContributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'DeleteUnknownPreferences':Called by the cleanupPreferences.php maintenance script to build a WHERE clause with which to delete preferences that are not known about. This hook is used by extensions that have dynamically-named preferences that should not be deleted in the usual cleanup process. For example, the Gadgets extension creates preferences prefixed with 'gadget-', and so anything with that prefix is excluded from the deletion. &where:An array that will be passed as the $cond parameter to IDatabase::select() to determine what will be deleted from the user_properties table. $db:The IDatabase object, useful for accessing $db->buildLike() etc. 'DifferenceEngineAfterLoadNewText':called in DifferenceEngine::loadNewText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before returning true from this function. $differenceEngine:DifferenceEngine object 'DifferenceEngineLoadTextAfterNewContentIsLoaded':called in DifferenceEngine::loadText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before checking if the variable 's value is null. This hook can be used to inject content into said class member variable. $differenceEngine:DifferenceEngine object 'DifferenceEngineMarkPatrolledLink':Allows extensions to change the "mark as patrolled" link which is shown both on the diff header as well as on the bottom of a page, usually wrapped in a span element which has class="patrollink". $differenceEngine:DifferenceEngine object & $markAsPatrolledLink:The "mark as patrolled" link HTML(string) $rcid:Recent change ID(rc_id) for this change(int) 'DifferenceEngineMarkPatrolledRCID':Allows extensions to possibly change the rcid parameter. For example the rcid might be set to zero due to the user being the same as the performer of the change but an extension might still want to show it under certain conditions. & $rcid:rc_id(int) of the change or 0 $differenceEngine:DifferenceEngine object $change:RecentChange object $user:User object representing the current user 'DifferenceEngineNewHeader':Allows extensions to change the $newHeader variable, which contains information about the new revision, such as the revision 's author, whether the revision was marked as a minor edit or not, etc. $differenceEngine:DifferenceEngine object & $newHeader:The string containing the various #mw-diff-otitle[1-5] divs, which include things like revision author info, revision comment, RevisionDelete link and more $formattedRevisionTools:Array containing revision tools, some of which may have been injected with the DiffRevisionTools hook $nextlink:String containing the link to the next revision(if any) $status
Definition: hooks.txt:1314
static openElement( $element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing &#39;/&#39;...
Definition: Html.php:252
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:210
Class for generating HTML <select> or <datalist> elements.
Definition: XmlSelect.php:26
static input( $name, $size=false, $value=false, $attribs=[])
Convenience function to build an HTML text input field.
Definition: Xml.php:276
$value
wfIsInfinity( $str)
Determine input string is represents as infinity.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
getOutput()
Get the OutputPage being used for this instance.
static newFromName( $database, $name, $ignoreInvalidDB=false)
Factory function; get a remote user entry by name.
const COMMENT_CHARACTER_LIMIT
Maximum length of a comment in UTF-8 characters.
fetchUser( $username, $writing=true)
Normalize the input username, which may be local or remote, and return a user (or proxy) object for m...
static serialiseUgmForLog( $ugm)
Serialise a UserGroupMembership object for storage in the log_params section of the logging table...
static getLink( $ugm, IContextSource $context, $format, $userName=null)
Gets a link for a user group, possibly including the expiry date if relevant.
This list may contain false positives That usually means there is additional text with links below the first Each row contains links to the first and second as well as the first line of the second redirect text
static search( $audience, $search, $limit, $offset=0)
Do a prefix search of user names and return a list of matching user names.
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response after the basic globals have been set but before ordinary actions take place $output
Definition: hooks.txt:2280
static getAllGroups()
Return the set of defined explicit groups.
Definition: User.php:5102
Class to simplify the use of log pages.
Definition: LogPage.php:33
static validDatabase( $database)
Confirm the selected database name is a valid local interwiki database name.
The User object encapsulates all of the user-specific settings (user_id, name, rights, email address, options, last login time).
Definition: User.php:47
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
static getCanonicalName( $name, $validate='valid')
Given unvalidated user input, return a canonical username, or false if the username is invalid...
Definition: User.php:1238
static newFatal( $message)
Factory function for fatal errors.
Definition: StatusValue.php:68
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
switchForm()
Output a form to allow searching for a user.
static openElement( $element, $attribs=null)
This opens an XML element.
Definition: Xml.php:110
static callLegacyAuthPlugin( $method, array $params, $return=null)
Call a legacy AuthPlugin method, if necessary.
static getGroupMemberName( $group, $username)
Gets the localized name for a member of a group, if it exists.
static fieldset( $legend=false, $content=false, $attribs=[])
Shortcut for creating fieldsets.
Definition: Xml.php:611
const MIGRATION_OLD
Definition: Defines.php:315
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:81
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
prefixSearchSubpages( $search, $limit, $offset)
Return an array of subpages beginning with $search that this special page will accept.
static submitButton( $value, $attribs=[])
Convenience function to build an HTML submit button When $wgUseMediaWikiUIEverywhere is true it will ...
Definition: Xml.php:461
userCanChangeRights( $targetUser, $checkIfSelf=true)
Check whether the current user (from context) can change the target user&#39;s rights.
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
getSkin()
Shortcut to get the skin being used for this instance.
static tags( $element, $attribs, $contents)
Same as Xml::element(), but does not escape contents.
Definition: Xml.php:132
static closeElement( $element)
Returns "</$element>".
Definition: Html.php:310
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes! ...
$mTarget
The target of the local right-adjuster&#39;s interest.
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 & $attribs
Definition: hooks.txt:2046
static getAutopromoteGroups(User $user)
Get the groups for the given user based on $wgAutopromote.
Definition: Autopromote.php:35
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
Show an error when the user tries to do something whilst blocked.
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
Definition: distributors.txt:9
static label( $label, $id, $attribs=[])
Convenience function to build an HTML form label.
Definition: Xml.php:360
saveUserGroups( $username, $reason, $user)
Save user groups changes in the database.
canProcessExpiries()
Returns true if this user rights form can set and change user group expiries.
showEditUserGroupsForm( $user, $groups, $groupMemberships)
Show the form to edit group memberships.
static getAllGroups()
Returns an array of all groups that may be edited.
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
this hook is for auditing only or null if authentication failed before getting that far $username
Definition: hooks.txt:822
static closeElement( $element)
Shortcut to close an XML element.
Definition: Xml.php:119
getUser()
Shortcut to get the User executing this instance.
static hidden( $name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition: Html.php:795
getConfig()
Shortcut to get main config object.
static element( $element, $attribs=null, $contents='', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.
Definition: Xml.php:41
getLanguage()
Shortcut to get user&#39;s language.
msg( $key)
Wrapper around wfMessage that sets the current context.
Special page to allow managing user group membership.
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
static inputLabel( $label, $name, $id, $size=false, $value=false, $attribs=[])
Convenience function to build an HTML text input field with a label.
Definition: Xml.php:382
static checkLabel( $label, $name, $id, $checked=false, $attribs=[])
Convenience function to build an HTML checkbox with a label.
Definition: Xml.php:421
static whoIs( $database, $id, $ignoreInvalidDB=false)
Same as User::whoIs()
groupCheckboxes( $usergroups, $user)
Adds a table with checkboxes where you can select what groups to add/remove.
getRequest()
Get the WebRequest being used for this instance.
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:592
showLogFragment( $user, $output)
Show a rights log fragment for the specified user.
static tooltipAndAccesskeyAttribs( $name, array $msgParams=[], $options=null)
Returns the attributes for the tooltip and access key.
Definition: Linker.php:2133
static userToolLinks( $userId, $userText, $redContribsWhenNoEdits=false, $flags=0, $edits=null)
Generate standard user tool links (talk, contributions, block link, etc.)
Definition: Linker.php:914
checkReadOnly()
If the wiki is currently in readonly mode, throws a ReadOnlyError.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
Definition: hooks.txt:2685
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
getPageTitle( $subpage=false)
Get a self-referential title object.
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
Definition: hooks.txt:244
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
const TOOL_LINKS_EMAIL
Definition: Linker.php:39
static showLogExtract(&$out, $types=[], $page='', $user='', $param=[])
Show log extract.