r92922 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92921‎ | r92922 | r92923 >
Date:00:28, 23 July 2011
Author:khorn
Status:resolved (Comments)
Tags:
Comment:
Finishing banner settings logging. (specifically, changed content flag is now accurate, and changed landing pages are also displayed now)
Modified paths:
  • /trunk/extensions/CentralNotice/special/SpecialCentralNoticeLogs.php (modified) (history)
  • /trunk/extensions/CentralNotice/special/SpecialNoticeTemplate.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/special/SpecialNoticeTemplate.php
@@ -865,11 +865,26 @@
866866 $article = new Article(
867867 Title::newFromText( "centralnotice-template-{$name}", NS_MEDIAWIKI )
868868 );
 869+
 870+ $bodyPage = Title::newFromText(
 871+ "Centralnotice-template-{$name}", NS_MEDIAWIKI );
 872+ $curRev = Revision::newFromTitle( $bodyPage );
 873+ $oldbody = $curRev ? $curRev->getText() : '';
 874+
869875 $article->doEdit( $body, '', EDIT_FORCE_BOT );
870876
 877+ $curRev = Revision::newFromTitle( $bodyPage );
 878+ $newbody = $curRev ? $curRev->getText() : '';
 879+
 880+ //test for body changes
 881+ $contentChanged = 0;
 882+ if ($newbody !== $oldbody){
 883+ $contentChanged = 1;
 884+ }
 885+
871886 $bannerId = SpecialNoticeTemplate::getTemplateId( $name );
872887 $finalBannerSettings = CentralNoticeDB::getBannerSettings( $name );
873 - $this->logBannerChange( 'modified', $bannerId, $initialBannerSettings, $finalBannerSettings );
 888+ $this->logBannerChange( 'modified', $bannerId, $initialBannerSettings, $finalBannerSettings, $contentChanged);
874889
875890 return;
876891 }
@@ -993,7 +1008,7 @@
9941009 * @param $endContent banner content after changes (optional)
9951010 */
9961011 function logBannerChange( $action, $bannerId, $beginSettings = array(),
997 - $endSettings = array(), $beginContent = null, $endContent = null )
 1012+ $endSettings = array(), $contentChanged = 0 )
9981013 {
9991014 global $wgUser;
10001015
@@ -1004,7 +1019,8 @@
10051020 'tmplog_user_id' => $wgUser->getId(),
10061021 'tmplog_action' => $action,
10071022 'tmplog_template_id' => $bannerId,
1008 - 'tmplog_template_name' => SpecialNoticeTemplate::getBannerName( $bannerId )
 1023+ 'tmplog_template_name' => SpecialNoticeTemplate::getBannerName( $bannerId ),
 1024+ 'tmplog_content_change' => $contentChanged
10091025 );
10101026
10111027 foreach ( $beginSettings as $key => $value ) {
Index: trunk/extensions/CentralNotice/special/SpecialCentralNoticeLogs.php
@@ -136,7 +136,7 @@
137137 * Sort the log list by timestamp
138138 */
139139 function getIndexField() {
140 - return 'notlog_timestamp';
 140+ return 'notlog_timestamp';
141141 }
142142
143143 /**
@@ -149,7 +149,7 @@
150150 );
151151 }
152152
153 - /**
 153+ /**
154154 * Generate the content of each table row (1 row = 1 log entry)
155155 */
156156 function formatRow( $row ) {
@@ -423,7 +423,7 @@
424424
425425 }
426426
427 -class CentralNoticeBannerLogPager extends ReverseChronologicalPager {
 427+class CentralNoticeBannerLogPager extends CentralNoticeLogPager {
428428 var $viewPage, $special;
429429
430430 function __construct( $special ) {
@@ -588,6 +588,7 @@
589589 $details .= $this->testBooleanChange( 'anon', $row );
590590 $details .= $this->testBooleanChange( 'account', $row );
591591 $details .= $this->testBooleanChange( 'fundraising', $row );
 592+ $details .= $this->testTextChange( 'landingpages', $row );
592593 if ( $row->tmplog_content_change ) {
593594 // Show changes to banner content
594595 $details .= wfMsg (
@@ -616,4 +617,22 @@
617618 }
618619 return $result;
619620 }
 621+
 622+ private function testTextChange( $param, $row ) {
 623+ $result = '';
 624+ $beginField = 'tmplog_begin_'.$param;
 625+ $endField = 'tmplog_end_'.$param;
 626+ if ( $row->$beginField !== $row->$endField ) {
 627+ $result .= wfMsg (
 628+ 'centralnotice-log-label',
 629+ wfMsg ( 'centralnotice-'.$param ),
 630+ wfMsg (
 631+ 'centralnotice-changed',
 632+ $row->$beginField,
 633+ $row->$endField
 634+ )
 635+ )."<br/>";
 636+ }
 637+ return $result;
 638+ }
620639 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r93251followup r92922...khorn21:55, 26 July 2011
r96496follow up to r92922 - removing banner content change detection from the banne...kaldari21:02, 7 September 2011

Comments

#Comment by Kaldari (talk | contribs)   00:38, 23 July 2011

I love banner setting logging!

#Comment by Nikerabbit (talk | contribs)   16:48, 23 July 2011

I'd use Title::makeTitle(Safe) instead of newFromText. What happened to indentation in getIndexField? I'd also use <br /> if outputting it manually.

#Comment by Awjrichards (talk | contribs)   22:54, 19 August 2011

Stylistic point:

 	function logBannerChange( $action, $bannerId, $beginSettings = array(), 
-		$endSettings = array(), $beginContent = null, $endContent = null )
+		$endSettings = array(), $contentChanged = 0 )

It looks like $contentChanged is a bool, the way it's being used. If that's the case, I suggest changing it to 'true'/'false' for clarity.

#Comment by Kaldari (talk | contribs)   21:04, 7 September 2011

Issues resolved in r96496.

Status & tagging log