r75369 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r75368‎ | r75369 | r75370 >
Date:17:51, 25 October 2010
Author:dantman
Status:deferred
Tags:
Comment:
Cleanup some stuff in mw-editcount noted in comment c10391 of r68613
Modified paths:
  • /trunk/extensions/mw-editcount/EditCountPage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/mw-editcount/EditCountPage.php
@@ -46,11 +46,11 @@
4747 * @param string $par the user that was entered into the form
4848 * @access public
4949 */
50 - function execute($par = null)
 50+ function execute($par)
5151 {
5252 global $wgRequest, $wgOut;
5353 wfProfileIn(__METHOD__);
54 - $this->target = ($par !== null) ? $par : $wgRequest->getVal("target");
 54+ $this->target = $wgRequest->getVal("target", isset($par) ? $par : null);
5555
5656 if ($this->target === null || !strlen($this->target)) {
5757 $this->showInputForm();
@@ -60,7 +60,7 @@
6161
6262 $this->showInputForm($this->target);
6363
64 - $nt = Title::newFromURL($this->target);
 64+ $nt = Title::newFromText($this->target);
6565 if (!$nt) {
6666 $wgOut->addWikiMsg("editcount-notuser", $this->target);
6767 wfProfileOut(__METHOD__);
@@ -92,12 +92,12 @@
9393 }
9494
9595 $table = "";
96 - $table .= wfElement("table", array("style" => "$this->border text-align: center; margin-left: 25%; margin-right: auto; margin-top: 7px; border-collapse: collapse"), null, null);
97 - $table .= wfElement("tr", array("style" => $this->border), null);
98 - $table .= wfElement("th", array("style" => $this->border), wfMsg("editcount-namespace"));
99 - $table .= wfElement("th", array("style" => $this->border), wfMsg("editcount-edits"));
100 - $table .= wfElement("th", array("style" => $this->border), wfMsg("editcount-percent"));
101 - $table .= wfCloseElement("tr");
 96+ $table .= Html::openElement("table", array("style" => "{$this->border} text-align: center; margin-left: 25%; margin-right: auto; margin-top: 7px; border-collapse: collapse;"));
 97+ $table .= Html::openElement("tr", array("style" => $this->border));
 98+ $table .= Html::element("th", array("style" => $this->border), wfMsg("editcount-namespace"));
 99+ $table .= Html::element("th", array("style" => $this->border), wfMsg("editcount-edits"));
 100+ $table .= Html::element("th", array("style" => $this->border), wfMsg("editcount-percent"));
 101+ $table .= Xml::closeElement("tr");
102102
103103 $totalEC = $ec->getTotal();
104104 $nsCount = $ec->getNamspaces();
@@ -108,16 +108,16 @@
109109 $table .= $this->doRow(array(
110110 $nsNames[$nsInt],
111111 $nsEC,
112 - round(($nsEC/$totalEC*100), 1) . wfMsg("editcount-percentsym"))
113 - );
 112+ round(($nsEC/$totalEC*100), 1) . wfMsg("editcount-percentsym")
 113+ ));
114114 }
115115
116 - $table .= wfElement("tr", null, null);
117 - $table .= wfElement("td", array("style" => "font-weight: bold; {$this->border}"), wfMsg("editcount-total"));
118 - $table .= wfElement("td", array("colspan" => "2", "style" => $this->border), $totalEC);
119 - $table .= wfCloseElement("tr");
 116+ $table .= Html::openElement("tr", null, null);
 117+ $table .= Html::element("td", array("style" => "font-weight: bold; {$this->border}"), wfMsg("editcount-total"));
 118+ $table .= Html::element("td", array("colspan" => "2", "style" => $this->border), $totalEC);
 119+ $table .= Xml::closeElement("tr");
120120
121 - $table .= wfCloseElement("table");
 121+ $table .= Xml::closeElement("table");
122122 $wgOut->addHtml($table);
123123
124124 wfProfileOut(__METHOD__);
@@ -133,17 +133,17 @@
134134 function doRow($cells)
135135 {
136136 wfProfileIn(__METHOD__);
137 - $ret = wfElement("tr", null, null);
 137+ $ret = Html::openElement("tr", null, null);
138138 if (count($cells) == 2) {
139 - $ret .= wfElement("td", array("style" => $this->border), $cells[0]);
140 - $ret .= wfElement("td", array("style" => $this->border, "colspan" => "2"), $cells[1]);
 139+ $ret .= Html::element("td", array("style" => $this->border), $cells[0]);
 140+ $ret .= Html::element("td", array("style" => $this->border, "colspan" => "2"), $cells[1]);
141141 }
142142 else {
143143 for ($i = 0; $i < 3; ++$i) {
144 - $ret .= wfElement("td", array("style" => $this->border), $cells[$i]);
 144+ $ret .= Html::element("td", array("style" => $this->border), $cells[$i]);
145145 }
146146 }
147 - $ret .= wfCloseElement("tr");
 147+ $ret .= Xml::closeElement("tr");
148148
149149 wfProfileOut(__METHOD__);
150150 return $ret;
@@ -156,20 +156,20 @@
157157 * @access private
158158 */
159159 function showInputForm($user = "") {
160 - global $wgOut, $wgScriptPath;
 160+ global $wgOut, $wgScript;
161161
162162 wfProfileIn(__METHOD__);
163163
164164 $ct = $this->getTitle();
165165 $form = "";
166166 // FIXME: use Xml::inputLabel etc
167 - $form .= wfElement("p", null, wfMsg("editcount-des"));
168 - $form .= wfElement("form", array("name" => "editcountform", "method" => "get", "action" => $wgScriptPath . "/index.php"), null);
169 - $form .= wfElement("input", array("type" => "hidden", "name" => "title", "value" => "Special:EditCount"), "") . " ";
170 - $form .= wfElement("label", array("for" => "target"), wfMsg("editcount-username")). " ";
171 - $form .= wfElement("input", array("type" => "textbox", "name" => "target", "size" => "24", "value" => $user), "") . " ";
172 - $form .= wfElement("input", array("type" => "submit", "name" => "doeditcount", "value" => wfMsg("editcount-show")));
173 - $form .= wfCloseElement("form");
 167+ $form .= Html::element("p", null, wfMsg("editcount-des"));
 168+ $form .= Html::openElement("form", array("name" => "editcountform", "method" => "get", "action" => $wgScript));
 169+ $form .= Html::hidden("title", "Special:EditCount") . " ";
 170+ $form .= Html::element("label", array("for" => "target"), wfMsg("editcount-username")). " ";
 171+ $form .= Html::input("target", $user, "textbox", array("size" => "24")) . " ";
 172+ $form .= Html::input("doeditcount", wfMsg("editcount-show"), "submit");
 173+ $form .= Xml::closeElement("form");
174174
175175 $this->setHeaders();
176176 $wgOut->addHtml($form);
@@ -236,16 +236,17 @@
237237 function getByNamespace($ns)
238238 {
239239 wfProfileIn(__METHOD__);
240 - global $wgDBprefix;
241 - //FIXME: don't construct SQL by hand, use selectField
242 - $cond = ($this->user->isAnon()) ? "r.rev_user_text = '" . $this->user->getName() . "'"
243 - : "r.rev_user = " . $this->id;
244 - $result = $this->db->query("SELECT COUNT(*) AS count
245 - FROM {$wgDBprefix}page p JOIN {$wgDBprefix}revision r ON p.page_id = r.rev_page
246 - WHERE $cond AND p.page_namespace = $ns
247 - GROUP BY p.page_namespace");
248 - $row = $this->db->fetchRow($result);
 240+ $conds = array("page_namespace" => $ns);
 241+ if ( $this->user->isAnon() )
 242+ $conds["rev_user_text"] = $this->user->getName();
 243+ else
 244+ $conds["rev_user"] = $this->id;
249245
 246+ $row = $this->db->selectRow("page", "COUNT(*) AS count",
 247+ $conds, __METHOD__,
 248+ array("GROUP BY" => "page_namespace"),
 249+ array("revision" => array("JOIN", "page_id = rev_page"));
 250+
250251 wfProfileOut(__METHOD__);
251252 return ($row["count"]) ? $row["count"] : 0;
252253 }
@@ -259,17 +260,23 @@
260261 function getNamspaces()
261262 {
262263 wfProfileIn(__METHOD__);
263 - global $wgContLang, $wgDBprefix;
264 - $cond = ($this->user->isAnon()) ? "rev_user_text = '" . $this->user->getName() . "'"
265 - : "rev_user = " . $this->id;
266 - $result = $this->db->query("SELECT page_namespace as ns, COUNT(*) as count
267 - FROM {$wgDBprefix}revision JOIN {$wgDBprefix}page p ON rev_page = p.page_id
268 - WHERE $cond GROUP BY ns", __METHOD__);
 264+ global $wgContLang;
 265+ $conds = array();
 266+ if ( $this->user->isAnon() )
 267+ $conds["rev_user_text"] = $this->user->getName();
 268+ else
 269+ $conds["rev_user"] = $this->id;
 270+
 271+ $res = $this->db->select(array("revision", "page"), array("page_namespace", "COUNT(*) as count"),
 272+ $conds, __METHOD__,
 273+ array("GROUP BY" => "page_namespace"),
 274+ array("page" => array("JOIN", "rev_page = page_id")));
269275 $nsResults = array();
270 -
271 - // Use foreach
272 - while (($row = $this->db->fetchRow($result)) !== false) {
273 - $nsResults[$row["ns"]] = $row["count"];
 276+
 277+ foreach ($res as $row) {
 278+ //while (($row = $this->db->fetchRow($result)) !== false) {
 279+ //$nsResults[$row["ns"]] = $row["count"];
 280+ $nsResults[$row->page_namespace] = $row->count;
274281 }
275282
276283 $nsNumbers = array_keys($wgContLang->getNamespaces());
@@ -293,11 +300,10 @@
294301 function getTotal()
295302 {
296303 wfProfileIn(__METHOD__);
297 - global $wgDBprefix;
298304 if ($this->id == 0) {
299305 wfProfileOut(__METHOD__);
300306 // This actually works?
301 - return $this->db->selectField("{$wgDBprefix}revision", "COUNT(*)", array("rev_user_text" => $this->user->getName()), __METHOD__);
 307+ return $this->db->selectField("revision", "COUNT(*)", array("rev_user_text" => $this->user->getName()), __METHOD__);
302308 }
303309
304310 wfProfileOut(__METHOD__);

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r68613Importing unmaintained extension from http://mw-editcount.svn.sourceforge.net...dantman03:56, 27 June 2010

Status & tagging log