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 public function __construct() {
34 parent
::__construct( 'Log' );
37 public function execute( $par ) {
41 $this->outputHeader();
43 $opts = new FormOptions
;
44 $opts->add( 'type', '' );
45 $opts->add( 'user', '' );
46 $opts->add( 'page', '' );
47 $opts->add( 'pattern', false );
48 $opts->add( 'year', null, FormOptions
::INTNULL
);
49 $opts->add( 'month', null, FormOptions
::INTNULL
);
50 $opts->add( 'tagfilter', '' );
51 $opts->add( 'offset', '' );
52 $opts->add( 'dir', '' );
53 $opts->add( 'offender', '' );
56 $opts->fetchValuesFromRequest( $wgRequest );
58 $this->parseParams( $opts, (string)$par );
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', '' );
67 if ( !LogPage
::isLogType( $opts->getValue( 'type' ) ) ) {
68 $opts->setValue( 'type', '' );
71 # Handle type-specific inputs
73 if ( $opts->getValue( 'type' ) == 'suppress' ) {
74 $offender = User
::newFromName( $opts->getValue( 'offender' ), false );
75 if ( $offender && $offender->getId() > 0 ) {
76 $qc = array( 'ls_field' => 'target_author_id', 'ls_value' => $offender->getId() );
77 } elseif ( $offender && IP
::isIPAddress( $offender->getName() ) ) {
78 $qc = array( 'ls_field' => 'target_author_ip', 'ls_value' => $offender->getName() );
82 $this->show( $opts, $qc );
85 private function parseParams( FormOptions
$opts, $par ) {
89 $parms = explode( '/', ($par = ( $par !== null ) ?
$par : '' ) );
90 $symsForAll = array( '*', 'all' );
91 if ( $parms[0] != '' && ( in_array( $par, $wgLogTypes ) ||
in_array( $par, $symsForAll ) ) ) {
92 $opts->setValue( 'type', $par );
93 } elseif ( count( $parms ) == 2 ) {
94 $opts->setValue( 'type', $parms[0] );
95 $opts->setValue( 'user', $parms[1] );
96 } elseif ( $par != '' ) {
97 $opts->setValue( 'user', $par );
101 private function show( FormOptions
$opts, array $extraConds ) {
104 # Create a LogPager item to get the results and a LogEventsList item to format them...
105 $loglist = new LogEventsList( $this->getSkin(), $wgOut, 0 );
106 $pager = new LogPager( $loglist, $opts->getValue( 'type' ), $opts->getValue( 'user' ),
107 $opts->getValue( 'page' ), $opts->getValue( 'pattern' ), $extraConds, $opts->getValue( 'year' ),
108 $opts->getValue( 'month' ), $opts->getValue( 'tagfilter' ) );
110 $this->addHeader( $opts->getValue( 'type' ) );
113 if ( $pager->getUser() ) {
114 $this->getSkin()->setRelevantUser( User
::newFromName( $pager->getUser() ) );
118 $loglist->showOptions( $pager->getType(), $pager->getUser(), $pager->getPage(), $pager->getPattern(),
119 $pager->getYear(), $pager->getMonth(), $pager->getFilterParams(), $opts->getValue( 'tagfilter' ) );
122 $logBody = $pager->getBody();
125 $pager->getNavigationBar() .
126 $loglist->beginLogEventsList() .
128 $loglist->endLogEventsList() .
129 $pager->getNavigationBar()
132 $wgOut->addWikiMsg( 'logempty' );
137 * Set page title and show header for this log type
138 * @param $type string
141 protected function addHeader( $type ) {
142 $page = new LogPage( $type );
143 $this->getOutput()->setPageTitle( $page->getName()->text() );
144 $this->getOutput()->addHTML( $page->getDescription()->parseAsBlock() );