X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FSpecialLog.php;h=0ed417ce424590658749ac913262f4d478aa1eaa;hb=b36b2f53400bff2609a2ae3619e7ac3ab43f7b11;hp=8d26aabdc9a815436625997ad660f4ea78b47e28;hpb=ba2afcd9fa9b1f3f6a865da054068466164fd2fa;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/SpecialLog.php b/includes/SpecialLog.php index 8d26aabdc9..0ed417ce42 100644 --- a/includes/SpecialLog.php +++ b/includes/SpecialLog.php @@ -1,26 +1,25 @@ # http://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 -# the Free Software Foundation; either version 2 of the License, or +# the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., -# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # http://www.gnu.org/copyleft/gpl.html /** * - * @package MediaWiki - * @subpackage SpecialPage + * @addtogroup SpecialPage */ /** @@ -28,43 +27,62 @@ */ function wfSpecialLog( $par = '' ) { global $wgRequest; - $logReader =& new LogReader( $wgRequest ); - if( '' == $wgRequest->getVal( 'type' ) && !empty( $par ) ) { + $logReader = new LogReader( $wgRequest ); + if( $wgRequest->getVal( 'type' ) == '' && $par != '' ) { $logReader->limitType( $par ); } - $logViewer =& new LogViewer( $logReader ); + $logViewer = new LogViewer( $logReader ); $logViewer->show(); } /** * - * @package MediaWiki - * @subpackage SpecialPage + * @addtogroup SpecialPage */ class LogReader { var $db, $joinClauses, $whereClauses; - var $type = '', $user = '', $title = null; - + var $type = '', $user = '', $title = null, $pattern = false; + + /** + * @param WebRequest $request For internal use use a FauxRequest object to pass arbitrary parameters. + */ function LogReader( $request ) { - $this->db =& wfGetDB( DB_SLAVE ); + $this->db = wfGetDB( DB_SLAVE ); $this->setupQuery( $request ); } - + + /** + * Basic setup and applies the limiting factors from the WebRequest object. + * @param WebRequest $request + * @private + */ function setupQuery( $request ) { - $cur = $this->db->tableName( 'cur' ); + $page = $this->db->tableName( 'page' ); $user = $this->db->tableName( 'user' ); - $this->joinClauses = array( "LEFT OUTER JOIN $cur ON log_namespace=cur_namespace AND log_title=cur_title" ); - $this->whereClauses = array( 'user_id=log_user' ); - + $this->joinClauses = array( + "LEFT OUTER JOIN $page ON log_namespace=page_namespace AND log_title=page_title", + "INNER JOIN $user ON user_id=log_user" ); + $this->whereClauses = array(); + $this->limitType( $request->getVal( 'type' ) ); $this->limitUser( $request->getText( 'user' ) ); - $this->limitTitle( $request->getText( 'page' ) ); + $this->limitTitle( $request->getText( 'page' ) , $request->getBool( 'pattern' ) ); $this->limitTime( $request->getVal( 'from' ), '>=' ); $this->limitTime( $request->getVal( 'until' ), '<=' ); - + list( $this->limit, $this->offset ) = $request->getLimitOffset(); + + // XXX This all needs to use Pager, ugly hack for now. + global $wgMiserMode; + if( $wgMiserMode ) + $this->offset = min( $this->offset, 10000 ); } - + + /** + * Set the log reader to return only entries of the given type. + * @param string $type A log type ('upload', 'delete', etc) + * @private + */ function limitType( $type ) { if( empty( $type ) ) { return false; @@ -73,29 +91,61 @@ class LogReader { $safetype = $this->db->strencode( $type ); $this->whereClauses[] = "log_type='$safetype'"; } - + + /** + * Set the log reader to return only entries by the given user. + * @param string $name (In)valid user name + * @private + */ function limitUser( $name ) { - $title = Title::makeTitleSafe( NS_USER, $name ); - if( empty( $name ) || is_null( $title ) ) { + if ( $name == '' ) return false; - } - $this->user = str_replace( '_', ' ', $title->getDBkey() ); - $safename = $this->db->strencode( $this->user ); - $user = $this->db->tableName( 'user' ); - $this->whereClauses[] = "user_name='$safename'"; + $usertitle = Title::makeTitleSafe( NS_USER, $name ); + if ( is_null( $usertitle ) ) + return false; + $this->user = $usertitle->getText(); + + /* Fetch userid at first, if known, provides awesome query plan afterwards */ + $userid = $this->db->selectField('user','user_id',array('user_name'=>$this->user)); + if (!$userid) + /* It should be nicer to abort query at all, + but for now it won't pass anywhere behind the optimizer */ + $this->whereClauses[] = "NULL"; + else + $this->whereClauses[] = "log_user=$userid"; } - - function limitTitle( $page ) { + + /** + * 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 Title name as text + * @private + */ + function limitTitle( $page , $pattern ) { + global $wgMiserMode; $title = Title::newFromText( $page ); - if( empty( $page ) || is_null( $title ) ) { + + if( strlen( $page ) == 0 || !$title instanceof Title ) return false; - } + $this->title =& $title; - $safetitle = $this->db->strencode( $title->getDBkey() ); + $this->pattern = $pattern; $ns = $title->getNamespace(); - $this->whereClauses[] = "log_namespace=$ns AND log_title='$safetitle'"; + if ( $pattern && !$wgMiserMode ) { + $safetitle = $this->db->escapeLike( $title->getDBkey() ); // use escapeLike to avoid expensive search patterns like 't%st%' + $this->whereClauses[] = "log_namespace=$ns AND log_title LIKE '$safetitle%'"; + } else { + $safetitle = $this->db->strencode( $title->getDBkey() ); + $this->whereClauses[] = "log_namespace=$ns AND log_title = '$safetitle'"; + } } - + + /** + * Set the log reader to return only entries in a given time range. + * @param string $time Timestamp of one endpoint + * @param string $direction either ">=" or "<=" operators + * @private + */ function limitTime( $time, $direction ) { # Direction should be a comparison operator if( empty( $time ) ) { @@ -104,37 +154,62 @@ class LogReader { $safetime = $this->db->strencode( wfTimestamp( TS_MW, $time ) ); $this->whereClauses[] = "log_timestamp $direction '$safetime'"; } - + + /** + * Build an SQL query from all the set parameters. + * @return string the SQL query + * @private + */ function getQuery() { $logging = $this->db->tableName( "logging" ); - $user = $this->db->tableName( 'user' ); - $sql = "SELECT log_type, log_action, log_timestamp, + $sql = "SELECT /*! STRAIGHT_JOIN */ log_type, log_action, log_timestamp, log_user, user_name, - log_namespace, log_title, cur_id, - log_comment FROM $logging, $user "; + log_namespace, log_title, page_id, + log_comment, log_params FROM $logging "; if( !empty( $this->joinClauses ) ) { - $sql .= implode( ',', $this->joinClauses ); + $sql .= implode( ' ', $this->joinClauses ); } if( !empty( $this->whereClauses ) ) { $sql .= " WHERE " . implode( ' AND ', $this->whereClauses ); } $sql .= " ORDER BY log_timestamp DESC "; - $sql .= $this->db->limitResult( $this->limit, $this->offset ); + $sql = $this->db->limitResult($sql, $this->limit, $this->offset ); return $sql; } - + + /** + * Execute the query and start returning results. + * @return ResultWrapper result object to return the relevant rows + */ function getRows() { - return $this->db->resultObject( $this->db->query( $this->getQuery() ) ); + $res = $this->db->query( $this->getQuery(), 'LogReader::getRows' ); + return $this->db->resultObject( $res ); } - + + /** + * @return string The query type that this LogReader has been limited to. + */ function queryType() { return $this->type; } - + + /** + * @return string The username type that this LogReader has been limited to, if any. + */ function queryUser() { return $this->user; } - + + /** + * @return boolean The checkbox, if titles should be searched by a pattern too + */ + function queryPattern() { + return $this->pattern; + } + + /** + * @return string The text of the title that this LogReader has been limited to. + */ function queryTitle() { if( is_null( $this->title ) ) { return ''; @@ -142,70 +217,198 @@ class LogReader { return $this->title->getPrefixedText(); } } + + /** + * Is there at least one row? + * + * @return bool + */ + public function hasRows() { + # Little hack... + $limit = $this->limit; + $this->limit = 1; + $res = $this->db->query( $this->getQuery() ); + $this->limit = $limit; + $ret = $this->db->numRows( $res ) > 0; + $this->db->freeResult( $res ); + return $ret; + } + } /** * - * @package MediaWiki - * @subpackage SpecialPage + * @addtogroup SpecialPage */ class LogViewer { - var $reader, $skin; - + /** + * @var LogReader $reader + */ + var $reader; + var $numResults = 0; + + /** + * @param LogReader &$reader where to get our data from + */ function LogViewer( &$reader ) { global $wgUser; - $this->skin =& $wgUser->getSkin(); + $this->skin = $wgUser->getSkin(); $this->reader =& $reader; } - + + /** + * Take over the whole output page in $wgOut with the log display. + */ function show() { global $wgOut; $this->showHeader( $wgOut ); $this->showOptions( $wgOut ); - $this->showPrevNext( $wgOut ); - $this->showList( $wgOut ); - $this->showPrevNext( $wgOut ); + $result = $this->getLogRows(); + if ( $this->numResults > 0 ) { + $this->showPrevNext( $wgOut ); + $this->doShowList( $wgOut, $result ); + $this->showPrevNext( $wgOut ); + } else { + $this->showError( $wgOut ); + } } - - function showList( &$out ) { - $html = ""; + + /** + * Load the data from the linked LogReader + * Preload the link cache + * Initialise numResults + * + * Must be called before calling showPrevNext + * + * @return object database result set + */ + function getLogRows() { $result = $this->reader->getRows(); + $this->numResults = 0; + + // Fetch results and form a batch link existence query + $batch = new LinkBatch; + while ( $s = $result->fetchObject() ) { + // User link + $batch->addObj( Title::makeTitleSafe( NS_USER, $s->user_name ) ); + $batch->addObj( Title::makeTitleSafe( NS_USER_TALK, $s->user_name ) ); + + // Move destination link + if ( $s->log_type == 'move' ) { + $paramArray = LogPage::extractParams( $s->log_params ); + $title = Title::newFromText( $paramArray[0] ); + $batch->addObj( $title ); + } + ++$this->numResults; + } + $batch->execute(); + + return $result; + } + + + /** + * Output just the list of entries given by the linked LogReader, + * with extraneous UI elements. Use for displaying log fragments in + * another page (eg at Special:Undelete) + * @param OutputPage $out where to send output + */ + function showList( &$out ) { + $result = $this->getLogRows(); + if ( $this->numResults > 0 ) { + $this->doShowList( $out, $result ); + } else { + $this->showError( $out ); + } + } + + function doShowList( &$out, $result ) { + // Rewind result pointer and go through it again, making the HTML + $html = "\n\n"; $out->addHTML( $html ); + $result->free(); } - - # wfMsg( unprotectedarticle, $text ) - # wfMsg( 'protectedarticle', $text ) - # wfMsg( 'deletedarticle', $text ) - # wfMsg( 'uploadedimage', $text ) - # wfMsg( "blocklogentry", $this->BlockAddress, $this->BlockExpiry ); - # wfMsg( "bureaucratlogentry", $this->mUser, implode( " ", $rightsNotation ) ); - # wfMsg( "undeletedarticle", $this->mTarget ), + + function showError( &$out ) { + $out->addWikiText( wfMsg( 'logempty' ) ); + } + + /** + * @param Object $s a single row from the result set + * @return string Formatted HTML list item + * @private + */ function logLine( $s ) { - global $wgLang; + global $wgLang, $wgUser;; + $skin = $wgUser->getSkin(); $title = Title::makeTitle( $s->log_namespace, $s->log_title ); - $user = Title::makeTitleSafe( NS_USER, $s->user_name ); - $time = $wgLang->timeanddate( $s->log_timestamp ); - if( $s->cur_id ) { - $titleLink = $this->skin->makeKnownLinkObj( $title ); + $time = $wgLang->timeanddate( wfTimestamp(TS_MW, $s->log_timestamp), true ); + + // Enter the existence or non-existence of this page into the link cache, + // for faster makeLinkObj() in LogPage::actionText() + $linkCache =& LinkCache::singleton(); + if( $s->page_id ) { + $linkCache->addGoodLinkObj( $s->page_id, $title ); } else { - $titleLink = $this->skin->makeBrokenLinkObj( $title ); + $linkCache->addBadLinkObj( $title ); } - $userLink = $this->skin->makeLinkObj( $user, htmlspecialchars( $s->user_name ) ); - if( '' === $s->log_comment ) { + + $userLink = $this->skin->userLink( $s->log_user, $s->user_name ) . $this->skin->userToolLinksRedContribs( $s->log_user, $s->user_name ); + $comment = $this->skin->commentBlock( $s->log_comment ); + $paramArray = LogPage::extractParams( $s->log_params ); + $revert = ''; + // show revertmove link + if ( $s->log_type == 'move' && isset( $paramArray[0] ) ) { + $destTitle = Title::newFromText( $paramArray[0] ); + if ( $destTitle ) { + $revert = '(' . $this->skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Movepage' ), + wfMsg( 'revertmove' ), + 'wpOldTitle=' . urlencode( $destTitle->getPrefixedDBkey() ) . + '&wpNewTitle=' . urlencode( $title->getPrefixedDBkey() ) . + '&wpReason=' . urlencode( wfMsgForContent( 'revertmove' ) ) . + '&wpMovetalk=0' ) . ')'; + } + // show undelete link + } elseif ( $s->log_action == 'delete' && $wgUser->isAllowed( 'delete' ) ) { + $revert = '(' . $this->skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Undelete' ), + wfMsg( 'undeletebtn' ) , + 'target='. urlencode( $title->getPrefixedDBkey() ) ) . ')'; + + // show unblock link + } elseif ( $s->log_action == 'block' && $wgUser->isAllowed( 'block' ) ) { + $revert = '(' . $skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Ipblocklist' ), + wfMsg( 'unblocklink' ), + 'action=unblock&ip=' . urlencode( $s->log_title ) ) . ')'; + // show change protection link + } elseif ( ( $s->log_action == 'protect' || $s->log_action == 'modify' ) && $wgUser->isAllowed( 'protect' ) ) { + $revert = '(' . $skin->makeKnownLinkObj( $title, wfMsg( 'protect_change' ), 'action=unprotect' ) . ')'; + // show user tool links for self created users + // TODO: The extension should be handling this, get it out of core! + } elseif ( $s->log_action == 'create2' ) { + if( isset( $paramArray[0] ) ) { + $revert = $this->skin->userToolLinks( $paramArray[0], $s->log_title, true ); + } else { + # Fall back to a blue contributions link + $revert = $this->skin->userToolLinks( 1, $s->log_title ); + } + # Suppress $comment from old entries, not needed and can contain incorrect links $comment = ''; - } else { - $comment = '(' . $this->skin->formatComment( $s->log_comment ) . ')'; } - - $action = LogPage::actionText( $s->log_type, $s->log_action, $titleLink ); - $out = "
  • $time $userLink $action $comment
  • \n"; + + $action = LogPage::actionText( $s->log_type, $s->log_action, $title, $this->skin, $paramArray, true, true ); + $out = "
  • $time $userLink $action $comment $revert
  • \n"; return $out; } - + + /** + * @param OutputPage &$out where to send output + * @private + */ function showHeader( &$out ) { $type = $this->reader->queryType(); if( LogPage::isLogType( $type ) ) { @@ -213,60 +416,107 @@ class LogViewer { $out->addWikiText( LogPage::logHeader( $type ) ); } } - + + /** + * @param OutputPage &$out where to send output + * @private + */ function showOptions( &$out ) { - global $wgScript; + global $wgScript, $wgMiserMode; $action = htmlspecialchars( $wgScript ); - $title = Title::makeTitle( NS_SPECIAL, 'Log' ); + $title = SpecialPage::getTitleFor( 'Log' ); $special = htmlspecialchars( $title->getPrefixedDBkey() ); $out->addHTML( "
    \n" . - "\n" . - $this->getTypeMenu() . - $this->getUserInput() . - $this->getTitleInput() . - "" . - "
    " ); + '
    ' . + Xml::element( 'legend', array(), wfMsg( 'log' ) ) . + Xml::hidden( 'title', $special ) . "\n" . + $this->getTypeMenu() . "\n" . + $this->getUserInput() . "\n" . + $this->getTitleInput() . "\n" . + (!$wgMiserMode?($this->getTitlePattern()."\n"):"") . + Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" . + "
    " ); } - + + /** + * @return string Formatted HTML + * @private + */ function getTypeMenu() { $out = "\n"; + + $out .= ''; return $out; } - + + /** + * @return string Formatted HTML + * @private + */ function getUserInput() { - $user = htmlspecialchars( $this->reader->queryUser() ); - return "User: \n"; + $user = $this->reader->queryUser(); + return Xml::inputLabel( wfMsg( 'specialloguserlabel' ), 'user', 'user', 12, $user ); } - + + /** + * @return string Formatted HTML + * @private + */ function getTitleInput() { - $title = htmlspecialchars( $this->reader->queryTitle() ); - return "Title: \n"; + $title = $this->reader->queryTitle(); + return Xml::inputLabel( wfMsg( 'speciallogtitlelabel' ), 'page', 'page', 20, $title ); } - + + /** + * @return boolean Checkbox + * @private + */ + function getTitlePattern() { + $pattern = $this->reader->queryPattern(); + return Xml::checkLabel( wfMsg( 'log-title-wildcard' ), 'pattern', 'pattern', $pattern ); + } + + /** + * @param OutputPage &$out where to send output + * @private + */ function showPrevNext( &$out ) { - global $wgLang; + global $wgContLang,$wgRequest; $pieces = array(); - $pieces[] = 'type=' . htmlspecialchars( $this->reader->queryType() ); - $pieces[] = 'user=' . htmlspecialchars( $this->reader->queryUser() ); - $pieces[] = 'page=' . htmlspecialchars( $this->reader->queryTitle() ); + $pieces[] = 'type=' . urlencode( $this->reader->queryType() ); + $pieces[] = 'user=' . urlencode( $this->reader->queryUser() ); + $pieces[] = 'page=' . urlencode( $this->reader->queryTitle() ); + $pieces[] = 'pattern=' . urlencode( $this->reader->queryPattern() ); $bits = implode( '&', $pieces ); - $offset = 0; $limit = 50; - + list( $limit, $offset ) = $wgRequest->getLimitOffset(); + # TODO: use timestamps instead of offsets to make it more natural # to go huge distances in time $html = wfViewPrevNext( $offset, $limit, - $wgLang->specialpage( 'Log' ), + $wgContLang->specialpage( 'Log' ), $bits, - false); + $this->numResults < $limit); $out->addHTML( '

    ' . $html . '

    ' ); } } -?> +