MediaWiki  1.27.3
SpecialLog.php
Go to the documentation of this file.
1 <?php
31 class SpecialLog extends SpecialPage {
32  public function __construct() {
33  parent::__construct( 'Log' );
34  }
35 
36  public function execute( $par ) {
37  $this->setHeaders();
38  $this->outputHeader();
39  $this->getOutput()->addModules( 'mediawiki.userSuggest' );
40 
41  $opts = new FormOptions;
42  $opts->add( 'type', '' );
43  $opts->add( 'user', '' );
44  $opts->add( 'page', '' );
45  $opts->add( 'pattern', false );
46  $opts->add( 'year', null, FormOptions::INTNULL );
47  $opts->add( 'month', null, FormOptions::INTNULL );
48  $opts->add( 'tagfilter', '' );
49  $opts->add( 'offset', '' );
50  $opts->add( 'dir', '' );
51  $opts->add( 'offender', '' );
52  $opts->add( 'subtype', '' );
53 
54  // Set values
55  $opts->fetchValuesFromRequest( $this->getRequest() );
56  if ( $par !== null ) {
57  $this->parseParams( $opts, (string)$par );
58  }
59 
60  # Don't let the user get stuck with a certain date
61  if ( $opts->getValue( 'offset' ) || $opts->getValue( 'dir' ) == 'prev' ) {
62  $opts->setValue( 'year', '' );
63  $opts->setValue( 'month', '' );
64  }
65 
66  // If the user doesn't have the right permission to view the specific
67  // log type, throw a PermissionsError
68  // If the log type is invalid, just show all public logs
69  $logRestrictions = $this->getConfig()->get( 'LogRestrictions' );
70  $type = $opts->getValue( 'type' );
71  if ( !LogPage::isLogType( $type ) ) {
72  $opts->setValue( 'type', '' );
73  } elseif ( isset( $logRestrictions[$type] )
74  && !$this->getUser()->isAllowed( $logRestrictions[$type] )
75  ) {
76  throw new PermissionsError( $logRestrictions[$type] );
77  }
78 
79  # Handle type-specific inputs
80  $qc = [];
81  if ( $opts->getValue( 'type' ) == 'suppress' ) {
82  $offender = User::newFromName( $opts->getValue( 'offender' ), false );
83  if ( $offender && $offender->getId() > 0 ) {
84  $qc = [ 'ls_field' => 'target_author_id', 'ls_value' => $offender->getId() ];
85  } elseif ( $offender && IP::isIPAddress( $offender->getName() ) ) {
86  $qc = [ 'ls_field' => 'target_author_ip', 'ls_value' => $offender->getName() ];
87  }
88  } else {
89  // Allow extensions to add relations to their search types
90  Hooks::run(
91  'SpecialLogAddLogSearchRelations',
92  [ $opts->getValue( 'type' ), $this->getRequest(), &$qc ]
93  );
94  }
95 
96  # Some log types are only for a 'User:' title but we might have been given
97  # only the username instead of the full title 'User:username'. This part try
98  # to lookup for a user by that name and eventually fix user input. See bug 1697.
99  if ( in_array( $opts->getValue( 'type' ), self::getLogTypesOnUser() ) ) {
100  # ok we have a type of log which expect a user title.
101  $target = Title::newFromText( $opts->getValue( 'page' ) );
102  if ( $target && $target->getNamespace() === NS_MAIN ) {
103  # User forgot to add 'User:', we are adding it for him
104  $opts->setValue( 'page',
105  Title::makeTitleSafe( NS_USER, $opts->getValue( 'page' ) )
106  );
107  }
108  }
109 
110  $this->show( $opts, $qc );
111  }
112 
121  public static function getLogTypesOnUser() {
122  static $types = null;
123  if ( $types !== null ) {
124  return $types;
125  }
126  $types = [
127  'block',
128  'newusers',
129  'rights',
130  ];
131 
132  Hooks::run( 'GetLogTypesOnUser', [ &$types ] );
133  return $types;
134  }
135 
141  public function getSubpagesForPrefixSearch() {
142  $subpages = $this->getConfig()->get( 'LogTypes' );
143  $subpages[] = 'all';
144  sort( $subpages );
145  return $subpages;
146  }
147 
148  private function parseParams( FormOptions $opts, $par ) {
149  # Get parameters
150  $par = $par !== null ? $par : '';
151  $parms = explode( '/', $par );
152  $symsForAll = [ '*', 'all' ];
153  if ( $parms[0] != '' &&
154  ( in_array( $par, $this->getConfig()->get( 'LogTypes' ) ) || in_array( $par, $symsForAll ) )
155  ) {
156  $opts->setValue( 'type', $par );
157  } elseif ( count( $parms ) == 2 ) {
158  $opts->setValue( 'type', $parms[0] );
159  $opts->setValue( 'user', $parms[1] );
160  } elseif ( $par != '' ) {
161  $opts->setValue( 'user', $par );
162  }
163  }
164 
165  private function show( FormOptions $opts, array $extraConds ) {
166  # Create a LogPager item to get the results and a LogEventsList item to format them...
167  $loglist = new LogEventsList(
168  $this->getContext(),
169  null,
171  );
172 
173  $pager = new LogPager(
174  $loglist,
175  $opts->getValue( 'type' ),
176  $opts->getValue( 'user' ),
177  $opts->getValue( 'page' ),
178  $opts->getValue( 'pattern' ),
179  $extraConds,
180  $opts->getValue( 'year' ),
181  $opts->getValue( 'month' ),
182  $opts->getValue( 'tagfilter' ),
183  $opts->getValue( 'subtype' )
184  );
185 
186  $this->addHeader( $opts->getValue( 'type' ) );
187 
188  # Set relevant user
189  if ( $pager->getPerformer() ) {
190  $performerUser = User::newFromName( $pager->getPerformer(), false );
191  $this->getSkin()->setRelevantUser( $performerUser );
192  }
193 
194  # Show form options
195  $loglist->showOptions(
196  $pager->getType(),
197  $pager->getPerformer(),
198  $pager->getPage(),
199  $pager->getPattern(),
200  $pager->getYear(),
201  $pager->getMonth(),
202  $pager->getFilterParams(),
203  $pager->getTagFilter(),
204  $pager->getAction()
205  );
206 
207  # Insert list
208  $logBody = $pager->getBody();
209  if ( $logBody ) {
210  $this->getOutput()->addHTML(
211  $pager->getNavigationBar() .
212  $this->getActionButtons(
213  $loglist->beginLogEventsList() .
214  $logBody .
215  $loglist->endLogEventsList()
216  ) .
217  $pager->getNavigationBar()
218  );
219  } else {
220  $this->getOutput()->addWikiMsg( 'logempty' );
221  }
222  }
223 
224  private function getActionButtons( $formcontents ) {
225  $user = $this->getUser();
226  $canRevDelete = $user->isAllowedAll( 'deletedhistory', 'deletelogentry' );
227  $showTagEditUI = ChangeTags::showTagEditingUI( $user );
228  # If the user doesn't have the ability to delete log entries nor edit tags,
229  # don't bother showing them the button(s).
230  if ( !$canRevDelete && !$showTagEditUI ) {
231  return $formcontents;
232  }
233 
234  # Show button to hide log entries and/or edit change tags
236  'form',
237  [ 'action' => wfScript(), 'id' => 'mw-log-deleterevision-submit' ]
238  ) . "\n";
239  $s .= Html::hidden( 'action', 'historysubmit' ) . "\n";
240  $s .= Html::hidden( 'type', 'logging' ) . "\n";
241 
242  $buttons = '';
243  if ( $canRevDelete ) {
244  $buttons .= Html::element(
245  'button',
246  [
247  'type' => 'submit',
248  'name' => 'revisiondelete',
249  'value' => '1',
250  'class' => "deleterevision-log-submit mw-log-deleterevision-button"
251  ],
252  $this->msg( 'showhideselectedlogentries' )->text()
253  ) . "\n";
254  }
255  if ( $showTagEditUI ) {
256  $buttons .= Html::element(
257  'button',
258  [
259  'type' => 'submit',
260  'name' => 'editchangetags',
261  'value' => '1',
262  'class' => "editchangetags-log-submit mw-log-editchangetags-button"
263  ],
264  $this->msg( 'log-edit-tags' )->text()
265  ) . "\n";
266  }
267 
268  $buttons .= ( new ListToggle( $this->getOutput() ) )->getHTML();
269 
270  $s .= $buttons . $formcontents . $buttons;
271  $s .= Html::closeElement( 'form' );
272 
273  return $s;
274  }
275 
281  protected function addHeader( $type ) {
282  $page = new LogPage( $type );
283  $this->getOutput()->setPageTitle( $page->getName() );
284  $this->getOutput()->addHTML( $page->getDescription()
285  ->setContext( $this->getContext() )->parseAsBlock() );
286  }
287 
288  protected function getGroupName() {
289  return 'changes';
290  }
291 }
Class for generating clickable toggle links for a list of checkboxes.
Definition: ListToggle.php:31
static newFromName($name, $validate= 'valid')
Static factory method for creation from username.
Definition: User.php:568
static closeElement($element)
Returns "".
Definition: Html.php:306
Helper class to keep track of options when mixing links and form elements.
Definition: FormOptions.php:35
const USE_CHECKBOXES
the array() calling protocol came about after MediaWiki 1.4rc1.
getContext()
Gets the context this SpecialPage is executed in.
wfScript($script= 'index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
getActionButtons($formcontents)
Definition: SpecialLog.php:224
parseParams(FormOptions $opts, $par)
Definition: SpecialLog.php:148
const NS_MAIN
Definition: Defines.php:69
setValue($name, $value, $force=false)
Use to set the value of an option.
const INTNULL
Integer type or null, maps to WebRequest::getIntOrNull() This is useful for the namespace selector...
Definition: FormOptions.php:54
getSubpagesForPrefixSearch()
Return an array of subpages that this special page will accept.
Definition: SpecialLog.php:141
addHeader($type)
Set page title and show header for this log type.
Definition: SpecialLog.php:281
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:189
static hidden($name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition: Html.php:759
msg()
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
static newFromText($text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:277
static isIPAddress($ip)
Determine if a string is as valid IP address or network (CIDR prefix).
Definition: IP.php:79
outputHeader($summaryMessageKey= '')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
Class to simplify the use of log pages.
Definition: LogPage.php:32
Parent class for all special pages.
Definition: SpecialPage.php:36
static openElement($element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
Definition: Html.php:248
getValue($name)
Get the value for the given option name.
getSkin()
Shortcut to get the skin being used for this instance.
static showTagEditingUI(User $user)
Indicate whether change tag editing UI is relevant.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes! ...
static makeTitleSafe($ns, $title, $fragment= '', $interwiki= '')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:548
A special page that lists log entries.
Definition: SpecialLog.php:31
static run($event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:131
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
static isLogType($type)
Is $type a valid log type.
Definition: LogPage.php:210
add($name, $default, $type=self::AUTO)
Add an option to be handled by this FormOptions instance.
Definition: FormOptions.php:78
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:246
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
show(FormOptions $opts, array $extraConds)
Definition: SpecialLog.php:165
getUser()
Shortcut to get the User executing this instance.
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:121
getConfig()
Shortcut to get main config object.
Show an error when a user tries to do something they do not have the necessary permissions for...
getRequest()
Get the WebRequest being used for this instance.
static element($element, $attribs=[], $contents= '')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:230
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached one of or reset my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type
Definition: hooks.txt:2342
execute($par)
Definition: SpecialLog.php:36
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached $page
Definition: hooks.txt:2342