1c4f1d792f6307cf577815f11bf33372fb09022e
[lhc/web/wiklou.git] / includes / specials / SpecialLog.php
1 <?php
2 /**
3 * Implements Special:Log
4 *
5 * Copyright © 2008 Aaron Schulz
6 *
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.
11 *
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.
16 *
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
21 *
22 * @file
23 * @ingroup SpecialPage
24 */
25
26 /**
27 * A special page that lists log entries
28 *
29 * @ingroup SpecialPage
30 */
31 class SpecialLog extends SpecialPage {
32
33 public function __construct() {
34 parent::__construct( 'Log' );
35 }
36
37 public function execute( $par ) {
38 $this->setHeaders();
39 $this->outputHeader();
40
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', '' );
52
53 // Set values
54 $opts->fetchValuesFromRequest( $this->getRequest() );
55 if ( $par ) {
56 $this->parseParams( $opts, (string)$par );
57 }
58
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', '' );
63 }
64
65 if ( !LogPage::isLogType( $opts->getValue( 'type' ) ) ) {
66 $opts->setValue( 'type', '' );
67 }
68
69 # Handle type-specific inputs
70 $qc = array();
71 if ( $opts->getValue( 'type' ) == 'suppress' ) {
72 $offender = User::newFromName( $opts->getValue( 'offender' ), false );
73 if ( $offender && $offender->getId() > 0 ) {
74 $qc = array( 'ls_field' => 'target_author_id', 'ls_value' => $offender->getId() );
75 } elseif ( $offender && IP::isIPAddress( $offender->getName() ) ) {
76 $qc = array( 'ls_field' => 'target_author_ip', 'ls_value' => $offender->getName() );
77 }
78 }
79
80 $this->show( $opts, $qc );
81 }
82
83 private function parseParams( FormOptions $opts, $par ) {
84 global $wgLogTypes;
85
86 # Get parameters
87 $parms = explode( '/', ($par = ( $par !== null ) ? $par : '' ) );
88 $symsForAll = array( '*', 'all' );
89 if ( $parms[0] != '' && ( in_array( $par, $wgLogTypes ) || in_array( $par, $symsForAll ) ) ) {
90 $opts->setValue( 'type', $par );
91 } elseif ( count( $parms ) == 2 ) {
92 $opts->setValue( 'type', $parms[0] );
93 $opts->setValue( 'user', $parms[1] );
94 } elseif ( $par != '' ) {
95 $opts->setValue( 'user', $par );
96 }
97 }
98
99 private function show( FormOptions $opts, array $extraConds ) {
100 # Create a LogPager item to get the results and a LogEventsList item to format them...
101 $loglist = new LogEventsList( $this->getSkin(), $this->getOutput(), 0 );
102 $pager = new LogPager( $loglist, $opts->getValue( 'type' ), $opts->getValue( 'user' ),
103 $opts->getValue( 'page' ), $opts->getValue( 'pattern' ), $extraConds, $opts->getValue( 'year' ),
104 $opts->getValue( 'month' ), $opts->getValue( 'tagfilter' ) );
105
106 $this->addHeader( $opts->getValue( 'type' ) );
107
108 # Set relevant user
109 if ( $pager->getPerformer() ) {
110 $this->getSkin()->setRelevantUser( User::newFromName( $pager->getPerformer() ) );
111 }
112
113 # Show form options
114 $loglist->showOptions( $pager->getType(), $pager->getPerformer(), $pager->getPage(), $pager->getPattern(),
115 $pager->getYear(), $pager->getMonth(), $pager->getFilterParams(), $opts->getValue( 'tagfilter' ) );
116
117 # Insert list
118 $logBody = $pager->getBody();
119 if ( $logBody ) {
120 $this->getOutput()->addHTML(
121 $pager->getNavigationBar() .
122 $loglist->beginLogEventsList() .
123 $logBody .
124 $loglist->endLogEventsList() .
125 $pager->getNavigationBar()
126 );
127 } else {
128 $this->getOutput()->addWikiMsg( 'logempty' );
129 }
130 }
131
132 /**
133 * Set page title and show header for this log type
134 * @param $type string
135 * @since 1.19
136 */
137 protected function addHeader( $type ) {
138 $page = new LogPage( $type );
139 $this->getOutput()->setPageTitle( $page->getName()->text() );
140 $this->getOutput()->addHTML( $page->getDescription()->parseAsBlock() );
141 }
142
143 }