MediaWiki r32685 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r32684‎ | r32685 (on ViewVC)‎ | r32686 >
Date:05:48, 2 April 2008
Author:aaron
Status:old
Tags:
Comment:
* User Pager for special:log
* Add LogEventList class. LogReader and Viewer added to the file for b/c for now.
* Add $wgLogRestrictions to restrict logs
* Show log items in watchlists
Modified paths:

Diff [purge]

Index: trunk/phase3/includes/SpecialWatchlist.php
@@ -163,7 +163,8 @@
164164 $andLatest='';
165165 $limitWatchlist = 'LIMIT ' . intval( $wgUser->getOption( 'wllimit' ) );
166166 } else {
167 - $andLatest= 'AND rc_this_oldid=page_latest';
 167+ # Top log Ids for a page are not stored
 168+ $andLatest = 'AND (rc_this_oldid=page_latest OR rc_type=' . RC_LOG . ') ';
168169 $limitWatchlist = '';
169170 }
170171
Index: trunk/phase3/includes/LogEventList.php
@@ -0,0 +1,643 @@
 2+<?php
 3+# Copyright (C) 2004 Brion Vibber <brion@pobox.com>, 2008 Aaron Schulz
 4+# http://www.mediawiki.org/
 5+#
 6+# This program is free software; you can redistribute it and/or modify
 7+# it under the terms of the GNU General Public License as published by
 8+# the Free Software Foundation; either version 2 of the License, or
 9+# (at your option) any later version.
 10+#
 11+# This program is distributed in the hope that it will be useful,
 12+# but WITHOUT ANY WARRANTY; without even the implied warranty of
 13+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 14+# GNU General Public License for more details.
 15+#
 16+# You should have received a copy of the GNU General Public License along
 17+# with this program; if not, write to the Free Software Foundation, Inc.,
 18+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 19+# http://www.gnu.org/copyleft/gpl.html
 20+
 21+class LogEventList {
 22+ const NO_ACTION_LINK = 1;
 23+
 24+ function __construct( &$skin, $flags = 0 ) {
 25+ $this->skin =& $skin;
 26+ $this->flags = $flags;
 27+ $this->preCacheMessages();
 28+ }
 29+
 30+ /**
 31+ * As we use the same small set of messages in various methods and that
 32+ * they are called often, we call them once and save them in $this->message
 33+ */
 34+ private function preCacheMessages() {
 35+ // Precache various messages
 36+ if( !isset( $this->message ) ) {
 37+ foreach( explode(' ', 'viewpagelogs revhistory filehist rev-delundel' ) as $msg ) {
 38+ $this->message[$msg] = wfMsgExt( $msg, array( 'escape') );
 39+ }
 40+ }
 41+ }
 42+
 43+ /**
 44+ * Set page title and show header for this log type
 45+ * @param OutputPage $out where to send output
 46+ * @param strin $type
 47+ */
 48+ public function showHeader( $out, $type ) {
 49+ if( LogPage::isLogType( $type ) ) {
 50+ $out->setPageTitle( LogPage::logName( $type ) );
 51+ $out->addWikiText( LogPage::logHeader( $type ) );
 52+ }
 53+ }
 54+
 55+ /**
 56+ * Show options for the log list
 57+ * @param OutputPage $out where to send output
 58+ * @param string $type,
 59+ * @param string $user,
 60+ * @param string $page,
 61+ * @param string $pattern
 62+ */
 63+ public function showOptions( $out, $type, $user, $page, $pattern ) {
 64+ global $wgScript, $wgMiserMode;
 65+ $action = htmlspecialchars( $wgScript );
 66+ $title = SpecialPage::getTitleFor( 'Log' );
 67+ $special = htmlspecialchars( $title->getPrefixedDBkey() );
 68+ $out->addHTML( "<form action=\"$action\" method=\"get\"><fieldset>" .
 69+ Xml::element( 'legend', array(), wfMsg( 'log' ) ) .
 70+ Xml::hidden( 'title', $special ) . "\n" .
 71+ $this->getTypeMenu( $type ) . "\n" .
 72+ $this->getUserInput( $user ) . "\n" .
 73+ $this->getTitleInput( $page ) . "\n" .
 74+ ( !$wgMiserMode ? ($this->getTitlePattern( $pattern )."\n") : "" ) .
 75+ Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
 76+ "</fieldset></form>" );
 77+ }
 78+
 79+ /**
 80+ * @return string Formatted HTML
 81+ */
 82+ private function getTypeMenu( $queryType ) {
 83+ global $wgLogRestrictions, $wgUser;
 84+
 85+ $out = "<select name='type'>\n";
 86+
 87+ $validTypes = LogPage::validTypes();
 88+ $m = array(); // Temporary array
 89+
 90+ // First pass to load the log names
 91+ foreach( $validTypes as $type ) {
 92+ $text = LogPage::logName( $type );
 93+ $m[$text] = $type;
 94+ }
 95+
 96+ // Second pass to sort by name
 97+ ksort($m);
 98+
 99+ // Third pass generates sorted XHTML content
 100+ foreach( $m as $text => $type ) {
 101+ $selected = ($type == $queryType);
 102+ // Restricted types
 103+ if ( isset($wgLogRestrictions[$type]) ) {
 104+ if ( $wgUser->isAllowed( $wgLogRestrictions[$type] ) ) {
 105+ $out .= Xml::option( $text, $type, $selected ) . "\n";
 106+ }
 107+ } else {
 108+ $out .= Xml::option( $text, $type, $selected ) . "\n";
 109+ }
 110+ }
 111+
 112+ $out .= '</select>';
 113+ return $out;
 114+ }
 115+
 116+ /**
 117+ * @return string Formatted HTML
 118+ */
 119+ private function getUserInput( $user ) {
 120+ return Xml::inputLabel( wfMsg( 'specialloguserlabel' ), 'user', 'user', 12, $user );
 121+ }
 122+
 123+ /**
 124+ * @return string Formatted HTML
 125+ */
 126+ private function getTitleInput( $title ) {
 127+ return Xml::inputLabel( wfMsg( 'speciallogtitlelabel' ), 'page', 'page', 20, $title );
 128+ }
 129+
 130+ /**
 131+ * @return boolean Checkbox
 132+ */
 133+ private function getTitlePattern( $pattern ) {
 134+ return Xml::checkLabel( wfMsg( 'log-title-wildcard' ), 'pattern', 'pattern', $pattern );
 135+ }
 136+
 137+ /**
 138+ * @param Row $row a single row from the result set
 139+ * @return string Formatted HTML list item
 140+ * @private
 141+ */
 142+ public function logLine( $row ) {
 143+ global $wgLang, $wgUser, $wgContLang;
 144+ $skin = $wgUser->getSkin();
 145+ $title = Title::makeTitle( $row->log_namespace, $row->log_title );
 146+ $time = $wgLang->timeanddate( wfTimestamp(TS_MW, $row->log_timestamp), true );
 147+ // Enter the existence or non-existence of this page into the link cache,
 148+ // for faster makeLinkObj() in LogPage::actionText()
 149+ $linkCache =& LinkCache::singleton();
 150+ $linkCache->addLinkObj( $title );
 151+ // User links
 152+ if( LogPage::isDeleted($row,LogPage::DELETED_USER) ) {
 153+ $userLink = '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
 154+ } else {
 155+ $userLink = $this->skin->userLink( $row->log_user, $row->user_name ) .
 156+ $this->skin->userToolLinksRedContribs( $row->log_user, $row->user_name );
 157+ }
 158+ // Comment
 159+ if( $row->log_action == 'create2' ) {
 160+ $comment = ''; // Suppress from old account creations, useless and can contain incorrect links
 161+ } else if( LogPage::isDeleted($row,LogPage::DELETED_COMMENT) ) {
 162+ $comment = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-comment') . '</span>';
 163+ } else {
 164+ $comment = $wgContLang->getDirMark() . $this->skin->commentBlock( $row->log_comment );
 165+ }
 166+ // Extract extra parameters
 167+ $paramArray = LogPage::extractParams( $row->log_params );
 168+ $revert = $del = '';
 169+ // Some user can hide log items and have review links
 170+ if( $wgUser->isAllowed( 'deleterevision' ) ) {
 171+ $del = $this->showhideLinks( $row ) . ' ';
 172+ }
 173+ // Add review links and such...
 174+ if( !($this->flags & self::NO_ACTION_LINK) && !($row->log_deleted & LogPage::DELETED_ACTION) ) {
 175+ if( $row->log_type == 'move' && isset( $paramArray[0] ) && $wgUser->isAllowed( 'move' ) ) {
 176+ $destTitle = Title::newFromText( $paramArray[0] );
 177+ if( $destTitle ) {
 178+ $revert = '(' . $this->skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Movepage' ),
 179+ wfMsg( 'revertmove' ),
 180+ 'wpOldTitle=' . urlencode( $destTitle->getPrefixedDBkey() ) .
 181+ '&wpNewTitle=' . urlencode( $title->getPrefixedDBkey() ) .
 182+ '&wpReason=' . urlencode( wfMsgForContent( 'revertmove' ) ) .
 183+ '&wpMovetalk=0' ) . ')';
 184+ }
 185+ // Show undelete link
 186+ } else if( $row->log_action == 'delete' && $wgUser->isAllowed( 'delete' ) ) {
 187+ $revert = '(' . $this->skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Undelete' ),
 188+ wfMsg( 'undeletelink' ) ,
 189+ 'target='. urlencode( $title->getPrefixedDBkey() ) ) . ')';
 190+ // Show unblock link
 191+ } else if( $row->log_action == 'block' && $wgUser->isAllowed( 'block' ) ) {
 192+ $revert = '(' . $this->skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Ipblocklist' ),
 193+ wfMsg( 'unblocklink' ),
 194+ 'action=unblock&ip=' . urlencode( $row->log_title ) ) . ')';
 195+ // Show change protection link
 196+ } else if( ( $row->log_action == 'protect' || $row->log_action == 'modify' ) && $wgUser->isAllowed( 'protect' ) ) {
 197+ $revert = '(' . $this->skin->makeKnownLinkObj( $title, wfMsg( 'protect_change' ), 'action=unprotect' ) . ')';
 198+ // Show unmerge link
 199+ } else if ( $row->log_action == 'merge' ) {
 200+ $merge = SpecialPage::getTitleFor( 'Mergehistory' );
 201+ $revert = '(' . $this->skin->makeKnownLinkObj( $merge, wfMsg('revertmerge'),
 202+ wfArrayToCGI(
 203+ array('target' => $paramArray[0], 'dest' => $title->getPrefixedText(), 'mergepoint' => $paramArray[1] )
 204+ )
 205+ ) . ')';
 206+ // If an edit was hidden from a page give a review link to the history
 207+ } else if( $row->log_action == 'revision' && $wgUser->isAllowed( 'deleterevision' ) ) {
 208+ $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
 209+ // Different revision types use different URL params...
 210+ $subtype = isset($paramArray[2]) ? $paramArray[1] : '';
 211+ // Link to each hidden object ID, $paramArray[1] is the url param. List if several...
 212+ $Ids = explode( ',', $paramArray[2] );
 213+ if( count($Ids) == 1 ) {
 214+ $revert = $this->skin->makeKnownLinkObj( $revdel, wfMsgHtml('revdel-restore'),
 215+ wfArrayToCGI( array('target' => $paramArray[0], $paramArray[1] => $Ids[0] ) ) );
 216+ } else {
 217+ $revert .= wfMsgHtml('revdel-restore').':';
 218+ foreach( $Ids as $n => $id ) {
 219+ $revert .= ' '.$this->skin->makeKnownLinkObj( $revdel, '#'.($n+1),
 220+ wfArrayToCGI( array('target' => $paramArray[0], $paramArray[1] => $id ) ) );
 221+ }
 222+ }
 223+ $revert = "($revert)";
 224+ // Hidden log items, give review link
 225+ } else if( $row->log_action == 'event' && $wgUser->isAllowed( 'deleterevision' ) ) {
 226+ $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
 227+ $revert .= wfMsgHtml('revdel-restore');
 228+ $Ids = explode( ',', $paramArray[0] );
 229+ // Link to each hidden object ID, $paramArray[1] is the url param. List if several...
 230+ if( count($Ids) == 1 ) {
 231+ $revert = $this->skin->makeKnownLinkObj( $revdel, wfMsgHtml('revdel-restore'),
 232+ wfArrayToCGI( array('logid' => $Ids[0] ) ) );
 233+ } else {
 234+ foreach( $Ids as $n => $id ) {
 235+ $revert .= $this->skin->makeKnownLinkObj( $revdel, '#'.($n+1),
 236+ wfArrayToCGI( array('logid' => $id ) ) );
 237+ }
 238+ }
 239+ $revert = "($revert)";
 240+ } else {
 241+ wfRunHooks( 'LogLine', array( $row->log_type, $row->log_action, $title, $paramArray,
 242+ &$comment, &$revert, $row->log_timestamp ) );
 243+ // wfDebug( "Invoked LogLine hook for " $row->log_type . ", " . $row->log_action . "\n" );
 244+ // Do nothing. The implementation is handled by the hook modifiying the passed-by-ref parameters.
 245+ }
 246+ }
 247+ // Event description
 248+ if( $row->log_deleted & LogPage::DELETED_ACTION ) {
 249+ $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
 250+ } else {
 251+ $action = LogPage::actionText( $row->log_type, $row->log_action, $title, $this->skin, $paramArray, true );
 252+ }
 253+
 254+ return "<li>$del$time $userLink $action $comment $revert</li>";
 255+ }
 256+
 257+ /**
 258+ * @param Row $row
 259+ * @private
 260+ */
 261+ private function showhideLinks( $row ) {
 262+ global $wgAllowLogDeletion;
 263+
 264+ if( !$wgAllowLogDeletion )
 265+ return "";
 266+
 267+ $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
 268+ // If event was hidden from sysops
 269+ if( !LogPage::userCan( $row, Revision::DELETED_RESTRICTED ) ) {
 270+ $del = $this->message['rev-delundel'];
 271+ } else if( $row->log_type == 'suppress' ) {
 272+ return ''; // No one should be hiding from the oversight log
 273+ } else {
 274+ $del = $this->skin->makeKnownLinkObj( $revdel, $this->message['rev-delundel'], 'logid='.$row->log_id );
 275+ // Bolden oversighted content
 276+ if( LogPage::isDeleted( $row, Revision::DELETED_RESTRICTED ) )
 277+ $del = "<strong>$del</strong>";
 278+ }
 279+ return "<tt>(<small>$del</small>)</tt>";
 280+ }
 281+}
 282+
 283+
 284+/**
 285+ *
 286+ * @addtogroup SpecialPage
 287+ */
 288+class LogReader {
 289+ const NO_ACTION_LINK = 1;
 290+
 291+ var $db, $joinClauses, $whereClauses;
 292+ var $type = '', $user = '', $title = null, $pattern = false;
 293+
 294+ /**
 295+ * @param WebRequest $request For internal use use a FauxRequest object to pass arbitrary parameters.
 296+ */
 297+ function LogReader( $request ) {
 298+ $this->db = wfGetDB( DB_SLAVE );
 299+ $this->setupQuery( $request );
 300+ }
 301+
 302+ /**
 303+ * Basic setup and applies the limiting factors from the WebRequest object.
 304+ * @param WebRequest $request
 305+ * @private
 306+ */
 307+ function setupQuery( $request ) {
 308+ $page = $this->db->tableName( 'page' );
 309+ $user = $this->db->tableName( 'user' );
 310+ $this->joinClauses = array(
 311+ "LEFT OUTER JOIN $page ON log_namespace=page_namespace AND log_title=page_title",
 312+ "INNER JOIN $user ON user_id=log_user" );
 313+ $this->whereClauses = array();
 314+
 315+ $this->limitType( $request->getVal( 'type' ) );
 316+ $this->limitUser( $request->getText( 'user' ) );
 317+ $this->limitTitle( $request->getText( 'page' ) , $request->getBool( 'pattern' ) );
 318+ $this->limitTime( $request->getVal( 'from' ), '>=' );
 319+ $this->limitTime( $request->getVal( 'until' ), '<=' );
 320+
 321+ list( $this->limit, $this->offset ) = $request->getLimitOffset();
 322+
 323+ // XXX This all needs to use Pager, ugly hack for now.
 324+ global $wgMiserMode;
 325+ if( $wgMiserMode )
 326+ $this->offset = min( $this->offset, 10000 );
 327+ }
 328+
 329+ /**
 330+ * Set the log reader to return only entries of the given type.
 331+ * Type restrictions enforced here
 332+ * @param string $type A log type ('upload', 'delete', etc)
 333+ * @private
 334+ */
 335+ function limitType( $type ) {
 336+ global $wgLogRestrictions, $wgUser;
 337+ // Reset the array, clears extra "where" clauses when $par is used
 338+ $this->whereClauses = $hiddenLogs = array();
 339+ // Nothing to show the user requested a log they can't see
 340+ if( isset($wgLogRestrictions[$type]) && !$wgUser->isAllowed($wgLogRestrictions[$type]) ) {
 341+ $this->whereClauses[] = "1 = 0";
 342+ return false;
 343+ }
 344+ // Don't show private logs to unpriviledged users
 345+ foreach( $wgLogRestrictions as $logtype => $right ) {
 346+ if( !$wgUser->isAllowed($right) || empty($type) ) {
 347+ $safetype = $this->db->strencode( $logtype );
 348+ $hiddenLogs[] = "'$safetype'";
 349+ }
 350+ }
 351+ if( !empty($hiddenLogs) ) {
 352+ $this->whereClauses[] = 'log_type NOT IN('.implode(',',$hiddenLogs).')';
 353+ }
 354+
 355+ if( empty($type) ) {
 356+ return false;
 357+ }
 358+ $this->type = $type;
 359+ $safetype = $this->db->strencode( $type );
 360+ $this->whereClauses[] = "log_type='$safetype'";
 361+ }
 362+
 363+ /**
 364+ * Set the log reader to return only entries by the given user.
 365+ * @param string $name (In)valid user name
 366+ * @private
 367+ */
 368+ function limitUser( $name ) {
 369+ if ( $name == '' )
 370+ return false;
 371+ $usertitle = Title::makeTitleSafe( NS_USER, $name );
 372+ if ( is_null( $usertitle ) )
 373+ return false;
 374+ $this->user = $usertitle->getText();
 375+
 376+ /* Fetch userid at first, if known, provides awesome query plan afterwards */
 377+ $userid = $this->db->selectField('user','user_id',array('user_name'=>$this->user));
 378+ if (!$userid)
 379+ /* It should be nicer to abort query at all,
 380+ but for now it won't pass anywhere behind the optimizer */
 381+ $this->whereClauses[] = "NULL";
 382+ else
 383+ $this->whereClauses[] = "log_user=$userid";
 384+ }
 385+
 386+ /**
 387+ * Set the log reader to return only entries affecting the given page.
 388+ * (For the block and rights logs, this is a user page.)
 389+ * @param string $page Title name as text
 390+ * @private
 391+ */
 392+ function limitTitle( $page , $pattern ) {
 393+ global $wgMiserMode;
 394+
 395+ $title = Title::newFromText( $page );
 396+
 397+ if( strlen( $page ) == 0 || !$title instanceof Title )
 398+ return false;
 399+
 400+ $this->title =& $title;
 401+ $this->pattern = $pattern;
 402+ $ns = $title->getNamespace();
 403+ if ( $pattern && !$wgMiserMode ) {
 404+ $safetitle = $this->db->escapeLike( $title->getDBkey() ); // use escapeLike to avoid expensive search patterns like 't%st%'
 405+ $this->whereClauses[] = "log_namespace=$ns AND log_title LIKE '$safetitle%'";
 406+ } else {
 407+ $safetitle = $this->db->strencode( $title->getDBkey() );
 408+ $this->whereClauses[] = "log_namespace=$ns AND log_title = '$safetitle'";
 409+ }
 410+ }
 411+
 412+ /**
 413+ * Set the log reader to return only entries in a given time range.
 414+ * @param string $time Timestamp of one endpoint
 415+ * @param string $direction either ">=" or "<=" operators
 416+ * @private
 417+ */
 418+ function limitTime( $time, $direction ) {
 419+ # Direction should be a comparison operator
 420+ if( empty( $time ) ) {
 421+ return false;
 422+ }
 423+ $safetime = $this->db->strencode( wfTimestamp( TS_MW, $time ) );
 424+ $this->whereClauses[] = "log_timestamp $direction '$safetime'";
 425+ }
 426+
 427+ /**
 428+ * Build an SQL query from all the set parameters.
 429+ * @return string the SQL query
 430+ * @private
 431+ */
 432+ function getQuery() {
 433+ global $wgAllowLogDeletion;
 434+
 435+ $logging = $this->db->tableName( "logging" );
 436+ $sql = "SELECT /*! STRAIGHT_JOIN */ log_type, log_action, log_timestamp,
 437+ log_user, user_name, log_namespace, log_title, page_id,
 438+ log_comment, log_params, log_deleted ";
 439+ if( $wgAllowLogDeletion )
 440+ $sql .= ", log_id ";
 441+
 442+ $sql .= "FROM $logging ";
 443+ if( !empty( $this->joinClauses ) ) {
 444+ $sql .= implode( ' ', $this->joinClauses );
 445+ }
 446+ if( !empty( $this->whereClauses ) ) {
 447+ $sql .= " WHERE " . implode( ' AND ', $this->whereClauses );
 448+ }
 449+ $sql .= " ORDER BY log_timestamp DESC ";
 450+ $sql = $this->db->limitResult($sql, $this->limit, $this->offset );
 451+ return $sql;
 452+ }
 453+
 454+ /**
 455+ * Execute the query and start returning results.
 456+ * @return ResultWrapper result object to return the relevant rows
 457+ */
 458+ function getRows() {
 459+ $res = $this->db->query( $this->getQuery(), __METHOD__ );
 460+ return $this->db->resultObject( $res );
 461+ }
 462+
 463+ /**
 464+ * @return string The query type that this LogReader has been limited to.
 465+ */
 466+ function queryType() {
 467+ return $this->type;
 468+ }
 469+
 470+ /**
 471+ * @return string The username type that this LogReader has been limited to, if any.
 472+ */
 473+ function queryUser() {
 474+ return $this->user;
 475+ }
 476+
 477+ /**
 478+ * @return boolean The checkbox, if titles should be searched by a pattern too
 479+ */
 480+ function queryPattern() {
 481+ return $this->pattern;
 482+ }
 483+
 484+ /**
 485+ * @return string The text of the title that this LogReader has been limited to.
 486+ */
 487+ function queryTitle() {
 488+ if( is_null( $this->title ) ) {
 489+ return '';
 490+ } else {
 491+ return $this->title->getPrefixedText();
 492+ }
 493+ }
 494+
 495+ /**
 496+ * Is there at least one row?
 497+ *
 498+ * @return bool
 499+ */
 500+ public function hasRows() {
 501+ # Little hack...
 502+ $limit = $this->limit;
 503+ $this->limit = 1;
 504+ $res = $this->db->query( $this->getQuery() );
 505+ $this->limit = $limit;
 506+ $ret = $this->db->numRows( $res ) > 0;
 507+ $this->db->freeResult( $res );
 508+ return $ret;
 509+ }
 510+
 511+}
 512+
 513+/**
 514+ *
 515+ * @addtogroup SpecialPage
 516+ */
 517+class LogViewer {
 518+ /**
 519+ * @var LogReader $reader
 520+ */
 521+ var $reader;
 522+ var $numResults = 0;
 523+ var $flags = 0;
 524+
 525+ /**
 526+ * @param LogReader &$reader where to get our data from
 527+ * @param integer $flags Bitwise combination of flags:
 528+ * LogEventList::NO_ACTION_LINK Don't show restore/unblock/block links
 529+ */
 530+ function LogViewer( &$reader, $flags = 0 ) {
 531+ global $wgUser;
 532+ $this->skin = $wgUser->getSkin();
 533+ $this->reader =& $reader;
 534+ $this->flags = $flags;
 535+ $this->logList = new LogEventList( $wgUser->getSkin(), $flags );
 536+ }
 537+
 538+ /**
 539+ * Take over the whole output page in $wgOut with the log display.
 540+ */
 541+ function show() {
 542+ global $wgOut;
 543+ $this->logList->showHeader( $wgOut, $this->reader->queryType() );
 544+ $this->logList->showOptions( $wgOut, $this->reader->queryType(), $this->reader->queryUser(),
 545+ $this->reader->queryTitle(), $this->reader->queryPattern() );
 546+ $result = $this->getLogRows();
 547+ if ( $this->numResults > 0 ) {
 548+ $this->showPrevNext( $wgOut );
 549+ $this->doShowList( $wgOut, $result );
 550+ $this->showPrevNext( $wgOut );
 551+ } else {
 552+ $this->showError( $wgOut );
 553+ }
 554+ }
 555+
 556+ /**
 557+ * Load the data from the linked LogReader
 558+ * Preload the link cache
 559+ * Initialise numResults
 560+ *
 561+ * Must be called before calling showPrevNext
 562+ *
 563+ * @return object database result set
 564+ */
 565+ function getLogRows() {
 566+ $result = $this->reader->getRows();
 567+ $this->numResults = 0;
 568+
 569+ // Fetch results and form a batch link existence query
 570+ $batch = new LinkBatch;
 571+ while ( $s = $result->fetchObject() ) {
 572+ // User link
 573+ $batch->addObj( Title::makeTitleSafe( NS_USER, $s->user_name ) );
 574+ $batch->addObj( Title::makeTitleSafe( NS_USER_TALK, $s->user_name ) );
 575+
 576+ // Move destination link
 577+ if ( $s->log_type == 'move' ) {
 578+ $paramArray = LogPage::extractParams( $s->log_params );
 579+ $title = Title::newFromText( $paramArray[0] );
 580+ $batch->addObj( $title );
 581+ }
 582+ ++$this->numResults;
 583+ }
 584+ $batch->execute();
 585+
 586+ return $result;
 587+ }
 588+
 589+
 590+ /**
 591+ * Output just the list of entries given by the linked LogReader,
 592+ * with extraneous UI elements. Use for displaying log fragments in
 593+ * another page (eg at Special:Undelete)
 594+ * @param OutputPage $out where to send output
 595+ */
 596+ function showList( &$out ) {
 597+ $result = $this->getLogRows();
 598+ if ( $this->numResults > 0 ) {
 599+ $this->doShowList( $out, $result );
 600+ } else {
 601+ $this->showError( $out );
 602+ }
 603+ }
 604+
 605+ function doShowList( &$out, $result ) {
 606+ // Rewind result pointer and go through it again, making the HTML
 607+ $html = "\n<ul>\n";
 608+ $result->seek( 0 );
 609+ while( $s = $result->fetchObject() ) {
 610+ $html .= $this->logList->logLine( $s );
 611+ }
 612+ $html .= "\n</ul>\n";
 613+ $out->addHTML( $html );
 614+ $result->free();
 615+ }
 616+
 617+ function showError( &$out ) {
 618+ $out->addWikiMsg( 'logempty' );
 619+ }
 620+
 621+ /**
 622+ * @param OutputPage &$out where to send output
 623+ * @private
 624+ */
 625+ function showPrevNext( &$out ) {
 626+ global $wgContLang,$wgRequest;
 627+ $pieces = array();
 628+ $pieces[] = 'type=' . urlencode( $this->reader->queryType() );
 629+ $pieces[] = 'user=' . urlencode( $this->reader->queryUser() );
 630+ $pieces[] = 'page=' . urlencode( $this->reader->queryTitle() );
 631+ $pieces[] = 'pattern=' . urlencode( $this->reader->queryPattern() );
 632+ $bits = implode( '&', $pieces );
 633+ list( $limit, $offset ) = $wgRequest->getLimitOffset();
 634+
 635+ # TODO: use timestamps instead of offsets to make it more natural
 636+ # to go huge distances in time
 637+ $html = wfViewPrevNext( $offset, $limit,
 638+ $wgContLang->specialpage( 'Log' ),
 639+ $bits,
 640+ $this->numResults < $limit);
 641+ $out->addHTML( '<p>' . $html . '</p>' );
 642+ }
 643+}
 644+
Property changes on: trunk/phase3/includes/LogEventList.php
___________________________________________________________________
Added: svn:eol-style
1645 + native
Index: trunk/phase3/includes/AutoLoader.php
@@ -135,8 +135,9 @@
136136 'LoadBalancer' => 'includes/LoadBalancer.php',
137137 'LoginForm' => 'includes/SpecialUserlogin.php',
138138 'LogPage' => 'includes/LogPage.php',
139 - 'LogReader' => 'includes/SpecialLog.php',
140 - 'LogViewer' => 'includes/SpecialLog.php',
 139+ 'LogEventList' => 'includes/LogEventList.php',
 140+ 'LogReader' => 'includes/LogEventList.php',
 141+ 'LogViewer' => 'includes/LogEventList.php',
141142 'LonelyPagesPage' => 'includes/SpecialLonelypages.php',
142143 'LongPagesPage' => 'includes/SpecialLongpages.php',
143144 'MacBinary' => 'includes/MacBinary.php',
Index: trunk/phase3/includes/SpecialLog.php
@@ -1,5 +1,5 @@
22 <?php
3 -# Copyright (C) 2004 Brion Vibber <brion@pobox.com>
 3+# Copyright (C) 2008 Aaron Schulz
44 # http://www.mediawiki.org/
55 #
66 # This program is free software; you can redistribute it and/or modify
@@ -26,93 +26,111 @@
2727 * constructor
2828 */
2929 function wfSpecialLog( $par = '' ) {
30 - global $wgRequest;
31 - $logReader = new LogReader( $wgRequest );
32 - if( $wgRequest->getVal( 'type' ) == '' && $par != '' ) {
33 - $logReader->limitType( $par );
34 - }
35 - $logViewer = new LogViewer( $logReader );
36 - $logViewer->show();
 30+ global $wgRequest, $wgOut, $wgUser;
 31+ # Get parameters
 32+ $type = $wgRequest->getVal( 'type', $par );
 33+ $user = $wgRequest->getText( 'user' );
 34+ $title = $wgRequest->getText( 'page' );
 35+ $pattern = $wgRequest->getBool( 'pattern' );
 36+ # Create a LogPager item to get the results and a LogEventList
 37+ # item to format them...
 38+ $loglist = new LogEventList( $wgUser->getSkin() );
 39+ $pager = new LogPager( $loglist, $type, $user, $title, $pattern );
 40+ # Set title and add header
 41+ $loglist->showHeader( $wgOut, $pager->getType() );
 42+ # Show form options
 43+ $loglist->showOptions( $wgOut, $pager->getType(), $pager->getUser(), $pager->getPage(), $pager->getPattern() );
 44+ # Insert list
 45+ $wgOut->addHTML(
 46+ $pager->getNavigationBar() .
 47+ '<ul id="logevents">' . "\n" .
 48+ $pager->getBody() .
 49+ '</ul>' . "\n" .
 50+ $pager->getNavigationBar()
 51+ );
3752 }
3853
3954 /**
40 - *
41 - * @addtogroup SpecialPage
 55+ * @addtogroup Pager
4256 */
43 -class LogReader {
44 - var $db, $joinClauses, $whereClauses;
45 - var $type = '', $user = '', $title = null, $pattern = false;
46 -
 57+class LogPager extends ReverseChronologicalPager {
 58+ var $type = '', $user = '', $title = '', $pattern = '';
4759 /**
48 - * @param WebRequest $request For internal use use a FauxRequest object to pass arbitrary parameters.
49 - */
50 - function LogReader( $request ) {
51 - $this->db = wfGetDB( DB_SLAVE );
52 - $this->setupQuery( $request );
53 - }
54 -
55 - /**
56 - * Basic setup and applies the limiting factors from the WebRequest object.
57 - * @param WebRequest $request
58 - * @private
59 - */
60 - function setupQuery( $request ) {
61 - $page = $this->db->tableName( 'page' );
62 - $user = $this->db->tableName( 'user' );
63 - $this->joinClauses = array(
64 - "LEFT OUTER JOIN $page ON log_namespace=page_namespace AND log_title=page_title",
65 - "INNER JOIN $user ON user_id=log_user" );
66 - $this->whereClauses = array();
67 -
68 - $this->limitType( $request->getVal( 'type' ) );
69 - $this->limitUser( $request->getText( 'user' ) );
70 - $this->limitTitle( $request->getText( 'page' ) , $request->getBool( 'pattern' ) );
71 - $this->limitTime( $request->getVal( 'from' ), '>=' );
72 - $this->limitTime( $request->getVal( 'until' ), '<=' );
73 -
74 - list( $this->limit, $this->offset ) = $request->getLimitOffset();
 60+ * constructor
 61+ * @param LogEventList $loglist,
 62+ * @param string $type,
 63+ * @param string $user,
 64+ * @param string $page,
 65+ * @param string $pattern
 66+ * @param array $conds
 67+ */
 68+ function __construct( $loglist, $type, $user, $title, $pattern, $conds = array() ) {
 69+ parent::__construct();
 70+ $this->mConds = $conds;
7571
76 - // XXX This all needs to use Pager, ugly hack for now.
77 - global $wgMiserMode;
78 - if( $wgMiserMode )
79 - $this->offset = min( $this->offset, 10000 );
 72+ $this->mLogList = $loglist;
 73+
 74+ $this->limitType( $type );
 75+ $this->limitUser( $user );
 76+ $this->limitTitle( $title, $pattern );
8077 }
81 -
 78+
8279 /**
8380 * Set the log reader to return only entries of the given type.
 81+ * Type restrictions enforced here
8482 * @param string $type A log type ('upload', 'delete', etc)
8583 * @private
8684 */
87 - function limitType( $type ) {
88 - if( empty( $type ) ) {
 85+ private function limitType( $type ) {
 86+ global $wgLogRestrictions, $wgUser;
 87+ // Reset the array, clears extra "where" clauses when $par is used
 88+ $hiddenLogs = array();
 89+ // Nothing to show the user requested a log they can't see
 90+ if( isset($wgLogRestrictions[$type]) && !$wgUser->isAllowed($wgLogRestrictions[$type]) ) {
 91+ $this->mConds[] = "NULL";
8992 return false;
9093 }
 94+ // Don't show private logs to unpriviledged users
 95+ foreach( $wgLogRestrictions as $logtype => $right ) {
 96+ if( !$wgUser->isAllowed($right) || empty($type) ) {
 97+ $safetype = $this->mDb->strencode( $logtype );
 98+ $hiddenLogs[] = "'$safetype'";
 99+ }
 100+ }
 101+ if( !empty($hiddenLogs) ) {
 102+ $this->mConds[] = 'log_type NOT IN('.implode(',',$hiddenLogs).')';
 103+ }
 104+
 105+ if( empty($type) ) {
 106+ return false;
 107+ }
91108 $this->type = $type;
92 - $safetype = $this->db->strencode( $type );
93 - $this->whereClauses[] = "log_type='$safetype'";
 109+ $this->mConds['log_type'] = $type;
94110 }
95 -
 111+
96112 /**
97113 * Set the log reader to return only entries by the given user.
98114 * @param string $name (In)valid user name
99115 * @private
100116 */
101117 function limitUser( $name ) {
102 - if ( $name == '' )
 118+ if( $name == '' ) {
103119 return false;
 120+ }
104121 $usertitle = Title::makeTitleSafe( NS_USER, $name );
105 - if ( is_null( $usertitle ) )
 122+ if( is_null($usertitle) ) {
106123 return false;
 124+ }
107125 $this->user = $usertitle->getText();
108 -
109126 /* Fetch userid at first, if known, provides awesome query plan afterwards */
110 - $userid = $this->db->selectField('user','user_id',array('user_name'=>$this->user));
111 - if (!$userid)
 127+ $userid = User::idFromName( $this->user );
 128+ if( !$userid ) {
112129 /* It should be nicer to abort query at all,
113130 but for now it won't pass anywhere behind the optimizer */
114 - $this->whereClauses[] = "NULL";
115 - else
116 - $this->whereClauses[] = "log_user=$userid";
 131+ $this->mConds[] = "NULL";
 132+ } else {
 133+ $this->mConds['log_user'] = $userid;
 134+ }
117135 }
118136
119137 /**
@@ -121,407 +139,59 @@
122140 * @param string $page Title name as text
123141 * @private
124142 */
125 - function limitTitle( $page , $pattern ) {
 143+ function limitTitle( $page, $pattern ) {
126144 global $wgMiserMode;
127145
128146 $title = Title::newFromText( $page );
129 -
130 - if( strlen( $page ) == 0 || !$title instanceof Title )
 147+ if( strlen($page) == 0 || !$title instanceof Title )
131148 return false;
132 -
133 - $this->title =& $title;
 149+
 150+ $this->title = $title->getPrefixedText();
134151 $this->pattern = $pattern;
135152 $ns = $title->getNamespace();
136 - if ( $pattern && !$wgMiserMode ) {
137 - $safetitle = $this->db->escapeLike( $title->getDBkey() ); // use escapeLike to avoid expensive search patterns like 't%st%'
138 - $this->whereClauses[] = "log_namespace=$ns AND log_title LIKE '$safetitle%'";
 153+ if( $pattern && !$wgMiserMode ) {
 154+ # use escapeLike to avoid expensive search patterns like 't%st%'
 155+ $safetitle = $this->mDb->escapeLike( $title->getDBkey() );
 156+ $this->mConds['log_namespace'] = $ns;
 157+ $this->mConds[] = "log_title LIKE '$safetitle%'";
139158 } else {
140 - $safetitle = $this->db->strencode( $title->getDBkey() );
141 - $this->whereClauses[] = "log_namespace=$ns AND log_title = '$safetitle'";
 159+ $this->mConds['log_namespace'] = $ns;
 160+ $this->mConds['log_title'] = $title->getDBkey();
142161 }
143162 }
144163
145 - /**
146 - * Set the log reader to return only entries in a given time range.
147 - * @param string $time Timestamp of one endpoint
148 - * @param string $direction either ">=" or "<=" operators
149 - * @private
150 - */
151 - function limitTime( $time, $direction ) {
152 - # Direction should be a comparison operator
153 - if( empty( $time ) ) {
154 - return false;
155 - }
156 - $safetime = $this->db->strencode( wfTimestamp( TS_MW, $time ) );
157 - $this->whereClauses[] = "log_timestamp $direction '$safetime'";
 164+ function getQueryInfo() {
 165+ $this->mConds[] = 'user_id = log_user';
 166+ return array(
 167+ 'tables' => array( 'logging', 'user' ),
 168+ 'fields' => array( 'log_type', 'log_action', 'log_user', 'log_namespace', 'log_title',
 169+ 'log_params', 'log_comment', 'log_id', 'log_deleted', 'log_timestamp', 'user_name' ),
 170+ 'conds' => $this->mConds,
 171+ 'options' => array()
 172+ );
158173 }
159174
160 - /**
161 - * Build an SQL query from all the set parameters.
162 - * @return string the SQL query
163 - * @private
164 - */
165 - function getQuery() {
166 - $logging = $this->db->tableName( "logging" );
167 - $sql = "SELECT /*! STRAIGHT_JOIN */ log_type, log_action, log_timestamp,
168 - log_user, user_name,
169 - log_namespace, log_title, page_id,
170 - log_comment, log_params FROM $logging ";
171 - if( !empty( $this->joinClauses ) ) {
172 - $sql .= implode( ' ', $this->joinClauses );
173 - }
174 - if( !empty( $this->whereClauses ) ) {
175 - $sql .= " WHERE " . implode( ' AND ', $this->whereClauses );
176 - }
177 - $sql .= " ORDER BY log_timestamp DESC ";
178 - $sql = $this->db->limitResult($sql, $this->limit, $this->offset );
179 - return $sql;
 175+ function getIndexField() {
 176+ return 'log_timestamp';
180177 }
181178
182 - /**
183 - * Execute the query and start returning results.
184 - * @return ResultWrapper result object to return the relevant rows
185 - */
186 - function getRows() {
187 - $res = $this->db->query( $this->getQuery(), __METHOD__ );
188 - return $this->db->resultObject( $res );
 179+ function formatRow( $row ) {
 180+ return $this->mLogList->logLine( $row );
189181 }
190 -
191 - /**
192 - * @return string The query type that this LogReader has been limited to.
193 - */
194 - function queryType() {
 182+
 183+ public function getType() {
195184 return $this->type;
196185 }
197 -
198 - /**
199 - * @return string The username type that this LogReader has been limited to, if any.
200 - */
201 - function queryUser() {
 186+
 187+ public function getUser() {
202188 return $this->user;
203189 }
204 -
205 - /**
206 - * @return boolean The checkbox, if titles should be searched by a pattern too
207 - */
208 - function queryPattern() {
209 - return $this->pattern;
210 - }
211 -
212 - /**
213 - * @return string The text of the title that this LogReader has been limited to.
214 - */
215 - function queryTitle() {
216 - if( is_null( $this->title ) ) {
217 - return '';
218 - } else {
219 - return $this->title->getPrefixedText();
220 - }
221 - }
222190
223 - /**
224 - * Is there at least one row?
225 - *
226 - * @return bool
227 - */
228 - public function hasRows() {
229 - # Little hack...
230 - $limit = $this->limit;
231 - $this->limit = 1;
232 - $res = $this->db->query( $this->getQuery() );
233 - $this->limit = $limit;
234 - $ret = $this->db->numRows( $res ) > 0;
235 - $this->db->freeResult( $res );
236 - return $ret;
 191+ public function getPage() {
 192+ return $this->title;
237193 }
238194
239 -}
240 -
241 -/**
242 - *
243 - * @addtogroup SpecialPage
244 - */
245 -class LogViewer {
246 - const NO_ACTION_LINK = 1;
247 -
248 - /**
249 - * @var LogReader $reader
250 - */
251 - var $reader;
252 - var $numResults = 0;
253 - var $flags = 0;
254 -
255 - /**
256 - * @param LogReader &$reader where to get our data from
257 - * @param integer $flags Bitwise combination of flags:
258 - * self::NO_ACTION_LINK Don't show restore/unblock/block links
259 - */
260 - function LogViewer( &$reader, $flags = 0 ) {
261 - global $wgUser;
262 - $this->skin = $wgUser->getSkin();
263 - $this->reader =& $reader;
264 - $this->flags = $flags;
 195+ public function getPattern() {
 196+ return $this->pattern;
265197 }
266 -
267 - /**
268 - * Take over the whole output page in $wgOut with the log display.
269 - */
270 - function show() {
271 - global $wgOut;
272 - $this->showHeader( $wgOut );
273 - $this->showOptions( $wgOut );
274 - $result = $this->getLogRows();
275 - if ( $this->numResults > 0 ) {
276 - $this->showPrevNext( $wgOut );
277 - $this->doShowList( $wgOut, $result );
278 - $this->showPrevNext( $wgOut );
279 - } else {
280 - $this->showError( $wgOut );
281 - }
282 - }
283 -
284 - /**
285 - * Load the data from the linked LogReader
286 - * Preload the link cache
287 - * Initialise numResults
288 - *
289 - * Must be called before calling showPrevNext
290 - *
291 - * @return object database result set
292 - */
293 - function getLogRows() {
294 - $result = $this->reader->getRows();
295 - $this->numResults = 0;
296 -
297 - // Fetch results and form a batch link existence query
298 - $batch = new LinkBatch;
299 - while ( $s = $result->fetchObject() ) {
300 - // User link
301 - $batch->addObj( Title::makeTitleSafe( NS_USER, $s->user_name ) );
302 - $batch->addObj( Title::makeTitleSafe( NS_USER_TALK, $s->user_name ) );
303 -
304 - // Move destination link
305 - if ( $s->log_type == 'move' ) {
306 - $paramArray = LogPage::extractParams( $s->log_params );
307 - $title = Title::newFromText( $paramArray[0] );
308 - $batch->addObj( $title );
309 - }
310 - ++$this->numResults;
311 - }
312 - $batch->execute();
313 -
314 - return $result;
315 - }
316 -
317 -
318 - /**
319 - * Output just the list of entries given by the linked LogReader,
320 - * with extraneous UI elements. Use for displaying log fragments in
321 - * another page (eg at Special:Undelete)
322 - * @param OutputPage $out where to send output
323 - */
324 - function showList( &$out ) {
325 - $result = $this->getLogRows();
326 - if ( $this->numResults > 0 ) {
327 - $this->doShowList( $out, $result );
328 - } else {
329 - $this->showError( $out );
330 - }
331 - }
332 -
333 - function doShowList( &$out, $result ) {
334 - // Rewind result pointer and go through it again, making the HTML
335 - $html = "\n<ul>\n";
336 - $result->seek( 0 );
337 - while( $s = $result->fetchObject() ) {
338 - $html .= $this->logLine( $s );
339 - }
340 - $html .= "\n</ul>\n";
341 - $out->addHTML( $html );
342 - $result->free();
343 - }
344 -
345 - function showError( &$out ) {
346 - $out->addWikiMsg( 'logempty' );
347 - }
348 -
349 - /**
350 - * @param Object $s a single row from the result set
351 - * @return string Formatted HTML list item
352 - * @private
353 - */
354 - function logLine( $s ) {
355 - global $wgLang, $wgUser, $wgContLang;
356 - $skin = $wgUser->getSkin();
357 - $title = Title::makeTitle( $s->log_namespace, $s->log_title );
358 - $time = $wgLang->timeanddate( wfTimestamp(TS_MW, $s->log_timestamp), true );
359 -
360 - // Enter the existence or non-existence of this page into the link cache,
361 - // for faster makeLinkObj() in LogPage::actionText()
362 - $linkCache =& LinkCache::singleton();
363 - if( $s->page_id ) {
364 - $linkCache->addGoodLinkObj( $s->page_id, $title );
365 - } else {
366 - $linkCache->addBadLinkObj( $title );
367 - }
368 -
369 - $userLink = $this->skin->userLink( $s->log_user, $s->user_name ) . $this->skin->userToolLinksRedContribs( $s->log_user, $s->user_name );
370 - $comment = $wgContLang->getDirMark() . $this->skin->commentBlock( $s->log_comment );
371 - $paramArray = LogPage::extractParams( $s->log_params );
372 - $revert = '';
373 - // show revertmove link
374 - if ( !( $this->flags & self::NO_ACTION_LINK ) ) {
375 - if ( $s->log_type == 'move' && isset( $paramArray[0] ) && $wgUser->isAllowed( 'move' ) ) {
376 - $destTitle = Title::newFromText( $paramArray[0] );
377 - if ( $destTitle ) {
378 - $revert = '(' . $this->skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Movepage' ),
379 - wfMsg( 'revertmove' ),
380 - 'wpOldTitle=' . urlencode( $destTitle->getPrefixedDBkey() ) .
381 - '&wpNewTitle=' . urlencode( $title->getPrefixedDBkey() ) .
382 - '&wpReason=' . urlencode( wfMsgForContent( 'revertmove' ) ) .
383 - '&wpMovetalk=0' ) . ')';
384 - }
385 - // show undelete link
386 - } elseif ( $s->log_action == 'delete' && $wgUser->isAllowed( 'delete' ) ) {
387 - $revert = '(' . $this->skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Undelete' ),
388 - wfMsg( 'undeletelink' ) ,
389 - 'target='. urlencode( $title->getPrefixedDBkey() ) ) . ')';
390 - // show unblock link
391 - } elseif ( $s->log_action == 'block' && $wgUser->isAllowed( 'block' ) ) {
392 - $revert = '(' . $skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Ipblocklist' ),
393 - wfMsg( 'unblocklink' ),
394 - 'action=unblock&ip=' . urlencode( $s->log_title ) ) . ')';
395 - // show change protection link
396 - } elseif ( ( $s->log_action == 'protect' || $s->log_action == 'modify' ) && $wgUser->isAllowed( 'protect' ) ) {
397 - $revert = '(' . $skin->makeKnownLinkObj( $title, wfMsg( 'protect_change' ), 'action=unprotect' ) . ')';
398 - // Show unmerge link
399 - } elseif ( $s->log_action == 'merge' ) {
400 - $merge = SpecialPage::getTitleFor( 'Mergehistory' );
401 - $revert = '(' . $this->skin->makeKnownLinkObj( $merge, wfMsg('revertmerge'),
402 - wfArrayToCGI(
403 - array('target' => $paramArray[0], 'dest' => $title->getPrefixedText(), 'mergepoint' => $paramArray[1] )
404 - )
405 - ) . ')';
406 - } elseif ( wfRunHooks( 'LogLine', array( $s->log_type, $s->log_action, $title, $paramArray, &$comment, &$revert, $s->log_timestamp ) ) ) {
407 - // wfDebug( "Invoked LogLine hook for " $s->log_type . ", " . $s->log_action . "\n" );
408 - // Do nothing. The implementation is handled by the hook modifiying the passed-by-ref parameters.
409 - }
410 - }
411 -
412 - $action = LogPage::actionText( $s->log_type, $s->log_action, $title, $this->skin, $paramArray, true );
413 - $out = "<li>$time $userLink $action $comment $revert</li>\n";
414 - return $out;
415 - }
416 -
417 - /**
418 - * @param OutputPage &$out where to send output
419 - * @private
420 - */
421 - function showHeader( &$out ) {
422 - $type = $this->reader->queryType();
423 - if( LogPage::isLogType( $type ) ) {
424 - $out->setPageTitle( LogPage::logName( $type ) );
425 - $out->addWikiText( LogPage::logHeader( $type ) );
426 - }
427 - }
428 -
429 - /**
430 - * @param OutputPage &$out where to send output
431 - * @private
432 - */
433 - function showOptions( &$out ) {
434 - global $wgScript, $wgMiserMode;
435 - $action = htmlspecialchars( $wgScript );
436 - $title = SpecialPage::getTitleFor( 'Log' );
437 - $special = htmlspecialchars( $title->getPrefixedDBkey() );
438 - $out->addHTML( "<form action=\"$action\" method=\"get\">\n" .
439 - '<fieldset>' .
440 - Xml::element( 'legend', array(), wfMsg( 'log' ) ) .
441 - Xml::hidden( 'title', $special ) . "\n" .
442 - $this->getTypeMenu() . "\n" .
443 - $this->getUserInput() . "\n" .
444 - $this->getTitleInput() . "\n" .
445 - (!$wgMiserMode?($this->getTitlePattern()."\n"):"") .
446 - Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
447 - "</fieldset></form>" );
448 - }
449 -
450 - /**
451 - * @return string Formatted HTML
452 - * @private
453 - */
454 - function getTypeMenu() {
455 - $out = "<select name='type'>\n";
456 -
457 - $validTypes = LogPage::validTypes();
458 - $m = array(); // Temporary array
459 -
460 - // First pass to load the log names
461 - foreach( $validTypes as $type ) {
462 - $text = LogPage::logName( $type );
463 - $m[$text] = $type;
464 - }
465 -
466 - // Second pass to sort by name
467 - ksort($m);
468 -
469 - // Third pass generates sorted XHTML content
470 - foreach( $m as $text => $type ) {
471 - $selected = ($type == $this->reader->queryType());
472 - $out .= Xml::option( $text, $type, $selected ) . "\n";
473 - }
474 -
475 - $out .= '</select>';
476 - return $out;
477 - }
478 -
479 - /**
480 - * @return string Formatted HTML
481 - * @private
482 - */
483 - function getUserInput() {
484 - $user = $this->reader->queryUser();
485 - return Xml::inputLabel( wfMsg( 'specialloguserlabel' ), 'user', 'user', 12, $user );
486 - }
487 -
488 - /**
489 - * @return string Formatted HTML
490 - * @private
491 - */
492 - function getTitleInput() {
493 - $title = $this->reader->queryTitle();
494 - return Xml::inputLabel( wfMsg( 'speciallogtitlelabel' ), 'page', 'page', 20, $title );
495 - }
496 -
497 - /**
498 - * @return boolean Checkbox
499 - * @private
500 - */
501 - function getTitlePattern() {
502 - $pattern = $this->reader->queryPattern();
503 - return Xml::checkLabel( wfMsg( 'log-title-wildcard' ), 'pattern', 'pattern', $pattern );
504 - }
505 -
506 - /**
507 - * @param OutputPage &$out where to send output
508 - * @private
509 - */
510 - function showPrevNext( &$out ) {
511 - global $wgContLang,$wgRequest;
512 - $pieces = array();
513 - $pieces[] = 'type=' . urlencode( $this->reader->queryType() );
514 - $pieces[] = 'user=' . urlencode( $this->reader->queryUser() );
515 - $pieces[] = 'page=' . urlencode( $this->reader->queryTitle() );
516 - $pieces[] = 'pattern=' . urlencode( $this->reader->queryPattern() );
517 - $bits = implode( '&', $pieces );
518 - list( $limit, $offset ) = $wgRequest->getLimitOffset();
519 -
520 - # TODO: use timestamps instead of offsets to make it more natural
521 - # to go huge distances in time
522 - $html = wfViewPrevNext( $offset, $limit,
523 - $wgContLang->specialpage( 'Log' ),
524 - $bits,
525 - $this->numResults < $limit);
526 - $out->addHTML( '<p>' . $html . '</p>' );
527 - }
528198 }
Index: trunk/phase3/includes/DefaultSettings.php
@@ -1152,10 +1152,16 @@
11531153 // Permission to change users' groups assignments across wikis
11541154 #$wgGroupPermissions['bureaucrat']['userrights-interwiki'] = true;
11551155
1156 -// Experimental permissions, not ready for production use
1157 -//$wgGroupPermissions['sysop']['deleterevision'] = true;
1158 -//$wgGroupPermissions['bureaucrat']['hiderevision'] = true;
 1156+#$wgGroupPermissions['sysop']['deleterevision'] = true;
 1157+// To hide usernames
 1158+#$wgGroupPermissions['suppress']['hideuser'] = true;
 1159+// To see hidden revs and unhide revs hidden from Sysops
 1160+#$wgGroupPermissions['suppress']['hiderevision'] = true;
 1161+// For private log access
 1162+#$wgGroupPermissions['suppress']['suppress'] = true;
11591163
 1164+$wgAllowLogDeletion = false;
 1165+
11601166 /**
11611167 * The developer group is deprecated, but can be activated if need be
11621168 * to use the 'lockdb' and 'unlockdb' special pages. Those require
@@ -2394,9 +2400,20 @@
23952401 'import',
23962402 'patrol',
23972403 'merge',
 2404+ 'suppress',
23982405 );
23992406
24002407 /**
 2408+ * This restricts log access to those who have a certain right
 2409+ * Users without this will not see it in the option menu and can not view it
 2410+ * Restricted logs are not added to recent changes
 2411+ * Logs should remain non-transcludable
 2412+ */
 2413+$wgLogRestrictions = array(
 2414+ 'suppress' => 'suppress'
 2415+);
 2416+
 2417+/**
24012418 * Lists the message key string for each log type. The localized messages
24022419 * will be listed in the user interface.
24032420 *
@@ -2413,6 +2430,7 @@
24142431 'import' => 'importlogpage',
24152432 'patrol' => 'patrol-log-page',
24162433 'merge' => 'mergelog',
 2434+ 'suppress' => 'suppressionlog',
24172435 );
24182436
24192437 /**
@@ -2432,6 +2450,7 @@
24332451 'import' => 'importlogpagetext',
24342452 'patrol' => 'patrol-log-header',
24352453 'merge' => 'mergelogpagetext',
 2454+ 'suppress' => 'suppressionlogtext',
24362455 );
24372456
24382457 /**
@@ -2458,6 +2477,11 @@
24592478 'import/upload' => 'import-logentry-upload',
24602479 'import/interwiki' => 'import-logentry-interwiki',
24612480 'merge/merge' => 'pagemerge-logentry',
 2481+ 'suppress/revision' => 'revdelete-logentry',
 2482+ 'suppress/file' => 'revdelete-logentry',
 2483+ 'suppress/event' => 'logdelete-logentry',
 2484+ 'suppress/delete' => 'suppressedarticle',
 2485+ 'suppress/block' => 'blocklogentry',
24622486 );
24632487
24642488 /**
Index: trunk/phase3/includes/LogPage.php
@@ -54,7 +54,7 @@
5555 function saveContent() {
5656 if( wfReadOnly() ) return false;
5757
58 - global $wgUser;
 58+ global $wgUser, $wgLogRestrictions;
5959 $fname = 'LogPage::saveContent';
6060
6161 $dbw = wfGetDB( DB_MASTER );
@@ -72,20 +72,18 @@
7373 'log_comment' => $this->comment,
7474 'log_params' => $this->params
7575 );
76 -
77 - # log_id doesn't exist on Wikimedia servers yet, and it's a tricky
78 - # schema update to do. Hack it for now to ignore the field on MySQL.
79 - if ( !is_null( $log_id ) ) {
80 - $data['log_id'] = $log_id;
81 - }
8276 $dbw->insert( 'logging', $data, $fname );
 77+ $newId = $dbw->insertId();
8378
8479 # And update recentchanges
85 - if ( $this->updateRecentChanges ) {
86 - $titleObj = SpecialPage::getTitleFor( 'Log', $this->type );
87 - $rcComment = $this->getRcComment();
88 - RecentChange::notifyLog( $now, $titleObj, $wgUser, $rcComment, '',
89 - $this->type, $this->action, $this->target, $this->comment, $this->params );
 80+ if( $this->updateRecentChanges ) {
 81+ # Don't add private logs to RC!
 82+ if( !isset($wgLogRestrictions[$this->type]) || $wgLogRestrictions[$this->type]=='*' ) {
 83+ $titleObj = SpecialPage::getTitleFor( 'Log', $this->type );
 84+ $rcComment = $this->getRcComment();
 85+ RecentChange::notifyLog( $now, $titleObj, $wgUser, $rcComment, '',
 86+ $this->type, $this->action, $this->target, $this->comment, $this->params, $newId );
 87+ }
9088 }
9189 return true;
9290 }
@@ -137,7 +135,7 @@
138136 */
139137 static function logHeader( $type ) {
140138 global $wgLogHeaders;
141 - return wfMsg( $wgLogHeaders[$type] );
 139+ return wfMsgHtml( $wgLogHeaders[$type] );
142140 }
143141
144142 /**
@@ -208,7 +206,7 @@
209207 }
210208 } else {
211209 array_unshift( $params, $titleLink );
212 - if ( $key == 'block/block' ) {
 210+ if ( $key == 'block/block' || $key == 'suppress/block' ) {
213211 if ( $skin ) {
214212 $params[1] = '<span title="' . htmlspecialchars( $params[1] ). '">' . $wgLang->translateBlockExpiry( $params[1] ) . '</span>';
215213 } else {
@@ -328,7 +326,7 @@
329327 $permission = ( $row->log_deleted & self::DELETED_RESTRICTED ) == self::DELETED_RESTRICTED
330328 ? 'hiderevision'
331329 : 'deleterevision';
332 - wfDebug( "Checking for $permission due to $field match on $event->log_deleted\n" );
 330+ wfDebug( "Checking for $permission due to $field match on $row->log_deleted\n" );
333331 return $wgUser->isAllowed( $permission );
334332 } else {
335333 return true;

Follow-up revisions

Rev.Commit summaryAuthorDate
r32702Fix a regression from r32685: Show a nice error message instead of a useless ...raymond12:20, 2 April 2008

Status & tagging log

  • 15:25, 12 September 2011 Meno25 (talk | contribs) changed the status of r32685 [removed: ok added: old]