Index: trunk/extensions/CentralNotice/CentralNotice.php |
— | — | @@ -144,7 +144,9 @@ |
145 | 145 | |
146 | 146 | $wgSpecialPages['NoticeTemplate'] = 'SpecialNoticeTemplate'; |
147 | 147 | $wgAutoloadClasses['SpecialNoticeTemplate'] = $dir . 'SpecialNoticeTemplate.php'; |
| 148 | + |
148 | 149 | $wgAutoloadClasses['CentralNoticeDB'] = $dir . 'CentralNotice.db.php'; |
| 150 | + $wgAutoloadClasses['TemplatePager'] = $dir . 'TemplatePager.php'; |
149 | 151 | } |
150 | 152 | } |
151 | 153 | |
Index: trunk/extensions/CentralNotice/TemplatePager.php |
— | — | @@ -0,0 +1,103 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +if ( !defined( 'MEDIAWIKI' ) ) { |
| 5 | + echo "CentralNotice extension\n"; |
| 6 | + exit( 1 ); |
| 7 | +} |
| 8 | + |
| 9 | +class TemplatePager extends ReverseChronologicalPager { |
| 10 | + var $onRemoveChange, $viewPage, $special; |
| 11 | + var $editable; |
| 12 | + |
| 13 | + function __construct( $special ) { |
| 14 | + $this->special = $special; |
| 15 | + $this->editable = $special->editable; |
| 16 | + parent::__construct(); |
| 17 | + |
| 18 | + // Override paging defaults |
| 19 | + list( $this->mLimit, /* $offset */ ) = $this->mRequest->getLimitOffset( 20, '' ); |
| 20 | + $this->mLimitsShown = array( 20, 50, 100 ); |
| 21 | + |
| 22 | + $msg = Xml::encodeJsVar( wfMsg( 'centralnotice-confirm-delete' ) ); |
| 23 | + $this->onRemoveChange = "if( this.checked ) { this.checked = confirm( $msg ) }"; |
| 24 | + $this->viewPage = SpecialPage::getTitleFor( 'NoticeTemplate', 'view' ); |
| 25 | + } |
| 26 | + |
| 27 | + function getQueryInfo() { |
| 28 | + return array( |
| 29 | + 'tables' => 'cn_templates', |
| 30 | + 'fields' => array( 'tmp_name', 'tmp_id' ), |
| 31 | + ); |
| 32 | + } |
| 33 | + |
| 34 | + function getIndexField() { |
| 35 | + return 'tmp_id'; |
| 36 | + } |
| 37 | + |
| 38 | + function formatRow( $row ) { |
| 39 | + $htmlOut = Xml::openElement( 'tr' ); |
| 40 | + |
| 41 | + if ( $this->editable ) { |
| 42 | + // Remove box |
| 43 | + $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ), |
| 44 | + Xml::check( 'removeTemplates[]', false, |
| 45 | + array( |
| 46 | + 'value' => $row->tmp_name, |
| 47 | + 'onchange' => $this->onRemoveChange |
| 48 | + ) |
| 49 | + ) |
| 50 | + ); |
| 51 | + } |
| 52 | + |
| 53 | + // Link and Preview |
| 54 | + $render = new SpecialNoticeText(); |
| 55 | + $render->project = 'wikipedia'; |
| 56 | + $render->language = $this->mRequest->getVal( 'wpUserLanguage' ); |
| 57 | + $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ), |
| 58 | + $this->getSkin()->makeLinkObj( $this->viewPage, |
| 59 | + htmlspecialchars( $row->tmp_name ), |
| 60 | + 'template=' . urlencode( $row->tmp_name ) ) . |
| 61 | + Xml::fieldset( wfMsg( 'centralnotice-preview' ), |
| 62 | + $render->getHtmlNotice( $row->tmp_name ), |
| 63 | + array( 'class' => 'cn-bannerpreview') |
| 64 | + ) |
| 65 | + ); |
| 66 | + |
| 67 | + $htmlOut .= Xml::closeElement( 'tr' ); |
| 68 | + return $htmlOut; |
| 69 | + } |
| 70 | + |
| 71 | + function getStartBody() { |
| 72 | + $htmlOut = ''; |
| 73 | + |
| 74 | + $htmlOut .= Xml::openElement( 'table', |
| 75 | + array( |
| 76 | + 'cellpadding' => 9, |
| 77 | + 'width' => '100%' |
| 78 | + ) |
| 79 | + ); |
| 80 | + if ( $this->editable ) { |
| 81 | + $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 'width' => '5%' ), |
| 82 | + wfMsg ( 'centralnotice-remove' ) |
| 83 | + ); |
| 84 | + } |
| 85 | + $htmlOut .= Xml::element( 'th', array( 'align' => 'left' ), |
| 86 | + wfMsg ( 'centralnotice-template-name' ) |
| 87 | + ); |
| 88 | + return $htmlOut; |
| 89 | + } |
| 90 | + |
| 91 | + function getEndBody() { |
| 92 | + global $wgUser; |
| 93 | + $htmlOut = ''; |
| 94 | + $htmlOut .= Xml::closeElement( 'table' ); |
| 95 | + if ( $this->editable ) { |
| 96 | + $htmlOut .= Xml::hidden( 'authtoken', $wgUser->editToken() ); |
| 97 | + $htmlOut .= Xml::tags( 'div', |
| 98 | + array( 'class' => 'cn-buttons' ), |
| 99 | + Xml::submitButton( wfMsg( 'centralnotice-modify' ) ) |
| 100 | + ); |
| 101 | + } |
| 102 | + return $htmlOut; |
| 103 | + } |
| 104 | +} |