Index: trunk/extensions/CentralNotice/special/SpecialCentralNoticeLogs.php |
— | — | @@ -68,65 +68,126 @@ |
69 | 69 | * Show a log. |
70 | 70 | */ |
71 | 71 | function showLog( $logType ) { |
72 | | - global $wgOut, $wgLang; |
| 72 | + global $wgOut; |
73 | 73 | |
| 74 | + $pager = new CentralNoticeLogPager( $this ); |
74 | 75 | $htmlOut = ''; |
75 | 76 | |
76 | 77 | // Begin log fieldset |
77 | 78 | $htmlOut .= Xml::openElement( 'fieldset', array( 'class' => 'prefsection' ) ); |
78 | 79 | |
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() ); |
80 | 88 | |
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 | | - |
98 | 89 | // End log fieldset |
99 | 90 | $htmlOut .= Xml::closeElement( 'fieldset' ); |
100 | 91 | |
101 | 92 | $wgOut->addHTML( $htmlOut ); |
102 | 93 | } |
| 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 | + } |
103 | 108 | |
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( |
111 | 123 | 'notlog_timestamp', |
112 | 124 | 'notlog_user_id', |
113 | 125 | 'notlog_action', |
114 | 126 | 'notlog_not_id', |
115 | 127 | 'notlog_not_name', |
116 | | - ), |
117 | | - null, |
118 | | - __METHOD__, |
119 | | - array( 'ORDER BY' => 'notlog_timestamp DESC' ) |
| 128 | + ) |
120 | 129 | ); |
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; |
131 | 130 | } |
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 | + } |
133 | 194 | } |
Index: trunk/extensions/CentralNotice/CentralNotice.i18n.php |
— | — | @@ -146,6 +146,9 @@ |
147 | 147 | 'centralnotice-preferred' => 'Preferred', |
148 | 148 | 'centralnotice-logs' => 'Logs', |
149 | 149 | 'centralnotice-view-logs' => 'View logs', |
| 150 | + 'centralnotice-timestamp' => 'Timestamp', |
| 151 | + 'centralnotice-user' => 'User', |
| 152 | + 'centralnotice-action' => 'Action', |
150 | 153 | ); |
151 | 154 | |
152 | 155 | /** Message documentation (Message documentation) |