wfMsgForContentNoTrans() was removed
[mediawiki.git] / includes / specials / SpecialLog.php
blobe44ce5f5b2b7d95e9ed21df7f75bcb59c8fb9bf1
1 <?php
2 /**
3 * Implements Special:Log
5 * Copyright © 2008 Aaron Schulz
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
22 * @file
23 * @ingroup SpecialPage
26 /**
27 * A special page that lists log entries
29 * @ingroup SpecialPage
31 class SpecialLog extends SpecialPage {
32 public function __construct() {
33 parent::__construct( 'Log' );
36 public function execute( $par ) {
37 $this->setHeaders();
38 $this->outputHeader();
39 $this->getOutput()->addModules( 'mediawiki.userSuggest' );
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', '' );
53 // Set values
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] )
74 ) {
75 throw new PermissionsError( $logRestrictions[$type] );
78 # Handle type-specific inputs
79 $qc = array();
80 if ( $opts->getValue( 'type' ) == 'suppress' ) {
81 $offender = User::newFromName( $opts->getValue( 'offender' ), false );
82 if ( $offender && $offender->getId() > 0 ) {
83 $qc = array( 'ls_field' => 'target_author_id', 'ls_value' => $offender->getId() );
84 } elseif ( $offender && IP::isIPAddress( $offender->getName() ) ) {
85 $qc = array( 'ls_field' => 'target_author_ip', 'ls_value' => $offender->getName() );
87 } else {
88 // Allow extensions to add relations to their search types
89 Hooks::run(
90 'SpecialLogAddLogSearchRelations',
91 array( $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 bug 1697.
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.
117 * @since 1.25
118 * @return array
120 public static function getLogTypesOnUser() {
121 static $types = null;
122 if ( $types !== null ) {
123 return $types;
125 $types = array(
126 'block',
127 'newusers',
128 'rights',
131 Hooks::run( 'GetLogTypesOnUser', array( &$types ) );
132 return $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' );
142 $subpages[] = 'all';
143 sort( $subpages );
144 return $subpages;
147 private function parseParams( FormOptions $opts, $par ) {
148 # Get parameters
149 $parms = explode( '/', ( $par = ( $par !== null ) ? $par : '' ) );
150 $symsForAll = array( '*', 'all' );
151 if ( $parms[0] != '' &&
152 ( in_array( $par, $this->getConfig()->get( 'LogTypes' ) ) || in_array( $par, $symsForAll ) )
154 $opts->setValue( 'type', $par );
155 } elseif ( count( $parms ) == 2 ) {
156 $opts->setValue( 'type', $parms[0] );
157 $opts->setValue( 'user', $parms[1] );
158 } elseif ( $par != '' ) {
159 $opts->setValue( 'user', $par );
163 private function show( FormOptions $opts, array $extraConds ) {
164 # Create a LogPager item to get the results and a LogEventsList item to format them...
165 $loglist = new LogEventsList(
166 $this->getContext(),
167 null,
168 LogEventsList::USE_CHECKBOXES
170 $pager = new LogPager(
171 $loglist,
172 $opts->getValue( 'type' ),
173 $opts->getValue( 'user' ),
174 $opts->getValue( 'page' ),
175 $opts->getValue( 'pattern' ),
176 $extraConds,
177 $opts->getValue( 'year' ),
178 $opts->getValue( 'month' ),
179 $opts->getValue( 'tagfilter' )
182 $this->addHeader( $opts->getValue( 'type' ) );
184 # Set relevant user
185 if ( $pager->getPerformer() ) {
186 $this->getSkin()->setRelevantUser( User::newFromName( $pager->getPerformer() ) );
189 # Show form options
190 $loglist->showOptions(
191 $pager->getType(),
192 $opts->getValue( 'user' ),
193 $pager->getPage(),
194 $pager->getPattern(),
195 $pager->getYear(),
196 $pager->getMonth(),
197 $pager->getFilterParams(),
198 $opts->getValue( 'tagfilter' )
201 # Insert list
202 $logBody = $pager->getBody();
203 if ( $logBody ) {
204 $this->getOutput()->addHTML(
205 $pager->getNavigationBar() .
206 $this->getActionButtons(
207 $loglist->beginLogEventsList() .
208 $logBody .
209 $loglist->endLogEventsList()
211 $pager->getNavigationBar()
213 } else {
214 $this->getOutput()->addWikiMsg( 'logempty' );
218 private function getActionButtons( $formcontents ) {
219 $user = $this->getUser();
220 $canRevDelete = $user->isAllowedAll( 'deletedhistory', 'deletelogentry' );
221 $showTagEditUI = ChangeTags::showTagEditingUI( $user );
222 # If the user doesn't have the ability to delete log entries nor edit tags,
223 # don't bother showing them the button(s).
224 if ( !$canRevDelete && !$showTagEditUI ) {
225 return $formcontents;
228 # Show button to hide log entries and/or edit change tags
229 $s = Html::openElement(
230 'form',
231 array( 'action' => wfScript(), 'id' => 'mw-log-deleterevision-submit' )
232 ) . "\n";
233 $s .= Html::hidden( 'action', 'historysubmit' ) . "\n";
234 $s .= Html::hidden( 'type', 'logging' ) . "\n";
236 $buttons = '';
237 if ( $canRevDelete ) {
238 $buttons .= Html::element(
239 'button',
240 array(
241 'type' => 'submit',
242 'name' => 'revisiondelete',
243 'value' => '1',
244 'class' => "deleterevision-log-submit mw-log-deleterevision-button"
246 $this->msg( 'showhideselectedlogentries' )->text()
247 ) . "\n";
249 if ( $showTagEditUI ) {
250 $buttons .= Html::element(
251 'button',
252 array(
253 'type' => 'submit',
254 'name' => 'editchangetags',
255 'value' => '1',
256 'class' => "editchangetags-log-submit mw-log-editchangetags-button"
258 $this->msg( 'log-edit-tags' )->text()
259 ) . "\n";
261 $s .= $buttons . $formcontents . $buttons;
262 $s .= Html::closeElement( 'form' );
264 return $s;
268 * Set page title and show header for this log type
269 * @param string $type
270 * @since 1.19
272 protected function addHeader( $type ) {
273 $page = new LogPage( $type );
274 $this->getOutput()->setPageTitle( $page->getName() );
275 $this->getOutput()->addHTML( $page->getDescription()
276 ->setContext( $this->getContext() )->parseAsBlock() );
279 protected function getGroupName() {
280 return 'changes';