MediaWiki  REL1_23
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         wfRunHooks( 'GetLogTypesOnUser', array( &$this->typeOnUser ) );
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] != '' &&
00123             ( in_array( $par, $wgLogTypes ) || in_array( $par, $symsForAll ) )
00124         ) {
00125             $opts->setValue( 'type', $par );
00126         } elseif ( count( $parms ) == 2 ) {
00127             $opts->setValue( 'type', $parms[0] );
00128             $opts->setValue( 'user', $parms[1] );
00129         } elseif ( $par != '' ) {
00130             $opts->setValue( 'user', $par );
00131         }
00132     }
00133 
00134     private function show( FormOptions $opts, array $extraConds ) {
00135         # Create a LogPager item to get the results and a LogEventsList item to format them...
00136         $loglist = new LogEventsList(
00137             $this->getContext(),
00138             null,
00139             LogEventsList::USE_REVDEL_CHECKBOXES
00140         );
00141         $pager = new LogPager(
00142             $loglist,
00143             $opts->getValue( 'type' ),
00144             $opts->getValue( 'user' ),
00145             $opts->getValue( 'page' ),
00146             $opts->getValue( 'pattern' ),
00147             $extraConds,
00148             $opts->getValue( 'year' ),
00149             $opts->getValue( 'month' ),
00150             $opts->getValue( 'tagfilter' )
00151         );
00152 
00153         $this->addHeader( $opts->getValue( 'type' ) );
00154 
00155         # Set relevant user
00156         if ( $pager->getPerformer() ) {
00157             $this->getSkin()->setRelevantUser( User::newFromName( $pager->getPerformer() ) );
00158         }
00159 
00160         # Show form options
00161         $loglist->showOptions(
00162             $pager->getType(),
00163             $opts->getValue( 'user' ),
00164             $pager->getPage(),
00165             $pager->getPattern(),
00166             $pager->getYear(),
00167             $pager->getMonth(),
00168             $pager->getFilterParams(),
00169             $opts->getValue( 'tagfilter' )
00170         );
00171 
00172         # Insert list
00173         $logBody = $pager->getBody();
00174         if ( $logBody ) {
00175             $this->getOutput()->addHTML(
00176                 $pager->getNavigationBar() .
00177                     $this->getRevisionButton(
00178                         $loglist->beginLogEventsList() .
00179                             $logBody .
00180                             $loglist->endLogEventsList()
00181                     ) .
00182                     $pager->getNavigationBar()
00183             );
00184         } else {
00185             $this->getOutput()->addWikiMsg( 'logempty' );
00186         }
00187     }
00188 
00189     private function getRevisionButton( $formcontents ) {
00190         # If the user doesn't have the ability to delete log entries,
00191         # don't bother showing them the button.
00192         if ( !$this->getUser()->isAllowedAll( 'deletedhistory', 'deletelogentry' ) ) {
00193             return $formcontents;
00194         }
00195 
00196         # Show button to hide log entries
00197         global $wgScript;
00198         $s = Html::openElement(
00199             'form',
00200             array( 'action' => $wgScript, 'id' => 'mw-log-deleterevision-submit' )
00201         ) . "\n";
00202         $s .= Html::hidden( 'title', SpecialPage::getTitleFor( 'Revisiondelete' ) ) . "\n";
00203         $s .= Html::hidden( 'target', SpecialPage::getTitleFor( 'Log' ) ) . "\n";
00204         $s .= Html::hidden( 'type', 'logging' ) . "\n";
00205         $button = Html::element(
00206             'button',
00207             array(
00208                 'type' => 'submit',
00209                 'class' => "deleterevision-log-submit mw-log-deleterevision-button"
00210             ),
00211             $this->msg( 'showhideselectedlogentries' )->text()
00212         ) . "\n";
00213         $s .= $button . $formcontents . $button;
00214         $s .= Html::closeElement( 'form' );
00215 
00216         return $s;
00217     }
00218 
00224     protected function addHeader( $type ) {
00225         $page = new LogPage( $type );
00226         $this->getOutput()->setPageTitle( $page->getName()->text() );
00227         $this->getOutput()->addHTML( $page->getDescription()->parseAsBlock() );
00228     }
00229 
00230     protected function getGroupName() {
00231         return 'changes';
00232     }
00233 }