MediaWiki  REL1_19
SpecialLog.php
Go to the documentation of this file.
00001 <?php
00031 class SpecialLog extends SpecialPage {
00032 
00038         private $typeOnUser = array(
00039                 'block',
00040                 'newusers',
00041                 'rights',
00042         );
00043 
00044         public function __construct() {
00045                 parent::__construct( 'Log' );
00046         }
00047 
00048         public function execute( $par ) {
00049                 global $wgLogRestrictions;
00050                 
00051                 $this->setHeaders();
00052                 $this->outputHeader();
00053 
00054                 $opts = new FormOptions;
00055                 $opts->add( 'type', '' );
00056                 $opts->add( 'user', '' );
00057                 $opts->add( 'page', '' );
00058                 $opts->add( 'pattern', false );
00059                 $opts->add( 'year', null, FormOptions::INTNULL );
00060                 $opts->add( 'month', null, FormOptions::INTNULL );
00061                 $opts->add( 'tagfilter', '' );
00062                 $opts->add( 'offset', '' );
00063                 $opts->add( 'dir', '' );
00064                 $opts->add( 'offender', '' );
00065 
00066                 // Set values
00067                 $opts->fetchValuesFromRequest( $this->getRequest() );
00068                 if ( $par ) {
00069                         $this->parseParams( $opts, (string)$par );
00070                 }
00071 
00072                 # Don't let the user get stuck with a certain date
00073                 if ( $opts->getValue( 'offset' ) || $opts->getValue( 'dir' ) == 'prev' ) {
00074                         $opts->setValue( 'year', '' );
00075                         $opts->setValue( 'month', '' );
00076                 }
00077 
00078                 // Reset the log type to default (nothing) if it's invalid or if the
00079                 // user does not possess the right to view it
00080                 $type = $opts->getValue( 'type' );
00081                 if ( !LogPage::isLogType( $type )
00082                         || ( isset( $wgLogRestrictions[$type] )
00083                                 && !$this->getUser()->isAllowed( $wgLogRestrictions[$type] ) )
00084                 ) {
00085                         $opts->setValue( 'type', '' );
00086                 }
00087 
00088                 # Handle type-specific inputs
00089                 $qc = array();
00090                 if ( $opts->getValue( 'type' ) == 'suppress' ) {
00091                         $offender = User::newFromName( $opts->getValue( 'offender' ), false );
00092                         if ( $offender && $offender->getId() > 0 ) {
00093                                 $qc = array( 'ls_field' => 'target_author_id', 'ls_value' => $offender->getId() );
00094                         } elseif ( $offender && IP::isIPAddress( $offender->getName() ) ) {
00095                                 $qc = array( 'ls_field' => 'target_author_ip', 'ls_value' => $offender->getName() );
00096                         }
00097                 }
00098 
00099                 # Some log types are only for a 'User:' title but we might have been given
00100                 # only the username instead of the full title 'User:username'. This part try
00101                 # to lookup for a user by that name and eventually fix user input. See bug 1697.
00102                 if( in_array( $opts->getValue( 'type' ), $this->typeOnUser ) ) {
00103                         # ok we have a type of log which expect a user title.
00104                         $target = Title::newFromText( $opts->getValue( 'page' ) );
00105                         if( $target && $target->getNamespace() === NS_MAIN ) {
00106                                 # User forgot to add 'User:', we are adding it for him
00107                                 $opts->setValue( 'page',
00108                                         Title::makeTitleSafe( NS_USER, $opts->getValue( 'page' ) )
00109                                 );
00110                         }
00111                 }
00112 
00113                 $this->show( $opts, $qc );
00114         }
00115 
00116         private function parseParams( FormOptions $opts, $par ) {
00117                 global $wgLogTypes;
00118 
00119                 # Get parameters
00120                 $parms = explode( '/', ($par = ( $par !== null ) ? $par : '' ) );
00121                 $symsForAll = array( '*', 'all' );
00122                 if ( $parms[0] != '' && ( in_array( $par, $wgLogTypes ) || in_array( $par, $symsForAll ) ) ) {
00123                         $opts->setValue( 'type', $par );
00124                 } elseif ( count( $parms ) == 2 ) {
00125                         $opts->setValue( 'type', $parms[0] );
00126                         $opts->setValue( 'user', $parms[1] );
00127                 } elseif ( $par != '' ) {
00128                         $opts->setValue( 'user', $par );
00129                 }
00130         }
00131 
00132         private function show( FormOptions $opts, array $extraConds ) {
00133                 # Create a LogPager item to get the results and a LogEventsList item to format them...
00134                 $loglist = new LogEventsList( $this->getSkin(), $this->getOutput(), 0 );
00135                 $pager = new LogPager( $loglist, $opts->getValue( 'type' ), $opts->getValue( 'user' ),
00136                         $opts->getValue( 'page' ), $opts->getValue( 'pattern' ), $extraConds, $opts->getValue( 'year' ),
00137                         $opts->getValue( 'month' ), $opts->getValue( 'tagfilter' ) );
00138 
00139                 $this->addHeader( $opts->getValue( 'type' ) );
00140 
00141                 # Set relevant user
00142                 if ( $pager->getPerformer() ) {
00143                         $this->getSkin()->setRelevantUser( User::newFromName( $pager->getPerformer() ) );
00144                 }
00145 
00146                 # Show form options
00147                 $loglist->showOptions( $pager->getType(), $opts->getValue( 'user' ), $pager->getPage(), $pager->getPattern(),
00148                         $pager->getYear(), $pager->getMonth(), $pager->getFilterParams(), $opts->getValue( 'tagfilter' ) );
00149 
00150                 # Insert list
00151                 $logBody = $pager->getBody();
00152                 if ( $logBody ) {
00153                         $this->getOutput()->addHTML(
00154                                 $pager->getNavigationBar() .
00155                                 $loglist->beginLogEventsList() .
00156                                 $logBody .
00157                                 $loglist->endLogEventsList() .
00158                                 $pager->getNavigationBar()
00159                         );
00160                 } else {
00161                         $this->getOutput()->addWikiMsg( 'logempty' );
00162                 }
00163         }
00164 
00170         protected function addHeader( $type ) {
00171                 $page = new LogPage( $type );
00172                 $this->getOutput()->setPageTitle( $page->getName()->text() );
00173                 $this->getOutput()->addHTML( $page->getDescription()->parseAsBlock() );
00174         }
00175 
00176 }