Index: trunk/extensions/CentralNotice/TemplatePager.php |
— | — | @@ -23,81 +23,168 @@ |
24 | 24 | $this->viewPage = SpecialPage::getTitleFor( 'NoticeTemplate', 'view' ); |
25 | 25 | } |
26 | 26 | |
| 27 | + /** |
| 28 | + * Pull all banners from the database |
| 29 | + */ |
27 | 30 | function getQueryInfo() { |
28 | 31 | return array( |
29 | 32 | 'tables' => 'cn_templates', |
30 | 33 | 'fields' => array( 'tmp_name', 'tmp_id' ), |
31 | 34 | ); |
32 | 35 | } |
33 | | - |
| 36 | + |
| 37 | + /** |
| 38 | + * Sort the banner list by tmp_id |
| 39 | + */ |
34 | 40 | function getIndexField() { |
35 | 41 | return 'tmp_id'; |
36 | 42 | } |
37 | 43 | |
| 44 | + /** |
| 45 | + * Generate the content of each table row (1 row = 1 banner) |
| 46 | + */ |
38 | 47 | function formatRow( $row ) { |
39 | | - $htmlOut = Xml::openElement( 'tr' ); |
| 48 | + |
| 49 | + $templatesAssigned = array(); |
| 50 | + // If we are calling the pager from the campaign editing interface... |
| 51 | + if ( $this->special->mName == 'CentralNotice' ) { |
| 52 | + // Find banners already assigned to the campaign |
| 53 | + $notice = $this->mRequest->getVal( 'notice' ); |
| 54 | + $templatesAssigned = $this->selectTemplatesAssigned( $notice ); |
| 55 | + } |
40 | 56 | |
41 | | - if ( $this->editable ) { |
42 | | - // Remove box |
| 57 | + // If banner is not already assigned... |
| 58 | + if ( !in_array ( $row->tmp_name, $templatesAssigned ) ) { |
| 59 | + |
| 60 | + // Begin banner row |
| 61 | + $htmlOut = Xml::openElement( 'tr' ); |
| 62 | + |
| 63 | + if ( $this->editable ) { |
| 64 | + // If we are calling the pager from the manage banners interface... |
| 65 | + if ( $this->special->mName == 'NoticeTemplate' ) { |
| 66 | + // Remove box |
| 67 | + $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ), |
| 68 | + Xml::check( 'removeTemplates[]', false, |
| 69 | + array( |
| 70 | + 'value' => $row->tmp_name, |
| 71 | + 'onchange' => $this->onRemoveChange |
| 72 | + ) |
| 73 | + ) |
| 74 | + ); |
| 75 | + // Else, if we are calling the pager from the campaign editing interface... |
| 76 | + } elseif ( $this->special->mName == 'CentralNotice' ) { |
| 77 | + // Add box |
| 78 | + $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ), |
| 79 | + Xml::check( 'addTemplates[]', '', array ( 'value' => $row->tmp_name ) ) |
| 80 | + ); |
| 81 | + // Weight select |
| 82 | + $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ), |
| 83 | + Xml::listDropDown( "weight[$row->tmp_name]", |
| 84 | + CentralNotice::dropDownList( wfMsg( 'centralnotice-weight' ), range ( 0, 100, 5 ) ) , |
| 85 | + '', |
| 86 | + '25', |
| 87 | + '', |
| 88 | + '' ) |
| 89 | + ); |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + // Link and Preview |
| 94 | + $viewPage = SpecialPage::getTitleFor( 'NoticeTemplate', 'view' ); |
| 95 | + $render = new SpecialNoticeText(); |
| 96 | + $render->project = 'wikipedia'; |
| 97 | + $render->language = $this->mRequest->getVal( 'wpUserLanguage' ); |
43 | 98 | $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ), |
44 | | - Xml::check( 'removeTemplates[]', false, |
45 | | - array( |
46 | | - 'value' => $row->tmp_name, |
47 | | - 'onchange' => $this->onRemoveChange |
48 | | - ) |
| 99 | + $this->getSkin()->makeLinkObj( $this->viewPage, |
| 100 | + htmlspecialchars( $row->tmp_name ), |
| 101 | + 'template=' . urlencode( $row->tmp_name ) ) . |
| 102 | + Xml::fieldset( wfMsg( 'centralnotice-preview' ), |
| 103 | + $render->getHtmlNotice( $row->tmp_name ), |
| 104 | + array( 'class' => 'cn-bannerpreview') |
49 | 105 | ) |
50 | 106 | ); |
| 107 | + |
| 108 | + // End banner row |
| 109 | + $htmlOut .= Xml::closeElement( 'tr' ); |
51 | 110 | } |
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' ); |
| 111 | + |
68 | 112 | return $htmlOut; |
69 | 113 | } |
70 | 114 | |
| 115 | + /** |
| 116 | + * Specify table headers |
| 117 | + */ |
71 | 118 | function getStartBody() { |
72 | 119 | $htmlOut = ''; |
73 | | - |
74 | | - $htmlOut .= Xml::openElement( 'table', |
75 | | - array( |
76 | | - 'cellpadding' => 9, |
77 | | - 'width' => '100%' |
78 | | - ) |
79 | | - ); |
| 120 | + $htmlOut .= Xml::openElement( 'table', array( 'cellpadding' => 9 ) ); |
| 121 | + $htmlOut .= Xml::openElement( 'tr' ); |
80 | 122 | if ( $this->editable ) { |
81 | | - $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 'width' => '5%' ), |
82 | | - wfMsg ( 'centralnotice-remove' ) |
83 | | - ); |
| 123 | + if ( $this->special->mName == 'CentralNotice' ) { |
| 124 | + $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 'width' => '5%' ), |
| 125 | + wfMsg ( "centralnotice-add" ) |
| 126 | + ); |
| 127 | + $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 'width' => '5%' ), |
| 128 | + wfMsg ( "centralnotice-weight" ) |
| 129 | + ); |
| 130 | + } elseif ( $this->special->mName == 'NoticeTemplate' ) { |
| 131 | + $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 'width' => '5%' ), |
| 132 | + wfMsg ( 'centralnotice-remove' ) |
| 133 | + ); |
| 134 | + } |
84 | 135 | } |
85 | 136 | $htmlOut .= Xml::element( 'th', array( 'align' => 'left' ), |
86 | | - wfMsg ( 'centralnotice-banner-name' ) |
| 137 | + wfMsg ( 'centralnotice-templates' ) |
87 | 138 | ); |
| 139 | + $htmlOut .= Xml::closeElement( 'tr' ); |
88 | 140 | return $htmlOut; |
89 | 141 | } |
90 | 142 | |
| 143 | + /** |
| 144 | + * Close table and add Submit button if we're on the Manage banners page |
| 145 | + */ |
91 | 146 | function getEndBody() { |
92 | 147 | global $wgUser; |
93 | 148 | $htmlOut = ''; |
94 | 149 | $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 | | - ); |
| 150 | + if ( $this->special->mName == 'NoticeTemplate' ) { |
| 151 | + if ( $this->editable ) { |
| 152 | + $htmlOut .= Xml::hidden( 'authtoken', $wgUser->editToken() ); |
| 153 | + $htmlOut .= Xml::tags( 'div', |
| 154 | + array( 'class' => 'cn-buttons' ), |
| 155 | + Xml::submitButton( wfMsg( 'centralnotice-modify' ) ) |
| 156 | + ); |
| 157 | + } |
101 | 158 | } |
102 | 159 | return $htmlOut; |
103 | 160 | } |
| 161 | + |
| 162 | + /** |
| 163 | + * Build a list of all the banners assigned to a campaign |
| 164 | + * @return An array of banner names |
| 165 | + */ |
| 166 | + function selectTemplatesAssigned ( $notice ) { |
| 167 | + $dbr = wfGetDB( DB_SLAVE ); |
| 168 | + $res = $dbr->select( |
| 169 | + array( |
| 170 | + 'cn_notices', |
| 171 | + 'cn_assignments', |
| 172 | + 'cn_templates' |
| 173 | + ), |
| 174 | + array( |
| 175 | + 'cn_templates.tmp_name', |
| 176 | + ), |
| 177 | + array( |
| 178 | + 'cn_notices.not_name' => $notice, |
| 179 | + 'cn_notices.not_id = cn_assignments.not_id', |
| 180 | + 'cn_assignments.tmp_id = cn_templates.tmp_id' |
| 181 | + ), |
| 182 | + __METHOD__, |
| 183 | + array( 'ORDER BY' => 'cn_notices.not_id' ) |
| 184 | + ); |
| 185 | + $templateNames = array(); |
| 186 | + foreach ( $res as $row ) { |
| 187 | + array_push( $templateNames, $row->tmp_name ) ; |
| 188 | + } |
| 189 | + return $templateNames; |
| 190 | + } |
104 | 191 | } |
Index: trunk/extensions/CentralNotice/SpecialCentralNotice.php |
— | — | @@ -924,67 +924,19 @@ |
925 | 925 | * Create form for adding banners to a campaign |
926 | 926 | */ |
927 | 927 | function addTemplatesForm( $notice ) { |
928 | | - global $wgUser; |
929 | | - $sk = $wgUser->getSkin(); |
| 928 | + $pager = new TemplatePager( $this ); |
930 | 929 | $dbr = wfGetDB( DB_SLAVE ); |
931 | 930 | $res = $dbr->select( 'cn_templates', 'tmp_name', '', '', array( 'ORDER BY' => 'tmp_id' ) ); |
932 | 931 | |
933 | 932 | if ( $dbr->numRows( $res ) > 0 ) { |
934 | 933 | // Build HTML |
935 | 934 | $htmlOut = Xml::fieldset( wfMsg( "centralnotice-available-templates" ) ); |
936 | | - $htmlOut .= Xml::openElement( 'table', array( 'cellpadding' => 9 ) ); |
937 | | - |
938 | | - $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 'width' => '5%' ), |
939 | | - wfMsg ( "centralnotice-add" ) ); |
940 | | - $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 'width' => '5%' ), |
941 | | - wfMsg ( "centralnotice-weight" ) ); |
942 | | - $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 'width' => '70%' ), |
943 | | - wfMsg ( "centralnotice-templates" ) ); |
944 | | - |
945 | | - // Find dups |
946 | | - $templatesAssigned = $this->selectTemplatesAssigned( $notice ); |
947 | | - |
948 | | - // Build rows |
949 | | - while ( $row = $dbr->fetchObject( $res ) ) { |
950 | | - if ( !in_array ( $row->tmp_name, $templatesAssigned ) ) { |
951 | | - $htmlOut .= Xml::openElement( 'tr' ); |
952 | | - |
953 | | - // Add |
954 | | - $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ), |
955 | | - Xml::check( 'addTemplates[]', '', array ( 'value' => $row->tmp_name ) ) |
956 | | - ); |
957 | | - |
958 | | - // Weight |
959 | | - $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ), |
960 | | - Xml::listDropDown( "weight[$row->tmp_name]", |
961 | | - $this->dropDownList( wfMsg( 'centralnotice-weight' ), range ( 0, 100, 5 ) ) , |
962 | | - '', |
963 | | - '25', |
964 | | - '', |
965 | | - '' ) |
966 | | - ); |
967 | | - |
968 | | - // Render preview |
969 | | - $viewPage = $this->getTitleFor( 'NoticeTemplate', 'view' ); |
970 | | - $render = new SpecialNoticeText(); |
971 | | - $render->project = 'wikipedia'; |
972 | | - global $wgRequest; |
973 | | - $render->language = $wgRequest->getVal( 'wpUserLanguage' ); |
974 | | - $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ), |
975 | | - $sk->makeLinkObj( $viewPage, |
976 | | - htmlspecialchars( $row->tmp_name ), |
977 | | - 'template=' . urlencode( $row->tmp_name ) ) . |
978 | | - Xml::fieldset( wfMsg( 'centralnotice-preview' ), |
979 | | - $render->getHtmlNotice( $row->tmp_name ), |
980 | | - array( 'class' => 'cn-bannerpreview') |
981 | | - ) |
982 | | - ); |
983 | | - |
984 | | - $htmlOut .= Xml::closeElement( 'tr' ); |
985 | | - } |
986 | | - } |
987 | | - |
988 | | - $htmlOut .= Xml::closeElement( 'table' ); |
| 935 | + |
| 936 | + // Show paginated list of banners |
| 937 | + $htmlOut .= Xml::tags( 'div', array( 'class' => 'cn-pager' ), $pager->getNavigationBar() ); |
| 938 | + $htmlOut .= $pager->getBody(); |
| 939 | + $htmlOut .= Xml::tags( 'div', array( 'class' => 'cn-pager' ), $pager->getNavigationBar() ); |
| 940 | + |
989 | 941 | $htmlOut .= Xml::closeElement( 'fieldset' ); |
990 | 942 | } else { |
991 | 943 | // Nothing found |
— | — | @@ -994,36 +946,6 @@ |
995 | 947 | } |
996 | 948 | |
997 | 949 | /** |
998 | | - * Build a list of all the banners assigned to a campaign |
999 | | - * @return An array of template names |
1000 | | - */ |
1001 | | - function selectTemplatesAssigned ( $notice ) { |
1002 | | - $dbr = wfGetDB( DB_SLAVE ); |
1003 | | - $res = $dbr->select( |
1004 | | - array( |
1005 | | - 'cn_notices', |
1006 | | - 'cn_assignments', |
1007 | | - 'cn_templates' |
1008 | | - ), |
1009 | | - array( |
1010 | | - 'cn_templates.tmp_name', |
1011 | | - ), |
1012 | | - array( |
1013 | | - 'cn_notices.not_name' => $notice, |
1014 | | - 'cn_notices.not_id = cn_assignments.not_id', |
1015 | | - 'cn_assignments.tmp_id = cn_templates.tmp_id' |
1016 | | - ), |
1017 | | - __METHOD__, |
1018 | | - array( 'ORDER BY' => 'cn_notices.not_id' ) |
1019 | | - ); |
1020 | | - $templateNames = array(); |
1021 | | - foreach ( $res as $row ) { |
1022 | | - array_push( $templateNames, $row->tmp_name ) ; |
1023 | | - } |
1024 | | - return $templateNames; |
1025 | | - } |
1026 | | - |
1027 | | - /** |
1028 | 950 | * Lookup function for active banners under a given language and project. This function is |
1029 | 951 | * called by SpecialNoticeText::getJsOutput() in order to build the static Javascript files for |
1030 | 952 | * each project. |