Index: trunk/extensions/CentralNotice/centralnotice.css |
— | — | @@ -31,6 +31,12 @@ |
32 | 32 | #preferences table tr.cn-active-campaign { |
33 | 33 | background-color: #ddffdd; |
34 | 34 | } |
| 35 | +#preferences table#envpicker { |
| 36 | + margin-bottom: 1em; |
| 37 | +} |
| 38 | +#preferences table#envpicker td { |
| 39 | + white-space:nowrap; |
| 40 | +} |
35 | 41 | #preferences div.cn-buttons { |
36 | 42 | padding:1em; |
37 | 43 | } |
Index: trunk/extensions/CentralNotice/SpecialBannerAllocation.php |
— | — | @@ -20,7 +20,7 @@ |
21 | 21 | * Handle different types of page requests |
22 | 22 | */ |
23 | 23 | function execute( $sub ) { |
24 | | - global $wgOut, $wgUser, $wgRequest, $wgScriptPath, $wgNoticeProjects, $wgContLanguageCode; |
| 24 | + global $wgOut, $wgUser, $wgRequest, $wgScriptPath, $wgNoticeProjects, $wgLanguageCode; |
25 | 25 | |
26 | 26 | // Begin output |
27 | 27 | $this->setHeaders(); |
— | — | @@ -52,13 +52,13 @@ |
53 | 53 | $htmlOut .= Xml::element( 'h2', null, 'View banner allocation' ); |
54 | 54 | $htmlOut .= Xml::tags( 'p', null, 'Choose the environment you would like to view banner allocation for:' ); |
55 | 55 | |
56 | | - $htmlOut .= Xml::openElement( 'table', array ( 'cellpadding' => 9 ) ); |
| 56 | + $htmlOut .= Xml::openElement( 'table', array ( 'id' => 'envpicker', 'cellpadding' => 7 ) ); |
57 | 57 | $htmlOut .= Xml::openElement( 'tr' ); |
58 | | - $htmlOut .= Xml::tags( 'td', array( 'style' => 'width: 150px;' ), wfMsgHtml( 'centralnotice-project-name' ) ); |
| 58 | + $htmlOut .= Xml::tags( 'td', array( 'style' => 'width: 20%;' ), wfMsgHtml( 'centralnotice-project-name' ) ); |
59 | 59 | $htmlOut .= Xml::openElement( 'td' ); |
60 | 60 | $htmlOut .= Xml::openElement( 'select', array( 'name' => 'project' ) ); |
61 | 61 | foreach ( $wgNoticeProjects as $value ) { |
62 | | - $htmlOut .= Xml::option( $value, $value, false ); |
| 62 | + $htmlOut .= Xml::option( $value, $value, $value == 'wikipedia' ); |
63 | 63 | } |
64 | 64 | $htmlOut .= Xml::closeElement( 'select' ); |
65 | 65 | $htmlOut .= Xml::closeElement( 'td' ); |
— | — | @@ -68,8 +68,8 @@ |
69 | 69 | $htmlOut .= Xml::openElement( 'td' ); |
70 | 70 | // Make sure the site language is in the list; a custom language code might not have a defined name... |
71 | 71 | $languages = Language::getLanguageNames( true ); |
72 | | - if( !array_key_exists( $wgContLanguageCode, $languages ) ) { |
73 | | - $languages[$wgContLanguageCode] = $wgContLanguageCode; |
| 72 | + if( !array_key_exists( $wgLanguageCode, $languages ) ) { |
| 73 | + $languages[$wgLanguageCode] = $wgLanguageCode; |
74 | 74 | } |
75 | 75 | ksort( $languages ); |
76 | 76 | $htmlOut .= Xml::openElement( 'select', array( 'name' => 'language' ) ); |
— | — | @@ -77,7 +77,7 @@ |
78 | 78 | $htmlOut .= Xml::option( |
79 | 79 | wfMsg( 'centralnotice-language-listing', $code, $name ), |
80 | 80 | $code, |
81 | | - false |
| 81 | + $code == 'en' |
82 | 82 | ); |
83 | 83 | } |
84 | 84 | $htmlOut .= Xml::closeElement( 'select' ); |
— | — | @@ -92,7 +92,7 @@ |
93 | 93 | $htmlOut .= Xml::option( |
94 | 94 | $name, |
95 | 95 | $code, |
96 | | - false |
| 96 | + $code == 'US' |
97 | 97 | ); |
98 | 98 | } |
99 | 99 | $htmlOut .= Xml::closeElement( 'select' ); |
— | — | @@ -113,10 +113,7 @@ |
114 | 114 | |
115 | 115 | // Handle form submissions |
116 | 116 | if ( $wgRequest->wasPosted() ) { |
117 | | - |
118 | | - // Show list of banners by default |
119 | 117 | $this->showList(); |
120 | | - |
121 | 118 | } |
122 | 119 | |
123 | 120 | // End Banners tab content |
— | — | @@ -127,14 +124,50 @@ |
128 | 125 | * Show a list of banners with allocation. Newer banners are shown first. |
129 | 126 | */ |
130 | 127 | function showList() { |
| 128 | + global $wgRequest, $wgOut, $wgUser, $wgRequest; |
| 129 | + |
| 130 | + $sk = $wgUser->getSkin(); |
| 131 | + $viewPage = $this->getTitleFor( 'NoticeTemplate', 'view' ); |
| 132 | + |
131 | 133 | // Begin building HTML |
132 | 134 | $htmlOut = ''; |
133 | 135 | |
134 | 136 | // Begin Allocation list fieldset |
135 | 137 | $htmlOut .= Xml::openElement( 'fieldset', array( 'class' => 'prefsection' ) ); |
136 | 138 | |
137 | | - $htmlOut .= "List goes here"; |
| 139 | + $htmlOut .= Xml::tags( 'p', null, 'Banner allocation for '.$wgRequest->getVal( 'language' ).'.'.$wgRequest->getVal( 'project' ).' in '.$wgRequest->getVal( 'country' ).':' ); |
138 | 140 | |
| 141 | + $bannerLister = new SpecialBannerListLoader(); |
| 142 | + $bannerLister->project = $wgRequest->getVal( 'project' ); |
| 143 | + $bannerLister->language = $wgRequest->getVal( 'language' ); |
| 144 | + $bannerLister->location = $wgRequest->getVal( 'country' ); |
| 145 | + $bannerList = $bannerLister->getJsonList(); |
| 146 | + $banners = json_decode( $bannerList, true ); |
| 147 | + $totalWeight = 0; |
| 148 | + foreach ( $banners as $banner ) { |
| 149 | + $totalWeight += $banner['weight']; |
| 150 | + } |
| 151 | + if ( $banners ) { |
| 152 | + $htmlOut .= Xml::openElement( 'table', array ( 'cellpadding' => 9, 'class' => 'wikitable sortable' ) ); |
| 153 | + $htmlOut .= Xml::openElement( 'tr' ); |
| 154 | + $htmlOut .= Xml::element( 'th', array( 'width' => '40%' ), 'Percentage' ); |
| 155 | + $htmlOut .= Xml::element( 'th', array( 'width' => '60%' ), wfMsg ( "centralnotice-banner" ) ); |
| 156 | + $htmlOut .= Xml::closeElement( 'tr' ); |
| 157 | + foreach ( $banners as $banner ) { |
| 158 | + $htmlOut .= Xml::openElement( 'tr' ); |
| 159 | + $htmlOut .= Xml::openElement( 'td' ); |
| 160 | + $htmlOut .= ( $banner['weight'] / $totalWeight ) * 100 . "%"; |
| 161 | + $htmlOut .= Xml::closeElement( 'td' ); |
| 162 | + $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ), |
| 163 | + $sk->makeLinkObj( $viewPage, htmlspecialchars( $banner['name'] ), 'template=' . urlencode( $banner['name'] ) ) |
| 164 | + ); |
| 165 | + $htmlOut .= Xml::closeElement( 'tr' ); |
| 166 | + } |
| 167 | + $htmlOut .= Xml::closeElement( 'table' ); |
| 168 | + } else { |
| 169 | + $htmlOut .= Xml::tags( 'p', null, 'No banners allocated.' ); |
| 170 | + } |
| 171 | + |
139 | 172 | // End Allocation list fieldset |
140 | 173 | $htmlOut .= Xml::closeElement( 'fieldset' ); |
141 | 174 | |