511cfbf5d0698ebf24d4c24c3f355b81181496d4
3 * Implements Special:Log
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup SpecialPage
25 * A special page that lists log entries
27 * @ingroup SpecialPage
29 class SpecialLog
extends SpecialPage
{
30 public function __construct() {
31 parent
::__construct( 'Log' );
34 public function execute( $par ) {
36 $this->outputHeader();
37 $this->getOutput()->addModules( 'mediawiki.userSuggest' );
38 $this->addHelpLink( 'Help:Log' );
40 $opts = new FormOptions
;
41 $opts->add( 'type', '' );
42 $opts->add( 'user', '' );
43 $opts->add( 'page', '' );
44 $opts->add( 'pattern', false );
45 $opts->add( 'year', null, FormOptions
::INTNULL
);
46 $opts->add( 'month', null, FormOptions
::INTNULL
);
47 $opts->add( 'tagfilter', '' );
48 $opts->add( 'offset', '' );
49 $opts->add( 'dir', '' );
50 $opts->add( 'offender', '' );
51 $opts->add( 'subtype', '' );
54 $opts->fetchValuesFromRequest( $this->getRequest() );
55 if ( $par !== null ) {
56 $this->parseParams( $opts, (string)$par );
59 # Don't let the user get stuck with a certain date
60 if ( $opts->getValue( 'offset' ) ||
$opts->getValue( 'dir' ) == 'prev' ) {
61 $opts->setValue( 'year', '' );
62 $opts->setValue( 'month', '' );
65 // If the user doesn't have the right permission to view the specific
66 // log type, throw a PermissionsError
67 // If the log type is invalid, just show all public logs
68 $logRestrictions = $this->getConfig()->get( 'LogRestrictions' );
69 $type = $opts->getValue( 'type' );
70 if ( !LogPage
::isLogType( $type ) ) {
71 $opts->setValue( 'type', '' );
72 } elseif ( isset( $logRestrictions[$type] )
73 && !$this->getUser()->isAllowed( $logRestrictions[$type] )
75 throw new PermissionsError( $logRestrictions[$type] );
78 # Handle type-specific inputs
80 if ( $opts->getValue( 'type' ) == 'suppress' ) {
81 $offender = User
::newFromName( $opts->getValue( 'offender' ), false );
82 if ( $offender && $offender->getId() > 0 ) {
83 $qc = [ 'ls_field' => 'target_author_id', 'ls_value' => $offender->getId() ];
84 } elseif ( $offender && IP
::isIPAddress( $offender->getName() ) ) {
85 $qc = [ 'ls_field' => 'target_author_ip', 'ls_value' => $offender->getName() ];
88 // Allow extensions to add relations to their search types
90 'SpecialLogAddLogSearchRelations',
91 [ $opts->getValue( 'type' ), $this->getRequest(), &$qc ]
95 # Some log types are only for a 'User:' title but we might have been given
96 # only the username instead of the full title 'User:username'. This part try
97 # to lookup for a user by that name and eventually fix user input. See T3697.
98 if ( in_array( $opts->getValue( 'type' ), self
::getLogTypesOnUser() ) ) {
99 # ok we have a type of log which expect a user title.
100 $target = Title
::newFromText( $opts->getValue( 'page' ) );
101 if ( $target && $target->getNamespace() === NS_MAIN
) {
102 # User forgot to add 'User:', we are adding it for him
103 $opts->setValue( 'page',
104 Title
::makeTitleSafe( NS_USER
, $opts->getValue( 'page' ) )
109 $this->show( $opts, $qc );
113 * List log type for which the target is a user
114 * Thus if the given target is in NS_MAIN we can alter it to be an NS_USER
115 * Title user instead.
120 public static function getLogTypesOnUser() {
121 static $types = null;
122 if ( $types !== null ) {
131 Hooks
::run( 'GetLogTypesOnUser', [ &$types ] );
136 * Return an array of subpages that this special page will accept.
138 * @return string[] subpages
140 public function getSubpagesForPrefixSearch() {
141 $subpages = $this->getConfig()->get( 'LogTypes' );
147 private function parseParams( FormOptions
$opts, $par ) {
149 $par = $par !== null ?
$par : '';
150 $parms = explode( '/', $par );
151 $symsForAll = [ '*', 'all' ];
152 if ( $parms[0] != '' &&
153 ( in_array( $par, $this->getConfig()->get( 'LogTypes' ) ) ||
in_array( $par, $symsForAll ) )
155 $opts->setValue( 'type', $par );
156 } elseif ( count( $parms ) == 2 ) {
157 $opts->setValue( 'type', $parms[0] );
158 $opts->setValue( 'user', $parms[1] );
159 } elseif ( $par != '' ) {
160 $opts->setValue( 'user', $par );
164 private function show( FormOptions
$opts, array $extraConds ) {
165 # Create a LogPager item to get the results and a LogEventsList item to format them...
166 $loglist = new LogEventsList(
168 $this->getLinkRenderer(),
169 LogEventsList
::USE_CHECKBOXES
172 $pager = new LogPager(
174 $opts->getValue( 'type' ),
175 $opts->getValue( 'user' ),
176 $opts->getValue( 'page' ),
177 $opts->getValue( 'pattern' ),
179 $opts->getValue( 'year' ),
180 $opts->getValue( 'month' ),
181 $opts->getValue( 'tagfilter' ),
182 $opts->getValue( 'subtype' )
185 $this->addHeader( $opts->getValue( 'type' ) );
188 if ( $pager->getPerformer() ) {
189 $performerUser = User
::newFromName( $pager->getPerformer(), false );
190 $this->getSkin()->setRelevantUser( $performerUser );
194 $loglist->showOptions(
196 $pager->getPerformer(),
198 $pager->getPattern(),
201 $pager->getFilterParams(),
202 $pager->getTagFilter(),
207 $logBody = $pager->getBody();
209 $this->getOutput()->addHTML(
210 $pager->getNavigationBar() .
211 $this->getActionButtons(
212 $loglist->beginLogEventsList() .
214 $loglist->endLogEventsList()
216 $pager->getNavigationBar()
219 $this->getOutput()->addWikiMsg( 'logempty' );
223 private function getActionButtons( $formcontents ) {
224 $user = $this->getUser();
225 $canRevDelete = $user->isAllowedAll( 'deletedhistory', 'deletelogentry' );
226 $showTagEditUI = ChangeTags
::showTagEditingUI( $user );
227 # If the user doesn't have the ability to delete log entries nor edit tags,
228 # don't bother showing them the button(s).
229 if ( !$canRevDelete && !$showTagEditUI ) {
230 return $formcontents;
233 # Show button to hide log entries and/or edit change tags
234 $s = Html
::openElement(
236 [ 'action' => wfScript(), 'id' => 'mw-log-deleterevision-submit' ]
238 $s .= Html
::hidden( 'action', 'historysubmit' ) . "\n";
239 $s .= Html
::hidden( 'type', 'logging' ) . "\n";
242 if ( $canRevDelete ) {
243 $buttons .= Html
::element(
247 'name' => 'revisiondelete',
249 'class' => "deleterevision-log-submit mw-log-deleterevision-button"
251 $this->msg( 'showhideselectedlogentries' )->text()
254 if ( $showTagEditUI ) {
255 $buttons .= Html
::element(
259 'name' => 'editchangetags',
261 'class' => "editchangetags-log-submit mw-log-editchangetags-button"
263 $this->msg( 'log-edit-tags' )->text()
267 $buttons .= ( new ListToggle( $this->getOutput() ) )->getHTML();
269 $s .= $buttons . $formcontents . $buttons;
270 $s .= Html
::closeElement( 'form' );
276 * Set page title and show header for this log type
277 * @param string $type
280 protected function addHeader( $type ) {
281 $page = new LogPage( $type );
282 $this->getOutput()->setPageTitle( $page->getName() );
283 $this->getOutput()->addHTML( $page->getDescription()
284 ->setContext( $this->getContext() )->parseAsBlock() );
287 protected function getGroupName() {