MediaWiki  1.33.0
SpecialLog.php
Go to the documentation of this file.
1 <?php
24 use Wikimedia\Timestamp\TimestampException;
25 
31 class SpecialLog extends SpecialPage {
32  public function __construct() {
33  parent::__construct( 'Log' );
34  }
35 
36  public function execute( $par ) {
38 
39  $this->setHeaders();
40  $this->outputHeader();
41  $out = $this->getOutput();
42  $out->addModules( 'mediawiki.userSuggest' );
43  $out->addModuleStyles( 'mediawiki.interface.helpers.styles' );
44  $this->addHelpLink( 'Help:Log' );
45 
46  $opts = new FormOptions;
47  $opts->add( 'type', '' );
48  $opts->add( 'user', '' );
49  $opts->add( 'page', '' );
50  $opts->add( 'pattern', false );
51  $opts->add( 'year', null, FormOptions::INTNULL );
52  $opts->add( 'month', null, FormOptions::INTNULL );
53  $opts->add( 'day', null, FormOptions::INTNULL );
54  $opts->add( 'tagfilter', '' );
55  $opts->add( 'offset', '' );
56  $opts->add( 'dir', '' );
57  $opts->add( 'offender', '' );
58  $opts->add( 'subtype', '' );
59  $opts->add( 'logid', '' );
60 
61  // Set values
62  $opts->fetchValuesFromRequest( $this->getRequest() );
63  if ( $par !== null ) {
64  $this->parseParams( $opts, (string)$par );
65  }
66 
67  // Set date values
68  $dateString = $this->getRequest()->getVal( 'wpdate' );
69  if ( !empty( $dateString ) ) {
70  try {
71  $dateStamp = MWTimestamp::getInstance( $dateString . ' 00:00:00' );
72  } catch ( TimestampException $e ) {
73  // If users provide an invalid date, silently ignore it
74  // instead of letting an exception bubble up (T201411)
75  $dateStamp = false;
76  }
77  if ( $dateStamp ) {
78  $opts->setValue( 'year', (int)$dateStamp->format( 'Y' ) );
79  $opts->setValue( 'month', (int)$dateStamp->format( 'm' ) );
80  $opts->setValue( 'day', (int)$dateStamp->format( 'd' ) );
81  }
82  }
83 
84  # Don't let the user get stuck with a certain date
85  if ( $opts->getValue( 'offset' ) || $opts->getValue( 'dir' ) == 'prev' ) {
86  $opts->setValue( 'year', '' );
87  $opts->setValue( 'month', '' );
88  }
89 
90  // If the user doesn't have the right permission to view the specific
91  // log type, throw a PermissionsError
92  // If the log type is invalid, just show all public logs
93  $logRestrictions = $this->getConfig()->get( 'LogRestrictions' );
94  $type = $opts->getValue( 'type' );
95  if ( !LogPage::isLogType( $type ) ) {
96  $opts->setValue( 'type', '' );
97  } elseif ( isset( $logRestrictions[$type] )
98  && !$this->getUser()->isAllowed( $logRestrictions[$type] )
99  ) {
100  throw new PermissionsError( $logRestrictions[$type] );
101  }
102 
103  # Handle type-specific inputs
104  $qc = [];
105  if ( $opts->getValue( 'type' ) == 'suppress' ) {
106  $offenderName = $opts->getValue( 'offender' );
107  $offender = empty( $offenderName ) ? null : User::newFromName( $offenderName, false );
108  if ( $offender ) {
110  $qc = [ 'ls_field' => 'target_author_actor', 'ls_value' => $offender->getActorId() ];
111  } elseif ( $offender->getId() > 0 ) {
112  $qc = [ 'ls_field' => 'target_author_id', 'ls_value' => $offender->getId() ];
113  } else {
114  $qc = [ 'ls_field' => 'target_author_ip', 'ls_value' => $offender->getName() ];
115  }
116  }
117  } else {
118  // Allow extensions to add relations to their search types
119  Hooks::run(
120  'SpecialLogAddLogSearchRelations',
121  [ $opts->getValue( 'type' ), $this->getRequest(), &$qc ]
122  );
123  }
124 
125  # Some log types are only for a 'User:' title but we might have been given
126  # only the username instead of the full title 'User:username'. This part try
127  # to lookup for a user by that name and eventually fix user input. See T3697.
128  if ( in_array( $opts->getValue( 'type' ), self::getLogTypesOnUser() ) ) {
129  # ok we have a type of log which expect a user title.
130  $target = Title::newFromText( $opts->getValue( 'page' ) );
131  if ( $target && $target->getNamespace() === NS_MAIN ) {
132  # User forgot to add 'User:', we are adding it for him
133  $opts->setValue( 'page',
134  Title::makeTitleSafe( NS_USER, $opts->getValue( 'page' ) )
135  );
136  }
137  }
138 
139  $this->show( $opts, $qc );
140  }
141 
150  public static function getLogTypesOnUser() {
151  static $types = null;
152  if ( $types !== null ) {
153  return $types;
154  }
155  $types = [
156  'block',
157  'newusers',
158  'rights',
159  ];
160 
161  Hooks::run( 'GetLogTypesOnUser', [ &$types ] );
162  return $types;
163  }
164 
170  public function getSubpagesForPrefixSearch() {
171  $subpages = LogPage::validTypes();
172  $subpages[] = 'all';
173  sort( $subpages );
174  return $subpages;
175  }
176 
186  private function parseParams( FormOptions $opts, $par ) {
187  # Get parameters
188  $par = $par !== null ? $par : '';
189  $parms = explode( '/', $par );
190  $symsForAll = [ '*', 'all' ];
191  if ( $parms[0] != '' &&
192  ( in_array( $par, LogPage::validTypes() ) || in_array( $par, $symsForAll ) )
193  ) {
194  $opts->setValue( 'type', $par );
195  } elseif ( count( $parms ) == 2 ) {
196  $opts->setValue( 'type', $parms[0] );
197  $opts->setValue( 'user', $parms[1] );
198  } elseif ( $par != '' ) {
199  $opts->setValue( 'user', $par );
200  }
201  }
202 
203  private function show( FormOptions $opts, array $extraConds ) {
204  # Create a LogPager item to get the results and a LogEventsList item to format them...
205  $loglist = new LogEventsList(
206  $this->getContext(),
207  $this->getLinkRenderer(),
209  );
210 
211  $pager = new LogPager(
212  $loglist,
213  $opts->getValue( 'type' ),
214  $opts->getValue( 'user' ),
215  $opts->getValue( 'page' ),
216  $opts->getValue( 'pattern' ),
217  $extraConds,
218  $opts->getValue( 'year' ),
219  $opts->getValue( 'month' ),
220  $opts->getValue( 'day' ),
221  $opts->getValue( 'tagfilter' ),
222  $opts->getValue( 'subtype' ),
223  $opts->getValue( 'logid' )
224  );
225 
226  $this->addHeader( $opts->getValue( 'type' ) );
227 
228  # Set relevant user
229  if ( $pager->getPerformer() ) {
230  $performerUser = User::newFromName( $pager->getPerformer(), false );
231  $this->getSkin()->setRelevantUser( $performerUser );
232  }
233 
234  # Show form options
235  $loglist->showOptions(
236  $pager->getType(),
237  $pager->getPerformer(),
238  $pager->getPage(),
239  $pager->getPattern(),
240  $pager->getYear(),
241  $pager->getMonth(),
242  $pager->getDay(),
243  $pager->getFilterParams(),
244  $pager->getTagFilter(),
245  $pager->getAction()
246  );
247 
248  # Insert list
249  $logBody = $pager->getBody();
250  if ( $logBody ) {
251  $this->getOutput()->addHTML(
252  $pager->getNavigationBar() .
253  $this->getActionButtons(
254  $loglist->beginLogEventsList() .
255  $logBody .
256  $loglist->endLogEventsList()
257  ) .
258  $pager->getNavigationBar()
259  );
260  } else {
261  $this->getOutput()->addWikiMsg( 'logempty' );
262  }
263  }
264 
265  private function getActionButtons( $formcontents ) {
266  $user = $this->getUser();
267  $canRevDelete = $user->isAllowedAll( 'deletedhistory', 'deletelogentry' );
268  $showTagEditUI = ChangeTags::showTagEditingUI( $user );
269  # If the user doesn't have the ability to delete log entries nor edit tags,
270  # don't bother showing them the button(s).
271  if ( !$canRevDelete && !$showTagEditUI ) {
272  return $formcontents;
273  }
274 
275  # Show button to hide log entries and/or edit change tags
276  $s = Html::openElement(
277  'form',
278  [ 'action' => wfScript(), 'id' => 'mw-log-deleterevision-submit' ]
279  ) . "\n";
280  $s .= Html::hidden( 'action', 'historysubmit' ) . "\n";
281  $s .= Html::hidden( 'type', 'logging' ) . "\n";
282 
283  $buttons = '';
284  if ( $canRevDelete ) {
285  $buttons .= Html::element(
286  'button',
287  [
288  'type' => 'submit',
289  'name' => 'revisiondelete',
290  'value' => '1',
291  'class' => "deleterevision-log-submit mw-log-deleterevision-button"
292  ],
293  $this->msg( 'showhideselectedlogentries' )->text()
294  ) . "\n";
295  }
296  if ( $showTagEditUI ) {
297  $buttons .= Html::element(
298  'button',
299  [
300  'type' => 'submit',
301  'name' => 'editchangetags',
302  'value' => '1',
303  'class' => "editchangetags-log-submit mw-log-editchangetags-button"
304  ],
305  $this->msg( 'log-edit-tags' )->text()
306  ) . "\n";
307  }
308 
309  $buttons .= ( new ListToggle( $this->getOutput() ) )->getHTML();
310 
311  $s .= $buttons . $formcontents . $buttons;
312  $s .= Html::closeElement( 'form' );
313 
314  return $s;
315  }
316 
322  protected function addHeader( $type ) {
323  $page = new LogPage( $type );
324  $this->getOutput()->setPageTitle( $page->getName() );
325  $this->getOutput()->addHTML( $page->getDescription()
326  ->setContext( $this->getContext() )->parseAsBlock() );
327  }
328 
329  protected function getGroupName() {
330  return 'changes';
331  }
332 }
$user
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1476
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:306
LogPage\validTypes
static validTypes()
Get the list of valid log types.
Definition: LogPage.php:194
SpecialPage\msg
msg( $key)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:796
SCHEMA_COMPAT_READ_NEW
const SCHEMA_COMPAT_READ_NEW
Definition: Defines.php:287
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
SpecialLog\parseParams
parseParams(FormOptions $opts, $par)
Set options based on the subpage title parts:
Definition: SpecialLog.php:186
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:725
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
FormOptions\INTNULL
const INTNULL
Integer type or null, maps to WebRequest::getIntOrNull() This is useful for the namespace selector.
Definition: FormOptions.php:54
$out
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password 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:780
SpecialLog\getActionButtons
getActionButtons( $formcontents)
Definition: SpecialLog.php:265
LogPager
Definition: LogPager.php:29
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:585
$s
$s
Definition: mergeMessageFileList.php:186
SpecialPage\getSkin
getSkin()
Shortcut to get the skin being used for this instance.
Definition: SpecialPage.php:745
ChangeTags\showTagEditingUI
static showTagEditingUI(User $user)
Indicate whether change tag editing UI is relevant.
Definition: ChangeTags.php:1510
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
NS_MAIN
const NS_MAIN
Definition: Defines.php:64
FormOptions\add
add( $name, $default, $type=self::AUTO)
Add an option to be handled by this FormOptions instance.
Definition: FormOptions.php:81
SpecialPage\addHelpLink
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition: SpecialPage.php:832
SpecialPage\getConfig
getConfig()
Shortcut to get main config object.
Definition: SpecialPage.php:764
wfScript
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
Definition: GlobalFunctions.php:2714
ListToggle
Class for generating clickable toggle links for a list of checkboxes.
Definition: ListToggle.php:31
LogPage\isLogType
static isLogType( $type)
Is $type a valid log type.
Definition: LogPage.php:206
LogPage
Class to simplify the use of log pages.
Definition: LogPage.php:33
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:150
SpecialLog\__construct
__construct()
Definition: SpecialLog.php:32
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
MWTimestamp\getInstance
static getInstance( $ts=false)
Get a timestamp instance in GMT.
Definition: MWTimestamp.php:39
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:531
SpecialPage\getUser
getUser()
Shortcut to get the User executing this instance.
Definition: SpecialPage.php:735
array
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))
LogEventsList
Definition: LogEventsList.php:30
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:698
FormOptions\setValue
setValue( $name, $value, $force=false)
Use to set the value of an option.
Definition: FormOptions.php:163
null
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:780
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:604
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2162
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:329
SpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: SpecialPage.php:715
SpecialLog\show
show(FormOptions $opts, array $extraConds)
Definition: SpecialLog.php:203
SpecialPage\getLinkRenderer
getLinkRenderer()
Definition: SpecialPage.php:908
text
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
Definition: All_system_messages.txt:1267
SpecialLog
A special page that lists log entries.
Definition: SpecialLog.php:31
NS_USER
const NS_USER
Definition: Defines.php:66
FormOptions
Helper class to keep track of options when mixing links and form elements.
Definition: FormOptions.php:35
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
SpecialLog\execute
execute( $par)
Default execute method Checks user permissions.
Definition: SpecialLog.php:36
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:633
SpecialLog\getSubpagesForPrefixSearch
getSubpagesForPrefixSearch()
Return an array of subpages that this special page will accept.
Definition: SpecialLog.php:170
SpecialLog\addHeader
addHeader( $type)
Set page title and show header for this log type.
Definition: SpecialLog.php:322
$type
$type
Definition: testCompression.php:48
$wgActorTableSchemaMigrationStage
int $wgActorTableSchemaMigrationStage
Actor table schema migration stage.
Definition: DefaultSettings.php:8979