r42845 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r42844‎ | r42845 | r42846 >
Date:22:18, 30 October 2008
Author:brion
Status:old
Tags:
Comment:
drop the never-quite-finished SVG-to-PNG rendering classes to avoid confusion
Modified paths:
  • /branches/CentralNotice-SpecialPage-Integration/CentralNotice.php (modified) (history)
  • /branches/CentralNotice-SpecialPage-Integration/NoticeRender.php (deleted) (history)
  • /branches/CentralNotice-SpecialPage-Integration/SpecialNoticeRender.php (deleted) (history)

Diff [purge]

Index: branches/CentralNotice-SpecialPage-Integration/NoticeRender.php
@@ -1,98 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * Generated parameters:
6 - * lang=en
7 - * dir=ltr
8 - * count=10,549 # localized
9 - * percent=10.549 # percentage
10 - *
11 - * Template defaults could be, eg:
12 - * progress=<tspan class="count">{{{count}}}</tspan> have donated
13 - * headline=<tspan class="you">You</tspan> can help Wikipedia change the world!
14 - * button=» Donate now!
15 - * font=Gill Sans
16 - * boldfont=Gill Sans Ultra Bold
17 - *
18 - * Per-language overrides for each...
19 - */
20 -
21 -class NoticeRender {
22 - // svg-o-matic!
23 -
24 - function __construct() {
25 - // fixme :D
26 - $this->languageCode = 'en';
27 - $this->languageObj = Language::factory( $this->languageCode );
28 - }
29 -
30 - function expandTemplate( $template ) {
31 - $count = 10550;
32 - $max = 100000;
33 - $params = array(
34 - // Locale information
35 - 'lang' => $this->languageCode,
36 - 'dir' => $this->languageObj->isRTL() ? 'rtl' : 'ltr',
37 -
38 - // Progress information...
39 - 'rawcount' => $count,
40 - 'count' => $this->languageObj->formatNum( $count ),
41 - 'percent' => strval( $count / $max * 100.0 ),
42 -
43 - // And the localized text...
44 - // @fixme
45 - );
46 -
47 - global $wgParser;
48 - $wgParser->firstCallInit();
49 - $parser = clone( $wgParser );
50 - // a damn dirty hack
51 - $parser->clearState();
52 - //$parser->setOutputType( OT_PREPROCESS );
53 - $parser->setOutputType( OT_HTML );
54 - $parser->mOptions = new ParserOptions();
55 - $parser->mTitle = Title::makeTitle( NS_MEDIAWIKI, 'Centralnotice-svg-template' );
56 - // and go!
57 - return $parser->replaceVariables( $template, $params );
58 - }
59 -
60 - function rasterize( $svg ) {
61 - global $wgNoticeRenderDirectory, $wgNoticeRenderPath;
62 -
63 - $hash = md5( $svg );
64 - $svgFile = "$wgNoticeRenderDirectory/$hash.svg";
65 - $pngFile = "$wgNoticeRenderDirectory/$hash.png";
66 - $pngUrl = "$wgNoticeRenderPath/$hash.png";
67 -
68 - if( file_exists( $pngFile ) ) {
69 - wfDebug( __METHOD__ . " $pngFile already rendered.\n" );
70 - return $pngUrl;
71 - }
72 -
73 - if( !file_exists( $wgNoticeRenderDirectory ) ) {
74 - wfDebug( __METHOD__ . " lazy-creating $wgNoticeRenderDirectory\n" );
75 - wfMkdirParents( $wgNoticeRenderDirectory );
76 - }
77 -
78 - file_put_contents( $svgFile, $svg );
79 -
80 - $command = strtr( 'inkscape -z -w $width -f $input -e $output',
81 - array(
82 - '$width' => 622,
83 - '$input' => wfEscapeShellArg( $svgFile ),
84 - '$output' => wfEscapeShellArg( $pngFile ) ) );
85 -
86 - $retval = 0;
87 - $out = wfShellExec( $command, $retval );
88 -
89 - if( $retval ) {
90 - // Error! error!
91 - wfDebug( __METHOD__ . " returned $retval from '$command'\n" );
92 - return false;
93 - }
94 -
95 - return $pngUrl;
96 - }
97 -}
98 -
99 -?>
\ No newline at end of file
Index: branches/CentralNotice-SpecialPage-Integration/SpecialNoticeRender.php
@@ -1,46 +0,0 @@
2 -<?php
3 -
4 -
5 -/**
6 - * Generated parameters:
7 - * lang=en
8 - * dir=ltr
9 - * count=10,549 # localized
10 - * percent=10.549 # percentage
11 - *
12 - * Template defaults could be, eg:
13 - * progress=<tspan class="count">{{{count}}}</tspan> have donated
14 - * headline=<tspan class="you">You</tspan> can help Wikipedia change the world!
15 - * button=» Donate now!
16 - * font=Gill Sans
17 - * boldfont=Gill Sans Ultra Bold
18 - *
19 - * Per-language overrides for each...
20 - *
21 - * {{#expr:ceil(20*{{{rawcount}}}/{{{rawmax}}})}}
22 - */
23 -class SpecialNoticeRender extends UnlistedSpecialPage {
24 - function __construct() {
25 - parent::__construct( "NoticeRender" );
26 - }
27 -
28 - function execute( $par ) {
29 - global $wgOut;
30 - $wgOut->disable();
31 - $this->sendHeaders();
32 - echo $this->getSvgOutput( $par );
33 - }
34 -
35 - private function sendHeaders() {
36 - header( "Content-type: image/svg+xml" );
37 - //header( "Content-type: image/png" );
38 - }
39 -
40 - private function getSvgOutput( $par ) {
41 - $render = new NoticeRender();
42 - $template = wfMsgForContentNoTrans( 'centralnotice-svg-template' );
43 - $svg = $render->expandTemplate( $template );
44 - $pngUrl = $render->rasterize( $svg );
45 - return $svg;
46 - }
47 -}
\ No newline at end of file
Index: branches/CentralNotice-SpecialPage-Integration/CentralNotice.php
@@ -51,10 +51,6 @@
5252 /// Source for live counter information
5353 $wgNoticeCounterSource = "http://donate.wikimedia.org/counter.php";
5454
55 -/// Directory for SVG-to-PNG rasterizations
56 -$wgNoticeRenderDirectory = false; // "$wgUploadDirectory/notice"
57 -$wgNoticeRenderPath = false; // $wgUploadPath/notice
58 -
5955 $wgExtensionFunctions[] = 'efCentralNoticeSetup';
6056
6157 $wgExtensionCredits['other'][] = array(

Status & tagging log