diff options
Diffstat (limited to 'includes/logging/LogPager.php')
-rw-r--r-- | includes/logging/LogPager.php | 112 |
1 files changed, 75 insertions, 37 deletions
diff --git a/includes/logging/LogPager.php b/includes/logging/LogPager.php index 09ae3b8c..256934e4 100644 --- a/includes/logging/LogPager.php +++ b/includes/logging/LogPager.php @@ -3,7 +3,7 @@ * Contain classes to list log entries * * Copyright © 2004 Brion Vibber <brion@pobox.com>, 2008 Aaron Schulz - * http://www.mediawiki.org/ + * https://www.mediawiki.org/ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,22 +27,36 @@ * @ingroup Pager */ class LogPager extends ReverseChronologicalPager { - private $types = array(), $performer = '', $title = '', $pattern = ''; + /** @var array Log types */ + private $types = array(); + + /** @var string Events limited to those by performer when set */ + private $performer = ''; + + /** @var string|Title Events limited to those about Title when set */ + private $title = ''; + + /** @var string */ + private $pattern = ''; + + /** @var string */ private $typeCGI = ''; + + /** @var LogEventsList */ public $mLogEventsList; /** * Constructor * * @param LogEventsList $list - * @param string $types or Array: log types to show - * @param string $performer the user who made the log entries - * @param string|Title $title the page title the log entries are for - * @param string $pattern do a prefix search rather than an exact title match - * @param array $conds extra conditions for the query - * @param int $year The year to start from - * @param int $month The month to start from - * @param string $tagFilter tag + * @param string|array $types Log types to show + * @param string $performer The user who made the log entries + * @param string|Title $title The page title the log entries are for + * @param string $pattern Do a prefix search rather than an exact title match + * @param array $conds Extra conditions for the query + * @param int|bool $year The year to start from. Default: false + * @param int|bool $month The month to start from. Default: false + * @param string $tagFilter Tag */ public function __construct( $list, $types = array(), $performer = '', $title = '', $pattern = '', $conds = array(), $year = false, $month = false, $tagFilter = '' ) { @@ -56,6 +70,8 @@ class LogPager extends ReverseChronologicalPager { $this->limitTitle( $title, $pattern ); $this->getDateCond( $year, $month ); $this->mTagFilter = $tagFilter; + + $this->mDb = wfGetDB( DB_SLAVE, 'logpager' ); } public function getDefaultQuery() { @@ -64,6 +80,7 @@ class LogPager extends ReverseChronologicalPager { $query['user'] = $this->performer; $query['month'] = $this->mMonth; $query['year'] = $this->mYear; + return $query; } @@ -84,6 +101,7 @@ class LogPager extends ReverseChronologicalPager { } } } + return $filters; } @@ -91,7 +109,7 @@ class LogPager extends ReverseChronologicalPager { * Set the log reader to return only entries of the given type. * Type restrictions enforced here * - * @param string $types or array: Log types ('upload', 'delete', etc); + * @param string|array $types Log types ('upload', 'delete', etc); * empty string means no restriction */ private function limitType( $types ) { @@ -136,43 +154,42 @@ class LogPager extends ReverseChronologicalPager { * Set the log reader to return only entries by the given user. * * @param string $name (In)valid user name - * @return bool + * @return void */ private function limitPerformer( $name ) { if ( $name == '' ) { - return false; + return; } $usertitle = Title::makeTitleSafe( NS_USER, $name ); if ( is_null( $usertitle ) ) { - return false; + return; } /* Fetch userid at first, if known, provides awesome query plan afterwards */ $userid = User::idFromName( $name ); if ( !$userid ) { - /* It should be nicer to abort query at all, - but for now it won't pass anywhere behind the optimizer */ - $this->mConds[] = "NULL"; + $this->mConds['log_user_text'] = IP::sanitizeIP( $name ); } else { $this->mConds['log_user'] = $userid; - // Paranoia: avoid brute force searches (bug 17342) - $user = $this->getUser(); - if ( !$user->isAllowed( 'deletedhistory' ) ) { - $this->mConds[] = $this->mDb->bitAnd( 'log_deleted', LogPage::DELETED_USER ) . ' = 0'; - } elseif ( !$user->isAllowed( 'suppressrevision' ) ) { - $this->mConds[] = $this->mDb->bitAnd( 'log_deleted', LogPage::SUPPRESSED_USER ) . - ' != ' . LogPage::SUPPRESSED_USER; - } - $this->performer = $usertitle->getText(); } + // Paranoia: avoid brute force searches (bug 17342) + $user = $this->getUser(); + if ( !$user->isAllowed( 'deletedhistory' ) ) { + $this->mConds[] = $this->mDb->bitAnd( 'log_deleted', LogPage::DELETED_USER ) . ' = 0'; + } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) { + $this->mConds[] = $this->mDb->bitAnd( 'log_deleted', LogPage::SUPPRESSED_USER ) . + ' != ' . LogPage::SUPPRESSED_USER; + } + + $this->performer = $usertitle->getText(); } /** * Set the log reader to return only entries affecting the given page. * (For the block and rights logs, this is a user page.) * - * @param string $page or Title object: Title name - * @param $pattern String - * @return bool + * @param string|Title $page Title name + * @param string $pattern + * @return void */ private function limitTitle( $page, $pattern ) { global $wgMiserMode; @@ -182,7 +199,7 @@ class LogPager extends ReverseChronologicalPager { } else { $title = Title::newFromText( $page ); if ( strlen( $page ) == 0 || !$title instanceof Title ) { - return false; + return; } } @@ -190,6 +207,18 @@ class LogPager extends ReverseChronologicalPager { $ns = $title->getNamespace(); $db = $this->mDb; + $doUserRightsLogLike = false; + if ( $this->types == array( 'rights' ) ) { + global $wgUserrightsInterwikiDelimiter; + $parts = explode( $wgUserrightsInterwikiDelimiter, $title->getDBKey() ); + if ( count( $parts ) == 2 ) { + list( $name, $database ) = array_map( 'trim', $parts ); + if ( strstr( $database, '*' ) ) { // Search for wildcard in database name + $doUserRightsLogLike = true; + } + } + } + # Using the (log_namespace, log_title, log_timestamp) index with a # range scan (LIKE) on the first two parts, instead of simple equality, # makes it unusable for sorting. Sorted retrieval using another index @@ -201,12 +230,19 @@ class LogPager extends ReverseChronologicalPager { # use the page_time index. That should have no more than a few hundred # log entries for even the busiest pages, so it can be safely scanned # in full to satisfy an impossible condition on user or similar. - if ( $pattern && !$wgMiserMode ) { - $this->mConds['log_namespace'] = $ns; - $this->mConds[] = 'log_title ' . $db->buildLike( $title->getDBkey(), $db->anyString() ); + $this->mConds['log_namespace'] = $ns; + if ( $doUserRightsLogLike ) { + $params = array( $name . $wgUserrightsInterwikiDelimiter ); + foreach ( explode( '*', $database ) as $databasepart ) { + $params[] = $databasepart; + $params[] = $db->anyString(); + } + array_pop( $params ); // Get rid of the last % we added. + $this->mConds[] = 'log_title' . $db->buildLike( $params ); + } elseif ( $pattern && !$wgMiserMode ) { + $this->mConds[] = 'log_title' . $db->buildLike( $title->getDBkey(), $db->anyString() ); $this->pattern = $pattern; } else { - $this->mConds['log_namespace'] = $ns; $this->mConds['log_title'] = $title->getDBkey(); } // Paranoia: avoid brute force searches (bug 17342) @@ -242,8 +278,8 @@ class LogPager extends ReverseChronologicalPager { $index['log_search'] = 'ls_field_val'; $index['logging'] = 'PRIMARY'; if ( !$this->hasEqualsClause( 'ls_field' ) - || !$this->hasEqualsClause( 'ls_value' ) ) - { + || !$this->hasEqualsClause( 'ls_value' ) + ) { # Since (ls_field,ls_value,ls_logid) is unique, if the condition is # to match a specific (ls_field,ls_value) tuple, then there will be # no duplicate log rows. Otherwise, we need to remove the duplicates. @@ -266,12 +302,13 @@ class LogPager extends ReverseChronologicalPager { # Add ChangeTags filter query ChangeTags::modifyDisplayQuery( $info['tables'], $info['fields'], $info['conds'], $info['join_conds'], $info['options'], $this->mTagFilter ); + return $info; } /** * Checks if $this->mConds has $field matched to a *single* value - * @param $field + * @param string $field * @return bool */ protected function hasEqualsClause( $field ) { @@ -303,6 +340,7 @@ class LogPager extends ReverseChronologicalPager { $this->mResult->seek( 0 ); } wfProfileOut( __METHOD__ ); + return ''; } |