Index: trunk/extensions/mw-editcount/EditCountPage.php |
— | — | @@ -46,11 +46,11 @@ |
47 | 47 | * @param string $par the user that was entered into the form |
48 | 48 | * @access public |
49 | 49 | */ |
50 | | - function execute($par = null) |
| 50 | + function execute($par) |
51 | 51 | { |
52 | 52 | global $wgRequest, $wgOut; |
53 | 53 | wfProfileIn(__METHOD__); |
54 | | - $this->target = ($par !== null) ? $par : $wgRequest->getVal("target"); |
| 54 | + $this->target = $wgRequest->getVal("target", isset($par) ? $par : null); |
55 | 55 | |
56 | 56 | if ($this->target === null || !strlen($this->target)) { |
57 | 57 | $this->showInputForm(); |
— | — | @@ -60,7 +60,7 @@ |
61 | 61 | |
62 | 62 | $this->showInputForm($this->target); |
63 | 63 | |
64 | | - $nt = Title::newFromURL($this->target); |
| 64 | + $nt = Title::newFromText($this->target); |
65 | 65 | if (!$nt) { |
66 | 66 | $wgOut->addWikiMsg("editcount-notuser", $this->target); |
67 | 67 | wfProfileOut(__METHOD__); |
— | — | @@ -92,12 +92,12 @@ |
93 | 93 | } |
94 | 94 | |
95 | 95 | $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"); |
102 | 102 | |
103 | 103 | $totalEC = $ec->getTotal(); |
104 | 104 | $nsCount = $ec->getNamspaces(); |
— | — | @@ -108,16 +108,16 @@ |
109 | 109 | $table .= $this->doRow(array( |
110 | 110 | $nsNames[$nsInt], |
111 | 111 | $nsEC, |
112 | | - round(($nsEC/$totalEC*100), 1) . wfMsg("editcount-percentsym")) |
113 | | - ); |
| 112 | + round(($nsEC/$totalEC*100), 1) . wfMsg("editcount-percentsym") |
| 113 | + )); |
114 | 114 | } |
115 | 115 | |
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"); |
120 | 120 | |
121 | | - $table .= wfCloseElement("table"); |
| 121 | + $table .= Xml::closeElement("table"); |
122 | 122 | $wgOut->addHtml($table); |
123 | 123 | |
124 | 124 | wfProfileOut(__METHOD__); |
— | — | @@ -133,17 +133,17 @@ |
134 | 134 | function doRow($cells) |
135 | 135 | { |
136 | 136 | wfProfileIn(__METHOD__); |
137 | | - $ret = wfElement("tr", null, null); |
| 137 | + $ret = Html::openElement("tr", null, null); |
138 | 138 | 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]); |
141 | 141 | } |
142 | 142 | else { |
143 | 143 | 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]); |
145 | 145 | } |
146 | 146 | } |
147 | | - $ret .= wfCloseElement("tr"); |
| 147 | + $ret .= Xml::closeElement("tr"); |
148 | 148 | |
149 | 149 | wfProfileOut(__METHOD__); |
150 | 150 | return $ret; |
— | — | @@ -156,20 +156,20 @@ |
157 | 157 | * @access private |
158 | 158 | */ |
159 | 159 | function showInputForm($user = "") { |
160 | | - global $wgOut, $wgScriptPath; |
| 160 | + global $wgOut, $wgScript; |
161 | 161 | |
162 | 162 | wfProfileIn(__METHOD__); |
163 | 163 | |
164 | 164 | $ct = $this->getTitle(); |
165 | 165 | $form = ""; |
166 | 166 | // 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"); |
174 | 174 | |
175 | 175 | $this->setHeaders(); |
176 | 176 | $wgOut->addHtml($form); |
— | — | @@ -236,16 +236,17 @@ |
237 | 237 | function getByNamespace($ns) |
238 | 238 | { |
239 | 239 | 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; |
249 | 245 | |
| 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 | + |
250 | 251 | wfProfileOut(__METHOD__); |
251 | 252 | return ($row["count"]) ? $row["count"] : 0; |
252 | 253 | } |
— | — | @@ -259,17 +260,23 @@ |
260 | 261 | function getNamspaces() |
261 | 262 | { |
262 | 263 | 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"))); |
269 | 275 | $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; |
274 | 281 | } |
275 | 282 | |
276 | 283 | $nsNumbers = array_keys($wgContLang->getNamespaces()); |
— | — | @@ -293,11 +300,10 @@ |
294 | 301 | function getTotal() |
295 | 302 | { |
296 | 303 | wfProfileIn(__METHOD__); |
297 | | - global $wgDBprefix; |
298 | 304 | if ($this->id == 0) { |
299 | 305 | wfProfileOut(__METHOD__); |
300 | 306 | // 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__); |
302 | 308 | } |
303 | 309 | |
304 | 310 | wfProfileOut(__METHOD__); |