#
# 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
*/
/**
*/
function wfSpecialLog( $par = '' ) {
global $wgRequest;
- $logReader =& new LogReader( $wgRequest );
+ $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;
* @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 );
}
function setupQuery( $request ) {
$page = $this->db->tableName( 'page' );
$user = $this->db->tableName( 'user' );
- $this->joinClauses = array( "LEFT OUTER JOIN $page ON log_namespace=page_namespace AND log_title=page_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' ) );
function limitUser( $name ) {
if ( $name == '' )
return false;
- $title = Title::makeTitle( NS_USER, $name );
- if ( is_null( $title ) )
+ $usertitle = Title::makeTitleSafe( NS_USER, $name );
+ if ( is_null( $usertitle ) )
return false;
- $this->user = $title->getText();
- $safename = $this->db->strencode( $this->user );
- $user = $this->db->tableName( 'user' );
- $this->whereClauses[] = "user_name='$safename'";
+ $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 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, page_id,
- log_comment, log_params FROM $user, $logging ";
+ 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 );
* @return ResultWrapper result object to return the relevant rows
*/
function getRows() {
- $res = $this->db->query( $this->getQuery() );
+ $res = $this->db->query( $this->getQuery(), 'LogReader::getRows' );
return $this->db->resultObject( $res );
}
/**
*
- * @package MediaWiki
- * @subpackage SpecialPage
+ * @addtogroup SpecialPage
*/
class LogViewer {
/**
*/
function LogViewer( &$reader ) {
global $wgUser;
- $this->skin =& $wgUser->getSkin();
+ $this->skin = $wgUser->getSkin();
$this->reader =& $reader;
}
* @return object database result set
*/
function getLogRows() {
- global $wgLinkCache;
$result = $this->reader->getRows();
$this->numResults = 0;
$batch = new LinkBatch;
while ( $s = $result->fetchObject() ) {
// User link
- $title = Title::makeTitleSafe( NS_USER, $s->user_name );
- $batch->addObj( $title );
+ $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' ) {
}
++$this->numResults;
}
- $batch->execute( $wgLinkCache );
+ $batch->execute();
return $result;
}
function doShowList( &$out, $result ) {
// Rewind result pointer and go through it again, making the HTML
- $html='';
if ($this->numResults > 0) {
$html = "\n<ul>\n";
$result->seek( 0 );
$html .= $this->logLine( $s );
}
$html .= "\n</ul>\n";
+ $out->addHTML( $html );
+ } else {
+ $out->addWikiText( wfMsg( 'logempty' ) );
}
$result->free();
- $out->addHTML( $html );
}
/**
* @private
*/
function logLine( $s ) {
- global $wgLang, $wgLinkCache;
+ global $wgLang;
$title = Title::makeTitle( $s->log_namespace, $s->log_title );
- $user = Title::makeTitleSafe( NS_USER, $s->user_name );
$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 ) {
- $wgLinkCache->addGoodLinkObj( $s->page_id, $title );
+ $linkCache->addGoodLinkObj( $s->page_id, $title );
} else {
- $wgLinkCache->addBadLinkObj( $title );
+ $linkCache->addBadLinkObj( $title );
}
- $userLink = $this->skin->makeLinkObj( $user, htmlspecialchars( $s->user_name ) );
+ $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 = '';
if ( $s->log_type == 'move' && isset( $paramArray[0] ) ) {
- $specialTitle = Title::makeTitle( NS_SPECIAL, 'Movepage' );
+ $specialTitle = SpecialPage::getTitleFor( 'Movepage' );
$destTitle = Title::newFromText( $paramArray[0] );
if ( $destTitle ) {
$revert = '(' . $this->skin->makeKnownLinkObj( $specialTitle, wfMsg( 'revertmove' ),
function showOptions( &$out ) {
global $wgScript;
$action = htmlspecialchars( $wgScript );
- $title = Title::makeTitle( NS_SPECIAL, 'Log' );
+ $title = SpecialPage::getTitleFor( 'Log' );
$special = htmlspecialchars( $title->getPrefixedDBkey() );
$out->addHTML( "<form action=\"$action\" method=\"get\">\n" .
- "<input type='hidden' name='title' value=\"$special\" />\n" .
- $this->getTypeMenu() .
- $this->getUserInput() .
- $this->getTitleInput() .
- "<input type='submit' value=\"" . wfMsg( 'allpagessubmit' ) . "\" />" .
+ Xml::hidden( 'title', $special ) . "\n" .
+ $this->getTypeMenu() . "\n" .
+ $this->getUserInput() . "\n" .
+ $this->getTitleInput() . "\n" .
+ Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
"</form>" );
}
function getTypeMenu() {
$out = "<select name='type'>\n";
foreach( LogPage::validTypes() as $type ) {
- $text = htmlspecialchars( LogPage::logName( $type ) );
- $selected = ($type == $this->reader->queryType()) ? ' selected="selected"' : '';
- $out .= "<option value=\"$type\"$selected>$text</option>\n";
+ $text = LogPage::logName( $type );
+ $selected = ($type == $this->reader->queryType());
+ $out .= Xml::option( $text, $type, $selected ) . "\n";
}
- $out .= "</select>\n";
+ $out .= '</select>';
return $out;
}
* @private
*/
function getUserInput() {
- $user = htmlspecialchars( $this->reader->queryUser() );
- return wfMsg('specialloguserlabel') . "<input type='text' name='user' size='12' value=\"$user\" />\n";
+ $user = $this->reader->queryUser();
+ return Xml::inputLabel( wfMsg( 'specialloguserlabel' ), 'user', 'user', 12, $user );
}
/**
* @private
*/
function getTitleInput() {
- $title = htmlspecialchars( $this->reader->queryTitle() );
- return wfMsg('speciallogtitlelabel') . "<input type='text' name='page' size='20' value=\"$title\" />\n";
+ $title = $this->reader->queryTitle();
+ return Xml::inputLabel( wfMsg( 'speciallogtitlelabel' ), 'page', 'page', 20, $title );
}
/**