Index: trunk/extensions/CategoryIntersection/CategoryIntersection.sql |
— | — | @@ -0,0 +1,14 @@ |
| 2 | +-- CategoryIntersection sql |
| 3 | +-- replace stuff between /* and */ with apropriate stuff |
| 4 | +-- or just run the update.php maintence script |
| 5 | + |
| 6 | +CREATE TABLE IF NOT EXISTS /*_*/categoryintersections ( |
| 7 | + `ci_page` int(10) unsigned NOT NULL, |
| 8 | + `ci_hash` int(10) unsigned NOT NULL, |
| 9 | + PRIMARY KEY (`ci_hash`,`ci_page`) |
| 10 | +) /*$wgDBTableOptions*/; |
| 11 | + |
| 12 | +CREATE INDEX /*i*/ci_page ON /*_*/categoryintersections (ci_page); |
| 13 | + |
| 14 | + |
| 15 | + |
Property changes on: trunk/extensions/CategoryIntersection/CategoryIntersection.sql |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 16 | + native |
Index: trunk/extensions/CategoryIntersection/CategoryIntersection_body.php |
— | — | @@ -43,7 +43,7 @@ |
44 | 44 | $ret = ''; |
45 | 45 | $ret .= "<form method='post'>"; |
46 | 46 | $ret .= "<textarea name='lines' rows='10' cols='50' style='width:100%'></textarea><br />"; |
47 | | - $ret .= "<input type='submit' name='doit' value='" . wfMsgHtml( 'categoryintersection-doit' ) . "' />"; |
| 47 | + $ret .= '<input type="submit" name="doit" value="' . wfMsgHtml( 'categoryintersection-doit' ) . '" />'; |
48 | 48 | $ret .= "</form>"; |
49 | 49 | return $ret; |
50 | 50 | } |
— | — | @@ -65,16 +65,29 @@ |
66 | 66 | $l = trim ( $l ); |
67 | 67 | if ( $l == '' ) continue; |
68 | 68 | $t = Title::newFromText ( $l ); |
69 | | - $arr[] = $t->getDBkey(); |
| 69 | + if ( $t ) { // in case of invalid input |
| 70 | + $arr[] = $t->getDBkey(); |
| 71 | + } |
70 | 72 | } |
71 | 73 | |
72 | | - if ( count ( $arr ) > $this->max_categories ) { |
| 74 | + $numb_categories = count( $arr ); |
| 75 | + if ( $numb_categories > $this->max_categories ) { |
73 | 76 | return wfMsgExt( 'categoryintersection-maxcategories', 'parsemag', $this->max_categories ); |
74 | 77 | } |
75 | 78 | |
| 79 | + if ( $numb_categories < 2 ) { |
| 80 | + return wfMsgExt( 'categoryintersection-mincategories', 'parsemag' ); |
| 81 | + } |
| 82 | + |
76 | 83 | # Generate hash values for all combinations |
77 | 84 | $hashes = CategoryIntersectionGetHashValues ( $arr ); |
78 | 85 | |
| 86 | + if ( empty( $hashes ) ) { |
| 87 | + // Could potentially happen if user tries to do the |
| 88 | + // intersection of a category with itself. |
| 89 | + return wfMsgExt( 'categoryintersection-mincategories', 'parsemag' ); |
| 90 | + } |
| 91 | + |
79 | 92 | # Generate (sub)query chain |
80 | 93 | # TODO : Do we really need all combinations? |
81 | 94 | $query = ""; |
Index: trunk/extensions/CategoryIntersection/CategoryIntersection.i18n.php |
— | — | @@ -16,6 +16,7 @@ |
17 | 17 | 'categoryintersection-desc' => 'Maintains a table with hash values for [[Special:CategoryIntersection|category intersections]] within a page', |
18 | 18 | 'categoryintersection-doit' => 'List pages in all these categories', |
19 | 19 | 'categoryintersection-maxcategories' => 'The maximum allowed number of intersecting categories is $1.', |
| 20 | + 'categoryintersection-mincategories' => 'You need to include at least two categories.', |
20 | 21 | 'categoryintersection-results' => 'The search returned $1 {{PLURAL:$1|result|results}}.', |
21 | 22 | ); |
22 | 23 | |
Index: trunk/extensions/CategoryIntersection/CategoryIntersection.php |
— | — | @@ -6,22 +6,17 @@ |
7 | 7 | * @copyright (c) 2008 by Magnus Manske |
8 | 8 | * @license Released under GPL |
9 | 9 | |
10 | | - // FIXME: creation of table should be done through hook. |
11 | | - SQL for creating categoryintersections table: |
12 | 10 | |
13 | | - CREATE TABLE `categoryintersections` ( |
14 | | - `ci_page` int(10) unsigned NOT NULL, |
15 | | - `ci_hash` int(10) unsigned NOT NULL, |
16 | | - PRIMARY KEY (`ci_hash`,`ci_page`) |
17 | | - ) ; |
18 | | - |
19 | 11 | **/ |
20 | 12 | |
21 | 13 | # Alert the user that this is not a valid entry point to MediaWiki if they try to access the skin file directly. |
22 | 14 | if ( !defined( 'MEDIAWIKI' ) ) { |
23 | 15 | echo <<<EOT |
24 | 16 | To install my extension, put the following line in LocalSettings.php: |
| 17 | +<br/> |
25 | 18 | require_once("\$IP/extensions/CategoryIntersection/CategoryIntersection.php"); |
| 19 | +<br/> |
| 20 | +Then run the update.php maintenance script, followed by the refreshLinks.php maintenance script. |
26 | 21 | EOT; |
27 | 22 | exit( 1 ); |
28 | 23 | } |
— | — | @@ -95,3 +90,16 @@ |
96 | 91 | $dbw->delete ( 'categoryintersections' , array ( "ci_page" => $article->getID() ) ) ; |
97 | 92 | return true ; |
98 | 93 | } |
| 94 | + |
| 95 | +# new tables needed (based on how ReaderFeedback extension does it) |
| 96 | +$wgHooks['LoadExtensionSchemaUpdates'][] = 'efCategoryIntersectionSchemaUpdates'; |
| 97 | + |
| 98 | +function efCategoryIntersectionSchemaUpdates() { |
| 99 | + global $wgDBtype, $wgExtNewTables; |
| 100 | + $base = dirname( __FILE__ ); |
| 101 | + if ( $wgDBtype == 'mysql' ) { |
| 102 | + $wgExtNewTables[] = array( 'categoryintersections', "$base/CategoryIntersection.sql" ); |
| 103 | + } |
| 104 | + return true; |
| 105 | +} |
| 106 | + |