http://www.mediawiki.org/wiki/Special:Code/MediaWiki/95822

Revision: 95822
Author:   kaldari
Date:     2011-08-31 00:06:51 +0000 (Wed, 31 Aug 2011)
Log Message:
-----------
adding banner content and banner message logging to CentralNotice

Modified Paths:
--------------
    trunk/extensions/CentralNotice/CentralNotice.i18n.php
    trunk/extensions/CentralNotice/CentralNotice.php
    trunk/extensions/CentralNotice/CentralNoticeBannerLogPager.php
    trunk/extensions/CentralNotice/special/SpecialCentralNoticeLogs.php

Added Paths:
-----------
    trunk/extensions/CentralNotice/CentralNoticeCampaignLogPager.php
    trunk/extensions/CentralNotice/CentralNoticePageLogPager.php

Removed Paths:
-------------
    trunk/extensions/CentralNotice/CentralNoticeLogPager.php

Modified: trunk/extensions/CentralNotice/CentralNotice.i18n.php
===================================================================
--- trunk/extensions/CentralNotice/CentralNotice.i18n.php       2011-08-30 
23:27:19 UTC (rev 95821)
+++ trunk/extensions/CentralNotice/CentralNotice.i18n.php       2011-08-31 
00:06:51 UTC (rev 95822)
@@ -139,6 +139,7 @@
        'centralnotice-view-allocation' => 'View banner allocation',
        'centralnotice-allocation-instructions' => 'Choose the environment you 
would like to view banner allocation for:',
        'centralnotice-languages' => 'Languages',
+       'centralnotice-language' => 'Language',
        'centralnotice-projects' => 'Projects',
        'centralnotice-country' => 'Country',
        'centralnotice-no-allocation' => 'No banners allocated.',
@@ -172,6 +173,7 @@
        'centralnotice-date' => 'Date',
        'centralnotice-apply-filters' => 'Apply filters',
        'centralnotice-clear-filters' => 'Clear filters',
+       'centralnotice-banner-messages' => 'Banner messages',
 );
 
 /** Message documentation (Message documentation)

Modified: trunk/extensions/CentralNotice/CentralNotice.php
===================================================================
--- trunk/extensions/CentralNotice/CentralNotice.php    2011-08-30 23:27:19 UTC 
(rev 95821)
+++ trunk/extensions/CentralNotice/CentralNotice.php    2011-08-31 00:06:51 UTC 
(rev 95822)
@@ -110,6 +110,7 @@
 
        $wgAutoloadClasses['CentralNotice'] = $specialDir . 
'SpecialCentralNotice.php';
        $wgAutoloadClasses['CentralNoticeDB'] = $dir . 'CentralNotice.db.php';
+       $wgAutoloadClasses['CentralNoticeMessageChanges'] = $dir . 
'CentralNoticeMessageChanges.php';
 
        if ( $wgNoticeInfrastructure ) {
                $wgSpecialPages['CentralNotice'] = 'CentralNotice';
@@ -126,8 +127,9 @@
                
                $wgAutoloadClasses['TemplatePager'] = $dir . 
'TemplatePager.php';
                $wgAutoloadClasses['CentralNoticePager'] = $dir . 
'CentralNoticePager.php';
-               $wgAutoloadClasses['CentralNoticeLogPager'] = $dir . 
'CentralNoticeLogPager.php';
+               $wgAutoloadClasses['CentralNoticeCampaignLogPager'] = $dir . 
'CentralNoticeCampaignLogPager.php';
                $wgAutoloadClasses['CentralNoticeBannerLogPager'] = $dir . 
'CentralNoticeBannerLogPager.php';
+               $wgAutoloadClasses['CentralNoticePageLogPager'] = $dir . 
'CentralNoticePageLogPager.php';
        }
 }
 

Modified: trunk/extensions/CentralNotice/CentralNoticeBannerLogPager.php
===================================================================
--- trunk/extensions/CentralNotice/CentralNoticeBannerLogPager.php      
2011-08-30 23:27:19 UTC (rev 95821)
+++ trunk/extensions/CentralNotice/CentralNoticeBannerLogPager.php      
2011-08-31 00:06:51 UTC (rev 95822)
@@ -1,6 +1,6 @@
 <?php
 
-class CentralNoticeBannerLogPager extends CentralNoticeLogPager {
+class CentralNoticeBannerLogPager extends CentralNoticeCampaignLogPager {
        var $viewPage, $special;
 
        function __construct( $special ) {

Copied: trunk/extensions/CentralNotice/CentralNoticeCampaignLogPager.php (from 
rev 95820, trunk/extensions/CentralNotice/CentralNoticeLogPager.php)
===================================================================
--- trunk/extensions/CentralNotice/CentralNoticeCampaignLogPager.php            
                (rev 0)
+++ trunk/extensions/CentralNotice/CentralNoticeCampaignLogPager.php    
2011-08-31 00:06:51 UTC (rev 95822)
@@ -0,0 +1,356 @@
+<?php
+
+class CentralNoticeCampaignLogPager extends ReverseChronologicalPager {
+       var $viewPage, $special;
+
+       function __construct( $special ) {
+               global $wgRequest;
+               $this->special = $special;
+               parent::__construct();
+               
+               // Override paging defaults
+               list( $this->mLimit, /* $offset */ ) = 
$this->mRequest->getLimitOffset( 20, '' );
+               $this->mLimitsShown = array( 20, 50, 100 );
+               
+               $this->viewPage = SpecialPage::getTitleFor( 'CentralNotice' );
+       }
+       
+       /**
+        * Sort the log list by timestamp
+        */
+       function getIndexField() {
+       return 'notlog_timestamp';
+       }
+       
+       /**
+        * Pull log entries from the database
+        */
+       function getQueryInfo() {
+               global $wgRequest;
+               
+               $filterStartDate = 0;
+               $filterEndDate = 0;
+               $startYear = $wgRequest->getVal( 'start_year' );
+               if ( $startYear === 'other' ) $startYear = null;
+               $startMonth = $wgRequest->getVal( 'start_month' );
+               if ( $startMonth === 'other' ) $startMonth = null;
+               $startDay = $wgRequest->getVal( 'start_day' );
+               if ( $startDay === 'other' ) $startDay = null;
+               $endYear = $wgRequest->getVal( 'end_year' );
+               if ( $endYear === 'other' ) $endYear = null;
+               $endMonth = $wgRequest->getVal( 'end_month' );
+               if ( $endMonth === 'other' ) $endMonth = null;
+               $endDay = $wgRequest->getVal( 'end_day' );
+               if ( $endDay === 'other' ) $endDay = null;
+                       
+               if ( $startYear && $startMonth && $startDay ) {
+                       $filterStartDate = $startYear . $startMonth . $startDay;
+               }
+               if ( $endYear && $endMonth && $endDay ) {
+                       $filterEndDate = $endYear . $endMonth . $endDay;
+               }
+               $filterCampaign = $wgRequest->getVal( 'campaign' );
+               $filterUser = $wgRequest->getVal( 'user' );
+               $reset = $wgRequest->getVal( 'centralnoticelogreset' );
+               
+               $info = array(
+                       'tables' => array( 'cn_notice_log' ),
+                       'fields' => '*',
+                       'conds' => array()
+               );
+               
+               if ( !$reset ) {
+                       if ( $filterStartDate > 0 ) {
+                               $filterStartDate = intval( 
$filterStartDate.'000000' );
+                               $info['conds'][] = "notlog_timestamp >= 
$filterStartDate";
+                       }
+                       if ( $filterEndDate > 0 ) {
+                               $filterEndDate = intval( 
$filterEndDate.'000000' );
+                               $info['conds'][] = "notlog_timestamp < 
$filterEndDate";
+                       }
+                       if ( $filterCampaign ) {
+                               $info['conds'][] = "notlog_not_name LIKE 
'$filterCampaign'";
+                       }
+                       if ( $filterUser ) {
+                               $user = User::newFromName( $filterUser );
+                               $userId = $user->getId();
+                               $info['conds'][] = "notlog_user_id = $userId";
+                       }
+               }
+               
+               return $info;
+       }
+       
+       /** 
+        * Generate the content of each table row (1 row = 1 log entry)
+        */
+       function formatRow( $row ) {
+               global $wgLang, $wgExtensionAssetsPath;
+               
+               // Create a user object so we can pull the name, user page, etc.
+               $loggedUser = User::newFromId( $row->notlog_user_id );
+               // Create the user page link
+               $userLink = $this->getSkin()->makeLinkObj( 
$loggedUser->getUserPage(), 
+                       $loggedUser->getName() );
+               $userTalkLink = $this->getSkin()->makeLinkObj( 
$loggedUser->getTalkPage(), 
+                       wfMsg ( 'centralnotice-talk-link' ) );
+               
+               // Create the campaign link
+               $campaignLink = $this->getSkin()->makeLinkObj( $this->viewPage,
+                       htmlspecialchars( $row->notlog_not_name ),
+                       'method=listNoticeDetail&notice=' . urlencode( 
$row->notlog_not_name ) );
+                               
+               // Begin log entry primary row
+               $htmlOut = Xml::openElement( 'tr' );
+               
+               $htmlOut .= Xml::openElement( 'td', array( 'valign' => 'top' ) 
);
+               if ( $row->notlog_action !== 'removed' ) {
+                       $htmlOut .= '<a 
href="javascript:toggleLogDisplay(\''.$row->notlog_id.'\')">'.
+                               '<img 
src="'.$wgExtensionAssetsPath.'/CentralNotice/collapsed.png" 
id="cn-collapsed-'.$row->notlog_id.'" style="display:block;"/>'.
+                               '<img 
src="'.$wgExtensionAssetsPath.'/CentralNotice/uncollapsed.png" 
id="cn-uncollapsed-'.$row->notlog_id.'" style="display:none;"/>'.
+                               '</a>';
+               }
+               $htmlOut .= Xml::closeElement( 'td' );
+               $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top', 'class' 
=> 'primary' ),
+                       $wgLang->date( $row->notlog_timestamp ) . ' ' . 
$wgLang->time( $row->notlog_timestamp )
+               );
+               $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top', 'class' 
=> 'primary' ),
+                       wfMsg ( 'centralnotice-user-links', $userLink, 
$userTalkLink )
+               );
+               $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top', 'class' 
=> 'primary' ),
+                       $row->notlog_action
+               );
+               $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top', 'class' 
=> 'primary' ),
+                       $campaignLink
+               );
+               $htmlOut .= Xml::tags( 'td', array(),
+                       '&nbsp;'
+               );
+               
+               // End log entry primary row
+               $htmlOut .= Xml::closeElement( 'tr' );
+               
+               if ( $row->notlog_action !== 'removed' ) {
+                       // Begin log entry secondary row
+                       $htmlOut .= Xml::openElement( 'tr', array( 'id' => 
'cn-log-details-'.$row->notlog_id, 'style' => 'display:none;' ) );
+                       
+                       $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ),
+                               '&nbsp;' // force a table cell in older browsers
+                       );
+                       $htmlOut .= Xml::openElement( 'td', array( 'valign' => 
'top', 'colspan' => '5' ) );
+                       if ( $row->notlog_action == 'created' ) {
+                               $htmlOut .= $this->showInitialSettings( $row );
+                       } else if ( $row->notlog_action == 'modified' ) {
+                               $htmlOut .= $this->showChanges( $row );
+                       }
+                       $htmlOut .= Xml::closeElement( 'td' );
+                       
+                       // End log entry primary row
+                       $htmlOut .= Xml::closeElement( 'tr' );
+               }
+               
+               return $htmlOut;
+       }
+       
+       function showInitialSettings( $row ) {
+               global $wgLang;
+               $details = '';
+               $details .= wfMsg (
+                       'centralnotice-log-label',
+                       wfMsg ( 'centralnotice-start-date' ), 
+                       $wgLang->date( $row->notlog_end_start ).' 
'.$wgLang->time( $row->notlog_end_start )
+               )."<br/>";
+               $details .= wfMsg (
+                       'centralnotice-log-label',
+                       wfMsg ( 'centralnotice-end-date' ),
+                       $wgLang->date( $row->notlog_end_end ).' 
'.$wgLang->time( $row->notlog_end_end )
+               )."<br/>";
+               $details .= wfMsg (
+                       'centralnotice-log-label',
+                       wfMsg ( 'centralnotice-projects' ),
+                       $row->notlog_end_projects
+               )."<br/>";
+               $language_count = count( explode ( ', ', 
$row->notlog_end_languages ) );
+               $languageList = '';
+               if ( $language_count > 15 ) {
+                       $languageList = wfMsg ( 
'centralnotice-multiple-languages', $language_count );
+               } elseif ( $language_count > 0 ) {
+                       $languageList = $row->notlog_end_languages;
+               }
+               $details .= wfMsg (
+                       'centralnotice-log-label',
+                       wfMsg ( 'centralnotice-languages' ),
+                       $languageList
+               )."<br/>";
+               $details .= wfMsg (
+                       'centralnotice-log-label',
+                       wfMsg ( 'centralnotice-geo' ),
+                       ($row->notlog_end_geo ? 'on' : 'off')
+               )."<br/>";
+               if ( $row->notlog_end_geo ) {
+                       $country_count = count( explode ( ', ', 
$row->notlog_end_countries ) );
+                       $countryList = '';
+                       if ( $country_count > 20 ) {
+                               $countryList = wfMsg ( 
'centralnotice-multiple-countries', $country_count );
+                       } elseif ( $country_count > 0 ) {
+                               $countryList = $row->notlog_end_countries;
+                       }
+                       $details .= wfMsg (
+                               'centralnotice-log-label',
+                               wfMsg ( 'centralnotice-countries' ),
+                               $countryList
+                       )."<br/>";
+               }
+               return $details;
+       }
+       
+       function showChanges( $row ) {
+               global $wgLang;
+               $details = '';
+               if ( $row->notlog_begin_start !== $row->notlog_end_start ) {
+                       $details .= wfMsg (
+                               'centralnotice-log-label',
+                               wfMsg ( 'centralnotice-start-date' ),
+                               wfMsg (
+                                       'centralnotice-changed', 
+                                       $wgLang->date( $row->notlog_begin_start 
).' '.$wgLang->time( $row->notlog_begin_start ), 
+                                       $wgLang->date( $row->notlog_end_start 
).' '.$wgLang->time( $row->notlog_end_start )
+                               )
+                       )."<br/>";
+               }
+               if ( $row->notlog_begin_end !== $row->notlog_end_end ) {
+                       $details .= wfMsg (
+                               'centralnotice-log-label',
+                               wfMsg ( 'centralnotice-end-date' ),
+                               wfMsg (
+                                       'centralnotice-changed', 
+                                       $wgLang->date( $row->notlog_begin_end 
).' '.$wgLang->time( $row->notlog_begin_end ), 
+                                       $wgLang->date( $row->notlog_end_end ).' 
'.$wgLang->time( $row->notlog_end_end )
+                               )
+                       )."<br/>";
+               }
+               $details .= $this->testBooleanChange( 'enabled', $row );
+               $details .= $this->testBooleanChange( 'preferred', $row );
+               $details .= $this->testBooleanChange( 'locked', $row );
+               $details .= $this->testBooleanChange( 'geo', $row );
+               $details .= $this->testSetChange( 'projects', $row );
+               $details .= $this->testSetChange( 'languages', $row );
+               $details .= $this->testSetChange( 'countries', $row );
+               if ( $row->notlog_begin_banners !== $row->notlog_end_banners ) {
+                       // Show changes to banner weights and assignment
+                       $beginBannersObject = json_decode( 
$row->notlog_begin_banners );
+                       $endBannersObject = json_decode( 
$row->notlog_end_banners );
+                       $beginBanners = array();
+                       $endBanners = array();
+                       foreach( $beginBannersObject as $key => $weight ) {
+                               $beginBanners[$key] = $key.' ('.$weight.')';
+                       }
+                       foreach( $endBannersObject as $key => $weight ) {
+                               $endBanners[$key] = $key.' ('.$weight.')';
+                       }
+                       if ( $beginBanners ) {
+                               $before = implode( ', ', $beginBanners );
+                       } else {
+                               $before = wfMsg ( 
'centralnotice-no-assignments' );
+                       }
+                       if ( $endBanners ) {
+                               $after = implode( ', ', $endBanners );
+                       } else {
+                               $after = wfMsg ( 'centralnotice-no-assignments' 
);
+                       }
+                       $details .= wfMsg (
+                               'centralnotice-log-label',
+                               wfMsg ( 'centralnotice-templates' ),
+                               wfMsg ( 'centralnotice-changed', $before, 
$after)
+                       )."<br/>";
+               }
+               return $details;
+       }
+       
+       private function testBooleanChange( $param, $row ) {
+               $result = '';
+               $beginField = 'notlog_begin_'.$param;
+               $endField = 'notlog_end_'.$param;
+               if ( $row->$beginField !== $row->$endField ) {
+                       $result .= wfMsg (
+                               'centralnotice-log-label',
+                               wfMsg ( 'centralnotice-'.$param ),
+                               wfMsg (
+                                       'centralnotice-changed', 
+                                       ( $row->$beginField ? wfMsg ( 
'centralnotice-on' ) : wfMsg ( 'centralnotice-off' ) ), 
+                                       ( $row->$endField ? wfMsg ( 
'centralnotice-on' ) : wfMsg ( 'centralnotice-off' ) )
+                               )
+                       )."<br/>";
+               }
+               return $result;
+       }
+       
+       private function testSetChange( $param, $row ) {
+               $result = '';
+               $beginField = 'notlog_begin_'.$param;
+               $endField = 'notlog_end_'.$param;
+               if ( $row->$beginField !== $row->$endField ) {
+                       $beginSet = array();
+                       $endSet = array();
+                       if ( $row->$beginField ) {
+                               $beginSet = explode( ', ', $row->$beginField );
+                       }
+                       if ( $row->$endField ) {
+                               $endSet = explode( ', ', $row->$endField );
+                       }
+                       $added = array_diff( $endSet, $beginSet );
+                       $removed = array_diff( $beginSet, $endSet );
+                       $differences = '';
+                       if ( $added ) {
+                               $differences .= wfMsg ( 'centralnotice-added', 
implode( ', ', $added ) );
+                               if ( $removed ) $differences .= '; ';
+                       }
+                       if ( $removed ) {
+                               $differences .= wfMsg ( 
'centralnotice-removed', implode( ', ', $removed ) );
+                       }
+                       $result .= wfMsg (
+                               'centralnotice-log-label',
+                               wfMsg ( 'centralnotice-'.$param ),
+                               $differences
+                       )."<br/>";
+               }
+               return $result;
+       }
+       
+       /**
+        * Specify table headers
+        */
+       function getStartBody() {
+               $htmlOut = '';
+               $htmlOut .= Xml::openElement( 'table', array( 'id' => 
'cn-campaign-logs', 'cellpadding' => 3 ) );
+               $htmlOut .= Xml::openElement( 'tr' );
+               $htmlOut .= Xml::element( 'th', array( 'style' => 'width: 
20px;' ) );
+               $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 
'style' => 'width: 130px;' ),
+                        wfMsg ( 'centralnotice-timestamp' )
+               );
+               $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 
'style' => 'width: 160px;' ),
+                        wfMsg ( 'centralnotice-user' )
+               );
+               $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 
'style' => 'width: 100px;' ),
+                        wfMsg ( 'centralnotice-action' )
+               );
+               $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 
'style' => 'width: 160px;' ),
+                       wfMsg ( 'centralnotice-notice' )
+               );
+               $htmlOut .= Xml::tags( 'td', array(),
+                       '&nbsp;'
+               );
+               $htmlOut .= Xml::closeElement( 'tr' );
+               return $htmlOut;
+       }
+       
+       /**
+        * Close table
+        */
+       function getEndBody() {
+               $htmlOut = '';
+               $htmlOut .= Xml::closeElement( 'table' );
+               return $htmlOut;
+       }
+       
+}

Deleted: trunk/extensions/CentralNotice/CentralNoticeLogPager.php
===================================================================
--- trunk/extensions/CentralNotice/CentralNoticeLogPager.php    2011-08-30 
23:27:19 UTC (rev 95821)
+++ trunk/extensions/CentralNotice/CentralNoticeLogPager.php    2011-08-31 
00:06:51 UTC (rev 95822)
@@ -1,356 +0,0 @@
-<?php
-
-class CentralNoticeLogPager extends ReverseChronologicalPager {
-       var $viewPage, $special;
-
-       function __construct( $special ) {
-               global $wgRequest;
-               $this->special = $special;
-               parent::__construct();
-               
-               // Override paging defaults
-               list( $this->mLimit, /* $offset */ ) = 
$this->mRequest->getLimitOffset( 20, '' );
-               $this->mLimitsShown = array( 20, 50, 100 );
-               
-               $this->viewPage = SpecialPage::getTitleFor( 'CentralNotice' );
-       }
-       
-       /**
-        * Sort the log list by timestamp
-        */
-       function getIndexField() {
-       return 'notlog_timestamp';
-       }
-       
-       /**
-        * Pull log entries from the database
-        */
-       function getQueryInfo() {
-               global $wgRequest;
-               
-               $filterStartDate = 0;
-               $filterEndDate = 0;
-               $startYear = $wgRequest->getVal( 'start_year' );
-               if ( $startYear === 'other' ) $startYear = null;
-               $startMonth = $wgRequest->getVal( 'start_month' );
-               if ( $startMonth === 'other' ) $startMonth = null;
-               $startDay = $wgRequest->getVal( 'start_day' );
-               if ( $startDay === 'other' ) $startDay = null;
-               $endYear = $wgRequest->getVal( 'end_year' );
-               if ( $endYear === 'other' ) $endYear = null;
-               $endMonth = $wgRequest->getVal( 'end_month' );
-               if ( $endMonth === 'other' ) $endMonth = null;
-               $endDay = $wgRequest->getVal( 'end_day' );
-               if ( $endDay === 'other' ) $endDay = null;
-                       
-               if ( $startYear && $startMonth && $startDay ) {
-                       $filterStartDate = $startYear . $startMonth . $startDay;
-               }
-               if ( $endYear && $endMonth && $endDay ) {
-                       $filterEndDate = $endYear . $endMonth . $endDay;
-               }
-               $filterCampaign = $wgRequest->getVal( 'campaign' );
-               $filterUser = $wgRequest->getVal( 'user' );
-               $reset = $wgRequest->getVal( 'centralnoticelogreset' );
-               
-               $info = array(
-                       'tables' => array( 'cn_notice_log' ),
-                       'fields' => '*',
-                       'conds' => array()
-               );
-               
-               if ( !$reset ) {
-                       if ( $filterStartDate > 0 ) {
-                               $filterStartDate = intval( 
$filterStartDate.'000000' );
-                               $info['conds'][] = "notlog_timestamp >= 
$filterStartDate";
-                       }
-                       if ( $filterEndDate > 0 ) {
-                               $filterEndDate = intval( 
$filterEndDate.'000000' );
-                               $info['conds'][] = "notlog_timestamp < 
$filterEndDate";
-                       }
-                       if ( $filterCampaign ) {
-                               $info['conds'][] = "notlog_not_name LIKE 
'$filterCampaign'";
-                       }
-                       if ( $filterUser ) {
-                               $user = User::newFromName( $filterUser );
-                               $userId = $user->getId();
-                               $info['conds'][] = "notlog_user_id = $userId";
-                       }
-               }
-               
-               return $info;
-       }
-       
-       /** 
-        * Generate the content of each table row (1 row = 1 log entry)
-        */
-       function formatRow( $row ) {
-               global $wgLang, $wgExtensionAssetsPath;
-               
-               // Create a user object so we can pull the name, user page, etc.
-               $loggedUser = User::newFromId( $row->notlog_user_id );
-               // Create the user page link
-               $userLink = $this->getSkin()->makeLinkObj( 
$loggedUser->getUserPage(), 
-                       $loggedUser->getName() );
-               $userTalkLink = $this->getSkin()->makeLinkObj( 
$loggedUser->getTalkPage(), 
-                       wfMsg ( 'centralnotice-talk-link' ) );
-               
-               // Create the campaign link
-               $campaignLink = $this->getSkin()->makeLinkObj( $this->viewPage,
-                       htmlspecialchars( $row->notlog_not_name ),
-                       'method=listNoticeDetail&notice=' . urlencode( 
$row->notlog_not_name ) );
-                               
-               // Begin log entry primary row
-               $htmlOut = Xml::openElement( 'tr' );
-               
-               $htmlOut .= Xml::openElement( 'td', array( 'valign' => 'top' ) 
);
-               if ( $row->notlog_action !== 'removed' ) {
-                       $htmlOut .= '<a 
href="javascript:toggleLogDisplay(\''.$row->notlog_id.'\')">'.
-                               '<img 
src="'.$wgExtensionAssetsPath.'/CentralNotice/collapsed.png" 
id="cn-collapsed-'.$row->notlog_id.'" style="display:block;"/>'.
-                               '<img 
src="'.$wgExtensionAssetsPath.'/CentralNotice/uncollapsed.png" 
id="cn-uncollapsed-'.$row->notlog_id.'" style="display:none;"/>'.
-                               '</a>';
-               }
-               $htmlOut .= Xml::closeElement( 'td' );
-               $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top', 'class' 
=> 'primary' ),
-                       $wgLang->date( $row->notlog_timestamp ) . ' ' . 
$wgLang->time( $row->notlog_timestamp )
-               );
-               $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top', 'class' 
=> 'primary' ),
-                       wfMsg ( 'centralnotice-user-links', $userLink, 
$userTalkLink )
-               );
-               $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top', 'class' 
=> 'primary' ),
-                       $row->notlog_action
-               );
-               $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top', 'class' 
=> 'primary' ),
-                       $campaignLink
-               );
-               $htmlOut .= Xml::tags( 'td', array(),
-                       '&nbsp;'
-               );
-               
-               // End log entry primary row
-               $htmlOut .= Xml::closeElement( 'tr' );
-               
-               if ( $row->notlog_action !== 'removed' ) {
-                       // Begin log entry secondary row
-                       $htmlOut .= Xml::openElement( 'tr', array( 'id' => 
'cn-log-details-'.$row->notlog_id, 'style' => 'display:none;' ) );
-                       
-                       $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ),
-                               '&nbsp;' // force a table cell in older browsers
-                       );
-                       $htmlOut .= Xml::openElement( 'td', array( 'valign' => 
'top', 'colspan' => '5' ) );
-                       if ( $row->notlog_action == 'created' ) {
-                               $htmlOut .= $this->showInitialSettings( $row );
-                       } else if ( $row->notlog_action == 'modified' ) {
-                               $htmlOut .= $this->showChanges( $row );
-                       }
-                       $htmlOut .= Xml::closeElement( 'td' );
-                       
-                       // End log entry primary row
-                       $htmlOut .= Xml::closeElement( 'tr' );
-               }
-               
-               return $htmlOut;
-       }
-       
-       function showInitialSettings( $row ) {
-               global $wgLang;
-               $details = '';
-               $details .= wfMsg (
-                       'centralnotice-log-label',
-                       wfMsg ( 'centralnotice-start-date' ), 
-                       $wgLang->date( $row->notlog_end_start ).' 
'.$wgLang->time( $row->notlog_end_start )
-               )."<br/>";
-               $details .= wfMsg (
-                       'centralnotice-log-label',
-                       wfMsg ( 'centralnotice-end-date' ),
-                       $wgLang->date( $row->notlog_end_end ).' 
'.$wgLang->time( $row->notlog_end_end )
-               )."<br/>";
-               $details .= wfMsg (
-                       'centralnotice-log-label',
-                       wfMsg ( 'centralnotice-projects' ),
-                       $row->notlog_end_projects
-               )."<br/>";
-               $language_count = count( explode ( ', ', 
$row->notlog_end_languages ) );
-               $languageList = '';
-               if ( $language_count > 15 ) {
-                       $languageList = wfMsg ( 
'centralnotice-multiple-languages', $language_count );
-               } elseif ( $language_count > 0 ) {
-                       $languageList = $row->notlog_end_languages;
-               }
-               $details .= wfMsg (
-                       'centralnotice-log-label',
-                       wfMsg ( 'centralnotice-languages' ),
-                       $languageList
-               )."<br/>";
-               $details .= wfMsg (
-                       'centralnotice-log-label',
-                       wfMsg ( 'centralnotice-geo' ),
-                       ($row->notlog_end_geo ? 'on' : 'off')
-               )."<br/>";
-               if ( $row->notlog_end_geo ) {
-                       $country_count = count( explode ( ', ', 
$row->notlog_end_countries ) );
-                       $countryList = '';
-                       if ( $country_count > 20 ) {
-                               $countryList = wfMsg ( 
'centralnotice-multiple-countries', $country_count );
-                       } elseif ( $country_count > 0 ) {
-                               $countryList = $row->notlog_end_countries;
-                       }
-                       $details .= wfMsg (
-                               'centralnotice-log-label',
-                               wfMsg ( 'centralnotice-countries' ),
-                               $countryList
-                       )."<br/>";
-               }
-               return $details;
-       }
-       
-       function showChanges( $row ) {
-               global $wgLang;
-               $details = '';
-               if ( $row->notlog_begin_start !== $row->notlog_end_start ) {
-                       $details .= wfMsg (
-                               'centralnotice-log-label',
-                               wfMsg ( 'centralnotice-start-date' ),
-                               wfMsg (
-                                       'centralnotice-changed', 
-                                       $wgLang->date( $row->notlog_begin_start 
).' '.$wgLang->time( $row->notlog_begin_start ), 
-                                       $wgLang->date( $row->notlog_end_start 
).' '.$wgLang->time( $row->notlog_end_start )
-                               )
-                       )."<br/>";
-               }
-               if ( $row->notlog_begin_end !== $row->notlog_end_end ) {
-                       $details .= wfMsg (
-                               'centralnotice-log-label',
-                               wfMsg ( 'centralnotice-end-date' ),
-                               wfMsg (
-                                       'centralnotice-changed', 
-                                       $wgLang->date( $row->notlog_begin_end 
).' '.$wgLang->time( $row->notlog_begin_end ), 
-                                       $wgLang->date( $row->notlog_end_end ).' 
'.$wgLang->time( $row->notlog_end_end )
-                               )
-                       )."<br/>";
-               }
-               $details .= $this->testBooleanChange( 'enabled', $row );
-               $details .= $this->testBooleanChange( 'preferred', $row );
-               $details .= $this->testBooleanChange( 'locked', $row );
-               $details .= $this->testBooleanChange( 'geo', $row );
-               $details .= $this->testSetChange( 'projects', $row );
-               $details .= $this->testSetChange( 'languages', $row );
-               $details .= $this->testSetChange( 'countries', $row );
-               if ( $row->notlog_begin_banners !== $row->notlog_end_banners ) {
-                       // Show changes to banner weights and assignment
-                       $beginBannersObject = json_decode( 
$row->notlog_begin_banners );
-                       $endBannersObject = json_decode( 
$row->notlog_end_banners );
-                       $beginBanners = array();
-                       $endBanners = array();
-                       foreach( $beginBannersObject as $key => $weight ) {
-                               $beginBanners[$key] = $key.' ('.$weight.')';
-                       }
-                       foreach( $endBannersObject as $key => $weight ) {
-                               $endBanners[$key] = $key.' ('.$weight.')';
-                       }
-                       if ( $beginBanners ) {
-                               $before = implode( ', ', $beginBanners );
-                       } else {
-                               $before = wfMsg ( 
'centralnotice-no-assignments' );
-                       }
-                       if ( $endBanners ) {
-                               $after = implode( ', ', $endBanners );
-                       } else {
-                               $after = wfMsg ( 'centralnotice-no-assignments' 
);
-                       }
-                       $details .= wfMsg (
-                               'centralnotice-log-label',
-                               wfMsg ( 'centralnotice-templates' ),
-                               wfMsg ( 'centralnotice-changed', $before, 
$after)
-                       )."<br/>";
-               }
-               return $details;
-       }
-       
-       private function testBooleanChange( $param, $row ) {
-               $result = '';
-               $beginField = 'notlog_begin_'.$param;
-               $endField = 'notlog_end_'.$param;
-               if ( $row->$beginField !== $row->$endField ) {
-                       $result .= wfMsg (
-                               'centralnotice-log-label',
-                               wfMsg ( 'centralnotice-'.$param ),
-                               wfMsg (
-                                       'centralnotice-changed', 
-                                       ( $row->$beginField ? wfMsg ( 
'centralnotice-on' ) : wfMsg ( 'centralnotice-off' ) ), 
-                                       ( $row->$endField ? wfMsg ( 
'centralnotice-on' ) : wfMsg ( 'centralnotice-off' ) )
-                               )
-                       )."<br/>";
-               }
-               return $result;
-       }
-       
-       private function testSetChange( $param, $row ) {
-               $result = '';
-               $beginField = 'notlog_begin_'.$param;
-               $endField = 'notlog_end_'.$param;
-               if ( $row->$beginField !== $row->$endField ) {
-                       $beginSet = array();
-                       $endSet = array();
-                       if ( $row->$beginField ) {
-                               $beginSet = explode( ', ', $row->$beginField );
-                       }
-                       if ( $row->$endField ) {
-                               $endSet = explode( ', ', $row->$endField );
-                       }
-                       $added = array_diff( $endSet, $beginSet );
-                       $removed = array_diff( $beginSet, $endSet );
-                       $differences = '';
-                       if ( $added ) {
-                               $differences .= wfMsg ( 'centralnotice-added', 
implode( ', ', $added ) );
-                               if ( $removed ) $differences .= '; ';
-                       }
-                       if ( $removed ) {
-                               $differences .= wfMsg ( 
'centralnotice-removed', implode( ', ', $removed ) );
-                       }
-                       $result .= wfMsg (
-                               'centralnotice-log-label',
-                               wfMsg ( 'centralnotice-'.$param ),
-                               $differences
-                       )."<br/>";
-               }
-               return $result;
-       }
-       
-       /**
-        * Specify table headers
-        */
-       function getStartBody() {
-               $htmlOut = '';
-               $htmlOut .= Xml::openElement( 'table', array( 'id' => 
'cn-campaign-logs', 'cellpadding' => 3 ) );
-               $htmlOut .= Xml::openElement( 'tr' );
-               $htmlOut .= Xml::element( 'th', array( 'style' => 'width: 
20px;' ) );
-               $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 
'style' => 'width: 130px;' ),
-                        wfMsg ( 'centralnotice-timestamp' )
-               );
-               $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 
'style' => 'width: 160px;' ),
-                        wfMsg ( 'centralnotice-user' )
-               );
-               $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 
'style' => 'width: 100px;' ),
-                        wfMsg ( 'centralnotice-action' )
-               );
-               $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 
'style' => 'width: 160px;' ),
-                       wfMsg ( 'centralnotice-notice' )
-               );
-               $htmlOut .= Xml::tags( 'td', array(),
-                       '&nbsp;'
-               );
-               $htmlOut .= Xml::closeElement( 'tr' );
-               return $htmlOut;
-       }
-       
-       /**
-        * Close table
-        */
-       function getEndBody() {
-               $htmlOut = '';
-               $htmlOut .= Xml::closeElement( 'table' );
-               return $htmlOut;
-       }
-       
-}

Added: trunk/extensions/CentralNotice/CentralNoticePageLogPager.php
===================================================================
--- trunk/extensions/CentralNotice/CentralNoticePageLogPager.php                
                (rev 0)
+++ trunk/extensions/CentralNotice/CentralNoticePageLogPager.php        
2011-08-31 00:06:51 UTC (rev 95822)
@@ -0,0 +1,207 @@
+<?php
+
+/**
+ * This class generates a paginated log of recent changes to banner messages 
(the parts that get 
+ * translated). We use the rencentchanges table since it is lightweight, 
however, this means that 
+ * the log only goes back 30 days.
+ */
+class CentralNoticePageLogPager extends ReverseChronologicalPager {
+       var $viewPage, $special, $logType;
+
+       /**
+        * Construct instance of class.
+        * @param $special object calling object
+        * @param $type string type of log - 'bannercontent' or 
'bannermessages' (optional)
+        */
+       function __construct( $special, $type = 'bannercontent' ) {
+               $this->special = $special;
+               parent::__construct( $special );
+               
+               $this->viewPage = SpecialPage::getTitleFor( 'NoticeTemplate', 
'view' );
+               $this->logType = $type;
+       }
+       
+       /**
+        * Sort the log list by timestamp
+        */
+       function getIndexField() {
+               return 'rc_timestamp';
+       }
+       
+       /**
+        * Pull log entries from the database
+        */
+       function getQueryInfo() {
+               $conds = array(
+                               'rc_bot' => 1, // include bot edits (all edits 
made by CentralNotice are bot edits)
+                               'rc_namespace' => 8, // only MediaWiki pages
+               );
+               if ( $this->logType == 'bannercontent' ) {
+                       // Add query contitions for banner content log
+                       $conds += array(
+                               "rc_title LIKE 'Centralnotice-template-%'", // 
get banner content
+                       );
+               } else {
+                       // Add query contitions for banner messages log
+                       $conds += array(
+                               "rc_title LIKE 'Centralnotice-%'", // get 
banner messages
+                               "rc_title NOT LIKE 'Centralnotice-template-%'", 
// exclude normal banner content
+                       );
+               }
+               return array(
+                       'tables' => array( 'recentchanges' ),
+                       'fields' => '*',
+                       'conds' => $conds, // WHERE conditions
+               );
+       }
+       
+       /**
+        * Generate the content of each table row (1 row = 1 log entry)
+        */
+       function formatRow( $row ) {
+               global $wgLang, $wgExtensionAssetsPath;
+               
+               // Create a user object so we can pull the name, user page, etc.
+               $loggedUser = User::newFromId( $row->rc_user );
+               // Create the user page link
+               $userLink = $this->getSkin()->makeLinkObj( 
$loggedUser->getUserPage(), 
+                       $loggedUser->getName() );
+               $userTalkLink = $this->getSkin()->makeLinkObj( 
$loggedUser->getTalkPage(), 
+                       wfMsg ( 'centralnotice-talk-link' ) );
+                       
+               $language = 'en'; // English is the default for CentralNotice 
messages
+               
+               if ( $this->logType == 'bannercontent' ) {
+                       // Extract the banner name from the title
+                       $pattern = '/Centralnotice-template-(.*)/';
+                       preg_match( $pattern, $row->rc_title, $matches );
+                       $banner = $matches[1];
+               } else if ( $this->logType == 'bannermessages' ) {
+                       // Split the title into banner, message, and language
+                       $titlePieces = explode( "/", $row->rc_title, 2 );
+                       $titleBase = $titlePieces[0];
+                       if ( array_key_exists( 1, $titlePieces ) ) $language = 
$titlePieces[1];
+                       $pattern = '/Centralnotice-([^-]*)-(.*)/';
+                       preg_match( $pattern, $titleBase, $matches );
+                       $banner = $matches[1];
+                       $message = $matches[2];
+               }
+               
+               // Create banner link
+               $bannerLink = $this->getSkin()->makeLinkObj( $this->viewPage,
+                       htmlspecialchars( $banner ),
+                       'template=' . urlencode( $banner ) );
+               
+               // Create title object
+               $title = Title::newFromText( "MediaWiki:{$row->rc_title}" );
+                       
+               if ( $this->logType == 'bannercontent' ) {
+                       // If the banner was just created, show a link to the 
banner. If the banner was 
+                       // edited, show a link to the banner and a link to the 
diff.
+                       if ( $row->rc_new ) {
+                               $bannerCell = $bannerLink;
+                       } else {
+                               $querydiff = array(
+                                       'curid' => $row->rc_cur_id,
+                                       'diff' => $row->rc_this_oldid,
+                                       'oldid' => $row->rc_last_oldid
+                               );
+                               $diffUrl = htmlspecialchars( 
$title->getLinkUrl( $querydiff ) );
+                               // Should "diff" be localized? It appears not 
to be elsewhere in the interface.
+                               // See ChangesList->preCacheMessages() for 
example.
+                               $bannerCell = $bannerLink . "&nbsp;(<a 
href=\"$diffUrl\">diff</a>)";
+                       }
+               } else if ( $this->logType == 'bannermessages' ) {
+                       $bannerCell = $bannerLink;
+                       
+                       // Create the message link
+                       $messageLink = $this->getSkin()->makeLinkObj( $title, 
htmlspecialchars( $message ) );
+                       
+                       // If the message was just created, show a link to the 
message. If the message was 
+                       // edited, show a link to the message and a link to the 
diff.
+                       if ( $row->rc_new ) {
+                               $messageCell = $messageLink;
+                       } else {
+                               $querydiff = array(
+                                       'curid' => $row->rc_cur_id,
+                                       'diff' => $row->rc_this_oldid,
+                                       'oldid' => $row->rc_last_oldid
+                               );
+                               $diffUrl = htmlspecialchars( 
$title->getLinkUrl( $querydiff ) );
+                               // Should "diff" be localized? It appears not 
to be elsewhere in the interface.
+                               // See ChangesList->preCacheMessages() for 
example.
+                               $messageCell = $messageLink . "&nbsp;(<a 
href=\"$diffUrl\">diff</a>)";
+                       }
+               }
+                               
+               // Begin log entry primary row
+               $htmlOut = Xml::openElement( 'tr' );
+               
+               $htmlOut .= Xml::openElement( 'td', array( 'valign' => 'top' ) 
);
+               $htmlOut .= Xml::closeElement( 'td' );
+               $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top', 'class' 
=> 'primary' ),
+                       $wgLang->date( $row->rc_timestamp ) . ' ' . 
$wgLang->time( $row->rc_timestamp )
+               );
+               $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top', 'class' 
=> 'primary' ),
+                       wfMsg ( 'centralnotice-user-links', $userLink, 
$userTalkLink )
+               );
+               $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top', 'class' 
=> 'primary' ),
+                       $bannerCell
+               );
+               if ( $this->logType == 'bannermessages' ) {
+                       $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top', 
'class' => 'primary' ),
+                               $messageCell
+                       );
+                       $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top', 
'class' => 'primary' ),
+                               $language
+                       );
+               }
+               $htmlOut .= Xml::tags( 'td', array(),
+                       '&nbsp;'
+               );
+               
+               // End log entry primary row
+               $htmlOut .= Xml::closeElement( 'tr' );
+               
+               return $htmlOut;
+       }
+       
+       function getStartBody() {
+               $htmlOut = '';
+               $htmlOut .= Xml::openElement( 'table', array( 'id' => 
'cn-campaign-logs', 'cellpadding' => 3 ) );
+               $htmlOut .= Xml::openElement( 'tr' );
+               $htmlOut .= Xml::element( 'th', array( 'style' => 'width: 
20px;' ) );
+               $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 
'style' => 'width: 130px;' ),
+                        wfMsg ( 'centralnotice-timestamp' )
+               );
+               $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 
'style' => 'width: 160px;' ),
+                        wfMsg ( 'centralnotice-user' )
+               );
+               $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 
'style' => 'width: 160px;' ),
+                        wfMsg ( 'centralnotice-banner' )
+               );
+               if ( $this->logType == 'bannermessages' ) {
+                       $htmlOut .= Xml::element( 'th', array( 'align' => 
'left', 'style' => 'width: 160px;' ),
+                               wfMsg ( 'centralnotice-message' )
+                       );
+                       $htmlOut .= Xml::element( 'th', array( 'align' => 
'left', 'style' => 'width: 100px;' ),
+                               wfMsg ( 'centralnotice-language' )
+                       );
+               }
+               $htmlOut .= Xml::tags( 'td', array(),
+                       '&nbsp;'
+               );
+               $htmlOut .= Xml::closeElement( 'tr' );
+               return $htmlOut;
+       }
+       
+       /**
+        * Close table
+        */
+       function getEndBody() {
+               $htmlOut = '';
+               $htmlOut .= Xml::closeElement( 'table' );
+               return $htmlOut;
+       }
+       
+}

Modified: trunk/extensions/CentralNotice/special/SpecialCentralNoticeLogs.php
===================================================================
--- trunk/extensions/CentralNotice/special/SpecialCentralNoticeLogs.php 
2011-08-30 23:27:19 UTC (rev 95821)
+++ trunk/extensions/CentralNotice/special/SpecialCentralNoticeLogs.php 
2011-08-31 00:06:51 UTC (rev 95822)
@@ -55,22 +55,16 @@
                $title = SpecialPage::getTitleFor( 'CentralNoticeLogs' );
                $fullUrl = wfExpandUrl( $title->getFullUrl(), PROTO_CURRENT );
                
-               $htmlOut .= Xml::radio( 
-                       'log_type',
-                       'campaign',
-                       ( $this->logType == 'campaignsettings' ? true : false ),
-                       array( 'onclick' => "switchLogs( '".$fullUrl."', 
'campaignsettings' )" )
-               );
-               $htmlOut .= Xml::label( wfMsg( 
'centralnotice-campaign-settings' ), 'campaign' );
+               // Build the radio buttons for switching the log type
+               $htmlOut .= $this->getLogSwitcher( 'campaignsettings', 
'campaignSettings', 
+                       'centralnotice-campaign-settings', $fullUrl );
+               $htmlOut .= $this->getLogSwitcher( 'bannersettings', 
'bannerSettings', 
+                       'centralnotice-banner-settings', $fullUrl );
+               $htmlOut .= $this->getLogSwitcher( 'bannercontent', 
'bannerContent', 
+                       'centralnotice-banner-content', $fullUrl );
+               $htmlOut .= $this->getLogSwitcher( 'bannermessages', 
'bannerMessages', 
+                       'centralnotice-banner-messages', $fullUrl );
                
-               $htmlOut .= Xml::radio(
-                       'log_type',
-                       'banner',
-                       ( $this->logType == 'bannersettings' ? true : false ),
-                       array( 'onclick' => "switchLogs( '".$fullUrl."', 
'bannersettings' )" )
-               );
-               $htmlOut .= Xml::label( wfMsg( 'centralnotice-banner-settings' 
), 'banner' );
-               
                $htmlOut .= Xml::closeElement( 'div' );
                
                if ( $this->logType == 'campaignsettings' ) {
@@ -221,10 +215,16 @@
        function showLog( $logType ) {
                global $wgOut;
                
-               if ( $logType == 'bannersettings' ) {
-                       $pager = new CentralNoticeBannerLogPager( $this );
-               } else {
-                       $pager = new CentralNoticeLogPager( $this );
+               switch ( $logType ) {
+                       case 'bannersettings':
+                               $pager = new CentralNoticeBannerLogPager( $this 
);
+                               break;
+                       case 'bannercontent':
+                       case 'bannermessages':
+                               $pager = new CentralNoticePageLogPager( $this, 
$logType );
+                               break;
+                       default:
+                               $pager = new CentralNoticeCampaignLogPager( 
$this );
                }
                
                $htmlOut = '';
@@ -247,11 +247,26 @@
                $wgOut->addHTML( $htmlOut );
        }
        
-       private function getDateValue( $type ) {
+       static function getDateValue( $type ) {
                global $wgRequest;
                $value = $wgRequest->getVal( $type );
                if ( $value === 'other' ) $value = null;
                return $value;
        }
+       
+       /**
+        * Build a radio button that switches the log type when you click it
+        */
+       private function getLogSwitcher( $type, $id, $message, $fullUrl ) {
+               $htmlOut = '';
+               $htmlOut .= Xml::radio(
+                       'log_type',
+                       $id,
+                       ( $this->logType == $type ? true : false ),
+                       array( 'onclick' => "switchLogs( '".$fullUrl."', 
'".$type."' )" )
+               );
+               $htmlOut .= Xml::label( wfMsg( $message ), $id );
+               return $htmlOut;
+       }
 
 }


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to