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
23 * @ingroup SpecialPage
27 * A special page that lists log entries
29 * @ingroup SpecialPage
31 class SpecialLog
extends SpecialPage
{
33 * List log type for which the target is a user
34 * Thus if the given target is in NS_MAIN we can alter it to be an NS_USER
37 private $typeOnUser = array(
43 public function __construct() {
44 parent
::__construct( 'Log' );
47 public function execute( $par ) {
49 $this->outputHeader();
50 $this->getOutput()->addModules( 'mediawiki.userSuggest' );
52 $opts = new FormOptions
;
53 $opts->add( 'type', '' );
54 $opts->add( 'user', '' );
55 $opts->add( 'page', '' );
56 $opts->add( 'pattern', false );
57 $opts->add( 'year', null, FormOptions
::INTNULL
);
58 $opts->add( 'month', null, FormOptions
::INTNULL
);
59 $opts->add( 'tagfilter', '' );
60 $opts->add( 'offset', '' );
61 $opts->add( 'dir', '' );
62 $opts->add( 'offender', '' );
65 $opts->fetchValuesFromRequest( $this->getRequest() );
66 if ( $par !== null ) {
67 $this->parseParams( $opts, (string)$par );
70 # Don't let the user get stuck with a certain date
71 if ( $opts->getValue( 'offset' ) ||
$opts->getValue( 'dir' ) == 'prev' ) {
72 $opts->setValue( 'year', '' );
73 $opts->setValue( 'month', '' );
76 // If the user doesn't have the right permission to view the specific
77 // log type, throw a PermissionsError
78 // If the log type is invalid, just show all public logs
79 $logRestrictions = $this->getConfig()->get( 'LogRestrictions' );
80 $type = $opts->getValue( 'type' );
81 if ( !LogPage
::isLogType( $type ) ) {
82 $opts->setValue( 'type', '' );
83 } elseif ( isset( $logRestrictions[$type] )
84 && !$this->getUser()->isAllowed( $logRestrictions[$type] )
86 throw new PermissionsError( $logRestrictions[$type] );
89 # Handle type-specific inputs
91 if ( $opts->getValue( 'type' ) == 'suppress' ) {
92 $offender = User
::newFromName( $opts->getValue( 'offender' ), false );
93 if ( $offender && $offender->getId() > 0 ) {
94 $qc = array( 'ls_field' => 'target_author_id', 'ls_value' => $offender->getId() );
95 } elseif ( $offender && IP
::isIPAddress( $offender->getName() ) ) {
96 $qc = array( 'ls_field' => 'target_author_ip', 'ls_value' => $offender->getName() );
99 // Allow extensions to add relations to their search types
100 Hooks
::run( 'SpecialLogAddLogSearchRelations', array( $opts->getValue( 'type' ), $this->getRequest(), &$qc ) );
103 # Some log types are only for a 'User:' title but we might have been given
104 # only the username instead of the full title 'User:username'. This part try
105 # to lookup for a user by that name and eventually fix user input. See bug 1697.
106 Hooks
::run( 'GetLogTypesOnUser', array( &$this->typeOnUser
) );
107 if ( in_array( $opts->getValue( 'type' ), $this->typeOnUser
) ) {
108 # ok we have a type of log which expect a user title.
109 $target = Title
::newFromText( $opts->getValue( 'page' ) );
110 if ( $target && $target->getNamespace() === NS_MAIN
) {
111 # User forgot to add 'User:', we are adding it for him
112 $opts->setValue( 'page',
113 Title
::makeTitleSafe( NS_USER
, $opts->getValue( 'page' ) )
118 $this->show( $opts, $qc );
122 * Return an array of subpages that this special page will accept.
124 * @return string[] subpages
126 public function getSubpagesForPrefixSearch() {
127 $subpages = $this->getConfig()->get( 'LogTypes' );
133 private function parseParams( FormOptions
$opts, $par ) {
135 $parms = explode( '/', ( $par = ( $par !== null ) ?
$par : '' ) );
136 $symsForAll = array( '*', 'all' );
137 if ( $parms[0] != '' &&
138 ( in_array( $par, $this->getConfig()->get( 'LogTypes' ) ) ||
in_array( $par, $symsForAll ) )
140 $opts->setValue( 'type', $par );
141 } elseif ( count( $parms ) == 2 ) {
142 $opts->setValue( 'type', $parms[0] );
143 $opts->setValue( 'user', $parms[1] );
144 } elseif ( $par != '' ) {
145 $opts->setValue( 'user', $par );
149 private function show( FormOptions
$opts, array $extraConds ) {
150 # Create a LogPager item to get the results and a LogEventsList item to format them...
151 $loglist = new LogEventsList(
154 LogEventsList
::USE_REVDEL_CHECKBOXES
156 $pager = new LogPager(
158 $opts->getValue( 'type' ),
159 $opts->getValue( 'user' ),
160 $opts->getValue( 'page' ),
161 $opts->getValue( 'pattern' ),
163 $opts->getValue( 'year' ),
164 $opts->getValue( 'month' ),
165 $opts->getValue( 'tagfilter' )
168 $this->addHeader( $opts->getValue( 'type' ) );
171 if ( $pager->getPerformer() ) {
172 $this->getSkin()->setRelevantUser( User
::newFromName( $pager->getPerformer() ) );
176 $loglist->showOptions(
178 $opts->getValue( 'user' ),
180 $pager->getPattern(),
183 $pager->getFilterParams(),
184 $opts->getValue( 'tagfilter' )
188 $logBody = $pager->getBody();
190 $this->getOutput()->addHTML(
191 $pager->getNavigationBar() .
192 $this->getRevisionButton(
193 $loglist->beginLogEventsList() .
195 $loglist->endLogEventsList()
197 $pager->getNavigationBar()
200 $this->getOutput()->addWikiMsg( 'logempty' );
204 private function getRevisionButton( $formcontents ) {
205 # If the user doesn't have the ability to delete log entries,
206 # don't bother showing them the button.
207 if ( !$this->getUser()->isAllowedAll( 'deletedhistory', 'deletelogentry' ) ) {
208 return $formcontents;
211 # Show button to hide log entries
212 $s = Html
::openElement(
214 array( 'action' => wfScript(), 'id' => 'mw-log-deleterevision-submit' )
216 $s .= Html
::hidden( 'title', SpecialPage
::getTitleFor( 'Revisiondelete' ) ) . "\n";
217 $s .= Html
::hidden( 'target', SpecialPage
::getTitleFor( 'Log' ) ) . "\n";
218 $s .= Html
::hidden( 'type', 'logging' ) . "\n";
219 $button = Html
::element(
223 'class' => "deleterevision-log-submit mw-log-deleterevision-button"
225 $this->msg( 'showhideselectedlogentries' )->text()
227 $s .= $button . $formcontents . $button;
228 $s .= Html
::closeElement( 'form' );
234 * Set page title and show header for this log type
235 * @param string $type
238 protected function addHeader( $type ) {
239 $page = new LogPage( $type );
240 $this->getOutput()->setPageTitle( $page->getName() );
241 $this->getOutput()->addHTML( $page->getDescription()
242 ->setContext( $this->getContext() )->parseAsBlock() );
245 protected function getGroupName() {