Index: trunk/extensions/CentralNotice/TemplatePager.php |
— | — | @@ -1,10 +1,5 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -if ( !defined( 'MEDIAWIKI' ) ) { |
5 | | - echo "CentralNotice extension\n"; |
6 | | - exit( 1 ); |
7 | | -} |
8 | | - |
9 | 4 | class TemplatePager extends ReverseChronologicalPager { |
10 | 5 | var $onRemoveChange, $viewPage, $special; |
11 | 6 | var $editable; |
— | — | @@ -22,41 +17,20 @@ |
23 | 18 | $this->onRemoveChange = "if( this.checked ) { this.checked = confirm( $msg ) }"; |
24 | 19 | $this->viewPage = SpecialPage::getTitleFor( 'NoticeTemplate', 'view' ); |
25 | 20 | } |
26 | | - |
27 | | - /** |
28 | | - * Pull banners from the database |
29 | | - */ |
| 21 | + |
30 | 22 | 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 | + ); |
54 | 28 | } |
55 | 29 | |
56 | 30 | /** |
57 | 31 | * Sort the banner list by tmp_id |
58 | 32 | */ |
59 | 33 | function getIndexField() { |
60 | | - return 'cn_templates.tmp_id'; |
| 34 | + return 'tmp_id'; |
61 | 35 | } |
62 | 36 | |
63 | 37 | /** |
— | — | @@ -67,35 +41,15 @@ |
68 | 42 | // Begin banner row |
69 | 43 | $htmlOut = Xml::openElement( 'tr' ); |
70 | 44 | |
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 | + ); |
100 | 54 | |
101 | 55 | // Link and Preview |
102 | 56 | $viewPage = SpecialPage::getTitleFor( 'NoticeTemplate', 'view' ); |
— | — | @@ -126,18 +80,9 @@ |
127 | 81 | $htmlOut .= Xml::openElement( 'table', array( 'cellpadding' => 9 ) ); |
128 | 82 | $htmlOut .= Xml::openElement( 'tr' ); |
129 | 83 | 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 | + ); |
142 | 87 | } |
143 | 88 | $htmlOut .= Xml::element( 'th', array( 'align' => 'left' ), |
144 | 89 | wfMsg ( 'centralnotice-templates' ) |
— | — | @@ -147,20 +92,18 @@ |
148 | 93 | } |
149 | 94 | |
150 | 95 | /** |
151 | | - * Close table and add Submit button if we're on the Manage banners page |
| 96 | + * Close table and add Submit button |
152 | 97 | */ |
153 | 98 | function getEndBody() { |
154 | 99 | global $wgUser; |
155 | 100 | $htmlOut = ''; |
156 | 101 | $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 | + ); |
165 | 108 | } |
166 | 109 | return $htmlOut; |
167 | 110 | } |
Index: trunk/extensions/CentralNotice/SpecialCentralNotice.php |
— | — | @@ -894,7 +894,7 @@ |
895 | 895 | * Create form for adding banners to a campaign |
896 | 896 | */ |
897 | 897 | function addTemplatesForm( $notice ) { |
898 | | - $pager = new TemplatePager( $this ); |
| 898 | + $pager = new CentralNoticePager( $this ); |
899 | 899 | $dbr = wfGetDB( DB_SLAVE ); |
900 | 900 | $res = $dbr->select( 'cn_templates', 'tmp_name', '', '', array( 'ORDER BY' => 'tmp_id' ) ); |
901 | 901 | |
— | — | @@ -1317,3 +1317,113 @@ |
1318 | 1318 | return $text; |
1319 | 1319 | } |
1320 | 1320 | } |
| 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 | +} |