MediaWiki  REL1_22
SpecialLog.php
Go to the documentation of this file.
00001 <?php
00031 class SpecialLog extends SpecialPage {
00037     private $typeOnUser = array(
00038         'block',
00039         'newusers',
00040         'rights',
00041     );
00042 
00043     public function __construct() {
00044         parent::__construct( 'Log' );
00045     }
00046 
00047     public function execute( $par ) {
00048         global $wgLogRestrictions;
00049 
00050         $this->setHeaders();
00051         $this->outputHeader();
00052 
00053         $opts = new FormOptions;
00054         $opts->add( 'type', '' );
00055         $opts->add( 'user', '' );
00056         $opts->add( 'page', '' );
00057         $opts->add( 'pattern', false );
00058         $opts->add( 'year', null, FormOptions::INTNULL );
00059         $opts->add( 'month', null, FormOptions::INTNULL );
00060         $opts->add( 'tagfilter', '' );
00061         $opts->add( 'offset', '' );
00062         $opts->add( 'dir', '' );
00063         $opts->add( 'offender', '' );
00064 
00065         // Set values
00066         $opts->fetchValuesFromRequest( $this->getRequest() );
00067         if ( $par !== null ) {
00068             $this->parseParams( $opts, (string)$par );
00069         }
00070 
00071         # Don't let the user get stuck with a certain date
00072         if ( $opts->getValue( 'offset' ) || $opts->getValue( 'dir' ) == 'prev' ) {
00073             $opts->setValue( 'year', '' );
00074             $opts->setValue( 'month', '' );
00075         }
00076 
00077         // If the user doesn't have the right permission to view the specific
00078         // log type, throw a PermissionsError
00079         // If the log type is invalid, just show all public logs
00080         $type = $opts->getValue( 'type' );
00081         if ( !LogPage::isLogType( $type ) ) {
00082             $opts->setValue( 'type', '' );
00083         } elseif ( isset( $wgLogRestrictions[$type] ) && !$this->getUser()->isAllowed( $wgLogRestrictions[$type] ) ) {
00084             throw new PermissionsError( $wgLogRestrictions[$type] );
00085         }
00086 
00087         # Handle type-specific inputs
00088         $qc = array();
00089         if ( $opts->getValue( 'type' ) == 'suppress' ) {
00090             $offender = User::newFromName( $opts->getValue( 'offender' ), false );
00091             if ( $offender && $offender->getId() > 0 ) {
00092                 $qc = array( 'ls_field' => 'target_author_id', 'ls_value' => $offender->getId() );
00093             } elseif ( $offender && IP::isIPAddress( $offender->getName() ) ) {
00094                 $qc = array( 'ls_field' => 'target_author_ip', 'ls_value' => $offender->getName() );
00095             }
00096         }
00097 
00098         # Some log types are only for a 'User:' title but we might have been given
00099         # only the username instead of the full title 'User:username'. This part try
00100         # to lookup for a user by that name and eventually fix user input. See bug 1697.
00101         if ( in_array( $opts->getValue( 'type' ), $this->typeOnUser ) ) {
00102             # ok we have a type of log which expect a user title.
00103             $target = Title::newFromText( $opts->getValue( 'page' ) );
00104             if ( $target && $target->getNamespace() === NS_MAIN ) {
00105                 # User forgot to add 'User:', we are adding it for him
00106                 $opts->setValue( 'page',
00107                     Title::makeTitleSafe( NS_USER, $opts->getValue( 'page' ) )
00108                 );
00109             }
00110         }
00111 
00112         $this->show( $opts, $qc );
00113     }
00114 
00115     private function parseParams( FormOptions $opts, $par ) {
00116         global $wgLogTypes;
00117 
00118         # Get parameters
00119         $parms = explode( '/', ( $par = ( $par !== null ) ? $par : '' ) );
00120         $symsForAll = array( '*', 'all' );
00121         if ( $parms[0] != '' &&
00122             ( in_array( $par, $wgLogTypes ) || in_array( $par, $symsForAll ) )
00123         ) {
00124             $opts->setValue( 'type', $par );
00125         } elseif ( count( $parms ) == 2 ) {
00126             $opts->setValue( 'type', $parms[0] );
00127             $opts->setValue( 'user', $parms[1] );
00128         } elseif ( $par != '' ) {
00129             $opts->setValue( 'user', $par );
00130         }
00131     }
00132 
00133     private function show( FormOptions $opts, array $extraConds ) {
00134         # Create a LogPager item to get the results and a LogEventsList item to format them...
00135         $loglist = new LogEventsList(
00136             $this->getContext(),
00137             null,
00138             LogEventsList::USE_REVDEL_CHECKBOXES
00139         );
00140         $pager = new LogPager(
00141             $loglist,
00142             $opts->getValue( 'type' ),
00143             $opts->getValue( 'user' ),
00144             $opts->getValue( 'page' ),
00145             $opts->getValue( 'pattern' ),
00146             $extraConds,
00147             $opts->getValue( 'year' ),
00148             $opts->getValue( 'month' ),
00149             $opts->getValue( 'tagfilter' )
00150         );
00151 
00152         $this->addHeader( $opts->getValue( 'type' ) );
00153 
00154         # Set relevant user
00155         if ( $pager->getPerformer() ) {
00156             $this->getSkin()->setRelevantUser( User::newFromName( $pager->getPerformer() ) );
00157         }
00158 
00159         # Show form options
00160         $loglist->showOptions(
00161             $pager->getType(),
00162             $opts->getValue( 'user' ),
00163             $pager->getPage(),
00164             $pager->getPattern(),
00165             $pager->getYear(),
00166             $pager->getMonth(),
00167             $pager->getFilterParams(),
00168             $opts->getValue( 'tagfilter' )
00169         );
00170 
00171         # Insert list
00172         $logBody = $pager->getBody();
00173         if ( $logBody ) {
00174             $this->getOutput()->addHTML(
00175                 $pager->getNavigationBar() .
00176                     $this->getRevisionButton(
00177                         $loglist->beginLogEventsList() .
00178                             $logBody .
00179                             $loglist->endLogEventsList()
00180                     ) .
00181                     $pager->getNavigationBar()
00182             );
00183         } else {
00184             $this->getOutput()->addWikiMsg( 'logempty' );
00185         }
00186     }
00187 
00188     private function getRevisionButton( $formcontents ) {
00189         # If the user doesn't have the ability to delete log entries,
00190         # don't bother showing them the button.
00191         if ( !$this->getUser()->isAllowedAll( 'deletedhistory', 'deletelogentry' ) ) {
00192             return $formcontents;
00193         }
00194 
00195         # Show button to hide log entries
00196         global $wgScript;
00197         $s = Html::openElement(
00198             'form',
00199             array( 'action' => $wgScript, 'id' => 'mw-log-deleterevision-submit' )
00200         ) . "\n";
00201         $s .= Html::hidden( 'title', SpecialPage::getTitleFor( 'Revisiondelete' ) ) . "\n";
00202         $s .= Html::hidden( 'target', SpecialPage::getTitleFor( 'Log' ) ) . "\n";
00203         $s .= Html::hidden( 'type', 'logging' ) . "\n";
00204         $button = Html::element(
00205             'button',
00206             array(
00207                 'type' => 'submit',
00208                 'class' => "deleterevision-log-submit mw-log-deleterevision-button"
00209             ),
00210             $this->msg( 'showhideselectedlogentries' )->text()
00211         ) . "\n";
00212         $s .= $button . $formcontents . $button;
00213         $s .= Html::closeElement( 'form' );
00214 
00215         return $s;
00216     }
00217 
00223     protected function addHeader( $type ) {
00224         $page = new LogPage( $type );
00225         $this->getOutput()->setPageTitle( $page->getName()->text() );
00226         $this->getOutput()->addHTML( $page->getDescription()->parseAsBlock() );
00227     }
00228 
00229     protected function getGroupName() {
00230         return 'changes';
00231     }
00232 }