• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

修订版3184f3842465cfab1497761d3acb852801cd3581 (tree)
时间2011-02-15 00:45:07
作者henoheno <henoheno>
Commiterhenoheno

Log Message

BugTrack2/343 BugTrack/779 Cleanup transition (3):
* Add/Correct/Simplify more comments, checks
* Simplify $param

更改概述

差异

--- a/plugin/ref.inc.php
+++ b/plugin/ref.inc.php
@@ -1,6 +1,6 @@
11 <?php
22 // PukiWiki - Yet another WikiWikiWeb clone
3-// $Id: ref.inc.php,v 1.55 2011-02-08 14:07:34 henoheno Exp $
3+// $Id: ref.inc.php,v 1.56 2011-02-14 15:45:07 henoheno Exp $
44 // Copyright (C)
55 // 2002-2006, 2011 PukiWiki Developers Team
66 // 2001-2002 Originally written by yu-ji
@@ -45,14 +45,17 @@ define('PLUGIN_REF_USAGE', '([pagename/]attached-file-name[,parameters, ... ][,t
4545
4646 function plugin_ref_inline()
4747 {
48- // "$aryargs[] = & $body" at plugin.php
48+ // NOTE: Already "$aryargs[] = & $body" at plugin.php
4949 if (func_num_args() == 1) {
5050 return htmlsc('&ref(): Usage:' . PLUGIN_REF_USAGE . ';');
5151 }
5252
5353 $params = plugin_ref_body(func_get_args());
54- if (isset($params['_error']) && $params['_error'] != '') {
55- return htmlsc('&ref(): ' . $params['_error'] . ';');
54+ if (isset($params['_error'])) {
55+ return htmlsc('&ref(): ERROR: ' . $params['_error'] . ';');
56+ }
57+ if (! isset($params['_body'])) {
58+ return htmlsc('&ref(): ERROR: No _body;');
5659 }
5760
5861 return $params['_body'];
@@ -65,12 +68,15 @@ function plugin_ref_convert()
6568 }
6669
6770 $params = plugin_ref_body(func_get_args());
68- if (isset($params['_error']) && $params['_error'] != '') {
69- return '<p>' . htmlsc('#ref(): ' . $params['_error']) . '</p>' . "\n";
71+ if (isset($params['_error'])) {
72+ return '<p>' . htmlsc('#ref(): ERROR: ' . $params['_error']) . '</p>' . "\n";
73+ }
74+ if (! isset($params['_body'])) {
75+ return '<p>' . htmlsc('#ref(): ERROR: No _body') . '</p>' . "\n";
7076 }
7177
7278 // Wrap with a table
73- if ((PLUGIN_REF_WRAP_TABLE && ! $params['nowrap']) || $params['wrap']) {
79+ if ((PLUGIN_REF_WRAP_TABLE && ! isset($params['nowrap'])) || isset($params['wrap'])) {
7480 // margin:auto
7581 // Mozilla 1.x = x (wrap, and around are ignored)
7682 // Opera 6 = o
@@ -81,9 +87,12 @@ function plugin_ref_convert()
8187 // Opera 6 = x (aligning seems ignored with wrap)
8288 // Netscape 6 = x (aligning seems ignored with wrap)
8389 // IE6 = o
84- $s_margin = htmlsc($params['around'] ? '0px' : 'auto');
85- $s_margin_align = htmlsc(($params['_align'] == 'center') ? '' :
86- ';margin-' . $params['_align'] . ':0px');
90+ $s_margin = isset($params['around']) ? '0px' : 'auto';
91+ if (! isset($params['_align']) || $params['_align'] == 'center') {
92+ $s_margin_align = '';
93+ } else {
94+ $s_margin_align = ';margin-' . htmlsc($params['_align']) . ':0px';
95+ }
8796 $params['_body'] = <<<EOD
8897 <table class="style_table" style="margin:$s_margin$s_margin_align">
8998 <tr>
@@ -93,7 +102,7 @@ function plugin_ref_convert()
93102 EOD;
94103 }
95104
96- if ($params['around']) {
105+ if (isset($params['around'])) {
97106 $style = ($params['_align'] == 'right') ? 'float:right' : 'float:left';
98107 } else {
99108 $style = 'text-align:' . $params['_align'];
@@ -112,30 +121,27 @@ function plugin_ref_body($args)
112121 $page = isset($vars['page']) ? $vars['page'] : '';
113122
114123 $params = array(
115- // Align
116- 'left' => FALSE,
117- 'center' => FALSE,
118- 'right' => FALSE,
119- '_align' => PLUGIN_REF_DEFAULT_ALIGN,
120-
121- // Wrap with table or not
122- 'wrap' => FALSE,
123- 'nowrap' => FALSE,
124-
125- 'around' => FALSE, // wrap around
124+ // Options
125+ 'left' => FALSE, // Align
126+ 'center' => FALSE, // Align
127+ 'right' => FALSE, // Align
128+ 'wrap' => FALSE, // Wrap the output with table ...
129+ 'nowrap' => FALSE, // or not
130+ 'around' => FALSE, // Text wrap around or not
126131 'noicon' => FALSE, // Suppress showing icon
127- 'nolink' => FALSE, // Suppress link to image itself
128132 'noimg' => FALSE, // Suppress showing image
133+ 'nolink' => FALSE, // Suppress link to image itself
134+ 'zoom' => FALSE, // Lock image width/height ratio as the original said
129135
130- 'zoom' => FALSE, // Lock image width/height ratio
131- '_%' => 0, // percentage
132-
136+ // Flags and values
137+ '_align' => PLUGIN_REF_DEFAULT_ALIGN,
133138 '_size' => FALSE, // Image size specified
134- '_w' => 0, // width
135- '_h' => 0, // height
136-
137- '_title' => '',
138- '_error' => ''
139+ '_w' => 0, // Width
140+ '_h' => 0, // Height
141+ '_%' => 0, // Percentage
142+ //'_title' => '', // Reserved
143+ //'_body => '', // Reserved
144+ //'_error' => '' // Reserved
139145 );
140146
141147 // [Page_name/maybe-separated-with/slashes/]AttachedFileName.sfx or URI
@@ -208,7 +214,7 @@ function plugin_ref_body($args)
208214
209215 ref_check_args($args, $params);
210216
211- $seems_image = (! $params['noimg'] && preg_match(PLUGIN_REF_IMAGE, $name));
217+ $seems_image = (! isset($params['noimg']) && preg_match(PLUGIN_REF_IMAGE, $name));
212218
213219 $width = $height = 0;
214220 $url = $url2 = '';
@@ -258,11 +264,12 @@ function plugin_ref_body($args)
258264 }
259265
260266 $s_url = htmlsc($url);
261- $s_title = htmlsc($params['_title']);
267+ $s_title = isset($params['_title']) ? htmlsc($params['_title']) : '';
262268 $s_info = '';
263269 if ($seems_image) {
264270 $s_title = make_line_rules($s_title);
265- if (ref_check_size($width, $height, $params)) {
271+ if (ref_check_size($width, $height, $params) &&
272+ isset($params['_w']) && isset($params['_h'])) {
266273 $s_info = 'width="' . htmlsc($params['_w']) .
267274 '" height="' . htmlsc($params['_h']) . '" ';
268275 }
@@ -270,7 +277,7 @@ function plugin_ref_body($args)
270277 'alt="' . $s_title . '" ' .
271278 'title="' . $s_title . '" ' .
272279 $s_info . '/>';
273- if (! $params['nolink'] && $url2) {
280+ if (! isset($params['nolink']) && $url2) {
274281 $params['_body'] =
275282 '<a href="' . htmlsc($url2) . '" title="' . $s_title . '">' . "\n" .
276283 $body . "\n" . '</a>';
@@ -282,7 +289,7 @@ function plugin_ref_body($args)
282289 $s_info = htmlsc(get_date('Y/m/d H:i:s', filemtime($file) - LOCALZONE) .
283290 ' ' . sprintf('%01.1f', round(filesize($file) / 1024, 1)) . 'KB');
284291 }
285- $icon = $params['noicon'] ? '' : FILE_ICON;
292+ $icon = isset($params['noicon']) ? '' : FILE_ICON;
286293 $params['_body'] = '<a href="' . $s_url . '" title="' . $s_info . '">' .
287294 $icon . $s_title . '</a>';
288295 }
@@ -325,12 +332,16 @@ function ref_check_args($args, & $params)
325332 }
326333 }
327334 unset($_args);
328-
329335 $params['_title'] = join(',', $_title);
330336 unset($_title);
337+ foreach(array_keys($params) as $key) {
338+ if (! preg_match('/^_/', $key) && empty($params[$key])) {
339+ unset($params[$key]);
340+ }
341+ }
331342
332343 foreach (array('right', 'left', 'center') as $align) {
333- if (isset($params[$align]) && $params[$align]) {
344+ if (isset($params[$align])) {
334345 $params['_align'] = $align;
335346 unset($params[$align]);
336347 break;
@@ -347,11 +358,11 @@ function ref_check_size($width = 0, $height = 0, & $params)
347358 $_width = isset($params['_w']) ? intval($params['_w']) : 0;
348359 $_height = isset($params['_h']) ? intval($params['_h']) : 0;
349360
350- if (isset($params['_size']) && $params['_size']) {
361+ if (isset($params['_size'])) {
351362 if ($width == 0 && $height == 0) {
352363 $width = $_width;
353364 $height = $_height;
354- } else if (isset($params['zoom']) && $params['zoom']) {
365+ } else if (isset($params['zoom'])) {
355366 $_w = $_width ? $width / $_width : 0;
356367 $_h = $_height ? $height / $_height : 0;
357368 $zoom = max($_w, $_h);
@@ -365,7 +376,7 @@ function ref_check_size($width = 0, $height = 0, & $params)
365376 }
366377 }
367378
368- if (isset($params['_%']) && $params['_%']) {
379+ if (isset($params['_%'])) {
369380 $width = $width * $params['_%'] / 100;
370381 $height = $height * $params['_%'] / 100;
371382 }