MediaWiki  1.23.2
SpecialLog.php
Go to the documentation of this file.
1 <?php
31 class SpecialLog extends SpecialPage {
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  global $wgLogRestrictions;
49 
50  $this->setHeaders();
51  $this->outputHeader();
52 
53  $opts = new FormOptions;
54  $opts->add( 'type', '' );
55  $opts->add( 'user', '' );
56  $opts->add( 'page', '' );
57  $opts->add( 'pattern', false );
58  $opts->add( 'year', null, FormOptions::INTNULL );
59  $opts->add( 'month', null, FormOptions::INTNULL );
60  $opts->add( 'tagfilter', '' );
61  $opts->add( 'offset', '' );
62  $opts->add( 'dir', '' );
63  $opts->add( 'offender', '' );
64 
65  // Set values
66  $opts->fetchValuesFromRequest( $this->getRequest() );
67  if ( $par !== null ) {
68  $this->parseParams( $opts, (string)$par );
69  }
70 
71  # Don't let the user get stuck with a certain date
72  if ( $opts->getValue( 'offset' ) || $opts->getValue( 'dir' ) == 'prev' ) {
73  $opts->setValue( 'year', '' );
74  $opts->setValue( 'month', '' );
75  }
76 
77  // If the user doesn't have the right permission to view the specific
78  // log type, throw a PermissionsError
79  // If the log type is invalid, just show all public logs
80  $type = $opts->getValue( 'type' );
81  if ( !LogPage::isLogType( $type ) ) {
82  $opts->setValue( 'type', '' );
83  } elseif ( isset( $wgLogRestrictions[$type] ) && !$this->getUser()->isAllowed( $wgLogRestrictions[$type] ) ) {
84  throw new PermissionsError( $wgLogRestrictions[$type] );
85  }
86 
87  # Handle type-specific inputs
88  $qc = array();
89  if ( $opts->getValue( 'type' ) == 'suppress' ) {
90  $offender = User::newFromName( $opts->getValue( 'offender' ), false );
91  if ( $offender && $offender->getId() > 0 ) {
92  $qc = array( 'ls_field' => 'target_author_id', 'ls_value' => $offender->getId() );
93  } elseif ( $offender && IP::isIPAddress( $offender->getName() ) ) {
94  $qc = array( 'ls_field' => 'target_author_ip', 'ls_value' => $offender->getName() );
95  }
96  }
97 
98  # Some log types are only for a 'User:' title but we might have been given
99  # only the username instead of the full title 'User:username'. This part try
100  # to lookup for a user by that name and eventually fix user input. See bug 1697.
101  wfRunHooks( 'GetLogTypesOnUser', array( &$this->typeOnUser ) );
102  if ( in_array( $opts->getValue( 'type' ), $this->typeOnUser ) ) {
103  # ok we have a type of log which expect a user title.
104  $target = Title::newFromText( $opts->getValue( 'page' ) );
105  if ( $target && $target->getNamespace() === NS_MAIN ) {
106  # User forgot to add 'User:', we are adding it for him
107  $opts->setValue( 'page',
108  Title::makeTitleSafe( NS_USER, $opts->getValue( 'page' ) )
109  );
110  }
111  }
112 
113  $this->show( $opts, $qc );
114  }
115 
116  private function parseParams( FormOptions $opts, $par ) {
117  global $wgLogTypes;
118 
119  # Get parameters
120  $parms = explode( '/', ( $par = ( $par !== null ) ? $par : '' ) );
121  $symsForAll = array( '*', 'all' );
122  if ( $parms[0] != '' &&
123  ( in_array( $par, $wgLogTypes ) || in_array( $par, $symsForAll ) )
124  ) {
125  $opts->setValue( 'type', $par );
126  } elseif ( count( $parms ) == 2 ) {
127  $opts->setValue( 'type', $parms[0] );
128  $opts->setValue( 'user', $parms[1] );
129  } elseif ( $par != '' ) {
130  $opts->setValue( 'user', $par );
131  }
132  }
133 
134  private function show( FormOptions $opts, array $extraConds ) {
135  # Create a LogPager item to get the results and a LogEventsList item to format them...
136  $loglist = new LogEventsList(
137  $this->getContext(),
138  null,
140  );
141  $pager = new LogPager(
142  $loglist,
143  $opts->getValue( 'type' ),
144  $opts->getValue( 'user' ),
145  $opts->getValue( 'page' ),
146  $opts->getValue( 'pattern' ),
147  $extraConds,
148  $opts->getValue( 'year' ),
149  $opts->getValue( 'month' ),
150  $opts->getValue( 'tagfilter' )
151  );
152 
153  $this->addHeader( $opts->getValue( 'type' ) );
154 
155  # Set relevant user
156  if ( $pager->getPerformer() ) {
157  $this->getSkin()->setRelevantUser( User::newFromName( $pager->getPerformer() ) );
158  }
159 
160  # Show form options
161  $loglist->showOptions(
162  $pager->getType(),
163  $opts->getValue( 'user' ),
164  $pager->getPage(),
165  $pager->getPattern(),
166  $pager->getYear(),
167  $pager->getMonth(),
168  $pager->getFilterParams(),
169  $opts->getValue( 'tagfilter' )
170  );
171 
172  # Insert list
173  $logBody = $pager->getBody();
174  if ( $logBody ) {
175  $this->getOutput()->addHTML(
176  $pager->getNavigationBar() .
177  $this->getRevisionButton(
178  $loglist->beginLogEventsList() .
179  $logBody .
180  $loglist->endLogEventsList()
181  ) .
182  $pager->getNavigationBar()
183  );
184  } else {
185  $this->getOutput()->addWikiMsg( 'logempty' );
186  }
187  }
188 
189  private function getRevisionButton( $formcontents ) {
190  # If the user doesn't have the ability to delete log entries,
191  # don't bother showing them the button.
192  if ( !$this->getUser()->isAllowedAll( 'deletedhistory', 'deletelogentry' ) ) {
193  return $formcontents;
194  }
195 
196  # Show button to hide log entries
197  global $wgScript;
199  'form',
200  array( 'action' => $wgScript, 'id' => 'mw-log-deleterevision-submit' )
201  ) . "\n";
202  $s .= Html::hidden( 'title', SpecialPage::getTitleFor( 'Revisiondelete' ) ) . "\n";
203  $s .= Html::hidden( 'target', SpecialPage::getTitleFor( 'Log' ) ) . "\n";
204  $s .= Html::hidden( 'type', 'logging' ) . "\n";
205  $button = Html::element(
206  'button',
207  array(
208  'type' => 'submit',
209  'class' => "deleterevision-log-submit mw-log-deleterevision-button"
210  ),
211  $this->msg( 'showhideselectedlogentries' )->text()
212  ) . "\n";
213  $s .= $button . $formcontents . $button;
214  $s .= Html::closeElement( 'form' );
215 
216  return $s;
217  }
218 
224  protected function addHeader( $type ) {
225  $page = new LogPage( $type );
226  $this->getOutput()->setPageTitle( $page->getName()->text() );
227  $this->getOutput()->addHTML( $page->getDescription()->parseAsBlock() );
228  }
229 
230  protected function getGroupName() {
231  return 'changes';
232  }
233 }
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:189
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
SpecialLog\parseParams
parseParams(FormOptions $opts, $par)
Definition: SpecialLog.php:116
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:535
FormOptions\getValue
getValue( $name)
Get the value for the given option name.
Definition: FormOptions.php:175
text
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition: design.txt:12
FormOptions\INTNULL
const INTNULL
Integer type or null, maps to WebRequest::getIntOrNull() This is useful for the namespace selector.
Definition: FormOptions.php:54
LogPager
Definition: LogPager.php:29
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:388
$s
$s
Definition: mergeMessageFileList.php:156
SpecialPage\getTitleFor
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name.
Definition: SpecialPage.php:74
SpecialPage\getSkin
getSkin()
Shortcut to get the skin being used for this instance.
Definition: SpecialPage.php:555
Html\hidden
static hidden( $name, $value, $attribs=array())
Convenience function to produce an input element with type=hidden.
Definition: Html.php:662
PermissionsError
Show an error when a user tries to do something they do not have the necessary permissions for.
Definition: PermissionsError.php:28
NS_MAIN
const NS_MAIN
Definition: Defines.php:79
FormOptions\add
add( $name, $default, $type=self::AUTO)
Add an option to be handled by this FormOptions instance.
Definition: FormOptions.php:78
Html\closeElement
static closeElement( $element)
Returns "</$element>", except if $wgWellFormedXml is off, in which case it returns the empty string w...
Definition: Html.php:235
Html\openElement
static openElement( $element, $attribs=array())
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
Definition: Html.php:166
SpecialLog\getRevisionButton
getRevisionButton( $formcontents)
Definition: SpecialLog.php:189
Html\element
static element( $element, $attribs=array(), $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:148
LogPage\isLogType
static isLogType( $type)
Is $type a valid log type.
Definition: LogPage.php:199
LogPage
Class to simplify the use of log pages.
Definition: LogPage.php:32
SpecialLog\__construct
__construct()
Definition: SpecialLog.php:43
wfRunHooks
wfRunHooks( $event, array $args=array(), $deprecatedVersion=null)
Call hook functions defined in $wgHooks.
Definition: GlobalFunctions.php:4001
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:352
SpecialPage\getUser
getUser()
Shortcut to get the User executing this instance.
Definition: SpecialPage.php:545
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
LogEventsList
Definition: LogEventsList.php:26
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:188
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:508
FormOptions\setValue
setValue( $name, $value, $force=false)
Use to set the value of an option.
Definition: FormOptions.php:158
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:422
SpecialPage\msg
msg()
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:609
SpecialPage
Parent class for all special pages.
Definition: SpecialPage.php:33
SpecialLog\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialLog.php:230
SpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: SpecialPage.php:525
LogEventsList\USE_REVDEL_CHECKBOXES
const USE_REVDEL_CHECKBOXES
Definition: LogEventsList.php:29
SpecialLog\show
show(FormOptions $opts, array $extraConds)
Definition: SpecialLog.php:134
SpecialLog
A special page that lists log entries.
Definition: SpecialLog.php:31
SpecialLog\$typeOnUser
$typeOnUser
List log type for which the target is a user Thus if the given target is in NS_MAIN we can alter it t...
Definition: SpecialLog.php:37
NS_USER
const NS_USER
Definition: Defines.php:81
FormOptions
Helper class to keep track of options when mixing links and form elements.
Definition: FormOptions.php:35
SpecialLog\execute
execute( $par)
Default execute method Checks user permissions, calls the function given in mFunction.
Definition: SpecialLog.php:47
SpecialPage\outputHeader
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
Definition: SpecialPage.php:443
IP\isIPAddress
static isIPAddress( $ip)
Determine if a string is as valid IP address or network (CIDR prefix).
Definition: IP.php:74
SpecialLog\addHeader
addHeader( $type)
Set page title and show header for this log type.
Definition: SpecialLog.php:224
$type
$type
Definition: testCompression.php:46