MediaWiki REL1_27
SpecialLog.php
Go to the documentation of this file.
1<?php
31class 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 $opts->add( 'logid', '' );
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 $offender = User::newFromName( $opts->getValue( 'offender' ), false );
84 if ( $offender && $offender->getId() > 0 ) {
85 $qc = [ 'ls_field' => 'target_author_id', 'ls_value' => $offender->getId() ];
86 } elseif ( $offender && IP::isIPAddress( $offender->getName() ) ) {
87 $qc = [ 'ls_field' => 'target_author_ip', 'ls_value' => $offender->getName() ];
88 }
89 } else {
90 // Allow extensions to add relations to their search types
91 Hooks::run(
92 'SpecialLogAddLogSearchRelations',
93 [ $opts->getValue( 'type' ), $this->getRequest(), &$qc ]
94 );
95 }
96
97 # Some log types are only for a 'User:' title but we might have been given
98 # only the username instead of the full title 'User:username'. This part try
99 # to lookup for a user by that name and eventually fix user input. See bug 1697.
100 if ( in_array( $opts->getValue( 'type' ), self::getLogTypesOnUser() ) ) {
101 # ok we have a type of log which expect a user title.
102 $target = Title::newFromText( $opts->getValue( 'page' ) );
103 if ( $target && $target->getNamespace() === NS_MAIN ) {
104 # User forgot to add 'User:', we are adding it for him
105 $opts->setValue( 'page',
106 Title::makeTitleSafe( NS_USER, $opts->getValue( 'page' ) )
107 );
108 }
109 }
110
111 $this->show( $opts, $qc );
112 }
113
122 public static function getLogTypesOnUser() {
123 static $types = null;
124 if ( $types !== null ) {
125 return $types;
126 }
127 $types = [
128 'block',
129 'newusers',
130 'rights',
131 ];
132
133 Hooks::run( 'GetLogTypesOnUser', [ &$types ] );
134 return $types;
135 }
136
142 public function getSubpagesForPrefixSearch() {
143 $subpages = $this->getConfig()->get( 'LogTypes' );
144 $subpages[] = 'all';
145 sort( $subpages );
146 return $subpages;
147 }
148
159 private function parseParams( FormOptions $opts, $par ) {
160 # Get parameters
161 $par = $par !== null ? $par : '';
162 $parms = explode( '/', $par );
163 $symsForAll = [ '*', 'all' ];
164 if ( $parms[0] != '' &&
165 ( in_array( $par, $this->getConfig()->get( 'LogTypes' ) ) || in_array( $par, $symsForAll ) )
166 ) {
167 $opts->setValue( 'type', $par );
168 } elseif ( count( $parms ) == 2 ) {
169 $opts->setValue( 'type', $parms[0] );
170 $opts->setValue( 'user', $parms[1] );
171 } elseif ( $par != '' ) {
172 $opts->setValue( 'user', $par );
173 }
174 }
175
176 private function show( FormOptions $opts, array $extraConds ) {
177 # Create a LogPager item to get the results and a LogEventsList item to format them...
178 $loglist = new LogEventsList(
179 $this->getContext(),
180 null,
182 );
183
184 $pager = new LogPager(
185 $loglist,
186 $opts->getValue( 'type' ),
187 $opts->getValue( 'user' ),
188 $opts->getValue( 'page' ),
189 $opts->getValue( 'pattern' ),
190 $extraConds,
191 $opts->getValue( 'year' ),
192 $opts->getValue( 'month' ),
193 $opts->getValue( 'tagfilter' ),
194 $opts->getValue( 'subtype' ),
195 $opts->getValue( 'logid' )
196 );
197
198 $this->addHeader( $opts->getValue( 'type' ) );
199
200 # Set relevant user
201 if ( $pager->getPerformer() ) {
202 $performerUser = User::newFromName( $pager->getPerformer(), false );
203 $this->getSkin()->setRelevantUser( $performerUser );
204 }
205
206 # Show form options
207 $loglist->showOptions(
208 $pager->getType(),
209 $pager->getPerformer(),
210 $pager->getPage(),
211 $pager->getPattern(),
212 $pager->getYear(),
213 $pager->getMonth(),
214 $pager->getFilterParams(),
215 $pager->getTagFilter(),
216 $pager->getAction()
217 );
218
219 # Insert list
220 $logBody = $pager->getBody();
221 if ( $logBody ) {
222 $this->getOutput()->addHTML(
223 $pager->getNavigationBar() .
224 $this->getActionButtons(
225 $loglist->beginLogEventsList() .
226 $logBody .
227 $loglist->endLogEventsList()
228 ) .
229 $pager->getNavigationBar()
230 );
231 } else {
232 $this->getOutput()->addWikiMsg( 'logempty' );
233 }
234 }
235
236 private function getActionButtons( $formcontents ) {
237 $user = $this->getUser();
238 $canRevDelete = $user->isAllowedAll( 'deletedhistory', 'deletelogentry' );
239 $showTagEditUI = ChangeTags::showTagEditingUI( $user );
240 # If the user doesn't have the ability to delete log entries nor edit tags,
241 # don't bother showing them the button(s).
242 if ( !$canRevDelete && !$showTagEditUI ) {
243 return $formcontents;
244 }
245
246 # Show button to hide log entries and/or edit change tags
248 'form',
249 [ 'action' => wfScript(), 'id' => 'mw-log-deleterevision-submit' ]
250 ) . "\n";
251 $s .= Html::hidden( 'action', 'historysubmit' ) . "\n";
252 $s .= Html::hidden( 'type', 'logging' ) . "\n";
253
254 $buttons = '';
255 if ( $canRevDelete ) {
256 $buttons .= Html::element(
257 'button',
258 [
259 'type' => 'submit',
260 'name' => 'revisiondelete',
261 'value' => '1',
262 'class' => "deleterevision-log-submit mw-log-deleterevision-button"
263 ],
264 $this->msg( 'showhideselectedlogentries' )->text()
265 ) . "\n";
266 }
267 if ( $showTagEditUI ) {
268 $buttons .= Html::element(
269 'button',
270 [
271 'type' => 'submit',
272 'name' => 'editchangetags',
273 'value' => '1',
274 'class' => "editchangetags-log-submit mw-log-editchangetags-button"
275 ],
276 $this->msg( 'log-edit-tags' )->text()
277 ) . "\n";
278 }
279
280 $buttons .= ( new ListToggle( $this->getOutput() ) )->getHTML();
281
282 $s .= $buttons . $formcontents . $buttons;
283 $s .= Html::closeElement( 'form' );
284
285 return $s;
286 }
287
293 protected function addHeader( $type ) {
294 $page = new LogPage( $type );
295 $this->getOutput()->setPageTitle( $page->getName() );
296 $this->getOutput()->addHTML( $page->getDescription()
297 ->setContext( $this->getContext() )->parseAsBlock() );
298 }
299
300 protected function getGroupName() {
301 return 'changes';
302 }
303}
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.
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition Html.php:230
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
static closeElement( $element)
Returns "</$element>".
Definition Html.php:306
static hidden( $name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition Html.php:759
static isIPAddress( $ip)
Determine if a string is as valid IP address or network (CIDR prefix).
Definition IP.php:79
Class for generating clickable toggle links for a list of checkboxes.
Class to simplify the use of log pages.
Definition LogPage.php:32
static isLogType( $type)
Is $type a valid log type.
Definition LogPage.php:210
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.
getConfig()
Shortcut to get main config object.
getRequest()
Get the WebRequest being used for this instance.
msg()
Wrapper around wfMessage that sets the current context.
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 makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition Title.php:548
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:72
const NS_MAIN
Definition Defines.php:70
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:249
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:2379
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:2413
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