http://www.mediawiki.org/wiki/Special:Code/MediaWiki/73266

Revision: 73266
Author:   kaldari
Date:     2010-09-18 01:04:29 +0000 (Sat, 18 Sep 2010)

Log Message:
-----------
more preliminary code for banner allocation viewer (not localizable yet)

Modified Paths:
--------------
    trunk/extensions/CentralNotice/SpecialBannerAllocation.php
    trunk/extensions/CentralNotice/centralnotice.css

Modified: trunk/extensions/CentralNotice/SpecialBannerAllocation.php
===================================================================
--- trunk/extensions/CentralNotice/SpecialBannerAllocation.php  2010-09-18 
00:57:49 UTC (rev 73265)
+++ trunk/extensions/CentralNotice/SpecialBannerAllocation.php  2010-09-18 
01:04:29 UTC (rev 73266)
@@ -20,7 +20,7 @@
         * Handle different types of page requests
         */
        function execute( $sub ) {
-               global $wgOut, $wgUser, $wgRequest, $wgScriptPath, 
$wgNoticeProjects, $wgContLanguageCode;
+               global $wgOut, $wgUser, $wgRequest, $wgScriptPath, 
$wgNoticeProjects, $wgLanguageCode;
 
                // Begin output
                $this->setHeaders();
@@ -52,13 +52,13 @@
                $htmlOut .= Xml::element( 'h2', null, 'View banner allocation' 
);
                $htmlOut .= Xml::tags( 'p', null, 'Choose the environment you 
would like to view banner allocation for:' );
                
-               $htmlOut .= Xml::openElement( 'table', array ( 'cellpadding' => 
9 ) );
+               $htmlOut .= Xml::openElement( 'table', array ( 'id' => 
'envpicker', 'cellpadding' => 7 ) );
                $htmlOut .= Xml::openElement( 'tr' );
-               $htmlOut .= Xml::tags( 'td', array( 'style' => 'width: 150px;' 
), wfMsgHtml( 'centralnotice-project-name' ) );
+               $htmlOut .= Xml::tags( 'td', array( 'style' => 'width: 20%;' ), 
wfMsgHtml( 'centralnotice-project-name' ) );
                $htmlOut .= Xml::openElement( 'td' );
                $htmlOut .= Xml::openElement( 'select', array( 'name' => 
'project' ) );
                foreach ( $wgNoticeProjects as $value ) {
-                       $htmlOut .= Xml::option( $value, $value, false );
+                       $htmlOut .= Xml::option( $value, $value, $value == 
'wikipedia' );
                }
                $htmlOut .= Xml::closeElement( 'select' );
                $htmlOut .= Xml::closeElement( 'td' );
@@ -68,8 +68,8 @@
                $htmlOut .= Xml::openElement( 'td' );
                // Make sure the site language is in the list; a custom 
language code might not have a defined name...
                $languages = Language::getLanguageNames( true );
-               if( !array_key_exists( $wgContLanguageCode, $languages ) ) {
-                       $languages[$wgContLanguageCode] = $wgContLanguageCode;
+               if( !array_key_exists( $wgLanguageCode, $languages ) ) {
+                       $languages[$wgLanguageCode] = $wgLanguageCode;
                }
                ksort( $languages );
                $htmlOut .= Xml::openElement( 'select', array( 'name' => 
'language' ) );
@@ -77,7 +77,7 @@
                        $htmlOut .= Xml::option(
                                wfMsg( 'centralnotice-language-listing', $code, 
$name ),
                                $code,
-                               false
+                               $code == 'en'
                        );
                }
                $htmlOut .= Xml::closeElement( 'select' );
@@ -92,7 +92,7 @@
                        $htmlOut .= Xml::option(
                                $name,
                                $code,
-                               false
+                               $code == 'US'
                        );
                }
                $htmlOut .= Xml::closeElement( 'select' );
@@ -113,10 +113,7 @@
                
                // Handle form submissions
                if ( $wgRequest->wasPosted() ) {
-                               
-                       // Show list of banners by default
                        $this->showList();
-                       
                }
 
                // End Banners tab content
@@ -127,14 +124,50 @@
         * Show a list of banners with allocation. Newer banners are shown 
first.
         */
        function showList() {
+               global $wgRequest, $wgOut, $wgUser, $wgRequest;
+               
+               $sk = $wgUser->getSkin();
+               $viewPage = $this->getTitleFor( 'NoticeTemplate', 'view' );
+               
                // Begin building HTML
                $htmlOut = '';
                
                // Begin Allocation list fieldset
                $htmlOut .= Xml::openElement( 'fieldset', array( 'class' => 
'prefsection' ) );
                
-               $htmlOut .= "List goes here";
+               $htmlOut .= Xml::tags( 'p', null, 'Banner allocation for 
'.$wgRequest->getVal( 'language' ).'.'.$wgRequest->getVal( 'project' ).' in 
'.$wgRequest->getVal( 'country' ).':' );
                
+               $bannerLister = new SpecialBannerListLoader();
+               $bannerLister->project = $wgRequest->getVal( 'project' );
+               $bannerLister->language = $wgRequest->getVal( 'language' );
+               $bannerLister->location = $wgRequest->getVal( 'country' );
+               $bannerList = $bannerLister->getJsonList();
+               $banners = json_decode( $bannerList, true );
+               $totalWeight = 0;
+               foreach ( $banners as $banner ) {
+                       $totalWeight += $banner['weight'];
+               }
+               if ( $banners ) {
+                       $htmlOut .= Xml::openElement( 'table', array ( 
'cellpadding' => 9, 'class' => 'wikitable sortable' ) );
+                       $htmlOut .= Xml::openElement( 'tr' );
+                       $htmlOut .= Xml::element( 'th', array( 'width' => '40%' 
), 'Percentage' );
+                       $htmlOut .= Xml::element( 'th', array( 'width' => '60%' 
), wfMsg ( "centralnotice-banner" ) );
+                       $htmlOut .= Xml::closeElement( 'tr' );
+                       foreach ( $banners as $banner ) {
+                               $htmlOut .= Xml::openElement( 'tr' );
+                               $htmlOut .= Xml::openElement( 'td' );
+                               $htmlOut .= ( $banner['weight'] / $totalWeight 
) * 100 . "%";
+                               $htmlOut .= Xml::closeElement( 'td' );
+                               $htmlOut .= Xml::tags( 'td', array( 'valign' => 
'top' ),
+                                       $sk->makeLinkObj( $viewPage, 
htmlspecialchars( $banner['name'] ), 'template=' . urlencode( $banner['name'] ) 
)
+                               );
+                               $htmlOut .= Xml::closeElement( 'tr' );
+                       }
+                       $htmlOut .= Xml::closeElement( 'table' );
+               } else {
+                       $htmlOut .= Xml::tags( 'p', null, 'No banners 
allocated.' );
+               }
+               
                // End Allocation list fieldset
                $htmlOut .= Xml::closeElement( 'fieldset' );
 

Modified: trunk/extensions/CentralNotice/centralnotice.css
===================================================================
--- trunk/extensions/CentralNotice/centralnotice.css    2010-09-18 00:57:49 UTC 
(rev 73265)
+++ trunk/extensions/CentralNotice/centralnotice.css    2010-09-18 01:04:29 UTC 
(rev 73266)
@@ -31,6 +31,12 @@
 #preferences table tr.cn-active-campaign {
        background-color: #ddffdd;
 }
+#preferences table#envpicker {
+       margin-bottom: 1em;
+}
+#preferences table#envpicker td {
+       white-space:nowrap;
+}
 #preferences div.cn-buttons {
        padding:1em;
 }



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to