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 ) {
48 global $wgLogRestrictions;
51 $this->outputHeader();
53 $opts = new FormOptions
;
54 $opts->add( 'type', '' );
55 $opts->add( 'user', '' );
56 $opts->add( 'page', '' );
57 $opts->add( 'pattern', false );
58 $opts->add( 'year', null, FormOptions
::INTNULL
);
59 $opts->add( 'month', null, FormOptions
::INTNULL
);
60 $opts->add( 'tagfilter', '' );
61 $opts->add( 'offset', '' );
62 $opts->add( 'dir', '' );
63 $opts->add( 'offender', '' );
66 $opts->fetchValuesFromRequest( $this->getRequest() );
67 if ( $par !== null ) {
68 $this->parseParams( $opts, (string)$par );
71 # Don't let the user get stuck with a certain date
72 if ( $opts->getValue( 'offset' ) ||
$opts->getValue( 'dir' ) == 'prev' ) {
73 $opts->setValue( 'year', '' );
74 $opts->setValue( 'month', '' );
77 // Reset the log type to default (nothing) if it's invalid or if the
78 // user does not possess the right to view it
79 $type = $opts->getValue( 'type' );
80 if ( !LogPage
::isLogType( $type )
81 ||
( isset( $wgLogRestrictions[$type] )
82 && !$this->getUser()->isAllowed( $wgLogRestrictions[$type] ) )
84 $opts->setValue( 'type', '' );
87 # Handle type-specific inputs
89 if ( $opts->getValue( 'type' ) == 'suppress' ) {
90 $offender = User
::newFromName( $opts->getValue( 'offender' ), false );
91 if ( $offender && $offender->getId() > 0 ) {
92 $qc = array( 'ls_field' => 'target_author_id', 'ls_value' => $offender->getId() );
93 } elseif ( $offender && IP
::isIPAddress( $offender->getName() ) ) {
94 $qc = array( 'ls_field' => 'target_author_ip', 'ls_value' => $offender->getName() );
98 # Some log types are only for a 'User:' title but we might have been given
99 # only the username instead of the full title 'User:username'. This part try
100 # to lookup for a user by that name and eventually fix user input. See bug 1697.
101 if ( in_array( $opts->getValue( 'type' ), $this->typeOnUser
) ) {
102 # ok we have a type of log which expect a user title.
103 $target = Title
::newFromText( $opts->getValue( 'page' ) );
104 if ( $target && $target->getNamespace() === NS_MAIN
) {
105 # User forgot to add 'User:', we are adding it for him
106 $opts->setValue( 'page',
107 Title
::makeTitleSafe( NS_USER
, $opts->getValue( 'page' ) )
112 $this->show( $opts, $qc );
115 private function parseParams( FormOptions
$opts, $par ) {
119 $parms = explode( '/', ( $par = ( $par !== null ) ?
$par : '' ) );
120 $symsForAll = array( '*', 'all' );
121 if ( $parms[0] != '' &&
122 ( in_array( $par, $wgLogTypes ) ||
in_array( $par, $symsForAll ) )
124 $opts->setValue( 'type', $par );
125 } elseif ( count( $parms ) == 2 ) {
126 $opts->setValue( 'type', $parms[0] );
127 $opts->setValue( 'user', $parms[1] );
128 } elseif ( $par != '' ) {
129 $opts->setValue( 'user', $par );
133 private function show( FormOptions
$opts, array $extraConds ) {
134 # Create a LogPager item to get the results and a LogEventsList item to format them...
135 $loglist = new LogEventsList(
138 LogEventsList
::USE_REVDEL_CHECKBOXES
140 $pager = new LogPager(
142 $opts->getValue( 'type' ),
143 $opts->getValue( 'user' ),
144 $opts->getValue( 'page' ),
145 $opts->getValue( 'pattern' ),
147 $opts->getValue( 'year' ),
148 $opts->getValue( 'month' ),
149 $opts->getValue( 'tagfilter' )
152 $this->addHeader( $opts->getValue( 'type' ) );
155 if ( $pager->getPerformer() ) {
156 $this->getSkin()->setRelevantUser( User
::newFromName( $pager->getPerformer() ) );
160 $loglist->showOptions(
162 $opts->getValue( 'user' ),
164 $pager->getPattern(),
167 $pager->getFilterParams(),
168 $opts->getValue( 'tagfilter' )
172 $logBody = $pager->getBody();
174 $this->getOutput()->addHTML(
175 $pager->getNavigationBar() .
176 $this->getRevisionButton(
177 $loglist->beginLogEventsList() .
179 $loglist->endLogEventsList()
181 $pager->getNavigationBar()
184 $this->getOutput()->addWikiMsg( 'logempty' );
188 private function getRevisionButton( $formcontents ) {
189 # If the user doesn't have the ability to delete log entries,
190 # don't bother showing them the button.
191 if ( !$this->getUser()->isAllowedAll( 'deletedhistory', 'deletelogentry' ) ) {
192 return $formcontents;
195 # Show button to hide log entries
197 $s = Html
::openElement(
199 array( 'action' => $wgScript, 'id' => 'mw-log-deleterevision-submit' )
201 $s .= Html
::hidden( 'title', SpecialPage
::getTitleFor( 'Revisiondelete' ) ) . "\n";
202 $s .= Html
::hidden( 'target', SpecialPage
::getTitleFor( 'Log' ) ) . "\n";
203 $s .= Html
::hidden( 'type', 'logging' ) . "\n";
204 $button = Html
::element(
208 'class' => "deleterevision-log-submit mw-log-deleterevision-button"
210 $this->msg( 'showhideselectedlogentries' )->text()
212 $s .= $button . $formcontents . $button;
213 $s .= Html
::closeElement( 'form' );
219 * Set page title and show header for this log type
220 * @param $type string
223 protected function addHeader( $type ) {
224 $page = new LogPage( $type );
225 $this->getOutput()->setPageTitle( $page->getName()->text() );
226 $this->getOutput()->addHTML( $page->getDescription()->parseAsBlock() );
229 protected function getGroupName() {