r91801 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91800‎ | r91801 | r91802 >
Date:19:20, 9 July 2011
Author:kaldari
Status:ok
Tags:
Comment:
setting up pagination for the campaign logs
Modified paths:
  • /trunk/extensions/CentralNotice/CentralNotice.i18n.php (modified) (history)
  • /trunk/extensions/CentralNotice/special/SpecialCentralNoticeLogs.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/special/SpecialCentralNoticeLogs.php
@@ -68,65 +68,126 @@
6969 * Show a log.
7070 */
7171 function showLog( $logType ) {
72 - global $wgOut, $wgLang;
 72+ global $wgOut;
7373
 74+ $pager = new CentralNoticeLogPager( $this );
7475 $htmlOut = '';
7576
7677 // Begin log fieldset
7778 $htmlOut .= Xml::openElement( 'fieldset', array( 'class' => 'prefsection' ) );
7879
79 - $campaignLogs = $this->getCampaignLogs();
 80+ // Show paginated list of log entries
 81+ $htmlOut .= Xml::tags( 'div',
 82+ array( 'class' => 'cn-pager' ),
 83+ $pager->getNavigationBar() );
 84+ $htmlOut .= $pager->getBody();
 85+ $htmlOut .= Xml::tags( 'div',
 86+ array( 'class' => 'cn-pager' ),
 87+ $pager->getNavigationBar() );
8088
81 - foreach( $campaignLogs as $campaignLog ) {
82 - $htmlOut .= Xml::openElement( 'div', array( 'class' => 'cn-log-entry' ) );
83 -
84 - // Create a user object so we can pull the name, user page link, etc.
85 - $loggedUser = User::newFromId( $campaignLog['user_id'] );
86 -
87 - $htmlOut .= Xml::tags( 'span', null,
88 - $wgLang->date( $campaignLog['timestamp'] ) . ' ' // date
89 - . $wgLang->time( $campaignLog['timestamp'] ) . ' ' // time
90 - . $loggedUser->getName() . ' ' // user
91 - . $campaignLog['action'] . ' ' // action
92 - . $campaignLog['campaign_name']. ' '. strtolower( wfMsg( 'centralnotice-notice' ) ) // campaign
93 - );
94 -
95 - $htmlOut .= Xml::closeElement( 'div', array( 'class' => 'cn-log-entry' ) );
96 - }
97 -
9889 // End log fieldset
9990 $htmlOut .= Xml::closeElement( 'fieldset' );
10091
10192 $wgOut->addHTML( $htmlOut );
10293 }
 94+
 95+}
 96+
 97+class CentralNoticeLogPager extends ReverseChronologicalPager {
 98+ var $special;
 99+
 100+ function __construct( $special ) {
 101+ $this->special = $special;
 102+ parent::__construct();
 103+
 104+ // Override paging defaults
 105+ list( $this->mLimit, /* $offset */ ) = $this->mRequest->getLimitOffset( 20, '' );
 106+ $this->mLimitsShown = array( 20, 50, 100 );
 107+ }
103108
104 - function getCampaignLogs() {
105 - global $wgCentralDBname;
106 - $dbr = wfGetDB( DB_SLAVE, array(), $wgCentralDBname );
107 - $logs = array();
108 -
109 - $results = $dbr->select( 'cn_notice_log',
110 - array(
 109+ /**
 110+ * Sort the log list by timestamp
 111+ */
 112+ function getIndexField() {
 113+ return 'notlog_timestamp';
 114+ }
 115+
 116+ /**
 117+ * Pull log entries from the database
 118+ */
 119+ function getQueryInfo() {
 120+ return array(
 121+ 'tables' => array( 'cn_notice_log' ),
 122+ 'fields' => array(
111123 'notlog_timestamp',
112124 'notlog_user_id',
113125 'notlog_action',
114126 'notlog_not_id',
115127 'notlog_not_name',
116 - ),
117 - null,
118 - __METHOD__,
119 - array( 'ORDER BY' => 'notlog_timestamp DESC' )
 128+ )
120129 );
121 - foreach ( $results as $row ) {
122 - $logs[] = array(
123 - 'timestamp' => $row->notlog_timestamp,
124 - 'user_id' => $row->notlog_user_id,
125 - 'action' => $row->notlog_action,
126 - 'campaign_id' => $row->notlog_not_id,
127 - 'campaign_name' => $row->notlog_not_name,
128 - );
129 - }
130 - return $logs;
131130 }
132 -
 131+
 132+ /**
 133+ * Generate the content of each table row (1 row = 1 log entry)
 134+ */
 135+ function formatRow( $row ) {
 136+ global $wgLang;
 137+
 138+ // Create a user object so we can pull the name, user page link, etc.
 139+ $loggedUser = User::newFromId( $row->notlog_user_id );
 140+
 141+ // Begin banner row
 142+ $htmlOut = Xml::openElement( 'tr' );
 143+
 144+ $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ),
 145+ $wgLang->date( $row->notlog_timestamp ) . ' ' . $wgLang->time( $row->notlog_timestamp )
 146+ );
 147+ $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ),
 148+ $loggedUser->getName()
 149+ );
 150+ $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ),
 151+ $row->notlog_action
 152+ );
 153+ $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ),
 154+ $row->notlog_not_name
 155+ );
 156+
 157+ // End banner row
 158+ $htmlOut .= Xml::closeElement( 'tr' );
 159+
 160+ return $htmlOut;
 161+ }
 162+
 163+ /**
 164+ * Specify table headers
 165+ */
 166+ function getStartBody() {
 167+ $htmlOut = '';
 168+ $htmlOut .= Xml::openElement( 'table', array( 'cellpadding' => 9 ) );
 169+ $htmlOut .= Xml::openElement( 'tr' );
 170+ $htmlOut .= Xml::element( 'th', array( 'align' => 'left' ),
 171+ wfMsg ( 'centralnotice-timestamp' )
 172+ );
 173+ $htmlOut .= Xml::element( 'th', array( 'align' => 'left' ),
 174+ wfMsg ( 'centralnotice-user' )
 175+ );
 176+ $htmlOut .= Xml::element( 'th', array( 'align' => 'left' ),
 177+ wfMsg ( 'centralnotice-action' )
 178+ );
 179+ $htmlOut .= Xml::element( 'th', array( 'align' => 'left' ),
 180+ wfMsg ( 'centralnotice-notice' )
 181+ );
 182+ $htmlOut .= Xml::closeElement( 'tr' );
 183+ return $htmlOut;
 184+ }
 185+
 186+ /**
 187+ * Close table
 188+ */
 189+ function getEndBody() {
 190+ $htmlOut = '';
 191+ $htmlOut .= Xml::closeElement( 'table' );
 192+ return $htmlOut;
 193+ }
133194 }
Index: trunk/extensions/CentralNotice/CentralNotice.i18n.php
@@ -146,6 +146,9 @@
147147 'centralnotice-preferred' => 'Preferred',
148148 'centralnotice-logs' => 'Logs',
149149 'centralnotice-view-logs' => 'View logs',
 150+ 'centralnotice-timestamp' => 'Timestamp',
 151+ 'centralnotice-user' => 'User',
 152+ 'centralnotice-action' => 'Action',
150153 );
151154
152155 /** Message documentation (Message documentation)

Status & tagging log