* Modified Special:Log to extend SpecialPage
[lhc/web/wiklou.git] / includes / specials / SpecialLog.php
1 <?php
2 /**
3 * Copyright (C) 2008 Aaron Schulz
4 *
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.
9 *
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.
14 *
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
19 */
20
21 /**
22 * Implements Special:Log
23 * @ingroup SpecialPage
24 */
25 class SpecialLog extends SpecialPage {
26
27 public function __construct() {
28 parent::__construct( 'Log' );
29 }
30
31 public function execute( $par ) {
32 global $wgRequest;
33
34 $this->setHeaders();
35 $this->outputHeader();
36
37 $opts = new FormOptions;
38 $opts->add( 'type', '' );
39 $opts->add( 'user', '' );
40 $opts->add( 'page', '' );
41 $opts->add( 'pattern', false );
42 $opts->add( 'year', null, FormOptions::INTNULL );
43 $opts->add( 'month', null, FormOptions::INTNULL );
44 $opts->add( 'tagfilter', '' );
45 $opts->add( 'offset', '' );
46 $opts->add( 'dir', '' );
47 $opts->add( 'offender', '' );
48
49 // Set values
50 $opts->fetchValuesFromRequest( $wgRequest );
51 if ( $par ) {
52 $this->parseParams( $opts, (string)$par );
53 }
54
55 # Don't let the user get stuck with a certain date
56 if ( $opts->getValue( 'offset' ) || $opts->getValue( 'dir' ) == 'prev' ) {
57 $opts->setValue( 'year', '' );
58 $opts->setValue( 'month', '' );
59 }
60
61 # Handle type-specific inputs
62 $qc = array();
63 if ( $opts->getValue( 'type' ) == 'suppress' ) {
64 $offender = User::newFromName( $opts->getValue( 'offender' ), false );
65 if ( $offender && $offender->getId() > 0 ) {
66 $qc = array( 'ls_field' => 'target_author_id', 'ls_value' => $offender->getId() );
67 } elseif ( $offender && IP::isIPAddress( $offender->getName() ) ) {
68 $qc = array( 'ls_field' => 'target_author_ip', 'ls_value' => $offender->getName() );
69 }
70 }
71
72 $this->show( $opts, $qc );
73 }
74
75 private function parseParams( FormOptions $opts, $par ) {
76 global $wgLogTypes;
77
78 # Get parameters
79 $parms = explode( '/', ($par = ( $par !== null ) ? $par : '' ) );
80 $symsForAll = array( '*', 'all' );
81 if ( $parms[0] != '' && ( in_array( $par, $wgLogTypes ) || in_array( $par, $symsForAll ) ) ) {
82 $opts->setValue( 'type', $par );
83 } elseif ( count( $parms ) == 2 ) {
84 $opts->setValue( 'type', $parms[0] );
85 $opts->setValue( 'user', $parms[1] );
86 } elseif ( $par != '' ) {
87 $opts->setValue( 'user', $par );
88 }
89 }
90
91 private function show( FormOptions $opts, array $extraConds ) {
92 global $wgOut, $wgUser;
93
94 # Create a LogPager item to get the results and a LogEventsList item to format them...
95 $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut, 0 );
96 $pager = new LogPager( $loglist, $opts->getValue( 'type' ), $opts->getValue( 'user' ),
97 $opts->getValue( 'page' ), $opts->getValue( 'pattern' ), $extraConds, $opts->getValue( 'year' ),
98 $opts->getValue( 'month' ), $opts->getValue( 'tagfilter' ) );
99
100 # Set title and add header
101 $loglist->showHeader( $pager->getType() );
102
103 # Show form options
104 $loglist->showOptions( $pager->getType(), $pager->getUser(), $pager->getPage(), $pager->getPattern(),
105 $pager->getYear(), $pager->getMonth(), $pager->getFilterParams(), $opts->getValue( 'tagfilter' ) );
106
107 # Insert list
108 $logBody = $pager->getBody();
109 if ( $logBody ) {
110 $wgOut->addHTML(
111 $pager->getNavigationBar() .
112 $loglist->beginLogEventsList() .
113 $logBody .
114 $loglist->endLogEventsList() .
115 $pager->getNavigationBar()
116 );
117 } else {
118 $wgOut->addWikiMsg( 'logempty' );
119 }
120 }
121 }