Index: trunk/extensions/CentralNotice/TemplatePager.php |
— | — | @@ -57,12 +57,17 @@ |
58 | 58 | $render = new SpecialBannerLoader(); |
59 | 59 | $render->siteName = 'Wikipedia'; |
60 | 60 | $render->language = $this->mRequest->getVal( 'wpUserLanguage' ); |
| 61 | + try { |
| 62 | + $preview = $render->getHtmlNotice( $row->tmp_name ); |
| 63 | + } catch ( SpecialBannerLoaderException $e ) { |
| 64 | + $preview = wfMsg( 'centralnotice-nopreview' ); |
| 65 | + } |
61 | 66 | $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ), |
62 | 67 | $this->getSkin()->makeLinkObj( $this->viewPage, |
63 | 68 | htmlspecialchars( $row->tmp_name ), |
64 | 69 | 'template=' . urlencode( $row->tmp_name ) ) . |
65 | 70 | Xml::fieldset( wfMsg( 'centralnotice-preview' ), |
66 | | - $render->getHtmlNotice( $row->tmp_name ), |
| 71 | + $preview, |
67 | 72 | array( 'class' => 'cn-bannerpreview') |
68 | 73 | ) |
69 | 74 | ); |
Index: trunk/extensions/CentralNotice/SpecialCentralNotice.php |
— | — | @@ -995,16 +995,23 @@ |
996 | 996 | ); |
997 | 997 | |
998 | 998 | $viewPage = $this->getTitleFor( 'NoticeTemplate', 'view' ); |
| 999 | + |
| 1000 | + /* XXX this code is duplicated in the CentralNoticePager::formatRow */ |
999 | 1001 | $render = new SpecialBannerLoader(); |
1000 | 1002 | $render->siteName = 'Wikipedia'; |
1001 | 1003 | global $wgRequest; |
1002 | 1004 | $render->language = $wgRequest->getVal( 'wpUserLanguage' ); |
| 1005 | + try { |
| 1006 | + $preview = $render->getHtmlNotice( $row->tmp_name ); |
| 1007 | + } catch ( SpecialBannerLoaderException $e ) { |
| 1008 | + $preview = wfMsg( 'centralnotice-nopreview' ); |
| 1009 | + } |
1003 | 1010 | $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ), |
1004 | 1011 | $sk->makeLinkObj( $viewPage, |
1005 | 1012 | htmlspecialchars( $row->tmp_name ), |
1006 | 1013 | 'template=' . urlencode( $row->tmp_name ) ) . |
1007 | 1014 | Xml::fieldset( wfMsg( 'centralnotice-preview' ), |
1008 | | - $render->getHtmlNotice( $row->tmp_name ), |
| 1015 | + $preview, |
1009 | 1016 | array( 'class' => 'cn-bannerpreview') |
1010 | 1017 | ) |
1011 | 1018 | ); |
— | — | @@ -1807,12 +1814,17 @@ |
1808 | 1815 | $render = new SpecialBannerLoader(); |
1809 | 1816 | $render->siteName = 'Wikipedia'; |
1810 | 1817 | $render->language = $this->mRequest->getVal( 'wpUserLanguage' ); |
| 1818 | + try { |
| 1819 | + $preview = $render->getHtmlNotice( $row->tmp_name ); |
| 1820 | + } catch ( SpecialBannerLoaderException $e ) { |
| 1821 | + $preview = wfMsg( 'centralnotice-nopreview' ); |
| 1822 | + } |
1811 | 1823 | $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ), |
1812 | 1824 | $this->getSkin()->makeLinkObj( $this->viewPage, |
1813 | 1825 | htmlspecialchars( $row->tmp_name ), |
1814 | 1826 | 'template=' . urlencode( $row->tmp_name ) ) . |
1815 | 1827 | Xml::fieldset( wfMsg( 'centralnotice-preview' ), |
1816 | | - $render->getHtmlNotice( $row->tmp_name ), |
| 1828 | + $preview, |
1817 | 1829 | array( 'class' => 'cn-bannerpreview') |
1818 | 1830 | ) |
1819 | 1831 | ); |
Index: trunk/extensions/CentralNotice/SpecialBannerLoader.php |
— | — | @@ -59,6 +59,7 @@ |
60 | 60 | * Generate the JS for the requested banner |
61 | 61 | * @return a string of Javascript containing a call to insertBanner() |
62 | 62 | * with JSON containing the banner content as the parameter |
| 63 | + * @throws SpecialBannerLoaderException |
63 | 64 | */ |
64 | 65 | function getJsNotice( $bannerName ) { |
65 | 66 | // Make sure the banner exists |
— | — | @@ -78,6 +79,7 @@ |
79 | 80 | |
80 | 81 | /** |
81 | 82 | * Generate the HTML for the requested banner |
| 83 | + * @throws SpecialBannerLoaderException |
82 | 84 | */ |
83 | 85 | function getHtmlNotice( $bannerName ) { |
84 | 86 | // Make sure the banner exists |
— | — | @@ -105,6 +107,7 @@ |
106 | 108 | * Extract a message name and send to getMessage() for translation |
107 | 109 | * @param $match A message array with 2 members: raw match, short name of message |
108 | 110 | * @return translated messsage string |
| 111 | + * @throws SpecialBannerLoaderException |
109 | 112 | */ |
110 | 113 | function getNoticeField( $match ) { |
111 | 114 | $field = $match[1]; |
— | — | @@ -156,22 +159,9 @@ |
157 | 160 | return $out; |
158 | 161 | } |
159 | 162 | |
160 | | - private function fetchUrl($url) { |
161 | | - $ctx = stream_context_create(array('http' => array( |
162 | | - 'method' => "GET", |
163 | | - 'header' => "User-Agent: CentralNotice/1.0 (+http://www.mediawiki.org/wiki/Extension:CentralNotice)\r\n") |
164 | | - )); |
165 | | - wfSuppressWarnings(); |
166 | | - $content = file_get_contents( $url, false, $ctx); |
167 | | - wfRestoreWarnings(); |
168 | | - if( !$content ) { |
169 | | - throw new RemoteServerProblemException(); |
170 | | - } |
171 | | - return $content; |
172 | | - } |
173 | | - |
174 | 163 | /** |
175 | 164 | * Pull the current amount raised during a fundraiser |
| 165 | + * @throws SpecialBannerLoaderException |
176 | 166 | */ |
177 | 167 | private function getDonationAmount() { |
178 | 168 | global $wgNoticeCounterSource, $wgMemc; |
— | — | @@ -179,7 +169,11 @@ |
180 | 170 | $count = intval( $wgMemc->get( wfMemcKey( 'centralnotice', 'counter' ) ) ); |
181 | 171 | if ( !$count ) { |
182 | 172 | // Pull from dynamic counter |
183 | | - $count = intval( $this->fetchUrl( $wgNoticeCounterSource )); |
| 173 | + $counter_value = Http::get( $wgNoticeCounterSource ); |
| 174 | + if( !$counter_value ) { |
| 175 | + throw new RemoteServerProblemException(); |
| 176 | + } |
| 177 | + $count = intval( $counter_value ); |
184 | 178 | if ( !$count ) { |
185 | 179 | // Pull long-cached amount |
186 | 180 | $count = intval( $wgMemc->get( |
Index: trunk/extensions/CentralNotice/CentralNotice.i18n.php |
— | — | @@ -25,6 +25,7 @@ |
26 | 26 | 'centralnotice-modify' => 'Submit', |
27 | 27 | 'centralnotice-save-banner' => 'Save banner', |
28 | 28 | 'centralnotice-preview' => 'Preview', |
| 29 | + 'centralnotice-nopreview' => '(Preview not available)', |
29 | 30 | 'centralnotice-add-new' => 'Add a new campaign', |
30 | 31 | 'centralnotice-remove' => 'Remove', |
31 | 32 | 'centralnotice-translate-heading' => 'Translation for $1', |
— | — | @@ -167,6 +168,7 @@ |
168 | 169 | 'centralnotice-modify' => '{{Identical|Submit}}', |
169 | 170 | 'centralnotice-save-banner' => 'Label for the submit button which saves a CentralNotice banner.', |
170 | 171 | 'centralnotice-preview' => '{{Identical|Preview}}', |
| 172 | + 'centralnotice-nopreview' => '{{Identical|Nopreview}}', |
171 | 173 | 'centralnotice-remove' => '{{Identical|Remove}}', |
172 | 174 | 'centralnotice-translate-heading' => 'Fieldset label. $1 is a name of a template.', |
173 | 175 | 'centralnotice-add' => '{{Identical|Add}}', |
Index: trunk/extensions/CentralNotice/SpecialNoticeTemplate.php |
— | — | @@ -338,14 +338,19 @@ |
339 | 339 | $render = new SpecialBannerLoader(); |
340 | 340 | $render->siteName = 'Wikipedia'; |
341 | 341 | $render->language = $wpUserLang; |
| 342 | + try { |
| 343 | + $preview = $render->getHtmlNotice( $wgRequest->getText( 'template' ) ); |
| 344 | + } catch ( SpecialBannerLoaderException $e ) { |
| 345 | + $preview = wfMsg( 'centralnotice-nopreview' ); |
| 346 | + } |
342 | 347 | if ( $render->language != '' ) { |
343 | 348 | $htmlOut .= Xml::fieldset( |
344 | 349 | wfMsg( 'centralnotice-preview' ) . " ($render->language)", |
345 | | - $render->getHtmlNotice( $wgRequest->getText( 'template' ) ) |
| 350 | + $preview |
346 | 351 | ); |
347 | 352 | } else { |
348 | 353 | $htmlOut .= Xml::fieldset( wfMsg( 'centralnotice-preview' ), |
349 | | - $render->getHtmlNotice( $wgRequest->getText( 'template' ) ) |
| 354 | + $preview |
350 | 355 | ); |
351 | 356 | } |
352 | 357 | |
— | — | @@ -628,12 +633,17 @@ |
629 | 634 | $render = new SpecialBannerLoader(); |
630 | 635 | $render->siteName = 'Wikipedia'; |
631 | 636 | $render->language = $lang; |
| 637 | + try { |
| 638 | + $preview = $render->getHtmlNotice( $template ); |
| 639 | + } catch ( SpecialBannerLoaderException $e ) { |
| 640 | + $preview = wfMsg( 'centralnotice-nopreview' ); |
| 641 | + } |
632 | 642 | $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ), |
633 | 643 | $sk->makeLinkObj( $viewPage, |
634 | 644 | $lang, |
635 | 645 | 'template=' . urlencode( $template ) . "&wpUserLanguage=$lang" ) . |
636 | 646 | Xml::fieldset( wfMsg( 'centralnotice-preview' ), |
637 | | - $render->getHtmlNotice( $template ), |
| 647 | + $preview, |
638 | 648 | array( 'class' => 'cn-bannerpreview') |
639 | 649 | ) |
640 | 650 | ); |