MediaWiki REL1_31
SpecialLog.php
Go to the documentation of this file.
1<?php
29class 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 $opts->add( 'logid', '' );
55
56 // Set values
57 $opts->fetchValuesFromRequest( $this->getRequest() );
58 if ( $par !== null ) {
59 $this->parseParams( $opts, (string)$par );
60 }
61
62 # Don't let the user get stuck with a certain date
63 if ( $opts->getValue( 'offset' ) || $opts->getValue( 'dir' ) == 'prev' ) {
64 $opts->setValue( 'year', '' );
65 $opts->setValue( 'month', '' );
66 }
67
68 // If the user doesn't have the right permission to view the specific
69 // log type, throw a PermissionsError
70 // If the log type is invalid, just show all public logs
71 $logRestrictions = $this->getConfig()->get( 'LogRestrictions' );
72 $type = $opts->getValue( 'type' );
73 if ( !LogPage::isLogType( $type ) ) {
74 $opts->setValue( 'type', '' );
75 } elseif ( isset( $logRestrictions[$type] )
76 && !$this->getUser()->isAllowed( $logRestrictions[$type] )
77 ) {
78 throw new PermissionsError( $logRestrictions[$type] );
79 }
80
81 # Handle type-specific inputs
82 $qc = [];
83 if ( $opts->getValue( 'type' ) == 'suppress' ) {
84 $offenderName = $opts->getValue( 'offender' );
85 $offender = empty( $offenderName ) ? null : User::newFromName( $offenderName, false );
86 if ( $offender ) {
88 $qc = [ 'ls_field' => 'target_author_actor', 'ls_value' => $offender->getActorId() ];
89 } else {
90 if ( $offender->getId() > 0 ) {
91 $field = 'target_author_id';
92 $value = $offender->getId();
93 } else {
94 $field = 'target_author_ip';
95 $value = $offender->getName();
96 }
97 if ( !$offender->getActorId() ) {
98 $qc = [ 'ls_field' => $field, 'ls_value' => $value ];
99 } else {
100 $db = wfGetDB( DB_REPLICA );
101 $qc = [
102 'ls_field' => [ 'target_author_actor', $field ], // So LogPager::getQueryInfo() works right
103 $db->makeList( [
104 $db->makeList(
105 [
106 'ls_field' => 'target_author_actor',
107 'ls_value' => $offender->getActorId()
108 ], LIST_AND
109 ),
110 $db->makeList( [ 'ls_field' => $field, 'ls_value' => $value ], LIST_AND ),
111 ], LIST_OR ),
112 ];
113 }
114 }
115 }
116 } else {
117 // Allow extensions to add relations to their search types
118 Hooks::run(
119 'SpecialLogAddLogSearchRelations',
120 [ $opts->getValue( 'type' ), $this->getRequest(), &$qc ]
121 );
122 }
123
124 # Some log types are only for a 'User:' title but we might have been given
125 # only the username instead of the full title 'User:username'. This part try
126 # to lookup for a user by that name and eventually fix user input. See T3697.
127 if ( in_array( $opts->getValue( 'type' ), self::getLogTypesOnUser() ) ) {
128 # ok we have a type of log which expect a user title.
129 $target = Title::newFromText( $opts->getValue( 'page' ) );
130 if ( $target && $target->getNamespace() === NS_MAIN ) {
131 # User forgot to add 'User:', we are adding it for him
132 $opts->setValue( 'page',
133 Title::makeTitleSafe( NS_USER, $opts->getValue( 'page' ) )
134 );
135 }
136 }
137
138 $this->show( $opts, $qc );
139 }
140
149 public static function getLogTypesOnUser() {
150 static $types = null;
151 if ( $types !== null ) {
152 return $types;
153 }
154 $types = [
155 'block',
156 'newusers',
157 'rights',
158 ];
159
160 Hooks::run( 'GetLogTypesOnUser', [ &$types ] );
161 return $types;
162 }
163
169 public function getSubpagesForPrefixSearch() {
170 $subpages = $this->getConfig()->get( 'LogTypes' );
171 $subpages[] = 'all';
172 sort( $subpages );
173 return $subpages;
174 }
175
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, $this->getConfig()->get( 'LogTypes' ) ) || 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( 'tagfilter' ),
221 $opts->getValue( 'subtype' ),
222 $opts->getValue( 'logid' )
223 );
224
225 $this->addHeader( $opts->getValue( 'type' ) );
226
227 # Set relevant user
228 if ( $pager->getPerformer() ) {
229 $performerUser = User::newFromName( $pager->getPerformer(), false );
230 $this->getSkin()->setRelevantUser( $performerUser );
231 }
232
233 # Show form options
234 $loglist->showOptions(
235 $pager->getType(),
236 $pager->getPerformer(),
237 $pager->getPage(),
238 $pager->getPattern(),
239 $pager->getYear(),
240 $pager->getMonth(),
241 $pager->getFilterParams(),
242 $pager->getTagFilter(),
243 $pager->getAction()
244 );
245
246 # Insert list
247 $logBody = $pager->getBody();
248 if ( $logBody ) {
249 $this->getOutput()->addHTML(
250 $pager->getNavigationBar() .
251 $this->getActionButtons(
252 $loglist->beginLogEventsList() .
253 $logBody .
254 $loglist->endLogEventsList()
255 ) .
256 $pager->getNavigationBar()
257 );
258 } else {
259 $this->getOutput()->addWikiMsg( 'logempty' );
260 }
261 }
262
263 private function getActionButtons( $formcontents ) {
264 $user = $this->getUser();
265 $canRevDelete = $user->isAllowedAll( 'deletedhistory', 'deletelogentry' );
266 $showTagEditUI = ChangeTags::showTagEditingUI( $user );
267 # If the user doesn't have the ability to delete log entries nor edit tags,
268 # don't bother showing them the button(s).
269 if ( !$canRevDelete && !$showTagEditUI ) {
270 return $formcontents;
271 }
272
273 # Show button to hide log entries and/or edit change tags
274 $s = Html::openElement(
275 'form',
276 [ 'action' => wfScript(), 'id' => 'mw-log-deleterevision-submit' ]
277 ) . "\n";
278 $s .= Html::hidden( 'action', 'historysubmit' ) . "\n";
279 $s .= Html::hidden( 'type', 'logging' ) . "\n";
280
281 // If no title is set, the fallback is to use the main page, as defined
282 // by MediaWiki:Mainpage
283 // On wikis where the main page can be translated, MediaWiki:Mainpage
284 // is sometimes set to use Special:MyLanguage to redirect to the
285 // appropriate version. This is interpreted as a special page, and
286 // Action::getActionName forces the action to be 'view' if the title
287 // cannot be used as a WikiPage, which includes all pages in NS_SPECIAL.
288 // Set a dummy title to avoid this. The title provided is unused
289 // by the SpecialPageAction class and does not matter.
290 // See T205908
291 $s .= Html::hidden( 'title', 'Unused' ) . "\n";
292
293 $buttons = '';
294 if ( $canRevDelete ) {
295 $buttons .= Html::element(
296 'button',
297 [
298 'type' => 'submit',
299 'name' => 'revisiondelete',
300 'value' => '1',
301 'class' => "deleterevision-log-submit mw-log-deleterevision-button"
302 ],
303 $this->msg( 'showhideselectedlogentries' )->text()
304 ) . "\n";
305 }
306 if ( $showTagEditUI ) {
307 $buttons .= Html::element(
308 'button',
309 [
310 'type' => 'submit',
311 'name' => 'editchangetags',
312 'value' => '1',
313 'class' => "editchangetags-log-submit mw-log-editchangetags-button"
314 ],
315 $this->msg( 'log-edit-tags' )->text()
316 ) . "\n";
317 }
318
319 $buttons .= ( new ListToggle( $this->getOutput() ) )->getHTML();
320
321 $s .= $buttons . $formcontents . $buttons;
322 $s .= Html::closeElement( 'form' );
323
324 return $s;
325 }
326
332 protected function addHeader( $type ) {
333 $page = new LogPage( $type );
334 $this->getOutput()->setPageTitle( $page->getName() );
335 $this->getOutput()->addHTML( $page->getDescription()
336 ->setContext( $this->getContext() )->parseAsBlock() );
337 }
338
339 protected function getGroupName() {
340 return 'changes';
341 }
342}
int $wgActorTableSchemaMigrationStage
Actor table schema migration stage.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
static showTagEditingUI(User $user)
Indicate whether change tag editing UI is relevant.
Helper class to keep track of options when mixing links and form elements.
add( $name, $default, $type=self::AUTO)
Add an option to be handled by this FormOptions instance.
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.
getValue( $name)
Get the value for the given option name.
Class for generating clickable toggle links for a list of checkboxes.
Class to simplify the use of log pages.
Definition LogPage.php:31
static isLogType( $type)
Is $type a valid log type.
Definition LogPage.php:204
Show an error when a user tries to do something they do not have the necessary permissions for.
A special page that lists log entries.
getSubpagesForPrefixSearch()
Return an array of subpages that this special page will accept.
execute( $par)
Default execute method Checks user permissions.
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...
show(FormOptions $opts, array $extraConds)
parseParams(FormOptions $opts, $par)
Set options based on the subpage title parts:
getActionButtons( $formcontents)
addHeader( $type)
Set page title and show header for this log type.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Parent class for all special pages.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
getUser()
Shortcut to get the User executing this instance.
getSkin()
Shortcut to get the skin being used for this instance.
getContext()
Gets the context this SpecialPage is executed in.
msg( $key)
Wrapper around wfMessage that sets the current context.
getConfig()
Shortcut to get main config object.
getRequest()
Get the WebRequest being used for this instance.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition User.php:591
when a variable name is used in a it is silently declared as a new local masking the global
Definition design.txt:95
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:18
const NS_USER
Definition Defines.php:76
const NS_MAIN
Definition Defines.php:74
const LIST_OR
Definition Defines.php:56
const MIGRATION_NEW
Definition Defines.php:305
const LIST_AND
Definition Defines.php:53
the array() calling protocol came about after MediaWiki 1.4rc1.
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:247
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:37
const DB_REPLICA
Definition defines.php:25