MediaWiki  REL1_24
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         $this->setHeaders();
00049         $this->outputHeader();
00050 
00051         $opts = new FormOptions;
00052         $opts->add( 'type', '' );
00053         $opts->add( 'user', '' );
00054         $opts->add( 'page', '' );
00055         $opts->add( 'pattern', false );
00056         $opts->add( 'year', null, FormOptions::INTNULL );
00057         $opts->add( 'month', null, FormOptions::INTNULL );
00058         $opts->add( 'tagfilter', '' );
00059         $opts->add( 'offset', '' );
00060         $opts->add( 'dir', '' );
00061         $opts->add( 'offender', '' );
00062 
00063         // Set values
00064         $opts->fetchValuesFromRequest( $this->getRequest() );
00065         if ( $par !== null ) {
00066             $this->parseParams( $opts, (string)$par );
00067         }
00068 
00069         # Don't let the user get stuck with a certain date
00070         if ( $opts->getValue( 'offset' ) || $opts->getValue( 'dir' ) == 'prev' ) {
00071             $opts->setValue( 'year', '' );
00072             $opts->setValue( 'month', '' );
00073         }
00074 
00075         // If the user doesn't have the right permission to view the specific
00076         // log type, throw a PermissionsError
00077         // If the log type is invalid, just show all public logs
00078         $logRestrictions = $this->getConfig()->get( 'LogRestrictions' );
00079         $type = $opts->getValue( 'type' );
00080         if ( !LogPage::isLogType( $type ) ) {
00081             $opts->setValue( 'type', '' );
00082         } elseif ( isset( $logRestrictions[$type] )
00083             && !$this->getUser()->isAllowed( $logRestrictions[$type] )
00084         ) {
00085             throw new PermissionsError( $logRestrictions[$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         wfRunHooks( 'GetLogTypesOnUser', array( &$this->typeOnUser ) );
00103         if ( in_array( $opts->getValue( 'type' ), $this->typeOnUser ) ) {
00104             # ok we have a type of log which expect a user title.
00105             $target = Title::newFromText( $opts->getValue( 'page' ) );
00106             if ( $target && $target->getNamespace() === NS_MAIN ) {
00107                 # User forgot to add 'User:', we are adding it for him
00108                 $opts->setValue( 'page',
00109                     Title::makeTitleSafe( NS_USER, $opts->getValue( 'page' ) )
00110                 );
00111             }
00112         }
00113 
00114         $this->show( $opts, $qc );
00115     }
00116 
00124     public function prefixSearchSubpages( $search, $limit = 10 ) {
00125         $subpages = $this->getConfig()->get( 'LogTypes' );
00126         $subpages[] = 'all';
00127         sort( $subpages );
00128         return self::prefixSearchArray( $search, $limit, $subpages );
00129     }
00130 
00131     private function parseParams( FormOptions $opts, $par ) {
00132         # Get parameters
00133         $parms = explode( '/', ( $par = ( $par !== null ) ? $par : '' ) );
00134         $symsForAll = array( '*', 'all' );
00135         if ( $parms[0] != '' &&
00136             ( in_array( $par, $this->getConfig()->get( 'LogTypes' ) ) || in_array( $par, $symsForAll ) )
00137         ) {
00138             $opts->setValue( 'type', $par );
00139         } elseif ( count( $parms ) == 2 ) {
00140             $opts->setValue( 'type', $parms[0] );
00141             $opts->setValue( 'user', $parms[1] );
00142         } elseif ( $par != '' ) {
00143             $opts->setValue( 'user', $par );
00144         }
00145     }
00146 
00147     private function show( FormOptions $opts, array $extraConds ) {
00148         # Create a LogPager item to get the results and a LogEventsList item to format them...
00149         $loglist = new LogEventsList(
00150             $this->getContext(),
00151             null,
00152             LogEventsList::USE_REVDEL_CHECKBOXES
00153         );
00154         $pager = new LogPager(
00155             $loglist,
00156             $opts->getValue( 'type' ),
00157             $opts->getValue( 'user' ),
00158             $opts->getValue( 'page' ),
00159             $opts->getValue( 'pattern' ),
00160             $extraConds,
00161             $opts->getValue( 'year' ),
00162             $opts->getValue( 'month' ),
00163             $opts->getValue( 'tagfilter' )
00164         );
00165 
00166         $this->addHeader( $opts->getValue( 'type' ) );
00167 
00168         # Set relevant user
00169         if ( $pager->getPerformer() ) {
00170             $this->getSkin()->setRelevantUser( User::newFromName( $pager->getPerformer() ) );
00171         }
00172 
00173         # Show form options
00174         $loglist->showOptions(
00175             $pager->getType(),
00176             $opts->getValue( 'user' ),
00177             $pager->getPage(),
00178             $pager->getPattern(),
00179             $pager->getYear(),
00180             $pager->getMonth(),
00181             $pager->getFilterParams(),
00182             $opts->getValue( 'tagfilter' )
00183         );
00184 
00185         # Insert list
00186         $logBody = $pager->getBody();
00187         if ( $logBody ) {
00188             $this->getOutput()->addHTML(
00189                 $pager->getNavigationBar() .
00190                     $this->getRevisionButton(
00191                         $loglist->beginLogEventsList() .
00192                             $logBody .
00193                             $loglist->endLogEventsList()
00194                     ) .
00195                     $pager->getNavigationBar()
00196             );
00197         } else {
00198             $this->getOutput()->addWikiMsg( 'logempty' );
00199         }
00200     }
00201 
00202     private function getRevisionButton( $formcontents ) {
00203         # If the user doesn't have the ability to delete log entries,
00204         # don't bother showing them the button.
00205         if ( !$this->getUser()->isAllowedAll( 'deletedhistory', 'deletelogentry' ) ) {
00206             return $formcontents;
00207         }
00208 
00209         # Show button to hide log entries
00210         $s = Html::openElement(
00211             'form',
00212             array( 'action' => wfScript(), 'id' => 'mw-log-deleterevision-submit' )
00213         ) . "\n";
00214         $s .= Html::hidden( 'title', SpecialPage::getTitleFor( 'Revisiondelete' ) ) . "\n";
00215         $s .= Html::hidden( 'target', SpecialPage::getTitleFor( 'Log' ) ) . "\n";
00216         $s .= Html::hidden( 'type', 'logging' ) . "\n";
00217         $button = Html::element(
00218             'button',
00219             array(
00220                 'type' => 'submit',
00221                 'class' => "deleterevision-log-submit mw-log-deleterevision-button"
00222             ),
00223             $this->msg( 'showhideselectedlogentries' )->text()
00224         ) . "\n";
00225         $s .= $button . $formcontents . $button;
00226         $s .= Html::closeElement( 'form' );
00227 
00228         return $s;
00229     }
00230 
00236     protected function addHeader( $type ) {
00237         $page = new LogPage( $type );
00238         $this->getOutput()->setPageTitle( $page->getName()->text() );
00239         $this->getOutput()->addHTML( $page->getDescription()->parseAsBlock() );
00240     }
00241 
00242     protected function getGroupName() {
00243         return 'changes';
00244     }
00245 }