r71580 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71579‎ | r71580 | r71581 >
Date:20:34, 24 August 2010
Author:kaldari
Status:ok
Tags:
Comment:
Moving banner paging for notices to a subclass so we don't have a dozen switches in TemplatePager.php
Modified paths:
  • /trunk/extensions/CentralNotice/SpecialCentralNotice.php (modified) (history)
  • /trunk/extensions/CentralNotice/TemplatePager.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/TemplatePager.php
@@ -1,10 +1,5 @@
22 <?php
33
4 -if ( !defined( 'MEDIAWIKI' ) ) {
5 - echo "CentralNotice extension\n";
6 - exit( 1 );
7 -}
8 -
94 class TemplatePager extends ReverseChronologicalPager {
105 var $onRemoveChange, $viewPage, $special;
116 var $editable;
@@ -22,41 +17,20 @@
2318 $this->onRemoveChange = "if( this.checked ) { this.checked = confirm( $msg ) }";
2419 $this->viewPage = SpecialPage::getTitleFor( 'NoticeTemplate', 'view' );
2520 }
26 -
27 - /**
28 - * Pull banners from the database
29 - */
 21+
3022 function getQueryInfo() {
31 - // If we are calling the pager from the manage banners interface...
32 - if ( $this->special->mName == 'NoticeTemplate' ) {
33 - // Return all the banners in the database
34 - return array(
35 - 'tables' => 'cn_templates',
36 - 'fields' => array( 'tmp_name', 'tmp_id' ),
37 - );
38 - // If we are calling the pager from the campaign editing interface...
39 - } elseif ( $this->special->mName == 'CentralNotice' ) {
40 - $notice = $this->mRequest->getVal( 'notice' );
41 - // Return all the banners not already assigned to the current campaign
42 - return array(
43 - 'tables' => array( 'cn_assignments', 'cn_templates' ),
44 - 'fields' => array( 'cn_templates.tmp_name', 'cn_templates.tmp_id' ),
45 - 'conds' => array( 'cn_assignments.tmp_id is null' ),
46 - 'join_conds' => array(
47 - 'cn_assignments' => array(
48 - 'LEFT JOIN',
49 - "cn_assignments.tmp_id = cn_templates.tmp_id AND cn_assignments.not_id = (SELECT not_id FROM cn_notices WHERE not_name LIKE '$notice')"
50 - )
51 - )
52 - );
53 - }
 23+ // Return all the banners in the database
 24+ return array(
 25+ 'tables' => 'cn_templates',
 26+ 'fields' => array( 'tmp_name', 'tmp_id' ),
 27+ );
5428 }
5529
5630 /**
5731 * Sort the banner list by tmp_id
5832 */
5933 function getIndexField() {
60 - return 'cn_templates.tmp_id';
 34+ return 'tmp_id';
6135 }
6236
6337 /**
@@ -67,35 +41,15 @@
6842 // Begin banner row
6943 $htmlOut = Xml::openElement( 'tr' );
7044
71 - if ( $this->editable ) {
72 - // If we are calling the pager from the manage banners interface...
73 - if ( $this->special->mName == 'NoticeTemplate' ) {
74 - // Remove box
75 - $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ),
76 - Xml::check( 'removeTemplates[]', false,
77 - array(
78 - 'value' => $row->tmp_name,
79 - 'onchange' => $this->onRemoveChange
80 - )
81 - )
82 - );
83 - // If we are calling the pager from the campaign editing interface...
84 - } elseif ( $this->special->mName == 'CentralNotice' ) {
85 - // Add box
86 - $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ),
87 - Xml::check( 'addTemplates[]', '', array ( 'value' => $row->tmp_name ) )
88 - );
89 - // Weight select
90 - $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ),
91 - Xml::listDropDown( "weight[$row->tmp_name]",
92 - CentralNotice::dropDownList( wfMsg( 'centralnotice-weight' ), range ( 0, 100, 5 ) ) ,
93 - '',
94 - '25',
95 - '',
96 - '' )
97 - );
98 - }
99 - }
 45+ // Remove box
 46+ $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ),
 47+ Xml::check( 'removeTemplates[]', false,
 48+ array(
 49+ 'value' => $row->tmp_name,
 50+ 'onchange' => $this->onRemoveChange
 51+ )
 52+ )
 53+ );
10054
10155 // Link and Preview
10256 $viewPage = SpecialPage::getTitleFor( 'NoticeTemplate', 'view' );
@@ -126,18 +80,9 @@
12781 $htmlOut .= Xml::openElement( 'table', array( 'cellpadding' => 9 ) );
12882 $htmlOut .= Xml::openElement( 'tr' );
12983 if ( $this->editable ) {
130 - if ( $this->special->mName == 'CentralNotice' ) {
131 - $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 'width' => '5%' ),
132 - wfMsg ( "centralnotice-add" )
133 - );
134 - $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 'width' => '5%' ),
135 - wfMsg ( "centralnotice-weight" )
136 - );
137 - } elseif ( $this->special->mName == 'NoticeTemplate' ) {
138 - $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 'width' => '5%' ),
139 - wfMsg ( 'centralnotice-remove' )
140 - );
141 - }
 84+ $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 'width' => '5%' ),
 85+ wfMsg ( 'centralnotice-remove' )
 86+ );
14287 }
14388 $htmlOut .= Xml::element( 'th', array( 'align' => 'left' ),
14489 wfMsg ( 'centralnotice-templates' )
@@ -147,20 +92,18 @@
14893 }
14994
15095 /**
151 - * Close table and add Submit button if we're on the Manage banners page
 96+ * Close table and add Submit button
15297 */
15398 function getEndBody() {
15499 global $wgUser;
155100 $htmlOut = '';
156101 $htmlOut .= Xml::closeElement( 'table' );
157 - if ( $this->special->mName == 'NoticeTemplate' ) {
158 - if ( $this->editable ) {
159 - $htmlOut .= Xml::hidden( 'authtoken', $wgUser->editToken() );
160 - $htmlOut .= Xml::tags( 'div',
161 - array( 'class' => 'cn-buttons' ),
162 - Xml::submitButton( wfMsg( 'centralnotice-modify' ) )
163 - );
164 - }
 102+ if ( $this->editable ) {
 103+ $htmlOut .= Xml::hidden( 'authtoken', $wgUser->editToken() );
 104+ $htmlOut .= Xml::tags( 'div',
 105+ array( 'class' => 'cn-buttons' ),
 106+ Xml::submitButton( wfMsg( 'centralnotice-modify' ) )
 107+ );
165108 }
166109 return $htmlOut;
167110 }
Index: trunk/extensions/CentralNotice/SpecialCentralNotice.php
@@ -894,7 +894,7 @@
895895 * Create form for adding banners to a campaign
896896 */
897897 function addTemplatesForm( $notice ) {
898 - $pager = new TemplatePager( $this );
 898+ $pager = new CentralNoticePager( $this );
899899 $dbr = wfGetDB( DB_SLAVE );
900900 $res = $dbr->select( 'cn_templates', 'tmp_name', '', '', array( 'ORDER BY' => 'tmp_id' ) );
901901
@@ -1317,3 +1317,113 @@
13181318 return $text;
13191319 }
13201320 }
 1321+
 1322+
 1323+class CentralNoticePager extends TemplatePager {
 1324+ var $viewPage, $special;
 1325+ var $editable;
 1326+
 1327+ function __construct( $special ) {
 1328+ parent::__construct( $special );
 1329+ }
 1330+
 1331+ /**
 1332+ * Pull banners from the database
 1333+ */
 1334+ function getQueryInfo() {
 1335+ $notice = $this->mRequest->getVal( 'notice' );
 1336+ // Return all the banners not already assigned to the current campaign
 1337+ return array(
 1338+ 'tables' => array( 'cn_templates', 'cn_assignments', 'cn_notices' ),
 1339+ 'fields' => array( 'cn_templates.tmp_name', 'cn_templates.tmp_id' ),
 1340+ 'conds' => array( 'cn_notices.not_id IS NULL' ),
 1341+ 'join_conds' => array(
 1342+ 'cn_assignments' => array(
 1343+ 'LEFT JOIN',
 1344+ 'cn_assignments.tmp_id = cn_templates.tmp_id'
 1345+ ),
 1346+ 'cn_notices' => array(
 1347+ 'LEFT JOIN',
 1348+ "cn_notices.not_id = cn_assignments.not_id AND cn_notices.not_name = '$notice'"
 1349+ )
 1350+ )
 1351+ );
 1352+ }
 1353+
 1354+ /**
 1355+ * Generate the content of each table row (1 row = 1 banner)
 1356+ */
 1357+ function formatRow( $row ) {
 1358+
 1359+ // Begin banner row
 1360+ $htmlOut = Xml::openElement( 'tr' );
 1361+
 1362+ if ( $this->editable ) {
 1363+ // Add box
 1364+ $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ),
 1365+ Xml::check( 'addTemplates[]', '', array ( 'value' => $row->tmp_name ) )
 1366+ );
 1367+ // Weight select
 1368+ $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ),
 1369+ Xml::listDropDown( "weight[$row->tmp_name]",
 1370+ CentralNotice::dropDownList( wfMsg( 'centralnotice-weight' ), range ( 0, 100, 5 ) ) ,
 1371+ '',
 1372+ '25',
 1373+ '',
 1374+ '' )
 1375+ );
 1376+ }
 1377+
 1378+ // Link and Preview
 1379+ $viewPage = SpecialPage::getTitleFor( 'NoticeTemplate', 'view' );
 1380+ $render = new SpecialNoticeText();
 1381+ $render->project = 'wikipedia';
 1382+ $render->language = $this->mRequest->getVal( 'wpUserLanguage' );
 1383+ $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ),
 1384+ $this->getSkin()->makeLinkObj( $this->viewPage,
 1385+ htmlspecialchars( $row->tmp_name ),
 1386+ 'template=' . urlencode( $row->tmp_name ) ) .
 1387+ Xml::fieldset( wfMsg( 'centralnotice-preview' ),
 1388+ $render->getHtmlNotice( $row->tmp_name ),
 1389+ array( 'class' => 'cn-bannerpreview')
 1390+ )
 1391+ );
 1392+
 1393+ // End banner row
 1394+ $htmlOut .= Xml::closeElement( 'tr' );
 1395+
 1396+ return $htmlOut;
 1397+ }
 1398+
 1399+ /**
 1400+ * Specify table headers
 1401+ */
 1402+ function getStartBody() {
 1403+ $htmlOut = '';
 1404+ $htmlOut .= Xml::openElement( 'table', array( 'cellpadding' => 9 ) );
 1405+ $htmlOut .= Xml::openElement( 'tr' );
 1406+ if ( $this->editable ) {
 1407+ $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 'width' => '5%' ),
 1408+ wfMsg ( "centralnotice-add" )
 1409+ );
 1410+ $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 'width' => '5%' ),
 1411+ wfMsg ( "centralnotice-weight" )
 1412+ );
 1413+ }
 1414+ $htmlOut .= Xml::element( 'th', array( 'align' => 'left' ),
 1415+ wfMsg ( 'centralnotice-templates' )
 1416+ );
 1417+ $htmlOut .= Xml::closeElement( 'tr' );
 1418+ return $htmlOut;
 1419+ }
 1420+
 1421+ /**
 1422+ * Close table
 1423+ */
 1424+ function getEndBody() {
 1425+ global $wgUser;
 1426+ $htmlOut = '';
 1427+ $htmlOut .= Xml::closeElement( 'table' );
 1428+ return $htmlOut;
 1429+ }
 1430+}

Follow-up revisions

RevisionCommit summaryAuthorDate
r71608new query added in r71580 doesn't work correctly, fixing (albeit with an ugly...kaldari00:46, 25 August 2010

Status & tagging log