Index: trunk/extensions/mw-editcount/EditCountPage.php |
— | — | @@ -0,0 +1,311 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Contians the Special pages classes |
| 5 | + * |
| 6 | + * @package MediaWiki |
| 7 | + * @subpackage EditCount |
| 8 | + */ |
| 9 | + |
| 10 | +/** |
| 11 | + * The EditCount special page class |
| 12 | + * |
| 13 | + * @package MediaWiki |
| 14 | + * @subpackage EditCount |
| 15 | + */ |
| 16 | +class EditCountPage extends SpecialPage { |
| 17 | + /** |
| 18 | + * the border style applied to table, td, and th elements |
| 19 | + * |
| 20 | + * @var string |
| 21 | + * @access private |
| 22 | + */ |
| 23 | + var $border = "border: solid 2px;"; |
| 24 | + |
| 25 | + /** |
| 26 | + * the target user |
| 27 | + * |
| 28 | + * @var string |
| 29 | + * @access protected |
| 30 | + */ |
| 31 | + var $target; |
| 32 | + |
| 33 | + /** |
| 34 | + * Creates the special page class |
| 35 | + * |
| 36 | + * @access public |
| 37 | + */ |
| 38 | + function EditCountPage() |
| 39 | + { |
| 40 | + parent::SpecialPage("EditCount", "", true); |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * execute and outputs the special page |
| 45 | + * |
| 46 | + * @param string $par the user that was entered into the form |
| 47 | + * @access public |
| 48 | + */ |
| 49 | + function execute($par = null) |
| 50 | + { |
| 51 | + global $wgRequest, $wgOut; |
| 52 | + wfProfileIn(__METHOD__); |
| 53 | + $this->target = ($par !== null) ? $par : $wgRequest->getVal("target"); |
| 54 | + |
| 55 | + if ($this->target === null || !strlen($this->target)) { |
| 56 | + $this->showInputForm(); |
| 57 | + wfProfileOut(__METHOD__); |
| 58 | + return; |
| 59 | + } |
| 60 | + |
| 61 | + $this->showInputForm($this->target); |
| 62 | + |
| 63 | + $nt = Title::newFromURL($this->target); |
| 64 | + if (!$nt) { |
| 65 | + $wgOut->addHTML(wfMsg("editcount-notuser", htmlspecialchars($this->target))); |
| 66 | + wfProfileOut(__METHOD__); |
| 67 | + return; |
| 68 | + } |
| 69 | + |
| 70 | + $ec = new EditCount($nt->getText()); |
| 71 | + $this->showEditCount($ec); |
| 72 | + |
| 73 | + wfProfileOut(__METHOD__); |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * adds the HTML for the EditCount of a user |
| 78 | + * |
| 79 | + * @param EditCount $ec the EditCount object to be shown |
| 80 | + * @access private |
| 81 | + */ |
| 82 | + function showEditCount($ec) |
| 83 | + { |
| 84 | + global $wgOut, $wgContLang; |
| 85 | + |
| 86 | + wfProfileIn(__METHOD__); |
| 87 | + |
| 88 | + if ($ec->getTotal() == 0) { |
| 89 | + $wgOut->addHTML(wfMsg("editcount-noedits", $ec->getName())); |
| 90 | + wfProfileOut(__METHOD__); |
| 91 | + return; |
| 92 | + } |
| 93 | + |
| 94 | + $table = ""; |
| 95 | + $table .= wfElement("table", array("style" => "$this->border text-align: center; margin-left: 25%; margin-right: auto; margin-top: 7px; border-collapse: collapse"), null, null); |
| 96 | + $table .= wfElement("tr", array("style" => $this->border), null); |
| 97 | + $table .= wfElement("th", array("style" => $this->border), wfMsg("editcount-namespace")); |
| 98 | + $table .= wfElement("th", array("style" => $this->border), wfMsg("editcount-edits")); |
| 99 | + $table .= wfElement("th", array("style" => $this->border), wfMsg("editcount-percent")); |
| 100 | + $table .= wfCloseElement("tr"); |
| 101 | + |
| 102 | + $totalEC = $ec->getTotal(); |
| 103 | + $nsCount = $ec->getNamspaces(); |
| 104 | + $nsNames = $wgContLang->getFormattedNamespaces(); |
| 105 | + $nsNames[0] = wfMsg("blanknamespace"); |
| 106 | + |
| 107 | + foreach ($nsCount as $nsInt => $nsEC) { |
| 108 | + $table .= $this->doRow(array( |
| 109 | + $nsNames[$nsInt], |
| 110 | + $nsEC, |
| 111 | + round(($nsEC/$totalEC*100), 1) . wfMsg("editcount-percentsym")) |
| 112 | + ); |
| 113 | + } |
| 114 | + |
| 115 | + $table .= wfElement("tr", null, null); |
| 116 | + $table .= wfElement("td", array("style" => "font-weight: bold; {$this->border}"), wfMsg("editcount-total")); |
| 117 | + $table .= wfElement("td", array("colspan" => "2", "style" => $this->border), $totalEC); |
| 118 | + $table .= wfCloseElement("tr"); |
| 119 | + |
| 120 | + $table .= wfCloseElement("table"); |
| 121 | + $wgOut->addHtml($table); |
| 122 | + |
| 123 | + wfProfileOut(__METHOD__); |
| 124 | + } |
| 125 | + |
| 126 | + /** |
| 127 | + * creates a HTML table row |
| 128 | + * |
| 129 | + * @param array $cells an array of the cells' content |
| 130 | + * @return string the created HTML |
| 131 | + * @access private |
| 132 | + */ |
| 133 | + function doRow($cells) |
| 134 | + { |
| 135 | + wfProfileIn(__METHOD__); |
| 136 | + $ret = wfElement("tr", null, null); |
| 137 | + if (count($cells) == 2) { |
| 138 | + $ret .= wfElement("td", array("style" => $this->border), $cells[0]); |
| 139 | + $ret .= wfElement("td", array("style" => $this->border, "colspan" => "2"), $cells[1]); |
| 140 | + } |
| 141 | + else { |
| 142 | + for ($i = 0; $i < 3; ++$i) { |
| 143 | + $ret .= wfElement("td", array("style" => $this->border), $cells[$i]); |
| 144 | + } |
| 145 | + } |
| 146 | + $ret .= wfCloseElement("tr"); |
| 147 | + |
| 148 | + wfProfileOut(__METHOD__); |
| 149 | + return $ret; |
| 150 | + } |
| 151 | + |
| 152 | + /** |
| 153 | + * shows the HTML for the input form |
| 154 | + * |
| 155 | + * @param string $user (optional) the text to put as a default in the textbox |
| 156 | + * @access private |
| 157 | + */ |
| 158 | + function showInputForm($user = "") { |
| 159 | + global $wgOut, $wgScriptPath; |
| 160 | + |
| 161 | + wfProfileIn(__METHOD__); |
| 162 | + |
| 163 | + $ct = Title::makeTitle(NS_SPECIAL, $this->getName()); |
| 164 | + $form = ""; |
| 165 | + $form .= wfElement("p", null, wfMsg("editcount-des")); |
| 166 | + $form .= wfElement("form", array("name" => "editcountform", "method" => "get", "action" => $wgScriptPath . "/index.php"), null); |
| 167 | + $form .= wfElement("input", array("type" => "hidden", "name" => "title", "value" => "Special:EditCount"), "") . " "; |
| 168 | + $form .= wfElement("label", array("for" => "target"), wfMsg("editcount-username")). " "; |
| 169 | + $form .= wfElement("input", array("type" => "textbox", "name" => "target", "size" => "24", "value" => $user), "") . " "; |
| 170 | + $form .= wfElement("input", array("type" => "submit", "name" => "doeditcount", "value" => wfMsg("editcount-show"))); |
| 171 | + $form .= wfCloseElement("form"); |
| 172 | + |
| 173 | + $this->setHeaders(); |
| 174 | + $wgOut->addHtml($form); |
| 175 | + |
| 176 | + wfProfileOut(__METHOD__); |
| 177 | + } |
| 178 | +} |
| 179 | + |
| 180 | +/** |
| 181 | + * Represents the edit count of a user |
| 182 | + * |
| 183 | + * @package MediaWiki |
| 184 | + * @subpackage EditCount |
| 185 | + */ |
| 186 | +class EditCount { |
| 187 | + /** |
| 188 | + * The database object |
| 189 | + * |
| 190 | + * @var Database |
| 191 | + * @access private |
| 192 | + */ |
| 193 | + var $db; |
| 194 | + |
| 195 | + /** |
| 196 | + * The user id |
| 197 | + * |
| 198 | + * @var int |
| 199 | + * @access private |
| 200 | + */ |
| 201 | + var $id; |
| 202 | + |
| 203 | + /** |
| 204 | + * the user object for the user this EditCount object represents |
| 205 | + * |
| 206 | + * @var User |
| 207 | + * @access private |
| 208 | + */ |
| 209 | + var $user; |
| 210 | + |
| 211 | + /** |
| 212 | + * Creates an EditCount object with a username or ip |
| 213 | + * |
| 214 | + * @var string $username the user name or IP to create from |
| 215 | + * @access public |
| 216 | + */ |
| 217 | + function EditCount($username) |
| 218 | + { |
| 219 | + $this->db = wfGetDB(DB_SLAVE); |
| 220 | + $this->user = User::newFromName($username); |
| 221 | + if ($this->user == null) { |
| 222 | + $this->user = new User; |
| 223 | + } |
| 224 | + $this->id = $this->user->getID(); |
| 225 | + } |
| 226 | + |
| 227 | + /** |
| 228 | + * Gets the number of edits in a namespace |
| 229 | + * |
| 230 | + * @param int $ns the namespace number |
| 231 | + * @return int the number of edits in the given namespace |
| 232 | + * @access public |
| 233 | + */ |
| 234 | + function getByNamespace($ns) |
| 235 | + { |
| 236 | + wfProfileIn(__METHOD__); |
| 237 | + global $wgDBprefix; |
| 238 | + $cond = ($this->user->isAnon()) ? "r.rev_user_text = '" . $this->user->getName() . "'" |
| 239 | + : "r.rev_user = " . $this->id; |
| 240 | + $result = $this->db->query("SELECT COUNT(*) AS count |
| 241 | + FROM {$wgDBprefix}page p JOIN {$wgDBprefix}revision r ON p.page_id = r.rev_page |
| 242 | + WHERE $cond AND p.page_namespace = $ns |
| 243 | + GROUP BY p.page_namespace"); |
| 244 | + $row = $this->db->fetchRow($result); |
| 245 | + |
| 246 | + wfProfileOut(__METHOD__); |
| 247 | + return ($row["count"]) ? $row["count"] : 0; |
| 248 | + } |
| 249 | + |
| 250 | + /** |
| 251 | + * Returns an array of the edits per namespace |
| 252 | + * |
| 253 | + * @access public |
| 254 | + * @return int |
| 255 | + */ |
| 256 | + function getNamspaces() |
| 257 | + { |
| 258 | + wfProfileIn(__METHOD__); |
| 259 | + global $wgContLang, $wgDBprefix; |
| 260 | + $cond = ($this->user->isAnon()) ? "rev_user_text = '" . $this->user->getName() . "'" |
| 261 | + : "rev_user = " . $this->id; |
| 262 | + $result = $this->db->query("SELECT page_namespace as ns, COUNT(*) as count |
| 263 | + FROM {$wgDBprefix}revision JOIN {$wgDBprefix}page p ON rev_page = p.page_id |
| 264 | + WHERE $cond GROUP BY ns", __METHOD__); |
| 265 | + $nsResults = array(); |
| 266 | + while (($row = $this->db->fetchRow($result)) !== false) { |
| 267 | + $nsResults[$row["ns"]] = $row["count"]; |
| 268 | + } |
| 269 | + |
| 270 | + $nsNumbers = array_keys($wgContLang->getNamespaces()); |
| 271 | + foreach ($nsNumbers as $nsNum) { |
| 272 | + if (!array_key_exists($nsNum, $nsResults) && $nsNum >= 0) { |
| 273 | + $nsResults[$nsNum] = 0; |
| 274 | + } |
| 275 | + } |
| 276 | + ksort($nsResults, SORT_NUMERIC); |
| 277 | + |
| 278 | + wfProfileOut(__METHOD__); |
| 279 | + return $nsResults; |
| 280 | + } |
| 281 | + |
| 282 | + /** |
| 283 | + * Gets the total edits for the user |
| 284 | + * |
| 285 | + * @access public |
| 286 | + * @return int |
| 287 | + */ |
| 288 | + function getTotal() |
| 289 | + { |
| 290 | + wfProfileIn(__METHOD__); |
| 291 | + global $wgDBprefix; |
| 292 | + if ($this->id == 0) { |
| 293 | + wfProfileOut(__METHOD__); |
| 294 | + return $this->db->selectField("{$wgDBprefix}revision", "COUNT(*)", array("rev_user_text" => $this->user->getName()), __METHOD__); |
| 295 | + } |
| 296 | + |
| 297 | + wfProfileOut(__METHOD__); |
| 298 | + return $this->user->edits($this->id); |
| 299 | + } |
| 300 | + |
| 301 | + /** |
| 302 | + * Gets the username |
| 303 | + * |
| 304 | + * @access public |
| 305 | + * @return string |
| 306 | + */ |
| 307 | + function getName() |
| 308 | + { |
| 309 | + return $this->user->getName(); |
| 310 | + } |
| 311 | +} |
| 312 | +?> |
\ No newline at end of file |
Property changes on: trunk/extensions/mw-editcount/EditCountPage.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 313 | + native |
Index: trunk/extensions/mw-editcount/EditCount.i18n.php |
— | — | @@ -0,0 +1,120 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Messages for the EditCount extension |
| 5 | + * |
| 6 | + * Feel free to translate these |
| 7 | + * @package MediaWiki |
| 8 | + * @subpackage EditCount |
| 9 | + */ |
| 10 | + |
| 11 | +$weECMessages['en'] = array( |
| 12 | + "editcount" => "Edit Count", |
| 13 | + "editcount-des" => "Enter an username or IP to view that user's edit count.", |
| 14 | + "editcount-edits" => "Edits", |
| 15 | + "editcount-namespace" => "Namespace", |
| 16 | + "editcount-noedits" => "No edits were found for $1.", |
| 17 | + "editcount-notuser" => "$1 is not a valid user.", |
| 18 | + "editcount-percent" => "Percent of total edits", |
| 19 | + "editcount-percentsym" => "%", |
| 20 | + "editcount-show" => "Show count", |
| 21 | + "editcount-toolbox" => "User edit count", |
| 22 | + "editcount-total" => "Total", |
| 23 | + "editcount-username" => "Username:" |
| 24 | +); |
| 25 | + |
| 26 | +//German |
| 27 | +$weECMessages['de'] = array( |
| 28 | + "editcount" => "Anzahl der Bearbeitungen", |
| 29 | + "editcount-des" => "Geben Sie einen Benutzernamen oder eine IP ein, um sich die Anzahl der |
| 30 | +Bearbeitungen eines Benutzers anzeigen zu lassen.", |
| 31 | + "editcount-edits" => "Bearbeitungen", |
| 32 | + "editcount-namespace" => "Namensraum", |
| 33 | + "editcount-noedits" => "Es wurden keine Bearbeitungen von $1 gefunden.", |
| 34 | + "editcount-notuser" => "$1 ist kein g�ltiger Benutzer.", |
| 35 | + "editcount-percent" => "Prozent der Bearbeitungen insgesamt", |
| 36 | + "editcount-percentsym" => "%", |
| 37 | + "editcount-show" => "Anzahl anzeigen", |
| 38 | + "editcount-toolbox" => "Bearbeitungsanzahl des Benutzers", |
| 39 | + "editcount-total" => "Gesamt", |
| 40 | + "editcount-username" => "Benutzername:" |
| 41 | +); |
| 42 | + |
| 43 | +//Finish |
| 44 | +$weECMessages['fi'] = array( |
| 45 | + "editcount" => "K�ytt�jien muokkausm��r�t", |
| 46 | + "editcount-des" => "Voit tarkastella k�ytt�j�n tekemien tai IP-osoitteesta tehtyjen muokkausten lukum��r�� sy�tt�m�ll� tunnuksen tai IP:n alla olevaan kentt��n.", |
| 47 | + "editcount-edits" => "muokkauksia", |
| 48 | + "editcount-namespace" => "nimiavaruus", |
| 49 | + "editcount-noedits" => "$1 ei ole tehnyt yht��n muokkausta.", |
| 50 | + "editcount-notuser" => "K�ytt�j�tunnusta $1 ei ole olemassa.", |
| 51 | + "editcount-percent" => "osuus k�ytt�j�n muokkauksista", |
| 52 | + "editcount-percentsym" => " %", |
| 53 | + "editcount-show" => "N�yt�", |
| 54 | + "editcount-toolbox" => "K�ytt�j�n muokkausten m��r�", |
| 55 | + "editcount-total" => "yhteens�", |
| 56 | + "editcount-username" => "K�ytt�j�:" ); |
| 57 | + |
| 58 | +//Polish |
| 59 | +$weECMessages['pl'] = array( |
| 60 | + "editcount" => "Liczba edycji", |
| 61 | + "editcount-des" => "Wpisz nazwe uzytkownika lub adres IP, aby zobaczyc liczbe jego edycji.", |
| 62 | + "editcount-edits" => "Edycji", |
| 63 | + "editcount-namespace" => "Zakres nazw", |
| 64 | + "editcount-noedits" => "Nie znaleziono zadnych edycji $1.", |
| 65 | + "editcount-notuser" => "$1 nie jest poprawna nazwa uzytkownika.", |
| 66 | + "editcount-percent" => "Procent wszystkich edycji", |
| 67 | + "editcount-percentsym" => "%", |
| 68 | + "editcount-show" => "Pokaz ilosc", |
| 69 | + "editcount-toolbox" => "Liczba edycji uzytkownika", |
| 70 | + "editcount-total" => "Razem", |
| 71 | + "editcount-username" => "Uzytkownik:" |
| 72 | +); |
| 73 | + |
| 74 | +//French |
| 75 | +$weECMessages['fr'] = array( |
| 76 | + "editcount" => "Compteur d'éditions", |
| 77 | + "editcount-des" => "Saisir un nom d'utilisateur ou une IP pour voir le nombre d'édition de l'utilisateur.", |
| 78 | + "editcount-edits" => "Editions", |
| 79 | + "editcount-namespace" => "Espaces de noms", |
| 80 | + "editcount-noedits" => "Aucune edition trouvée pour $1.", |
| 81 | + "editcount-notuser" => "$1 n'est pas un utilisateur valide.", |
| 82 | + "editcount-percent" => "Poucentage d'éditions", |
| 83 | + "editcount-percentsym" => "%", |
| 84 | + "editcount-show" => "Montrer le nombre d'éditions", |
| 85 | + "editcount-toolbox" => "Compteur d'éditions de l'utilisateur", |
| 86 | + "editcount-total" => "Total", |
| 87 | + "editcount-username" => "Utilisateur:" |
| 88 | +); |
| 89 | + |
| 90 | +//brazilian portuguese |
| 91 | +$weECMessages['pt-br'] = array( |
| 92 | + "editcount" => "Contador de Edições", |
| 93 | + "editcount-des" => "Incira um nome de usuário ou IP para ver a contagem de edições do usuário.", |
| 94 | + "editcount-edits" => "Edições", |
| 95 | + "editcount-namespace" => "Espaço do nome", |
| 96 | + "editcount-noedits" => "Não foram encontradas edições para $1.", |
| 97 | + "editcount-notuser" => "$1 não é um usuário válido.", |
| 98 | + "editcount-percent" => "Porcentagem do total de edições", |
| 99 | + "editcount-percentsym" => "%", |
| 100 | + "editcount-show" => "Mostrar Contagem", |
| 101 | + "editcount-toolbox" => "Contagem de Edições do Usuário", |
| 102 | + "editcount-total" => "Total", |
| 103 | + "editcount-username" => "Nome de Usuário:" |
| 104 | +); |
| 105 | + |
| 106 | +//Dutch |
| 107 | +$weECMessages['nl'] = array( |
| 108 | + "editcount" => "Bewerkingsteller", |
| 109 | + "editcount-des" => "Geef een gebruikersnaam of een IP-adres om .", |
| 110 | + "editcount-edits" => "Bewerkingen", |
| 111 | + "editcount-namespace" => "Naamruimte", |
| 112 | + "editcount-noedits" => "Er zijn geen bewerkingen gevonden voor $1.", |
| 113 | + "editcount-notuser" => "$1 is geen bestaande gebruiker.", |
| 114 | + "editcount-percent" => "Percentage van het de totale bewerkingen", |
| 115 | + "editcount-percentsym" => "%", |
| 116 | + "editcount-show" => "Toon teller", |
| 117 | + "editcount-toolbox" => "Gebruiker bewerkingsteller", |
| 118 | + "editcount-total" => "Totaal", |
| 119 | + "editcount-username" => "Gebruikersnaam:" |
| 120 | +); |
| 121 | +?> |
\ No newline at end of file |
Property changes on: trunk/extensions/mw-editcount/EditCount.i18n.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 122 | + native |
Index: trunk/extensions/mw-editcount/.project |
— | — | @@ -0,0 +1,22 @@ |
| 2 | +<?xml version="1.0" encoding="UTF-8"?>
|
| 3 | +<projectDescription>
|
| 4 | + <name>mw-editcount</name>
|
| 5 | + <comment></comment>
|
| 6 | + <projects>
|
| 7 | + </projects>
|
| 8 | + <buildSpec>
|
| 9 | + <buildCommand>
|
| 10 | + <name>org.eclipse.php.core.PhpIncrementalProjectBuilder</name>
|
| 11 | + <arguments>
|
| 12 | + </arguments>
|
| 13 | + </buildCommand>
|
| 14 | + <buildCommand>
|
| 15 | + <name>org.eclipse.php.core.ValidationManagerWrapper</name>
|
| 16 | + <arguments>
|
| 17 | + </arguments>
|
| 18 | + </buildCommand>
|
| 19 | + </buildSpec>
|
| 20 | + <natures>
|
| 21 | + <nature>org.eclipse.php.core.PHPNature</nature>
|
| 22 | + </natures>
|
| 23 | +</projectDescription>
|
Index: trunk/extensions/mw-editcount/EditCount.php |
— | — | @@ -0,0 +1,242 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * This extension creates a special page which lets users find their edit counts. |
| 5 | + * |
| 6 | + * @package MediaWiki |
| 7 | + * @subpackage EditCount |
| 8 | + * @author Fahad Sadah
|
| 9 | + * @copyright 2009 Fahad Sadah and Benjamin Peterson
|
| 10 | + * @license GPL http://www.gnu.org/copyleft/gpl.html |
| 11 | + */ |
| 12 | + |
| 13 | +if (!defined("MEDIAWIKI")) { |
| 14 | + die("This is not valid entry point"); |
| 15 | +} |
| 16 | + |
| 17 | +/************************************* |
| 18 | + Configuartion |
| 19 | + ***************************************/ |
| 20 | + |
| 21 | +/** |
| 22 | + * True to turn on parser function and false to not |
| 23 | + */ |
| 24 | +$egECParserFunction = true;
|
| 25 | +
|
| 26 | +/**
|
| 27 | + * An array of the names of the parser functions
|
| 28 | + *
|
| 29 | + * This array of parser function names must be single words (can have - and _). They are not case sensitive. These will have "#" appended to the front of them in wikimarkup.
|
| 30 | + * @var array
|
| 31 | + */
|
| 32 | +$egECParserFunctionNames = array("editcount", "ec");
|
| 33 | +
|
| 34 | +/**
|
| 35 | + * True to enable the Special:EditCount page
|
| 36 | + */
|
| 37 | +$egECEnableSpecialPage = true; |
| 38 | + |
| 39 | +/************************************* |
| 40 | + End Config |
| 41 | + ***************************************/ |
| 42 | + |
| 43 | +$egEditCountCredits = array( |
| 44 | + "name" => "Edit Count", |
| 45 | + "author" => "Fahad Sadah", |
| 46 | + "description" => "Gets the edit count of a user", |
| 47 | + "url" => "http://www.mediawiki.org/wiki/Extension:EditCount" |
| 48 | +); |
| 49 | +$wgExtensionCredits["parserhook"][] = $egEditCountCredits; |
| 50 | +$wgExtensionCredits["specialpage"][] = $egEditCountCredits; |
| 51 | + |
| 52 | +$wgExtensionFunctions[] = "efEditCount"; |
| 53 | +if ($egECParserFunction) { |
| 54 | + $wgHooks["LanguageGetMagic"][] = "efEditCountMagic"; |
| 55 | +}
|
| 56 | +
|
| 57 | +if ($egECEnableSpecialPage) { |
| 58 | + $wgHooks["SkinTemplateBuildNavUrlsNav_urlsAfterPermalink"][] = "efEditCountNavUrls"; |
| 59 | + $wgHooks["MonoBookTemplateToolboxEnd"][] = "efEditCountToolbox";
|
| 60 | +} |
| 61 | +
|
| 62 | +/**
|
| 63 | + * The extension function that's called to set up EditCount.
|
| 64 | + */ |
| 65 | +function efEditCount() { |
| 66 | + global $wgAutoloadClasses, $wgSpecialPages, $wgParser,
|
| 67 | + $egECParserFunction, $egECEnableSpecialPage, $egECParserFunctionNames, $wgVersion; |
| 68 | + |
| 69 | + //for cross version compatibility |
| 70 | + $before17 = version_compare($wgVersion, "1.7", "<"); |
| 71 | + |
| 72 | + //Autoload |
| 73 | + $wgAutoloadClasses["EditCountPage"] = dirname(__FILE__) . "/EditCountPage.php"; |
| 74 | + $wgAutoloadClasses["EditCount"] = dirname(__FILE__) . "/EditCountPage.php";
|
| 75 | + if ($before17) {
|
| 76 | + //autoloading not supported
|
| 77 | + require_once "EditCountPage.php";
|
| 78 | + } |
| 79 | +
|
| 80 | + if ($egECEnableSpecialPage) { |
| 81 | + //add to special page (object if less than 1.7) |
| 82 | + if ($before17) { |
| 83 | + $wgSpecialPages["EditCount"] = new EditCountPage; |
| 84 | + } |
| 85 | + else { |
| 86 | + $wgSpecialPages["EditCount"] = "EditCountPage"; |
| 87 | + }
|
| 88 | + } |
| 89 | + |
| 90 | + if ($egECParserFunction) { |
| 91 | + if ($before17) {
|
| 92 | + //have to do this without magic words
|
| 93 | + foreach ($egECParserFunctionNames as $funcName) {
|
| 94 | + $wgParser->setFunctionHook("#" . $funcName, "efEditCountParserFunction");
|
| 95 | + } |
| 96 | + }
|
| 97 | + else {
|
| 98 | + $wgParser->setFunctionHook("editcount", "efEditCountParserFunction");
|
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + efEditCountMsgs(); |
| 103 | +} |
| 104 | +
|
| 105 | +/**
|
| 106 | + * Sets up the parser function magic words in Mediawiki 1.7 and greater.
|
| 107 | + *
|
| 108 | + * @param array $magicWords the array of magic word we'll add to
|
| 109 | + * @return bool always true
|
| 110 | + */ |
| 111 | +function efEditCountMagic(&$magicWords) {
|
| 112 | + global $egECParserFunctionNames;
|
| 113 | +
|
| 114 | + if (!is_array($egECParserFunctionNames) || count($egECParserFunctionNames) == 0) {
|
| 115 | + $egECParserFunctionNames = array("editcount", "ec");
|
| 116 | + }
|
| 117 | + |
| 118 | + $magicWords["editcount"] = array_merge(array(0), $egECParserFunctionNames); |
| 119 | + return true; |
| 120 | +}
|
| 121 | +
|
| 122 | +/**
|
| 123 | + * Injects EditCount's messages into the message system
|
| 124 | + */ |
| 125 | +function efEditCountMsgs() { |
| 126 | + global $wgMessageCache, $wgContLang, $wgVersion; |
| 127 | + static $msgsLoaded = false; |
| 128 | + |
| 129 | + wfProfileIn(__FUNCTION__);
|
| 130 | +
|
| 131 | + $before17 = version_compare($wgVersion, "1.7", "<");
|
| 132 | + |
| 133 | + if (!$msgsLoaded) { |
| 134 | + $weECMessages = array(); |
| 135 | + require_once "EditCount.i18n.php";
|
| 136 | + if ($before17) {
|
| 137 | + //1.6 doesn't support multiple languages |
| 138 | + $code = $wgContLang->getCode(); |
| 139 | + if (!array_key_exists($code, $weECMessages)) { |
| 140 | + $code = "en"; |
| 141 | + } |
| 142 | + $wgMessageCache->addMessages($weECMessages[$code], $code);
|
| 143 | + }
|
| 144 | + else {
|
| 145 | + //add all the message to fill in language gaps
|
| 146 | + foreach ($weECMessages as $code => $msgs) {
|
| 147 | + $wgMessageCache->addMessages($weECMessages[$code], $code);
|
| 148 | + }
|
| 149 | + }
|
| 150 | + $msgsLoaded = true; |
| 151 | + } |
| 152 | + |
| 153 | + wfProfileOut(__FUNCTION__); |
| 154 | +} |
| 155 | +
|
| 156 | +/**
|
| 157 | + * Adds the path of the EditCount special page to toolboxes on user pages
|
| 158 | + *
|
| 159 | + * @param SkinTemplate $skinTemplate
|
| 160 | + * @param array $navUrls the navagation urls
|
| 161 | + * @param int $oldid the oldid of the article
|
| 162 | + * @param int $revisionid the revision id
|
| 163 | + * @return bool always true
|
| 164 | + */ |
| 165 | +function efEditCountNavUrls(&$skinTemplate, &$navUrls, $oldid, $revisionid) { |
| 166 | + global $wgAutoloadClasses, $egECEnableSpecialPage;
|
| 167 | +
|
| 168 | + if (!$egECEnableSpecialPage) {
|
| 169 | + return;
|
| 170 | + }
|
| 171 | + |
| 172 | + $title = $skinTemplate->mTitle; |
| 173 | + if ($title->getNamespace() == NS_USER && $revisionid !== 0) { |
| 174 | + $navUrls["editcount"] = array( |
| 175 | + "text" => wfMsg("editcount-toolbox"), |
| 176 | + "href" => $skinTemplate->makeSpecialUrl("EditCount", "target=" . wfUrlencode($title->getText()))); |
| 177 | + } |
| 178 | + return true; |
| 179 | +} |
| 180 | +
|
| 181 | +/**
|
| 182 | + * Preforms the parser function action (getting the edit count of a user)
|
| 183 | + *
|
| 184 | + * @param Parser $parser the parser instance
|
| 185 | + * @param string $param1 the name of the user in question (hopefully)
|
| 186 | + * @param string $param2 (optional) namespace
|
| 187 | + * @return mixed
|
| 188 | + */ |
| 189 | +function efEditCountParserFunction($parser, $param1 = "", $param2 = "") { |
| 190 | + global $wgContLang; |
| 191 | + |
| 192 | + wfProfileIn(__FUNCTION__); |
| 193 | + |
| 194 | + if ($param1 == "" || !Title::newFromText($param1)) { |
| 195 | + wfProfileOut(__FUNCTION__); |
| 196 | + return array("found" => false); |
| 197 | + } |
| 198 | + |
| 199 | + $ec = new EditCount($param1); |
| 200 | + |
| 201 | + if ($param2 === "") { |
| 202 | + wfProfileOut(__FUNCTION__); |
| 203 | + return $ec->getTotal(); |
| 204 | + } |
| 205 | + |
| 206 | + if (!is_numeric($param2)) { |
| 207 | + $index = Namespace::getCanonicalIndex(strtolower($param2)); |
| 208 | + if ($index === null) { |
| 209 | + wfProfileOut(__FUNCTION__); |
| 210 | + return array("found" => false); |
| 211 | + } |
| 212 | + } |
| 213 | + else { |
| 214 | + $namespaces = $wgContLang->getNamespaces(); |
| 215 | + if (!array_key_exists($param2, $namespaces)) { |
| 216 | + wfProfileOut(__FUNCTION__); |
| 217 | + return array("found" => false); |
| 218 | + } |
| 219 | + $index = $param2; |
| 220 | + } |
| 221 | + |
| 222 | + wfProfileOut(__FUNCTION__); |
| 223 | + return $ec->getByNamespace($index); |
| 224 | +} |
| 225 | +
|
| 226 | +/**
|
| 227 | + * Actually adds the HTML
|
| 228 | + *
|
| 229 | + * @param SkinMonoBook $monobook the template we're in
|
| 230 | + * @return bool always true
|
| 231 | + */ |
| 232 | +function efEditcountToolbox(&$monobook) { |
| 233 | + if (array_key_exists("editcount", $monobook->data["nav_urls"])) { |
| 234 | + ?><li id="t-editcount"> |
| 235 | + <a href="<?php echo htmlspecialchars($monobook->data["nav_urls"]["editcount"]["href"]) ?>"><?php |
| 236 | + echo $monobook->msg("editcount-toolbox"); ?></a> |
| 237 | + </li> |
| 238 | + <?php |
| 239 | + } |
| 240 | + return true; |
| 241 | +} |
| 242 | + |
| 243 | +?> |
\ No newline at end of file |
Index: trunk/extensions/mw-editcount/CHANGELOG |
— | — | @@ -0,0 +1,29 @@ |
| 2 | +1.0.0 First release
|
| 3 | +
|
| 4 | +1.0.1 Fixed error when name is not valid
|
| 5 | +
|
| 6 | +1.1.0 Added parser function
|
| 7 | +
|
| 8 | +1.1.1 Added link in Monobook toolbox on pages in the NS_USER namespace
|
| 9 | +
|
| 10 | +1.2.0 Parser function now can report edits for a certain namespace, a German translation
|
| 11 | +
|
| 12 | +1.2.1 Fixed bugs to allow EditCount to work on 1.6.10 and above
|
| 13 | +
|
| 14 | +1.2.2 Adminstrators now choose parser functions and more flexible message loading
|
| 15 | +
|
| 16 | +1.2.3 Documented code and fixed disabling of special page bug
|
| 17 | +
|
| 18 | +1.2.4 Fixed profiler calls
|
| 19 | +
|
| 20 | +1.2.5 Fixed disabling of special page bug in MediaWiki 1.6
|
| 21 | +
|
| 22 | +1.2.6 Fixed SQL querys to use $wgDBPrefix
|
| 23 | +
|
| 24 | +1.2.7 Added Finish and Polish translation
|
| 25 | +
|
| 26 | +1.2.8 Fixed problems with $wgDBprefix and ISS
|
| 27 | +
|
| 28 | +1.2.9 Added Brazilian Portuguese, Dutch, and French translations
|
| 29 | +
|
| 30 | +1.2.9.1 BUGFIX removed newline + space after ?> in EditCount.i18n.php |
\ No newline at end of file |