r26389 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r26388‎ | r26389 | r26390 >
Date:02:17, 4 October 2007
Author:brion
Status:old
Tags:
Comment:
Quick stab at rotating quotes. Quotes in rotation are send as a batch with the JS and picked at random at runtime, so the whole set is cached together.
Modified paths:
  • /trunk/extensions/CentralNotice/SpecialNoticeText.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/SpecialNoticeText.php
@@ -16,14 +16,25 @@
1717 }
1818
1919 function getJsOutput() {
20 - global $wgSiteNotice;
21 - $encNotice = Xml::escapeJsString( $this->getHtmlNotice() );
22 - return <<<EOT
23 -wgNotice = "$encNotice";
24 -EOT;
 20+ return 'wgNotice="' .
 21+ str_replace( '$quote',
 22+ '"+' . $this->getJsQuoteSelector() . '+"',
 23+ Xml::escapeJsString( $this->getHtmlNotice() ) )
 24+ . '";';
2525 }
2626
 27+ function getJsQuoteSelector() {
 28+ $quotes = $this->getQuotes();
 29+ return
 30+ 'function(){' .
 31+ 'var quotes=' . Xml::encodeJsVar( $quotes ) . ';' .
 32+ 'return quotes[Math.floor(Math.random()*quotes.length)];' .
 33+ '}()';
 34+ }
 35+
2736 function getHtmlNotice() {
 37+ $headline = $this->getHeadline();
 38+ $meter = $this->getMeter();
2839 return <<<EOT
2940 <style type="text/css">
3041 .fundraiser-box {
@@ -58,8 +69,7 @@
5970
6071 overflow: hidden;
6172 }
62 -
63 -.fundraiser-bar {
 73+.fundraiser-meter {
6474 margin-top: 5px;
6575 margin-bottom: 0px;
6676 }
@@ -68,13 +78,13 @@
6979 <tr>
7080 <td class="fundraiser-text">
7181 <div class="fundraiser-headline">
72 - <a href="http://fundraising.wikimedia.org/">What you didn't know about Wikipedia . . . <small>(See more)</small></a>
 82+ <a href="http://fundraising.wikimedia.org/">$headline</a>
7383 </div>
7484 <div class='fundraiser-quote'>
75 - <a href="http://fundraising.wikimedia.org/">Anonymous: Well Done! Anonymous: What on earth did we do...</a>
 85+ <a href="http://fundraising.wikimedia.org/">\$quote</a>
7686 </div>
77 - <div class='fundraiser-bar'>
78 - <a href="http://fundraising.wikimedia.org/"><img src="http://upload.wikimedia.org/fundraising/2007/meter.png" width='407' height='14' /></a>
 87+ <div class='fundraiser-meter'>
 88+ <a href="http://fundraising.wikimedia.org/">$meter</a>
7989 </div>
8090 </td>
8191 <td width="109" height="75">
@@ -84,6 +94,21 @@
8595 </table>
8696 EOT;
8797 }
 98+
 99+ function getHeadline() {
 100+ return "What you didn't know about Wikipedia . . . <small>(See more)</small>";
 101+ }
 102+
 103+ function getQuotes() {
 104+ return array(
 105+ "Anonymous: Well Done!",
 106+ "Anonymous: What on earth did we do...",
 107+ );
 108+ }
 109+
 110+ function getMeter() {
 111+ return "<img src=\"http://upload.wikimedia.org/fundraising/2007/meter.png\" width='407' height='14' />";
 112+ }
88113 }
89114
90115 ?>
\ No newline at end of file

Status & tagging log