r92701 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92700‎ | r92701 | r92702 >
Date:22:21, 20 July 2011
Author:kaldari
Status:ok
Tags:
Comment:
very beginning of banner setting logging - mostly doesnt work currently
Modified paths:
  • /trunk/extensions/CentralNotice/CentralNotice.i18n.php (modified) (history)
  • /trunk/extensions/CentralNotice/CentralNotice.php (modified) (history)
  • /trunk/extensions/CentralNotice/patches/patch-template_log.sql (added) (history)
  • /trunk/extensions/CentralNotice/special/SpecialCentralNoticeLogs.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/CentralNotice.php
@@ -149,6 +149,8 @@
150150 $base . '/patches/patch-notice_projects.sql' );
151151 $wgExtNewTables[] = array( 'cn_notice_log',
152152 $base . '/patches/patch-notice_log.sql' );
 153+ $wgExtNewTables[] = array( 'cn_template_log',
 154+ $base . '/patches/patch-template_log.sql' );
153155 }
154156 } else {
155157 if ( $updater->getDB()->getType() == 'mysql' ) {
@@ -168,6 +170,8 @@
169171 $base . '/patches/patch-notice_projects.sql', true ) );
170172 $updater->addExtensionUpdate( array( 'addTable', 'cn_notice_log',
171173 $base . '/patches/patch-notice_log.sql', true ) );
 174+ $updater->addExtensionUpdate( array( 'addTable', 'cn_template_log',
 175+ $base . '/patches/patch-template_log.sql', true ) );
172176 }
173177 }
174178 return true;
Index: trunk/extensions/CentralNotice/special/SpecialCentralNoticeLogs.php
@@ -51,32 +51,41 @@
5252
5353 $htmlOut .= Xml::openElement( 'form', array( 'method' => 'post' ) );
5454 $htmlOut .= Xml::element( 'h2', null, wfMsg( 'centralnotice-view-logs' ) );
 55+ // TODO: interface for switching between log types.
 56+ $htmlOut .= Xml::openElement( 'div', array( 'id' => 'cn-log-switcher' ) );
 57+
 58+ $htmlOut .= Xml::radio( 'log_type', 'campaign', true );
 59+ $htmlOut .= Xml::label( wfMsg( 'centralnotice-campaign-settings' ), 'campaign' );
 60+
 61+ $htmlOut .= Xml::radio( 'log_type', 'banner', false );
 62+ $htmlOut .= Xml::label( wfMsg( 'centralnotice-banner-settings' ), 'banner' );
 63+
 64+ $htmlOut .= Xml::closeElement( 'div' );
5565 $htmlOut .= Xml::closeElement( 'form' );
5666
5767 // End log selection fieldset
58 - // Uncomment when we have multiple logs
59 - //$htmlOut .= Xml::closeElement( 'fieldset' );
 68+ $htmlOut .= Xml::closeElement( 'fieldset' );
6069
6170 $wgOut->addHTML( $htmlOut );
6271
63 - $this->showLog( $this->logType );
 72+ $this->showCampaignLog( $this->logType );
6473
6574 // End Banners tab content
6675 $wgOut->addHTML( Xml::closeElement( 'div' ) );
6776 }
6877
6978 /**
70 - * Show a log.
 79+ * Show a log of campaign changes.
7180 */
72 - function showLog( $logType ) {
 81+ function showCampaignLog( $logType ) {
7382 global $wgOut;
7483
75 - $pager = new CentralNoticeLogPager( $this );
 84+ //$pager = new CentralNoticeLogPager( $this );
 85+ $pager = new CentralNoticeBannerLogPager( $this );
7686 $htmlOut = '';
7787
7888 // Begin log fieldset
79 - // Uncomment when we have multiple logs
80 - //$htmlOut .= Xml::openElement( 'fieldset', array( 'class' => 'prefsection' ) );
 89+ $htmlOut .= Xml::openElement( 'fieldset', array( 'class' => 'prefsection' ) );
8190
8291 // Show paginated list of log entries
8392 $htmlOut .= Xml::tags( 'div',
@@ -397,4 +406,137 @@
398407 $htmlOut .= Xml::closeElement( 'table' );
399408 return $htmlOut;
400409 }
 410+
401411 }
 412+
 413+class CentralNoticeBannerLogPager extends ReverseChronologicalPager {
 414+ var $viewPage, $special;
 415+
 416+ function __construct( $special ) {
 417+ $this->special = $special;
 418+ parent::__construct();
 419+
 420+ $this->viewPage = SpecialPage::getTitleFor( 'NoticeTemplate', 'view' );
 421+ }
 422+
 423+ /**
 424+ * Sort the log list by timestamp
 425+ */
 426+ function getIndexField() {
 427+ return 'templog_timestamp';
 428+ }
 429+
 430+ /**
 431+ * Pull log entries from the database
 432+ */
 433+ function getQueryInfo() {
 434+ return array(
 435+ 'tables' => array( 'cn_template_log' ),
 436+ 'fields' => '*',
 437+ );
 438+ }
 439+
 440+ /**
 441+ * Generate the content of each table row (1 row = 1 log entry)
 442+ */
 443+ function formatRow( $row ) {
 444+ global $wgLang, $wgExtensionAssetsPath;
 445+
 446+ // Create a user object so we can pull the name, user page, etc.
 447+ $loggedUser = User::newFromId( $row->templog_user_id );
 448+ // Create the user page link
 449+ $userLink = $this->getSkin()->makeLinkObj( $loggedUser->getUserPage(),
 450+ $loggedUser->getName() );
 451+ $userTalkLink = $this->getSkin()->makeLinkObj( $loggedUser->getTalkPage(),
 452+ wfMsg ( 'centralnotice-talk-link' ) );
 453+
 454+ // Create the banner link
 455+ $bannerLink = $this->getSkin()->makeLinkObj( $this->viewPage,
 456+ htmlspecialchars( $row->templog_template_name ),
 457+ 'template=' . urlencode( $row->templog_template_name ) );
 458+
 459+ // Begin log entry primary row
 460+ $htmlOut = Xml::openElement( 'tr' );
 461+
 462+ $htmlOut .= Xml::openElement( 'td', array( 'valign' => 'top' ) );
 463+ if ( $row->templog_action !== 'removed' ) {
 464+ $htmlOut .= '<a href="javascript:toggleDisplay(\''.$row->templog_id.'\')">'.
 465+ '<img src="'.$wgExtensionAssetsPath.'/CentralNotice/collapsed.png" id="cn-collapsed-'.$row->templog_id.'" style="display:block;vertical-align:baseline;"/>'.
 466+ '<img src="'.$wgExtensionAssetsPath.'/CentralNotice/uncollapsed.png" id="cn-uncollapsed-'.$row->templog_id.'" style="display:none;vertical-align:baseline;"/>'.
 467+ '</a>';
 468+ }
 469+ $htmlOut .= Xml::closeElement( 'td' );
 470+ $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top', 'class' => 'primary' ),
 471+ $wgLang->date( $row->templog_timestamp ) . ' ' . $wgLang->time( $row->templog_timestamp )
 472+ );
 473+ $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top', 'class' => 'primary' ),
 474+ wfMsg ( 'centralnotice-user-links', $userLink, $userTalkLink )
 475+ );
 476+ $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top', 'class' => 'primary' ),
 477+ $row->templog_action
 478+ );
 479+ $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top', 'class' => 'primary' ),
 480+ $bannerLink
 481+ );
 482+ $htmlOut .= Xml::tags( 'td', array(),
 483+ '&nbsp;'
 484+ );
 485+
 486+ // End log entry primary row
 487+ $htmlOut .= Xml::closeElement( 'tr' );
 488+
 489+ if ( $row->templog_action !== 'removed' ) {
 490+ // Begin log entry secondary row
 491+ $htmlOut .= Xml::openElement( 'tr', array( 'id' => 'cn-log-details-'.$row->templog_id, 'style' => 'display:none;' ) );
 492+
 493+ $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ),
 494+ '&nbsp;' // force a table cell in older browsers
 495+ );
 496+ $htmlOut .= Xml::openElement( 'td', array( 'valign' => 'top', 'colspan' => '5' ) );
 497+ if ( $row->templog_action == 'created' ) {
 498+ //$htmlOut .= $this->showInitialSettings( $row );
 499+ } else if ( $row->templog_action == 'modified' ) {
 500+ //$htmlOut .= $this->showChanges( $row );
 501+ }
 502+ $htmlOut .= Xml::closeElement( 'td' );
 503+
 504+ // End log entry primary row
 505+ $htmlOut .= Xml::closeElement( 'tr' );
 506+ }
 507+
 508+ return $htmlOut;
 509+ }
 510+
 511+ function getStartBody() {
 512+ $htmlOut = '';
 513+ $htmlOut .= Xml::openElement( 'table', array( 'id' => 'cn-campaign-logs', 'cellpadding' => 3 ) );
 514+ $htmlOut .= Xml::openElement( 'tr' );
 515+ $htmlOut .= Xml::element( 'th', array( 'style' => 'width: 20px;' ) );
 516+ $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 'style' => 'width: 130px;' ),
 517+ wfMsg ( 'centralnotice-timestamp' )
 518+ );
 519+ $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 'style' => 'width: 160px;' ),
 520+ wfMsg ( 'centralnotice-user' )
 521+ );
 522+ $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 'style' => 'width: 100px;' ),
 523+ wfMsg ( 'centralnotice-action' )
 524+ );
 525+ $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 'style' => 'width: 160px;' ),
 526+ wfMsg ( 'centralnotice-banner' )
 527+ );
 528+ $htmlOut .= Xml::tags( 'td', array(),
 529+ '&nbsp;'
 530+ );
 531+ $htmlOut .= Xml::closeElement( 'tr' );
 532+ return $htmlOut;
 533+ }
 534+
 535+ /**
 536+ * Close table
 537+ */
 538+ function getEndBody() {
 539+ $htmlOut = '';
 540+ $htmlOut .= Xml::closeElement( 'table' );
 541+ return $htmlOut;
 542+ }
 543+}
Index: trunk/extensions/CentralNotice/patches/patch-template_log.sql
@@ -0,0 +1,22 @@
 2+-- Update to allow for logging of changes to banner settings.
 3+
 4+CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/cn_template_log (
 5+ `templog_id` int unsigned NOT NULL PRIMARY KEY auto_increment,
 6+ `templog_timestamp` binary(14) NOT NULL,
 7+ `templog_user_id` int unsigned NOT NULL,
 8+ `templog_action` enum('created','modified','removed') NOT NULL DEFAULT 'modified',
 9+ `templog_template_id` int unsigned NOT NULL,
 10+ `templog_template_name` varchar(255) DEFAULT NULL,
 11+ `templog_begin_anon_display` tinyint(1) DEFAULT NULL,
 12+ `templog_end_anon_display` tinyint(1) DEFAULT NULL,
 13+ `templog_begin_account_display` tinyint(1) DEFAULT NULL,
 14+ `templog_end_account_display` tinyint(1) DEFAULT NULL,
 15+ `templog_begin_fundraising` tinyint(1) DEFAULT NULL,
 16+ `templog_end_fundraising` tinyint(1) DEFAULT NULL,
 17+ `templog_begin_landing_pages` varchar(255) DEFAULT NULL,
 18+ `templog_end_landing_pages` varchar(255) DEFAULT NULL,
 19+ `templog_content_change` tinyint(1) DEFAULT 0
 20+) /*$wgDBTableOptions*/;
 21+CREATE INDEX /*i*/templog_timestamp ON /*_*/cn_template_log (templog_timestamp);
 22+CREATE INDEX /*i*/templog_user_id ON /*_*/cn_template_log (templog_user_id, templog_timestamp);
 23+CREATE INDEX /*i*/templog_template_id ON /*_*/cn_template_log (templog_template_id, templog_timestamp);
\ No newline at end of file
Index: trunk/extensions/CentralNotice/CentralNotice.i18n.php
@@ -161,6 +161,8 @@
162162 'centralnotice-talk-link' => 'talk',
163163 'centralnotice-user-links' => '$1 ($2)',
164164 'centralnotice-log-label' => '<span class="cn-log-label">$1:</span> $2',
 165+ 'centralnotice-campaign-settings' => 'Campaign settings',
 166+ 'centralnotice-banner-settings' => 'Banner settings',
165167 );
166168
167169 /** Message documentation (Message documentation)
@@ -253,6 +255,8 @@
254256 'centralnotice-talk-link' => 'Link for user talk page; should be lower case.',
255257 'centralnotice-user-links' => '$1 is a link to the user page, $2 is a link to the user talk page.',
256258 'centralnotice-log-label' => '$1 is a label for a setting, $2 is the value of the setting (or changes to the setting)',
 259+ 'centralnotice-campaign-settings' => 'Label for a radio button',
 260+ 'centralnotice-banner-settings' => 'Label for a radio button',
257261 );
258262
259263 /** Afrikaans (Afrikaans)

Follow-up revisions

RevisionCommit summaryAuthorDate
r98916MFT r92701, r95822, r95914, r98296awjrichards21:00, 4 October 2011

Status & tagging log