[ Index ] |
PHP Cross Reference of MediaWiki-1.24.0 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Implements Special:Log 4 * 5 * Copyright © 2008 Aaron Schulz 6 * 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. 11 * 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. 16 * 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 21 * 22 * @file 23 * @ingroup SpecialPage 24 */ 25 26 /** 27 * A special page that lists log entries 28 * 29 * @ingroup SpecialPage 30 */ 31 class SpecialLog extends SpecialPage { 32 /** 33 * List log type for which the target is a user 34 * Thus if the given target is in NS_MAIN we can alter it to be an NS_USER 35 * Title user instead. 36 */ 37 private $typeOnUser = array( 38 'block', 39 'newusers', 40 'rights', 41 ); 42 43 public function __construct() { 44 parent::__construct( 'Log' ); 45 } 46 47 public function execute( $par ) { 48 $this->setHeaders(); 49 $this->outputHeader(); 50 51 $opts = new FormOptions; 52 $opts->add( 'type', '' ); 53 $opts->add( 'user', '' ); 54 $opts->add( 'page', '' ); 55 $opts->add( 'pattern', false ); 56 $opts->add( 'year', null, FormOptions::INTNULL ); 57 $opts->add( 'month', null, FormOptions::INTNULL ); 58 $opts->add( 'tagfilter', '' ); 59 $opts->add( 'offset', '' ); 60 $opts->add( 'dir', '' ); 61 $opts->add( 'offender', '' ); 62 63 // Set values 64 $opts->fetchValuesFromRequest( $this->getRequest() ); 65 if ( $par !== null ) { 66 $this->parseParams( $opts, (string)$par ); 67 } 68 69 # Don't let the user get stuck with a certain date 70 if ( $opts->getValue( 'offset' ) || $opts->getValue( 'dir' ) == 'prev' ) { 71 $opts->setValue( 'year', '' ); 72 $opts->setValue( 'month', '' ); 73 } 74 75 // If the user doesn't have the right permission to view the specific 76 // log type, throw a PermissionsError 77 // If the log type is invalid, just show all public logs 78 $logRestrictions = $this->getConfig()->get( 'LogRestrictions' ); 79 $type = $opts->getValue( 'type' ); 80 if ( !LogPage::isLogType( $type ) ) { 81 $opts->setValue( 'type', '' ); 82 } elseif ( isset( $logRestrictions[$type] ) 83 && !$this->getUser()->isAllowed( $logRestrictions[$type] ) 84 ) { 85 throw new PermissionsError( $logRestrictions[$type] ); 86 } 87 88 # Handle type-specific inputs 89 $qc = array(); 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() ); 96 } 97 } 98 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 wfRunHooks( 'GetLogTypesOnUser', array( &$this->typeOnUser ) ); 103 if ( in_array( $opts->getValue( 'type' ), $this->typeOnUser ) ) { 104 # ok we have a type of log which expect a user title. 105 $target = Title::newFromText( $opts->getValue( 'page' ) ); 106 if ( $target && $target->getNamespace() === NS_MAIN ) { 107 # User forgot to add 'User:', we are adding it for him 108 $opts->setValue( 'page', 109 Title::makeTitleSafe( NS_USER, $opts->getValue( 'page' ) ) 110 ); 111 } 112 } 113 114 $this->show( $opts, $qc ); 115 } 116 117 /** 118 * Return an array of subpages beginning with $search that this special page will accept. 119 * 120 * @param string $search Prefix to search for 121 * @param int $limit Maximum number of results to return 122 * @return string[] Matching subpages 123 */ 124 public function prefixSearchSubpages( $search, $limit = 10 ) { 125 $subpages = $this->getConfig()->get( 'LogTypes' ); 126 $subpages[] = 'all'; 127 sort( $subpages ); 128 return self::prefixSearchArray( $search, $limit, $subpages ); 129 } 130 131 private function parseParams( FormOptions $opts, $par ) { 132 # Get parameters 133 $parms = explode( '/', ( $par = ( $par !== null ) ? $par : '' ) ); 134 $symsForAll = array( '*', 'all' ); 135 if ( $parms[0] != '' && 136 ( in_array( $par, $this->getConfig()->get( 'LogTypes' ) ) || in_array( $par, $symsForAll ) ) 137 ) { 138 $opts->setValue( 'type', $par ); 139 } elseif ( count( $parms ) == 2 ) { 140 $opts->setValue( 'type', $parms[0] ); 141 $opts->setValue( 'user', $parms[1] ); 142 } elseif ( $par != '' ) { 143 $opts->setValue( 'user', $par ); 144 } 145 } 146 147 private function show( FormOptions $opts, array $extraConds ) { 148 # Create a LogPager item to get the results and a LogEventsList item to format them... 149 $loglist = new LogEventsList( 150 $this->getContext(), 151 null, 152 LogEventsList::USE_REVDEL_CHECKBOXES 153 ); 154 $pager = new LogPager( 155 $loglist, 156 $opts->getValue( 'type' ), 157 $opts->getValue( 'user' ), 158 $opts->getValue( 'page' ), 159 $opts->getValue( 'pattern' ), 160 $extraConds, 161 $opts->getValue( 'year' ), 162 $opts->getValue( 'month' ), 163 $opts->getValue( 'tagfilter' ) 164 ); 165 166 $this->addHeader( $opts->getValue( 'type' ) ); 167 168 # Set relevant user 169 if ( $pager->getPerformer() ) { 170 $this->getSkin()->setRelevantUser( User::newFromName( $pager->getPerformer() ) ); 171 } 172 173 # Show form options 174 $loglist->showOptions( 175 $pager->getType(), 176 $opts->getValue( 'user' ), 177 $pager->getPage(), 178 $pager->getPattern(), 179 $pager->getYear(), 180 $pager->getMonth(), 181 $pager->getFilterParams(), 182 $opts->getValue( 'tagfilter' ) 183 ); 184 185 # Insert list 186 $logBody = $pager->getBody(); 187 if ( $logBody ) { 188 $this->getOutput()->addHTML( 189 $pager->getNavigationBar() . 190 $this->getRevisionButton( 191 $loglist->beginLogEventsList() . 192 $logBody . 193 $loglist->endLogEventsList() 194 ) . 195 $pager->getNavigationBar() 196 ); 197 } else { 198 $this->getOutput()->addWikiMsg( 'logempty' ); 199 } 200 } 201 202 private function getRevisionButton( $formcontents ) { 203 # If the user doesn't have the ability to delete log entries, 204 # don't bother showing them the button. 205 if ( !$this->getUser()->isAllowedAll( 'deletedhistory', 'deletelogentry' ) ) { 206 return $formcontents; 207 } 208 209 # Show button to hide log entries 210 $s = Html::openElement( 211 'form', 212 array( 'action' => wfScript(), 'id' => 'mw-log-deleterevision-submit' ) 213 ) . "\n"; 214 $s .= Html::hidden( 'title', SpecialPage::getTitleFor( 'Revisiondelete' ) ) . "\n"; 215 $s .= Html::hidden( 'target', SpecialPage::getTitleFor( 'Log' ) ) . "\n"; 216 $s .= Html::hidden( 'type', 'logging' ) . "\n"; 217 $button = Html::element( 218 'button', 219 array( 220 'type' => 'submit', 221 'class' => "deleterevision-log-submit mw-log-deleterevision-button" 222 ), 223 $this->msg( 'showhideselectedlogentries' )->text() 224 ) . "\n"; 225 $s .= $button . $formcontents . $button; 226 $s .= Html::closeElement( 'form' ); 227 228 return $s; 229 } 230 231 /** 232 * Set page title and show header for this log type 233 * @param string $type 234 * @since 1.19 235 */ 236 protected function addHeader( $type ) { 237 $page = new LogPage( $type ); 238 $this->getOutput()->setPageTitle( $page->getName()->text() ); 239 $this->getOutput()->addHTML( $page->getDescription()->parseAsBlock() ); 240 } 241 242 protected function getGroupName() { 243 return 'changes'; 244 } 245 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 14:03:12 2014 | Cross-referenced by PHPXref 0.7.1 |