r106436 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106435‎ | r106436 | r106437 >
Date:14:36, 16 December 2011
Author:petrb
Status:deferred
Tags:
Comment:
small improvements of parsing the values from db
Modified paths:
  • /trunk/tools/wmib/Core.cs (modified) (history)

Diff [purge]

Index: trunk/tools/wmib/Core.cs
@@ -125,10 +125,10 @@
126126 }
127127
128128 /// <summary>
129 - ///
 129+ /// Delete user
130130 /// </summary>
131131 /// <param name="user">Regex</param>
132 - /// <returns></returns>
 132+ /// <returns>bool</returns>
133133 public bool delUser(string user)
134134 {
135135 foreach (user u in Users)
@@ -153,8 +153,8 @@
154154 /// <summary>
155155 /// Return level
156156 /// </summary>
157 - /// <param name="level"></param>
158 - /// <returns></returns>
 157+ /// <param name="level">User level</param>
 158+ /// <returns>0</returns>
159159 private int getLevel(string level)
160160 {
161161 if (level == "admin")
@@ -208,8 +208,8 @@
209209 /// <summary>
210210 /// Check if user match the necessary level
211211 /// </summary>
212 - /// <param name="level"></param>
213 - /// <param name="rights"></param>
 212+ /// <param name="level">Permission level</param>
 213+ /// <param name="rights">Userrights</param>
214214 /// <returns></returns>
215215 public bool matchLevel(int level, string rights)
216216 {
@@ -227,8 +227,8 @@
228228 /// <summary>
229229 /// Check if user is approved to do operation requested
230230 /// </summary>
231 - /// <param name="User"></param>
232 - /// <param name="Host"></param>
 231+ /// <param name="User">Username</param>
 232+ /// <param name="Host">Hostname</param>
233233 /// <param name="command"></param>
234234 /// <returns></returns>
235235 public bool isApproved(string User, string Host, string command)
@@ -282,10 +282,10 @@
283283 /// <summary>
284284 /// Constructor
285285 /// </summary>
286 - /// <param name="Key"></param>
287 - /// <param name="Text"></param>
288 - /// <param name="User"></param>
289 - /// <param name="Lock"></param>
 286+ /// <param name="Key">Key</param>
 287+ /// <param name="Text">Text of the key</param>
 288+ /// <param name="User">User who created the key</param>
 289+ /// <param name="Lock">If key is locked or not</param>
290290 public item(string Key, string Text, string User, string Lock = "false")
291291 {
292292 text = Text;
@@ -307,8 +307,8 @@
308308 /// <summary>
309309 /// Constructor
310310 /// </summary>
311 - /// <param name="name"></param>
312 - /// <param name="key"></param>
 311+ /// <param name="name">Alias</param>
 312+ /// <param name="key">Key</param>
313313 public staticalias(string name, string key)
314314 {
315315 Name = name;
@@ -350,7 +350,8 @@
351351 string name = info[0];
352352 if (type == "key")
353353 {
354 - text.Add(new item(name, value, ""));
 354+ string locked = info[3];
 355+ text.Add(new item(name, value, "", locked));
355356 }
356357 else
357358 {
@@ -399,7 +400,7 @@
400401 /// <summary>
401402 /// Get value of key
402403 /// </summary>
403 - /// <param name="key"></param>
 404+ /// <param name="key">Key</param>
404405 /// <returns></returns>
405406 public string getValue(string key)
406407 {
@@ -416,10 +417,10 @@
417418 /// <summary>
418419 /// Print a value to channel if found this message doesn't need to be a valid command
419420 /// </summary>
420 - /// <param name="name"></param>
421 - /// <param name="user"></param>
422 - /// <param name="chan"></param>
423 - /// <param name="host"></param>
 421+ /// <param name="name">Name</param>
 422+ /// <param name="user">User</param>
 423+ /// <param name="chan">Channel</param>
 424+ /// <param name="host">Host name</param>
424425 /// <returns></returns>
425426 public bool print(string name, string user, config.channel chan, string host)
426427 {
@@ -513,15 +514,19 @@
514515 name = name.Substring(0, name.IndexOf("|"));
515516 }
516517 string[] p = name.Split(' ');
517 - string p1 = "";
518 - if (p.Length > 1)
519 - {
520 - p1 = p[1];
521 - }
 518+ int parameters = p.Length;
522519 string keyv = getValue(p[0]);
523520 if (!(keyv == ""))
524521 {
525 - keyv = keyv.Replace("$1", p1);
 522+ if ( parameters > 1)
 523+ {
 524+ int curr = 0;
 525+ while ( parameters >= curr )
 526+ {
 527+ curr++;
 528+ keyv = keyv.Replace("$" + curr.ToString(), p[curr]);
 529+ }
 530+ }
526531 if (User == "")
527532 {
528533 Message(keyv, Channel);
@@ -538,7 +543,15 @@
539544 keyv = getValue(b.Key);
540545 if (keyv != "")
541546 {
542 - keyv = keyv.Replace("$1", p1);
 547+ if ( parameters > 1)
 548+ {
 549+ int curr = 0;
 550+ while ( parameters >= curr )
 551+ {
 552+ curr++;
 553+ keyv = keyv.Replace("$" + curr.ToString(), p[curr]);
 554+ }
 555+ }
543556 if (User == "")
544557 {
545558 Message(keyv, Channel);
@@ -557,7 +570,7 @@
558571 /// <summary>
559572 /// Search
560573 /// </summary>
561 - /// <param name="key"></param>
 574+ /// <param name="key">Key</param>
562575 /// <param name="Chan"></param>
563576 public void RSearch(string key, config.channel Chan)
564577 {
@@ -623,9 +636,9 @@
624637 /// <summary>
625638 /// Save a new key
626639 /// </summary>
627 - /// <param name="Text"></param>
628 - /// <param name="key"></param>
629 - /// <param name="user"></param>
 640+ /// <param name="Text">Text</param>
 641+ /// <param name="key">Key</param>
 642+ /// <param name="user">User who created it</param>
630643 public void setKey(string Text, string key, string user)
631644 {
632645 while (locked)
@@ -655,9 +668,9 @@
656669 /// <summary>
657670 /// Alias
658671 /// </summary>
659 - /// <param name="key"></param>
660 - /// <param name="al"></param>
661 - /// <param name="user"></param>
 672+ /// <param name="key">Key</param>
 673+ /// <param name="al">Alias</param>
 674+ /// <param name="user">User</param>
662675 public void aliasKey(string key, string al, string user)
663676 {
664677 foreach(staticalias stakey in this.Alias)
@@ -709,7 +722,7 @@
710723 /// <summary>
711724 /// Encode a data before saving it to a file
712725 /// </summary>
713 - /// <param name="text"></param>
 726+ /// <param name="text">Text</param>
714727 /// <returns></returns>
715728 public static string encode(string text)
716729 {
@@ -734,7 +747,7 @@
735748 /// <summary>
736749 /// Decode
737750 /// </summary>
738 - /// <param name="text"></param>
 751+ /// <param name="text">String</param>
739752 /// <returns></returns>
740753 public static string decode(string text)
741754 {
@@ -744,8 +757,8 @@
745758 /// <summary>
746759 /// Exceptions :o
747760 /// </summary>
748 - /// <param name="ex"></param>
749 - /// <param name="chan"></param>
 761+ /// <param name="ex">Exception pointer</param>
 762+ /// <param name="chan">Channel name</param>
750763 public static void handleException(Exception ex, string chan)
751764 {
752765 Message("DEBUG Exception: " + ex.Message + " I feel crushed, uh :|", chan);
@@ -754,7 +767,7 @@
755768 /// <summary>
756769 /// Get a channel object
757770 /// </summary>
758 - /// <param name="name"></param>
 771+ /// <param name="name">Name</param>
759772 /// <returns></returns>
760773 public static config.channel getChannel(string name)
761774 {
@@ -768,6 +781,9 @@
769782 return null;
770783 }
771784
 785+ /// <summary>
 786+ /// Convert the number to format we want to have in log
 787+ /// </summary>
772788 public static string timedateToString(int number)
773789 {
774790 if (number <= 9 && number >= 0)
@@ -780,8 +796,8 @@
781797 /// <summary>
782798 /// Send a message to channel
783799 /// </summary>
784 - /// <param name="message"></param>
785 - /// <param name="channel"></param>
 800+ /// <param name="message">Message</param>
 801+ /// <param name="channel">Channel</param>
786802 /// <returns></returns>
787803 public static bool Message(string message, string channel)
788804 {
@@ -795,10 +811,10 @@
796812 /// <summary>
797813 /// Change rights of user
798814 /// </summary>
799 - /// <param name="message"></param>
800 - /// <param name="channel"></param>
801 - /// <param name="user"></param>
802 - /// <param name="host"></param>
 815+ /// <param name="message">Message</param>
 816+ /// <param name="channel">Channel</param>
 817+ /// <param name="user">User</param>
 818+ /// <param name="host">Host</param>
803819 /// <returns></returns>
804820 public static int modifyRights(string message, config.channel channel, string user, string host)
805821 {
@@ -871,11 +887,11 @@
872888 /// <summary>
873889 /// Log file
874890 /// </summary>
875 - /// <param name="message"></param>
876 - /// <param name="channel"></param>
877 - /// <param name="user"></param>
878 - /// <param name="host"></param>
879 - /// <param name="noac"></param>
 891+ /// <param name="message">Message</param>
 892+ /// <param name="channel">Channel</param>
 893+ /// <param name="user">User</param>
 894+ /// <param name="host">Host</param>
 895+ /// <param name="noac">Action (if true it's logged as message, if false it's action)</param>
880896 public static void chanLog(string message, config.channel channel, string user, string host, bool noac = true)
881897 {
882898 try
@@ -904,10 +920,10 @@
905921 /// <summary>
906922 /// Called on action
907923 /// </summary>
908 - /// <param name="message"></param>
909 - /// <param name="Channel"></param>
910 - /// <param name="host"></param>
911 - /// <param name="nick"></param>
 924+ /// <param name="message">Message</param>
 925+ /// <param name="Channel">Channel</param>
 926+ /// <param name="host">Host</param>
 927+ /// <param name="nick">Nick</param>
912928 /// <returns></returns>
913929 public static bool getAction(string message, string Channel, string host, string nick)
914930 {
@@ -919,10 +935,10 @@
920936 /// <summary>
921937 ///
922938 /// </summary>
923 - /// <param name="chan"></param>
924 - /// <param name="user"></param>
925 - /// <param name="host"></param>
926 - /// <param name="message"></param>
 939+ /// <param name="chan">Channel</param>
 940+ /// <param name="user">User</param>
 941+ /// <param name="host">Host</param>
 942+ /// <param name="message">Message</param>
927943 public static void addChannel(config.channel chan, string user, string host, string message)
928944 {
929945 if (message.StartsWith("@add"))
@@ -1131,10 +1147,10 @@
11321148 /// <summary>
11331149 /// Called when someone post a message to server
11341150 /// </summary>
1135 - /// <param name="channel"></param>
1136 - /// <param name="nick"></param>
1137 - /// <param name="host"></param>
1138 - /// <param name="message"></param>
 1151+ /// <param name="channel">Channel</param>
 1152+ /// <param name="nick">Nick</param>
 1153+ /// <param name="host">Host</param>
 1154+ /// <param name="message">Message</param>
11391155 /// <returns></returns>
11401156 public static bool getMessage(string channel, string nick, string host, string message)
11411157 {

Status & tagging log