Index: trunk/extensions/CentralNotice/special/SpecialNoticeTemplate.php |
— | — | @@ -743,6 +743,17 @@ |
744 | 744 | } |
745 | 745 | return null; |
746 | 746 | } |
| 747 | + |
| 748 | + public static function getBannerName( $bannerId ) { |
| 749 | + $dbr = wfGetDB( DB_MASTER ); |
| 750 | + if ( is_numeric( $bannerId ) ) { |
| 751 | + $row = $dbr->selectRow( 'cn_templates', 'tmp_name', array( 'tmp_id' => $bannerId ) ); |
| 752 | + if ( $row ) { |
| 753 | + return $row->tmp_name; |
| 754 | + } |
| 755 | + } |
| 756 | + return null; |
| 757 | + } |
747 | 758 | |
748 | 759 | private function removeTemplate ( $name ) { |
749 | 760 | $id = $this->getTemplateId( $name ); |
— | — | @@ -805,12 +816,24 @@ |
806 | 817 | ), |
807 | 818 | __METHOD__ |
808 | 819 | ); |
| 820 | + $bannerId = $dbw->insertId(); |
809 | 821 | |
810 | 822 | // Perhaps these should move into the db as blobs instead of being stored as articles |
811 | 823 | $article = new Article( |
812 | 824 | Title::newFromText( "centralnotice-template-{$name}", NS_MEDIAWIKI ) |
813 | 825 | ); |
814 | 826 | $article->doEdit( $body, '', EDIT_FORCE_BOT ); |
| 827 | + |
| 828 | + // Log the creation of the banner |
| 829 | + $beginSettings = array(); |
| 830 | + $endSettings = array( |
| 831 | + 'anon_display' => $displayAnon, |
| 832 | + 'account_display' => $displayAccount, |
| 833 | + 'fundraising' => $fundraising, |
| 834 | + 'landing_pages' => $landingPages |
| 835 | + ); |
| 836 | + $this->logBannerChange( 'created', $bannerId, $beginSettings, $endSettings ); |
| 837 | + |
815 | 838 | return true; |
816 | 839 | } |
817 | 840 | } |
— | — | @@ -960,5 +983,41 @@ |
961 | 984 | $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", $message ); |
962 | 985 | $this->centralNoticeError = true; |
963 | 986 | } |
| 987 | + |
| 988 | + /** |
| 989 | + * Log setting changes related to a banner |
| 990 | + * @param $action string: 'created', 'modified', or 'removed' |
| 991 | + * @param $bannerId integer: ID of banner |
| 992 | + * @param $beginSettings array of banner settings before changes (optional) |
| 993 | + * @param $endSettings array of banner settings after changes (optional) |
| 994 | + * @param $beginContent banner content before changes (optional) |
| 995 | + * @param $endContent banner content after changes (optional) |
| 996 | + */ |
| 997 | + function logBannerChange( $action, $bannerId, $beginSettings = array(), |
| 998 | + $endSettings = array(), $beginContent = null, $endContent = null ) |
| 999 | + { |
| 1000 | + global $wgUser; |
| 1001 | + |
| 1002 | + $dbw = wfGetDB( DB_MASTER ); |
| 1003 | + |
| 1004 | + $log = array( |
| 1005 | + 'tmplog_timestamp' => $dbw->timestamp(), |
| 1006 | + 'tmplog_user_id' => $wgUser->getId(), |
| 1007 | + 'tmplog_action' => $action, |
| 1008 | + 'tmplog_template_id' => $bannerId, |
| 1009 | + 'tmplog_template_name' => SpecialNoticeTemplate::getBannerName( $bannerId ) |
| 1010 | + ); |
| 1011 | + |
| 1012 | + foreach ( $beginSettings as $key => $value ) { |
| 1013 | + $log['tmplog_begin_'.$key] = $value; |
| 1014 | + } |
| 1015 | + foreach ( $endSettings as $key => $value ) { |
| 1016 | + $log['tmplog_end_'.$key] = $value; |
| 1017 | + } |
| 1018 | + |
| 1019 | + $res = $dbw->insert( 'cn_template_log', $log ); |
| 1020 | + $log_id = $dbw->insertId(); |
| 1021 | + return $log_id; |
| 1022 | + } |
964 | 1023 | |
965 | 1024 | } |
Index: trunk/extensions/CentralNotice/special/SpecialCentralNoticeLogs.php |
— | — | @@ -19,9 +19,7 @@ |
20 | 20 | function execute( $sub ) { |
21 | 21 | global $wgOut, $wgRequest, $wgExtensionAssetsPath; |
22 | 22 | |
23 | | - if ( $wgRequest->wasPosted() ) { |
24 | | - $this->logType = $wgRequest->getText( 'log', 'campaignsettings' ); |
25 | | - } |
| 23 | + $this->logType = $wgRequest->getText( 'log', 'campaignsettings' ); |
26 | 24 | |
27 | 25 | // Begin output |
28 | 26 | $this->setHeaders(); |
— | — | @@ -68,20 +66,25 @@ |
69 | 67 | |
70 | 68 | $wgOut->addHTML( $htmlOut ); |
71 | 69 | |
72 | | - $this->showCampaignLog( $this->logType ); |
| 70 | + $this->showLog( $this->logType ); |
73 | 71 | |
74 | 72 | // End Banners tab content |
75 | 73 | $wgOut->addHTML( Xml::closeElement( 'div' ) ); |
76 | 74 | } |
77 | 75 | |
78 | 76 | /** |
79 | | - * Show a log of campaign changes. |
| 77 | + * Show a log of changes. |
| 78 | + * @param $logType string: which type of log to show |
80 | 79 | */ |
81 | | - function showCampaignLog( $logType ) { |
| 80 | + function showLog( $logType ) { |
82 | 81 | global $wgOut; |
83 | 82 | |
84 | | - //$pager = new CentralNoticeLogPager( $this ); |
85 | | - $pager = new CentralNoticeBannerLogPager( $this ); |
| 83 | + if ( $logType == 'bannersettings' ) { |
| 84 | + $pager = new CentralNoticeBannerLogPager( $this ); |
| 85 | + } else { |
| 86 | + $pager = new CentralNoticeLogPager( $this ); |
| 87 | + } |
| 88 | + |
86 | 89 | $htmlOut = ''; |
87 | 90 | |
88 | 91 | // Begin log fieldset |
— | — | @@ -423,7 +426,7 @@ |
424 | 427 | * Sort the log list by timestamp |
425 | 428 | */ |
426 | 429 | function getIndexField() { |
427 | | - return 'templog_timestamp'; |
| 430 | + return 'tmplog_timestamp'; |
428 | 431 | } |
429 | 432 | |
430 | 433 | /** |
— | — | @@ -443,7 +446,7 @@ |
444 | 447 | global $wgLang, $wgExtensionAssetsPath; |
445 | 448 | |
446 | 449 | // Create a user object so we can pull the name, user page, etc. |
447 | | - $loggedUser = User::newFromId( $row->templog_user_id ); |
| 450 | + $loggedUser = User::newFromId( $row->tmplog_user_id ); |
448 | 451 | // Create the user page link |
449 | 452 | $userLink = $this->getSkin()->makeLinkObj( $loggedUser->getUserPage(), |
450 | 453 | $loggedUser->getName() ); |
— | — | @@ -452,28 +455,28 @@ |
453 | 456 | |
454 | 457 | // Create the banner link |
455 | 458 | $bannerLink = $this->getSkin()->makeLinkObj( $this->viewPage, |
456 | | - htmlspecialchars( $row->templog_template_name ), |
457 | | - 'template=' . urlencode( $row->templog_template_name ) ); |
| 459 | + htmlspecialchars( $row->tmplog_template_name ), |
| 460 | + 'template=' . urlencode( $row->tmplog_template_name ) ); |
458 | 461 | |
459 | 462 | // Begin log entry primary row |
460 | 463 | $htmlOut = Xml::openElement( 'tr' ); |
461 | 464 | |
462 | 465 | $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;"/>'. |
| 466 | + if ( $row->tmplog_action !== 'removed' ) { |
| 467 | + $htmlOut .= '<a href="javascript:toggleDisplay(\''.$row->tmplog_id.'\')">'. |
| 468 | + '<img src="'.$wgExtensionAssetsPath.'/CentralNotice/collapsed.png" id="cn-collapsed-'.$row->tmplog_id.'" style="display:block;vertical-align:baseline;"/>'. |
| 469 | + '<img src="'.$wgExtensionAssetsPath.'/CentralNotice/uncollapsed.png" id="cn-uncollapsed-'.$row->tmplog_id.'" style="display:none;vertical-align:baseline;"/>'. |
467 | 470 | '</a>'; |
468 | 471 | } |
469 | 472 | $htmlOut .= Xml::closeElement( 'td' ); |
470 | 473 | $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top', 'class' => 'primary' ), |
471 | | - $wgLang->date( $row->templog_timestamp ) . ' ' . $wgLang->time( $row->templog_timestamp ) |
| 474 | + $wgLang->date( $row->tmplog_timestamp ) . ' ' . $wgLang->time( $row->tmplog_timestamp ) |
472 | 475 | ); |
473 | 476 | $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top', 'class' => 'primary' ), |
474 | 477 | wfMsg ( 'centralnotice-user-links', $userLink, $userTalkLink ) |
475 | 478 | ); |
476 | 479 | $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top', 'class' => 'primary' ), |
477 | | - $row->templog_action |
| 480 | + $row->tmplog_action |
478 | 481 | ); |
479 | 482 | $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top', 'class' => 'primary' ), |
480 | 483 | $bannerLink |
— | — | @@ -485,17 +488,17 @@ |
486 | 489 | // End log entry primary row |
487 | 490 | $htmlOut .= Xml::closeElement( 'tr' ); |
488 | 491 | |
489 | | - if ( $row->templog_action !== 'removed' ) { |
| 492 | + if ( $row->tmplog_action !== 'removed' ) { |
490 | 493 | // Begin log entry secondary row |
491 | | - $htmlOut .= Xml::openElement( 'tr', array( 'id' => 'cn-log-details-'.$row->templog_id, 'style' => 'display:none;' ) ); |
| 494 | + $htmlOut .= Xml::openElement( 'tr', array( 'id' => 'cn-log-details-'.$row->tmplog_id, 'style' => 'display:none;' ) ); |
492 | 495 | |
493 | 496 | $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ), |
494 | 497 | ' ' // force a table cell in older browsers |
495 | 498 | ); |
496 | 499 | $htmlOut .= Xml::openElement( 'td', array( 'valign' => 'top', 'colspan' => '5' ) ); |
497 | | - if ( $row->templog_action == 'created' ) { |
| 500 | + if ( $row->tmplog_action == 'created' ) { |
498 | 501 | //$htmlOut .= $this->showInitialSettings( $row ); |
499 | | - } else if ( $row->templog_action == 'modified' ) { |
| 502 | + } else if ( $row->tmplog_action == 'modified' ) { |
500 | 503 | //$htmlOut .= $this->showChanges( $row ); |
501 | 504 | } |
502 | 505 | $htmlOut .= Xml::closeElement( 'td' ); |
Index: trunk/extensions/CentralNotice/patches/patch-template_log.sql |
— | — | @@ -1,22 +1,22 @@ |
2 | 2 | -- Update to allow for logging of changes to banner settings. |
3 | 3 | |
4 | 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 |
| 5 | + `tmplog_id` int unsigned NOT NULL PRIMARY KEY auto_increment, |
| 6 | + `tmplog_timestamp` binary(14) NOT NULL, |
| 7 | + `tmplog_user_id` int unsigned NOT NULL, |
| 8 | + `tmplog_action` enum('created','modified','removed') NOT NULL DEFAULT 'modified', |
| 9 | + `tmplog_template_id` int unsigned NOT NULL, |
| 10 | + `tmplog_template_name` varchar(255) DEFAULT NULL, |
| 11 | + `tmplog_begin_anon_display` tinyint(1) DEFAULT NULL, |
| 12 | + `tmplog_end_anon_display` tinyint(1) DEFAULT NULL, |
| 13 | + `tmplog_begin_account_display` tinyint(1) DEFAULT NULL, |
| 14 | + `tmplog_end_account_display` tinyint(1) DEFAULT NULL, |
| 15 | + `tmplog_begin_fundraising` tinyint(1) DEFAULT NULL, |
| 16 | + `tmplog_end_fundraising` tinyint(1) DEFAULT NULL, |
| 17 | + `tmplog_begin_landing_pages` varchar(255) DEFAULT NULL, |
| 18 | + `tmplog_end_landing_pages` varchar(255) DEFAULT NULL, |
| 19 | + `tmplog_content_change` tinyint(1) DEFAULT 0 |
20 | 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 |
| 21 | +CREATE INDEX /*i*/tmplog_timestamp ON /*_*/cn_template_log (tmplog_timestamp); |
| 22 | +CREATE INDEX /*i*/tmplog_user_id ON /*_*/cn_template_log (tmplog_user_id, tmplog_timestamp); |
| 23 | +CREATE INDEX /*i*/tmplog_template_id ON /*_*/cn_template_log (tmplog_template_id, tmplog_timestamp); |
\ No newline at end of file |