r62771 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62770‎ | r62771 | r62772 >
Date:14:28, 21 February 2010
Author:jeblad
Status:deferred
Tags:
Comment:
Mostly style changes
Modified paths:
  • /trunk/extensions/TagContent/TagContent.php (modified) (history)

Diff [purge]

Index: trunk/extensions/TagContent/TagContent.php
@@ -30,66 +30,71 @@
3131 # Extension initialization
3232 #----------------------------------------------------------------------------
3333
34 -$wgTagContent = array();
35 -$TagContentVersion = '0.1';
 34+$TagContentVersion = '0.2';
3635 $wgExtensionCredits['parserhook'][] = array(
3736 'name'=>'TagContent',
3837 'version'=>$TagContentVersion,
3938 'author'=>'John Erling Blad',
4039 'url'=>'http://www.mediawiki.org/wiki/Extension:TagContent',
4140 'description' => 'Translate from tags to parser functions'
42 - );
 41+);
4342
44 -$dir = dirname(__FILE__) . '/';
45 -$wgExtensionFunctions[] = 'wfTagContentSetup';
46 -$wgExtensionMessagesFiles['TagContent'] = $dir . 'TagContent.i18n.php';
 43+$wgExtensionFunctions[] = 'efTagContentSetup';
 44+$wgExtensionMessagesFiles['TagContent'] = dirname(__FILE__) . '/TagContent.i18n.php';
4745
48 -$wgTagContentDefine = array(
 46+$egTagContentDefine = array(
4947 );
5048
51 -$wgTagContentBlacklist = array(
 49+$egTagContentBlacklist = array(
5250
5351 // mediawiki
54 - 'noinclude' => true, 'includeonly' => true, 'onlyinclude' => true, 'gallery' => true,
 52+ 'noinclude' => true, 'includeonly' => true, 'onlyinclude' => true, 'gallery' => true,
5553
5654 // html tags
57 - 'address' => true, 'applet' => true, 'area' => true, 'a' => true,
58 - 'base' => true, 'basefont' => true, 'big' => true, 'blockquote' => true,
59 - 'body' => true, 'br' => true, 'b' => true, 'caption' => true,
60 - 'center' => true, 'cite' => true, 'code' => true, 'dd' => true,
61 - 'dfn' => true, 'dir' => true, 'div' => true, 'dl' => true,
62 - 'dt' => true, 'em' => true, 'font' => true, 'form' => true,
63 - 'h1' => true, 'h2' => true, 'h3' => true, 'h4' => true,
64 - 'h5' => true, 'h6' => true, 'head' => true, 'hr' => true,
65 - 'html' => true, 'img' => true, 'input' => true, 'isindex' => true,
66 - 'i' => true, 'kbd' => true, 'link' => true, 'li' => true,
67 - 'map' => true, 'menu' => true, 'meta' => true, 'ol' => true,
68 - 'option' => true, 'param' => true, 'pre' => true, 'p' => true,
69 - 'samp' => true, 'script' => true, 'select' => true, 'small' => true,
70 - 'strike' => true, 'strong' => true, 'style' => true, 'sub' => true,
71 - 'sup' => true, 'table' => true, 'td' => true, 'textarea' => true,
72 - 'th' => true, 'title' => true, 'tr' => true, 'tt' => true,
73 - 'ul' => true, 'u' => true, 'var' => true,
 55+ 'address' => true, 'applet' => true, 'area' => true, 'a' => true,
 56+ 'base' => true, 'basefont' => true, 'big' => true, 'blockquote' => true,
 57+ 'body' => true, 'br' => true, 'b' => true, 'caption' => true,
 58+ 'center' => true, 'cite' => true, 'code' => true, 'dd' => true,
 59+ 'dfn' => true, 'dir' => true, 'div' => true, 'dl' => true,
 60+ 'dt' => true, 'em' => true, 'font' => true, 'form' => true,
 61+ 'h1' => true, 'h2' => true, 'h3' => true, 'h4' => true,
 62+ 'h5' => true, 'h6' => true, 'head' => true, 'hr' => true,
 63+ 'html' => true, 'img' => true, 'input' => true, 'isindex' => true,
 64+ 'i' => true, 'kbd' => true, 'link' => true, 'li' => true,
 65+ 'map' => true, 'menu' => true, 'meta' => true, 'ol' => true,
 66+ 'option' => true, 'param' => true, 'pre' => true, 'p' => true,
 67+ 'samp' => true, 'script' => true, 'select' => true, 'small' => true,
 68+ 'strike' => true, 'strong' => true, 'style' => true, 'sub' => true,
 69+ 'sup' => true, 'table' => true, 'td' => true, 'textarea' => true,
 70+ 'th' => true, 'title' => true, 'tr' => true, 'tt' => true,
 71+ 'ul' => true, 'u' => true, 'var' => true,
7472
7573 );
7674
7775 class TagContent {
78 - private $mParms = null; # hash
79 - private $mTemplate = null; # string
80 - private static $mDefinitions = null; # Title
81 - private $mTag = null; # string
82 - private $mChangeable = false; # bolean
83 - private $mTitle = null; # Title
 76+ private $mParms = null; # hash
 77+ private $mTemplate = null; # string
 78+ private static $mDefinitions = null; # Title
 79+ private $mTag = null; # string
 80+ private $mChangeable = false; # boolean
 81+ private $mTitle = null; # Title
8482
85 - // contructor
 83+ /**
 84+ * Contructor for the TagContent class
 85+ * @param $tag Name of the new tag, that is the
 86+ * @param $template Optional name of the template to use during rendering
 87+ * @param $params Optional default parameters
 88+ * @param $changable
 89+ */
8690 public function TagContent( $tag, $template=null, &$params=null, $changeable=false ) {
8791 if ($params) {
8892 $h = array();
8993 $p = explode('|', htmlspecialchars($params));
9094 $n = 1;
9195 foreach ($p as $item) {
92 - if (false === strrpos($item, '='))
 96+ if (false === strrpos($item, '=')) {
9397 $item = $n++ . '=' . $item;
 98+ }
9499 list($k, $v) = explode('=', $item, 2);
95100 $h[trim($k)] = $v;
96101 }
@@ -100,17 +105,27 @@
101106 $this->mChangeable = $changeable;
102107 }
103108
104 - // accessor
 109+ /**
 110+ * Accessor function for changeable
 111+ * @param $val If set the new value for the changable attribute
 112+ * @return The existing or new value if it is set
 113+ */
105114 public function changeable ( $val ) {
106 - if (isset($val))
 115+ if (isset($val)) {
107116 $this->mChangeable = $val;
 117+ }
108118 return $this->mChangeable;
109119 }
110120
111 - // our own reimplementation of addLink
 121+ /**
 122+ * Local reimplementation of addLink
 123+ * @param $parser Reference to the parser instance
 124+ * @param $title Title of the additional link
 125+ */
112126 private function addLink( &$parser, &$title ) {
113 - if (!$title)
 127+ if (!$title) {
114128 throw new Exception( 'none' );
 129+ }
115130 $lc = LinkCache::singleton();
116131 $pdbk = $title->getPrefixedDBkey();
117132 if ( 0 != ( $id = $lc->getGoodLinkID( $pdbk ) ) ) {
@@ -123,16 +138,24 @@
124139 else {
125140 $id = $title->getArticleID();
126141 $parser->mOutput->addLink( $title, $id );
127 - if (!$id)
 142+ if (!$id) {
128143 throw new Exception( $title->getPrefixedText() );
 144+ }
129145 }
130146 }
131147
132 - // callback function for inserting our own rendering
 148+ /**
 149+ * Callback function for inserting our own rendering
 150+ * @param $text Content for the tag call
 151+ * @param $params Parameters for the tag call
 152+ * @param $parser Reference to the parser instance
 153+ * @return Replaced content wrapped in a recursive call
 154+ */
133155 public function onRender ( $text, $params, &$parser ) {
134156 if ($this->mChangeable) {
135 - if (!$this->mDefinitions)
 157+ if (!$this->mDefinitions) {
136158 $this->mDefinitions = Title::newFromText("Mediawiki:tags-definition");
 159+ }
137160 try {
138161 $this->addLink($parser, $this->mDefinitions);
139162 }
@@ -140,8 +163,9 @@
141164 return $parser->recursiveTagParse( wfMsg( 'tags-definitions-unknown', $e->getMessage() ) );
142165 }
143166 }
144 - if (!$this->mTitle)
 167+ if (!$this->mTitle) {
145168 $this->mTitle = Title::newFromText($this->mTemplate);
 169+ }
146170 try {
147171 $this->addLink($parser, $this->mTitle);
148172 }
@@ -150,25 +174,31 @@
151175 }
152176 $cont = array($this->mTemplate, $text);
153177 foreach ($this->mParms as $k => $v) {
154 - if (isset($params[$k]))
 178+ if (isset($params[$k])) {
155179 $cont[] = "$k=$params[$k]";
156 - else
 180+ }
 181+ else {
157182 $cont[] = "$k=$v";
 183+ }
158184 }
159185 foreach ($params as $k => $v) {
160 - if (!isset($this->mParms[$k]))
 186+ if (!isset($this->mParms[$k])) {
161187 $cont[] = "$k=$v";
 188+ }
162189 }
163190 $output = '{{' . implode('|', $cont) . '}}';
164191 return $parser->recursiveTagParse($output);
165192 }
166193 }
167194
168 -// build necessary structures
169 -function wfTagContentSetup () {
170 - global $wgParser, $wgTagContentBlacklist, $wgTagContentDefine;
 195+/**
 196+* Setup function for the extension
 197+@return True is returned unconditionally
 198+*/
 199+function efTagContentSetup () {
 200+ global $wgParser, $egTagContentBlacklist, $egTagContentDefine;
171201 wfLoadExtensionMessages('TagContent');
172 - foreach ($wgTagContentDefine as $k => $a) {
 202+ foreach ($egTagContentDefine as $k => $a) {
173203 $template = $a[0];
174204 $tag = strtolower($k);
175205 $c = new TagContent($tag, $template, $a[1], false);
@@ -181,7 +211,7 @@
182212 $a = explode('|', $line, 3);
183213 $template = trim($a[1]);
184214 $tag = strtolower(trim($a[0]));
185 - if ( !$wgTagContentBlacklist[$tag] && !isset($wgTagContentDefine[$tag])) {
 215+ if ( !$egTagContentBlacklist[$tag] && !isset($egTagContentDefine[$tag])) {
186216 $c = new TagContent($tag, $template, $a[2], true);
187217 $wgParser->setHook( $tag, array( $c, 'onRender' ));
188218 }

Status & tagging log