r44350 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r44349‎ | r44350 | r44351 >
Date:17:46, 9 December 2008
Author:tomasz
Status:ok (Comments)
Tags:
Comment:
simplifying to allow all or specific project filter for en
Modified paths:
  • /trunk/extensions/CentralNotice/CentralNotice.db.php (modified) (history)
  • /trunk/extensions/CentralNotice/SpecialNoticeText.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/CentralNotice.db.php
@@ -31,11 +31,10 @@
3232 if ( $language )
3333 $conds[] = "not_language =" . $dbr->addQuotes( $language );
3434 if ( $preferred )
35 - $conds[] = "not_preferred =" . $dbr->addQuotes( $preferred );
36 -
 35+ $conds[] = "not_preferred = 1";
3736 $conds[] = ( $enabled ) ? "not_enabled = " . $dbr->addQuotes( $enabled ) : "not_enabled = " . $dbr->addQuotes( 1 );
3837 $conds[] = ( $date ) ? "not_start <= ". $dbr->addQuotes( $date ) : "not_start <= " . $dbr->addQuotes( $dbr->timestamp() );
39 - $conds[] = ( $date ) ? "not_end >= ". $dbr->addQuotes( $date ) : "not_end >= " . $dbr->addQuotes( $dbr->timestamp() );
 38+ $conds[] = ( $date ) ? "not_end >= " . $dbr->addQuotes( $date ) : "not_end >= " . $dbr->addQuotes( $dbr->timestamp() );
4039
4140
4241 // Pull db data
@@ -45,6 +44,8 @@
4645 ),
4746 array(
4847 'not_name',
 48+ 'not_project',
 49+ 'not_language',
4950 'not_locked',
5051 'not_enabled',
5152 'not_preferred',
@@ -61,6 +62,8 @@
6263 // Loop through result set and return attributes
6364 while ( $row = $dbr->fetchObject( $res ) ) {
6465 $notice = $row->not_name;
 66+ $notices[$notice]['project'] = $row->not_project;
 67+ $notices[$notice]['language'] = $row->not_language;
6568 $notices[$notice]['preferred'] = $row->not_preferred;
6669 $notices[$notice]['locked'] = $row->not_locked;
6770 $notices[$notice]['enabled'] = $row->not_enabled;
Index: trunk/extensions/CentralNotice/SpecialNoticeText.php
@@ -23,25 +23,25 @@
2424
2525 // Quick short circuit to be able to show preferred notices
2626 $templates = array();
27 - if ( $this->language == 'en' ) {
28 - // See if we have any preferred notices
 27+
 28+ if ( $this->language == 'en' && $this->project != null ) {
 29+ // See if we have any preferred notices for all of en
2930 $notices = CentralNoticeDB::getNotices( '', 'en', '', '', 1 );
30 - if ( !$notices ) {
31 - // If there were no preferred notices do a normal lookup for enabled
32 - $notices = CentralNoticeDB::getNotices( '', 'en' );
33 - // Last ditch effort. Try to find an all match
34 - if ( !$notices ) {
35 - $notices = CentralNoticeDB::getNotices();
 31+
 32+ if ( $notices ) {
 33+ // Pull out values
 34+ foreach( $notices as $notice => $val ) {
 35+ // Either match against ALL project or a specific project
 36+ if ( $val['project'] == '' || $val['project'] == $this->project ) {
 37+ $templates = CentralNoticeDB::selectTemplatesAssigned( $notice );
 38+ break;
 39+ }
3640 }
3741 }
38 - // Pull the notice name
39 - $notice = array_keys( $notices );
40 - // Pull the actual templates from only the first match
41 - $templates = CentralNoticeDB::selectTemplatesAssigned( $notice[0] );
42 - } else {
43 - // Continue as normal with non en notices
44 - $templates = CentralNotice::selectNoticeTemplates( $this->project, $this->language );
45 - }
 42+ }
 43+ // Didn't find any preferred matches so do an old style lookup
 44+ if ( !$templates )
 45+ $templates = CentralNotice::selectNoticeTemplates( $this->project, $this->language );
4646
4747 $templateNames = array_keys( $templates );
4848

Comments

#Comment by Brion VIBBER (talk | contribs)   19:42, 9 December 2008

A little more cleanup to go, but lookin' good...

Status & tagging log