r98787 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98786‎ | r98787 | r98788 >
Date:18:02, 3 October 2011
Author:ashley
Status:deferred (Comments)
Tags:
Comment:
FreqPatternTagCloud: cleanup, rewrite one SQL query to use our Database functions properly + add FIXME for class name (too generic, should be prefixed with the extension name or something)
Modified paths:
  • /trunk/extensions/FreqPatternTagCloud/includes/Search.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FreqPatternTagCloud/includes/Search.php
@@ -1,71 +1,75 @@
22 <?php
3 -
43 /**
5 -* Frequent Pattern Tag Cloud Plug-in
6 -* Search checks, whether the attribute is available in the database.
7 -*
8 -* @author Tobias Beck, University of Heidelberg
9 -* @author Andreas Fay, University of Heidelberg
10 -* @version 1.0
11 -*/
12 -include_once ("exceptions/InvalidAttributeException.php");
 4+ * Frequent Pattern Tag Cloud Plug-in
 5+ * Search checks, whether the attribute is available in the database.
 6+ *
 7+ * @author Tobias Beck, University of Heidelberg
 8+ * @author Andreas Fay, University of Heidelberg
 9+ * @version 1.0
 10+ */
 11+include_once( "exceptions/InvalidAttributeException.php" );
1312
 13+// @todo FIXME: this is a bit too generic class name...
1414 class Search {
1515 /**
1616 * Attribute name for search
1717 *
18 - * @var string
 18+ * @var string
1919 */
2020 private $_attribute;
21 -
 21+
2222 /**
23 - * Constructor
24 - *
25 - * @param string $attribute Attribute name for search
26 - * @return
27 - * @throws InvalidAttributeException If attribute is not valid, i.e. present in database
28 - */
29 - public function __construct($attribute) {
30 - if (!$this->attributeAvailable($attribute)) {
 23+ * Constructor
 24+ *
 25+ * @param $attribute String: attribute name for search
 26+ * @throws InvalidAttributeException If attribute is not valid, i.e. present in database
 27+ */
 28+ public function __construct( $attribute ) {
 29+ if ( !$this->attributeAvailable( $attribute ) ) {
3130 // Check if attribute is available
32 - throw new InvalidAttributeException($attribute);
 31+ throw new InvalidAttributeException( $attribute );
3332 }
3433 }
35 -
 34+
3635 /**
37 - * Checks whether attribute is correct, i.e. it exists in database; if yes it fetches the name of the attribute
 36+ * Checks whether attribute is correct, i.e. it exists in database; if yes,
 37+ * it fetches the name of the attribute
3838 *
39 - * @param string $attribute Attribute
40 - * @return bool
 39+ * @param $attribute String: attribute
 40+ * @return bool
4141 */
42 - private function attributeAvailable($attribute) {
 42+ private function attributeAvailable( $attribute ) {
4343 // Category
44 - if (wfMsg("fptc-categoryname") == $attribute) {
 44+ if ( wfMsg( 'fptc-categoryname' ) == $attribute ) {
4545 return true;
4646 }
47 -
48 - $dbr = & wfGetDB(DB_SLAVE);
49 -
50 - $res = $dbr->query("SELECT smw_title
51 - FROM " . $dbr->tableName("smw_ids") . "
52 - WHERE smw_namespace = 102
53 - AND LENGTH(smw_iw) = 0
54 - AND smw_title = '" . mysql_real_escape_string($attribute) . "'");
55 -
56 - if ($res->numRows() == 0) {
 47+
 48+ $dbr = wfGetDB( DB_SLAVE );
 49+
 50+ $res = $dbr->select(
 51+ 'smw_ids',
 52+ 'smw_title',
 53+ array(
 54+ 'smw_namespace' => 102,
 55+ 'LENGTH(smw_iw) = 0',
 56+ 'smw_title' => $attribute
 57+ ),
 58+ __METHOD__
 59+ );
 60+
 61+ if ( $res->numRows() == 0 ) {
5762 // Attribute not found
5863 return false;
5964 }
60 -
 65+
6166 $row = $res->fetchRow();
62 -
 67+
6368 // Assign name
6469 $this->_attribute = $row[0];
65 -
66 - $res->free();
 70+
6771 return true;
6872 }
69 -
 73+
7074 /**
7175 * Gets the available Attribute
7276 *

Comments

#Comment by Johnduhart (talk | contribs)   10:50, 5 October 2011

Why the include_once? Shouldn't that be added to the autoloader?

#Comment by Jack Phoenix (talk | contribs)   16:24, 5 October 2011

I have no idea, and probably, I was just cleaning up the messy code. You'll want to talk to the original author(s) of the extension to find out the answers.

Status & tagging log