MediaWiki  1.31.0
SpecialLog.php
Go to the documentation of this file.
1 <?php
29 class SpecialLog extends SpecialPage {
30  public function __construct() {
31  parent::__construct( 'Log' );
32  }
33 
34  public function execute( $par ) {
36 
37  $this->setHeaders();
38  $this->outputHeader();
39  $this->getOutput()->addModules( 'mediawiki.userSuggest' );
40  $this->addHelpLink( 'Help:Log' );
41 
42  $opts = new FormOptions;
43  $opts->add( 'type', '' );
44  $opts->add( 'user', '' );
45  $opts->add( 'page', '' );
46  $opts->add( 'pattern', false );
47  $opts->add( 'year', null, FormOptions::INTNULL );
48  $opts->add( 'month', null, FormOptions::INTNULL );
49  $opts->add( 'tagfilter', '' );
50  $opts->add( 'offset', '' );
51  $opts->add( 'dir', '' );
52  $opts->add( 'offender', '' );
53  $opts->add( 'subtype', '' );
54 
55  // Set values
56  $opts->fetchValuesFromRequest( $this->getRequest() );
57  if ( $par !== null ) {
58  $this->parseParams( $opts, (string)$par );
59  }
60 
61  # Don't let the user get stuck with a certain date
62  if ( $opts->getValue( 'offset' ) || $opts->getValue( 'dir' ) == 'prev' ) {
63  $opts->setValue( 'year', '' );
64  $opts->setValue( 'month', '' );
65  }
66 
67  // If the user doesn't have the right permission to view the specific
68  // log type, throw a PermissionsError
69  // If the log type is invalid, just show all public logs
70  $logRestrictions = $this->getConfig()->get( 'LogRestrictions' );
71  $type = $opts->getValue( 'type' );
72  if ( !LogPage::isLogType( $type ) ) {
73  $opts->setValue( 'type', '' );
74  } elseif ( isset( $logRestrictions[$type] )
75  && !$this->getUser()->isAllowed( $logRestrictions[$type] )
76  ) {
77  throw new PermissionsError( $logRestrictions[$type] );
78  }
79 
80  # Handle type-specific inputs
81  $qc = [];
82  if ( $opts->getValue( 'type' ) == 'suppress' ) {
83  $offenderName = $opts->getValue( 'offender' );
84  $offender = empty( $offenderName ) ? null : User::newFromName( $offenderName, false );
85  if ( $offender ) {
87  $qc = [ 'ls_field' => 'target_author_actor', 'ls_value' => $offender->getActorId() ];
88  } else {
89  if ( $offender->getId() > 0 ) {
90  $field = 'target_author_id';
91  $value = $offender->getId();
92  } else {
93  $field = 'target_author_ip';
94  $value = $offender->getName();
95  }
96  if ( !$offender->getActorId() ) {
97  $qc = [ 'ls_field' => $field, 'ls_value' => $value ];
98  } else {
99  $db = wfGetDB( DB_REPLICA );
100  $qc = [
101  'ls_field' => [ 'target_author_actor', $field ], // So LogPager::getQueryInfo() works right
102  $db->makeList( [
103  $db->makeList(
104  [ 'ls_field' => 'target_author_actor', 'ls_value' => $offender->getActorId() ], LIST_AND
105  ),
106  $db->makeList( [ 'ls_field' => $field, 'ls_value' => $value ], LIST_AND ),
107  ], LIST_OR ),
108  ];
109  }
110  }
111  }
112  } else {
113  // Allow extensions to add relations to their search types
114  Hooks::run(
115  'SpecialLogAddLogSearchRelations',
116  [ $opts->getValue( 'type' ), $this->getRequest(), &$qc ]
117  );
118  }
119 
120  # Some log types are only for a 'User:' title but we might have been given
121  # only the username instead of the full title 'User:username'. This part try
122  # to lookup for a user by that name and eventually fix user input. See T3697.
123  if ( in_array( $opts->getValue( 'type' ), self::getLogTypesOnUser() ) ) {
124  # ok we have a type of log which expect a user title.
125  $target = Title::newFromText( $opts->getValue( 'page' ) );
126  if ( $target && $target->getNamespace() === NS_MAIN ) {
127  # User forgot to add 'User:', we are adding it for him
128  $opts->setValue( 'page',
129  Title::makeTitleSafe( NS_USER, $opts->getValue( 'page' ) )
130  );
131  }
132  }
133 
134  $this->show( $opts, $qc );
135  }
136 
145  public static function getLogTypesOnUser() {
146  static $types = null;
147  if ( $types !== null ) {
148  return $types;
149  }
150  $types = [
151  'block',
152  'newusers',
153  'rights',
154  ];
155 
156  Hooks::run( 'GetLogTypesOnUser', [ &$types ] );
157  return $types;
158  }
159 
165  public function getSubpagesForPrefixSearch() {
166  $subpages = $this->getConfig()->get( 'LogTypes' );
167  $subpages[] = 'all';
168  sort( $subpages );
169  return $subpages;
170  }
171 
172  private function parseParams( FormOptions $opts, $par ) {
173  # Get parameters
174  $par = $par !== null ? $par : '';
175  $parms = explode( '/', $par );
176  $symsForAll = [ '*', 'all' ];
177  if ( $parms[0] != '' &&
178  ( in_array( $par, $this->getConfig()->get( 'LogTypes' ) ) || in_array( $par, $symsForAll ) )
179  ) {
180  $opts->setValue( 'type', $par );
181  } elseif ( count( $parms ) == 2 ) {
182  $opts->setValue( 'type', $parms[0] );
183  $opts->setValue( 'user', $parms[1] );
184  } elseif ( $par != '' ) {
185  $opts->setValue( 'user', $par );
186  }
187  }
188 
189  private function show( FormOptions $opts, array $extraConds ) {
190  # Create a LogPager item to get the results and a LogEventsList item to format them...
191  $loglist = new LogEventsList(
192  $this->getContext(),
193  $this->getLinkRenderer(),
195  );
196 
197  $pager = new LogPager(
198  $loglist,
199  $opts->getValue( 'type' ),
200  $opts->getValue( 'user' ),
201  $opts->getValue( 'page' ),
202  $opts->getValue( 'pattern' ),
203  $extraConds,
204  $opts->getValue( 'year' ),
205  $opts->getValue( 'month' ),
206  $opts->getValue( 'tagfilter' ),
207  $opts->getValue( 'subtype' )
208  );
209 
210  $this->addHeader( $opts->getValue( 'type' ) );
211 
212  # Set relevant user
213  if ( $pager->getPerformer() ) {
214  $performerUser = User::newFromName( $pager->getPerformer(), false );
215  $this->getSkin()->setRelevantUser( $performerUser );
216  }
217 
218  # Show form options
219  $loglist->showOptions(
220  $pager->getType(),
221  $pager->getPerformer(),
222  $pager->getPage(),
223  $pager->getPattern(),
224  $pager->getYear(),
225  $pager->getMonth(),
226  $pager->getFilterParams(),
227  $pager->getTagFilter(),
228  $pager->getAction()
229  );
230 
231  # Insert list
232  $logBody = $pager->getBody();
233  if ( $logBody ) {
234  $this->getOutput()->addHTML(
235  $pager->getNavigationBar() .
236  $this->getActionButtons(
237  $loglist->beginLogEventsList() .
238  $logBody .
239  $loglist->endLogEventsList()
240  ) .
241  $pager->getNavigationBar()
242  );
243  } else {
244  $this->getOutput()->addWikiMsg( 'logempty' );
245  }
246  }
247 
248  private function getActionButtons( $formcontents ) {
249  $user = $this->getUser();
250  $canRevDelete = $user->isAllowedAll( 'deletedhistory', 'deletelogentry' );
251  $showTagEditUI = ChangeTags::showTagEditingUI( $user );
252  # If the user doesn't have the ability to delete log entries nor edit tags,
253  # don't bother showing them the button(s).
254  if ( !$canRevDelete && !$showTagEditUI ) {
255  return $formcontents;
256  }
257 
258  # Show button to hide log entries and/or edit change tags
260  'form',
261  [ 'action' => wfScript(), 'id' => 'mw-log-deleterevision-submit' ]
262  ) . "\n";
263  $s .= Html::hidden( 'action', 'historysubmit' ) . "\n";
264  $s .= Html::hidden( 'type', 'logging' ) . "\n";
265 
266  $buttons = '';
267  if ( $canRevDelete ) {
268  $buttons .= Html::element(
269  'button',
270  [
271  'type' => 'submit',
272  'name' => 'revisiondelete',
273  'value' => '1',
274  'class' => "deleterevision-log-submit mw-log-deleterevision-button"
275  ],
276  $this->msg( 'showhideselectedlogentries' )->text()
277  ) . "\n";
278  }
279  if ( $showTagEditUI ) {
280  $buttons .= Html::element(
281  'button',
282  [
283  'type' => 'submit',
284  'name' => 'editchangetags',
285  'value' => '1',
286  'class' => "editchangetags-log-submit mw-log-editchangetags-button"
287  ],
288  $this->msg( 'log-edit-tags' )->text()
289  ) . "\n";
290  }
291 
292  $buttons .= ( new ListToggle( $this->getOutput() ) )->getHTML();
293 
294  $s .= $buttons . $formcontents . $buttons;
295  $s .= Html::closeElement( 'form' );
296 
297  return $s;
298  }
299 
305  protected function addHeader( $type ) {
306  $page = new LogPage( $type );
307  $this->getOutput()->setPageTitle( $page->getName() );
308  $this->getOutput()->addHTML( $page->getDescription()
309  ->setContext( $this->getContext() )->parseAsBlock() );
310  }
311 
312  protected function getGroupName() {
313  return 'changes';
314  }
315 }
$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:244
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:273
SpecialPage\msg
msg( $key)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:747
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
SpecialLog\parseParams
parseParams(FormOptions $opts, $par)
Definition: SpecialLog.php:172
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:676
FormOptions\getValue
getValue( $name)
Get the value for the given option name.
Definition: FormOptions.php:180
captcha-old.count
count
Definition: captcha-old.py:249
text
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition: design.txt:12
FormOptions\INTNULL
const INTNULL
Integer type or null, maps to WebRequest::getIntOrNull() This is useful for the namespace selector.
Definition: FormOptions.php:54
MIGRATION_NEW
const MIGRATION_NEW
Definition: Defines.php:296
SpecialLog\getActionButtons
getActionButtons( $formcontents)
Definition: SpecialLog.php:248
LogPager
Definition: LogPager.php:29
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:591
$s
$s
Definition: mergeMessageFileList.php:187
SpecialPage\getSkin
getSkin()
Shortcut to get the skin being used for this instance.
Definition: SpecialPage.php:696
ChangeTags\showTagEditingUI
static showTagEditingUI(User $user)
Indicate whether change tag editing UI is relevant.
Definition: ChangeTags.php:1460
PermissionsError
Show an error when a user tries to do something they do not have the necessary permissions for.
Definition: PermissionsError.php:28
LogEventsList\USE_CHECKBOXES
const USE_CHECKBOXES
Definition: LogEventsList.php:33
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
LIST_AND
const LIST_AND
Definition: Defines.php:44
NS_MAIN
const NS_MAIN
Definition: Defines.php:65
FormOptions\add
add( $name, $default, $type=self::AUTO)
Add an option to be handled by this FormOptions instance.
Definition: FormOptions.php:81
Html\closeElement
static closeElement( $element)
Returns "</$element>".
Definition: Html.php:309
SpecialPage\addHelpLink
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition: SpecialPage.php:786
LIST_OR
const LIST_OR
Definition: Defines.php:47
SpecialPage\getConfig
getConfig()
Shortcut to get main config object.
Definition: SpecialPage.php:715
wfScript
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
Definition: GlobalFunctions.php:2878
ListToggle
Class for generating clickable toggle links for a list of checkboxes.
Definition: ListToggle.php:31
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2800
LogPage\isLogType
static isLogType( $type)
Is $type a valid log type.
Definition: LogPage.php:204
LogPage
Class to simplify the use of log pages.
Definition: LogPage.php:31
SpecialLog\getLogTypesOnUser
static getLogTypesOnUser()
List log type for which the target is a user Thus if the given target is in NS_MAIN we can alter it t...
Definition: SpecialLog.php:145
SpecialLog\__construct
__construct()
Definition: SpecialLog.php:30
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:484
SpecialPage\getUser
getUser()
Shortcut to get the User executing this instance.
Definition: SpecialPage.php:686
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
LogEventsList
Definition: LogEventsList.php:30
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:649
FormOptions\setValue
setValue( $name, $value, $force=false)
Use to set the value of an option.
Definition: FormOptions.php:163
Html\hidden
static hidden( $name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition: Html.php:774
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:562
$value
$value
Definition: styleTest.css.php:45
SpecialPage
Parent class for all special pages.
Definition: SpecialPage.php:36
SpecialLog\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialLog.php:312
SpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: SpecialPage.php:666
SpecialLog\show
show(FormOptions $opts, array $extraConds)
Definition: SpecialLog.php:189
SpecialPage\getLinkRenderer
getLinkRenderer()
Definition: SpecialPage.php:861
SpecialLog
A special page that lists log entries.
Definition: SpecialLog.php:29
Html\openElement
static openElement( $element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
Definition: Html.php:251
NS_USER
const NS_USER
Definition: Defines.php:67
FormOptions
Helper class to keep track of options when mixing links and form elements.
Definition: FormOptions.php:35
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:231
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:203
SpecialLog\execute
execute( $par)
Default execute method Checks user permissions.
Definition: SpecialLog.php:34
SpecialPage\outputHeader
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
Definition: SpecialPage.php:583
SpecialLog\getSubpagesForPrefixSearch
getSubpagesForPrefixSearch()
Return an array of subpages that this special page will accept.
Definition: SpecialLog.php:165
array
the array() calling protocol came about after MediaWiki 1.4rc1.
SpecialLog\addHeader
addHeader( $type)
Set page title and show header for this log type.
Definition: SpecialLog.php:305
$type
$type
Definition: testCompression.php:48
$wgActorTableSchemaMigrationStage
int $wgActorTableSchemaMigrationStage
Actor table schema migration stage.
Definition: DefaultSettings.php:8822