From 441068209bf5d553cc1374a44e18943903f5622a Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 2 Apr 2008 20:20:47 +0000 Subject: [PATCH] Add showLogExtract() and remove use of FauxRequest hacks --- includes/Article.php | 7 +------ includes/EditPage.php | 21 +++++++++------------ includes/FileDeleteForm.php | 12 +----------- includes/LogEventsList.php | 25 ++++++++++++++++++++++++- includes/ProtectionForm.php | 7 +------ includes/SpecialBlockip.php | 4 +--- includes/SpecialMergeHistory.php | 8 +------- includes/SpecialMovepage.php | 4 +--- includes/SpecialRevisiondelete.php | 11 ++--------- includes/SpecialUndelete.php | 12 +----------- includes/SpecialUpload.php | 20 +++++++++----------- includes/SpecialUserrights.php | 12 +----------- 12 files changed, 52 insertions(+), 91 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 1fb6c2b275..9137a1cd3f 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -2156,12 +2156,7 @@ class Article { */ function showLogExtract( $out ) { $out->addHtml( Xml::element( 'h2', null, LogPage::logName( 'delete' ) ) ); - $logViewer = new LogViewer( - new LogReader( - new FauxRequest( - array( 'page' => $this->mTitle->getPrefixedText(), - 'type' => 'delete' ) ) ) ); - $logViewer->showList( $out ); + LogEventsList::showLogExtract( $out, 'delete', $this->mTitle->getPrefixedText() ); } diff --git a/includes/EditPage.php b/includes/EditPage.php index 7faab316cd..409034e9a0 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -2205,20 +2205,17 @@ END * @param OutputPage $out */ private function showDeletionLog( $out ) { - $title = $this->mTitle; - $reader = new LogReader( - new FauxRequest( - array( - 'page' => $title->getPrefixedText(), - 'type' => 'delete', - ) - ) - ); - if( $reader->hasRows() ) { + global $wgUser; + $loglist = new LogEventsList( $wgUser->getSkin() ); + $pager = new LogPager( $loglist, 'delete', false, $this->mTitle->getPrefixedText() ); + if( $pager->getNumRows() > 0 ) { $out->addHtml( '
' ); $out->addWikiMsg( 'recreate-deleted-warn' ); - $viewer = new LogViewer( $reader ); - $viewer->showList( $out ); + $out->addHTML( + $loglist->beginLogEventsList() . + $pager->getBody() . + $loglist->endLogEventsList() + ); $out->addHtml( '
' ); } } diff --git a/includes/FileDeleteForm.php b/includes/FileDeleteForm.php index 16a2d1159e..8a6f058884 100644 --- a/includes/FileDeleteForm.php +++ b/includes/FileDeleteForm.php @@ -179,17 +179,7 @@ class FileDeleteForm { private function showLogEntries() { global $wgOut; $wgOut->addHtml( '

' . htmlspecialchars( LogPage::logName( 'delete' ) ) . "

\n" ); - $reader = new LogViewer( - new LogReader( - new FauxRequest( - array( - 'type' => 'delete', - 'page' => $this->title->getPrefixedText(), - ) - ) - ) - ); - $reader->showList( $wgOut ); + LogEventsList::showLogExtract( $wgOut, 'delete', $this->title->getPrefixedText() ); } /** diff --git a/includes/LogEventsList.php b/includes/LogEventsList.php index a81068df5c..583036fc94 100644 --- a/includes/LogEventsList.php +++ b/includes/LogEventsList.php @@ -318,6 +318,29 @@ class LogEventsList { } /** + * Quick function to show a short log extract + * @param OutputPage $out + * @param string $type + * @param string $page + */ + public static function showLogExtract( $out, $type='', $page='', $user='' ) { + global $wgUser; + # Insert list of top 50 or so items + $loglist = new LogEventsList( $wgUser->getSkin() ); + $pager = new LogPager( $loglist, $type, $user, $page, '' ); + $logBody = $pager->getBody(); + if( $logBody ) { + $out->addHTML( + $loglist->beginLogEventsList() . + $logBody . + $loglist->endLogEventsList() + ); + } else { + $out->addWikiMsg( 'logempty' ); + } + } + + /** * SQL clause to skip forbidden log types for this user * @param Database $db * @returns mixed (string or false) @@ -355,7 +378,7 @@ class LogPager extends ReverseChronologicalPager { * @param string $pattern * @param array $conds */ - function __construct( $loglist, $type, $user, $title, $pattern, $conds = array() ) { + function __construct( $loglist, $type='', $user='', $title='', $pattern='', $conds = array() ) { parent::__construct(); $this->mConds = $conds; diff --git a/includes/ProtectionForm.php b/includes/ProtectionForm.php index 6d3264c606..0d2d88cc34 100644 --- a/includes/ProtectionForm.php +++ b/includes/ProtectionForm.php @@ -374,12 +374,7 @@ class ProtectionForm { function showLogExtract( &$out ) { # Show relevant lines from the protection log: $out->addHTML( Xml::element( 'h2', null, LogPage::logName( 'protect' ) ) ); - $logViewer = new LogViewer( - new LogReader( - new FauxRequest( - array( 'page' => $this->mTitle->getPrefixedText(), - 'type' => 'protect' ) ) ) ); - $logViewer->showList( $out ); + LogEventsList::showLogExtract( $out, 'protect', $this->mTitle->getPrefixedText() ); } } diff --git a/includes/SpecialBlockip.php b/includes/SpecialBlockip.php index e3b828e5c5..aa48968ef9 100644 --- a/includes/SpecialBlockip.php +++ b/includes/SpecialBlockip.php @@ -400,9 +400,7 @@ class IPBlockForm { function showLogFragment( $out, $title ) { $out->addHtml( Xml::element( 'h2', NULL, LogPage::logName( 'block' ) ) ); - $request = new FauxRequest( array( 'page' => $title->getPrefixedText(), 'type' => 'block' ) ); - $viewer = new LogViewer( new LogReader( $request ) ); - $viewer->showList( $out ); + LogEventsList::showLogExtract( $out, 'block', $title->getPrefixedText() ); } /** diff --git a/includes/SpecialMergeHistory.php b/includes/SpecialMergeHistory.php index 8302b7e065..e0de5cc27d 100644 --- a/includes/SpecialMergeHistory.php +++ b/includes/SpecialMergeHistory.php @@ -205,14 +205,8 @@ class MergehistoryForm { # Show relevant lines from the deletion log: $wgOut->addHTML( "

" . htmlspecialchars( LogPage::logName( 'merge' ) ) . "

\n" ); - $logViewer = new LogViewer( - new LogReader( - new FauxRequest( - array( 'page' => $this->mTargetObj->getPrefixedText(), - 'type' => 'merge' ) ) ) ); - $logViewer->showList( $wgOut ); + LogEventsList::showLogExtract( $wgOut, 'merge', $this->mTargetObj->getPrefixedText() ); - # Slip in the hidden controls here # When we submit, go by page ID to avoid some nasty but unlikely collisions. # Such would happen if a page was renamed after the form loaded, but before submit $misc = Xml::hidden( 'targetID', $this->mTargetObj->getArticleID() ); diff --git a/includes/SpecialMovepage.php b/includes/SpecialMovepage.php index 4e844e83f7..3fa67466a4 100644 --- a/includes/SpecialMovepage.php +++ b/includes/SpecialMovepage.php @@ -345,9 +345,7 @@ class MovePageForm { function showLogFragment( $title, &$out ) { $out->addHTML( Xml::element( 'h2', NULL, LogPage::logName( 'move' ) ) ); - $request = new FauxRequest( array( 'page' => $title->getPrefixedText(), 'type' => 'move' ) ); - $viewer = new LogViewer( new LogReader( $request ) ); - $viewer->showList( $out ); + LogEventsList::showLogExtract( $out, 'move', $title->getPrefixedText() ); } } diff --git a/includes/SpecialRevisiondelete.php b/includes/SpecialRevisiondelete.php index bb0f9a7ab0..0a23031b8c 100644 --- a/includes/SpecialRevisiondelete.php +++ b/includes/SpecialRevisiondelete.php @@ -45,17 +45,10 @@ function wfSpecialRevisiondelete( $par = null ) { # does not exist...might be helpful if( !is_null($page) ) { $wgOut->addHTML( "

" . htmlspecialchars( LogPage::logName( 'delete' ) ) . "

\n" ); - $logViewer = new LogViewer( - new LogReader( - new FauxRequest( - array( 'page' => $page->getPrefixedText(), 'type' => 'delete' ) ) ) ); - $logViewer->showList( $wgOut ); + LogEventsList::showLogExtract( $wgOut, 'delete', $page->getPrefixedText() ); if( $wgUser->isAllowed( 'suppress' ) ){ $wgOut->addHTML( "

" . htmlspecialchars( LogPage::logName( 'suppress' ) ) . "

\n" ); - $logViewer = new LogViewer( - new LogReader( - new FauxRequest( - array( 'page' => $page->getPrefixedText(), 'type' => 'suppress' ) ) ) ); + LogEventsList::showLogExtract( $wgOut, 'suppress', $page->getPrefixedText() ); $logViewer->showList( $wgOut ); } } diff --git a/includes/SpecialUndelete.php b/includes/SpecialUndelete.php index ef7944b5aa..a7348155d7 100644 --- a/includes/SpecialUndelete.php +++ b/includes/SpecialUndelete.php @@ -956,17 +956,7 @@ class UndeleteForm { # Show relevant lines from the deletion log: $wgOut->addHTML( Xml::element( 'h2', null, LogPage::logName( 'delete' ) ) . "\n" ); - $logViewer = new LogViewer( - new LogReader( - new FauxRequest( - array( - 'page' => $this->mTargetObj->getPrefixedText(), - 'type' => 'delete' - ) - ) - ), LogViewer::NO_ACTION_LINK - ); - $logViewer->showList( $wgOut ); + LogEventsList::showLogExtract( $wgOut, 'delete', $this->mTargetObj->getPrefixedText() ); if( $this->mAllowed && ( $haveRevisions || $haveFiles ) ) { # Format the user-visible controls (comment field, submission button) diff --git a/includes/SpecialUpload.php b/includes/SpecialUpload.php index a8aa91e1ad..8ea9a8e1d2 100644 --- a/includes/SpecialUpload.php +++ b/includes/SpecialUpload.php @@ -1662,19 +1662,17 @@ wgUploadAutoFill = {$autofill}; * @param string filename */ private function showDeletionLog( $out, $filename ) { - $reader = new LogReader( - new FauxRequest( - array( - 'page' => $filename, - 'type' => 'delete', - ) - ) - ); - if( $reader->hasRows() ) { + global $wgUser; + $loglist = new LogEventsList( $wgUser->getSkin() ); + $pager = new LogPager( $loglist, 'delete', false, $filename ); + if( $pager->getNumRows() > 0 ) { $out->addHtml( '
' ); $out->addWikiMsg( 'upload-wasdeleted' ); - $viewer = new LogViewer( $reader ); - $viewer->showList( $out ); + $out->addHTML( + $loglist->beginLogEventsList() . + $pager->getBody() . + $loglist->endLogEventsList() + ); $out->addHtml( '
' ); } } diff --git a/includes/SpecialUserrights.php b/includes/SpecialUserrights.php index f4caab192f..769d05fd5d 100644 --- a/includes/SpecialUserrights.php +++ b/includes/SpecialUserrights.php @@ -540,17 +540,7 @@ class UserrightsPage extends SpecialPage { * @param OutputPage $output OutputPage to use */ protected function showLogFragment( $user, $output ) { - $viewer = new LogViewer( - new LogReader( - new FauxRequest( - array( - 'type' => 'rights', - 'page' => $user->getUserPage()->getPrefixedText(), - ) - ) - ) - ); $output->addHtml( Xml::element( 'h2', null, LogPage::logName( 'rights' ) . "\n" ) ); - $viewer->showList( $output ); + LogEventsList::showLogExtract( $output, 'rights', $user->getUserPage()->getPrefixedText() ); } } -- 2.20.1