2c96e83d0c2471702ab4333ebe653cb84f214619
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
{
34 * List log type for which the target is a user
35 * Thus if the given target is in NS_MAIN we can alter it to be an NS_USER
38 private $typeOnUser = array(
44 public function __construct() {
45 parent
::__construct( 'Log' );
48 public function execute( $par ) {
49 global $wgLogRestrictions;
52 $this->outputHeader();
54 $opts = new FormOptions
;
55 $opts->add( 'type', '' );
56 $opts->add( 'user', '' );
57 $opts->add( 'page', '' );
58 $opts->add( 'pattern', false );
59 $opts->add( 'year', null, FormOptions
::INTNULL
);
60 $opts->add( 'month', null, FormOptions
::INTNULL
);
61 $opts->add( 'tagfilter', '' );
62 $opts->add( 'offset', '' );
63 $opts->add( 'dir', '' );
64 $opts->add( 'offender', '' );
67 $opts->fetchValuesFromRequest( $this->getRequest() );
69 $this->parseParams( $opts, (string)$par );
72 # Don't let the user get stuck with a certain date
73 if ( $opts->getValue( 'offset' ) ||
$opts->getValue( 'dir' ) == 'prev' ) {
74 $opts->setValue( 'year', '' );
75 $opts->setValue( 'month', '' );
78 // Reset the log type to default (nothing) if it's invalid or if the
79 // user does not possess the right to view it
80 $type = $opts->getValue( 'type' );
81 if ( !LogPage
::isLogType( $type )
82 ||
( isset( $wgLogRestrictions[$type] )
83 && !$this->getUser()->isAllowed( $wgLogRestrictions[$type] ) )
85 $opts->setValue( 'type', '' );
88 # Handle type-specific inputs
90 if ( $opts->getValue( 'type' ) == 'suppress' ) {
91 $offender = User
::newFromName( $opts->getValue( 'offender' ), false );
92 if ( $offender && $offender->getId() > 0 ) {
93 $qc = array( 'ls_field' => 'target_author_id', 'ls_value' => $offender->getId() );
94 } elseif ( $offender && IP
::isIPAddress( $offender->getName() ) ) {
95 $qc = array( 'ls_field' => 'target_author_ip', 'ls_value' => $offender->getName() );
99 # Some log types are only for a 'User:' title but we might have been given
100 # only the username instead of the full title 'User:username'. This part try
101 # to lookup for a user by that name and eventually fix user input. See bug 1697.
102 if( in_array( $opts->getValue( 'type' ), $this->typeOnUser
) ) {
103 # ok we have a type of log which expect a user title.
104 $target = Title
::newFromText( $opts->getValue( 'page' ) );
105 if( $target && $target->getNamespace() === NS_MAIN
) {
106 # User forgot to add 'User:', we are adding it for him
107 $opts->setValue( 'page',
108 Title
::makeTitleSafe( NS_USER
, $opts->getValue( 'page' ) )
113 $this->show( $opts, $qc );
116 private function parseParams( FormOptions
$opts, $par ) {
120 $parms = explode( '/', ($par = ( $par !== null ) ?
$par : '' ) );
121 $symsForAll = array( '*', 'all' );
122 if ( $parms[0] != '' && ( in_array( $par, $wgLogTypes ) ||
in_array( $par, $symsForAll ) ) ) {
123 $opts->setValue( 'type', $par );
124 } elseif ( count( $parms ) == 2 ) {
125 $opts->setValue( 'type', $parms[0] );
126 $opts->setValue( 'user', $parms[1] );
127 } elseif ( $par != '' ) {
128 $opts->setValue( 'user', $par );
132 private function show( FormOptions
$opts, array $extraConds ) {
133 # Create a LogPager item to get the results and a LogEventsList item to format them...
134 $loglist = new LogEventsList( $this->getContext(), null, LogEventsList
::USE_REVDEL_CHECKBOXES
);
135 $pager = new LogPager( $loglist, $opts->getValue( 'type' ), $opts->getValue( 'user' ),
136 $opts->getValue( 'page' ), $opts->getValue( 'pattern' ), $extraConds, $opts->getValue( 'year' ),
137 $opts->getValue( 'month' ), $opts->getValue( 'tagfilter' ) );
139 $this->addHeader( $opts->getValue( 'type' ) );
142 if ( $pager->getPerformer() ) {
143 $this->getSkin()->setRelevantUser( User
::newFromName( $pager->getPerformer() ) );
147 $loglist->showOptions( $pager->getType(), $opts->getValue( 'user' ), $pager->getPage(), $pager->getPattern(),
148 $pager->getYear(), $pager->getMonth(), $pager->getFilterParams(), $opts->getValue( 'tagfilter' ) );
151 $logBody = $pager->getBody();
153 $this->getOutput()->addHTML(
154 $pager->getNavigationBar() .
155 $this->getRevisionButton( $loglist->beginLogEventsList() . $logBody . $loglist->endLogEventsList() ) .
156 $pager->getNavigationBar()
159 $this->getOutput()->addWikiMsg( 'logempty' );
163 private function getRevisionButton( $formcontents ) {
164 # If the user doesn't have the ability to delete revisions, don't bother showing him/her the button.
165 if ( !$this->getUser()->isAllowed( 'deleterevision' ) ) {
166 return $formcontents;
169 # Show button to hide log entries
171 $s = Html
::openElement( 'form', array( 'action' => $wgScript, 'id' => 'mw-log-deleterevision-submit' ) ) . "\n";
172 $s .= Html
::hidden( 'title', SpecialPage
::getTitleFor( 'Revisiondelete' ) ) . "\n";
173 $s .= Html
::hidden( 'target', SpecialPage
::getTitleFor( 'Log' ) ) . "\n";
174 $s .= Html
::hidden( 'type', 'logging' ) . "\n";
175 $button = Html
::element( 'button',
176 array( 'type' => 'submit', 'class' => "deleterevision-log-submit mw-log-deleterevision-button" ),
177 $this->msg( 'showhideselectedlogentries' )->text()
179 $s .= $button . $formcontents . $button;
180 $s .= Html
::closeElement( 'form' );
187 * Set page title and show header for this log type
188 * @param $type string
191 protected function addHeader( $type ) {
192 $page = new LogPage( $type );
193 $this->getOutput()->setPageTitle( $page->getName()->text() );
194 $this->getOutput()->addHTML( $page->getDescription()->parseAsBlock() );