r65355 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65354‎ | r65355 | r65356 >
Date:05:33, 21 April 2010
Author:bawolff
Status:deferred
Tags:
Comment:
Some fixes to Category Intersection extension (I hope original author
doesn't mind)

*Make it fail more gracefully on invalid input from user
*make new table creation happen from hook instead of just telling people
to create table in comments.
Modified paths:
  • /trunk/extensions/CategoryIntersection/CategoryIntersection.i18n.php (modified) (history)
  • /trunk/extensions/CategoryIntersection/CategoryIntersection.php (modified) (history)
  • /trunk/extensions/CategoryIntersection/CategoryIntersection.sql (added) (history)
  • /trunk/extensions/CategoryIntersection/CategoryIntersection_body.php (modified) (history)

Diff [purge]

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
116 + native
Index: trunk/extensions/CategoryIntersection/CategoryIntersection_body.php
@@ -43,7 +43,7 @@
4444 $ret = '';
4545 $ret .= "<form method='post'>";
4646 $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' ) . '" />';
4848 $ret .= "</form>";
4949 return $ret;
5050 }
@@ -65,16 +65,29 @@
6666 $l = trim ( $l );
6767 if ( $l == '' ) continue;
6868 $t = Title::newFromText ( $l );
69 - $arr[] = $t->getDBkey();
 69+ if ( $t ) { // in case of invalid input
 70+ $arr[] = $t->getDBkey();
 71+ }
7072 }
7173
72 - if ( count ( $arr ) > $this->max_categories ) {
 74+ $numb_categories = count( $arr );
 75+ if ( $numb_categories > $this->max_categories ) {
7376 return wfMsgExt( 'categoryintersection-maxcategories', 'parsemag', $this->max_categories );
7477 }
7578
 79+ if ( $numb_categories < 2 ) {
 80+ return wfMsgExt( 'categoryintersection-mincategories', 'parsemag' );
 81+ }
 82+
7683 # Generate hash values for all combinations
7784 $hashes = CategoryIntersectionGetHashValues ( $arr );
7885
 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+
7992 # Generate (sub)query chain
8093 # TODO : Do we really need all combinations?
8194 $query = "";
Index: trunk/extensions/CategoryIntersection/CategoryIntersection.i18n.php
@@ -16,6 +16,7 @@
1717 'categoryintersection-desc' => 'Maintains a table with hash values for [[Special:CategoryIntersection|category intersections]] within a page',
1818 'categoryintersection-doit' => 'List pages in all these categories',
1919 'categoryintersection-maxcategories' => 'The maximum allowed number of intersecting categories is $1.',
 20+ 'categoryintersection-mincategories' => 'You need to include at least two categories.',
2021 'categoryintersection-results' => 'The search returned $1 {{PLURAL:$1|result|results}}.',
2122 );
2223
Index: trunk/extensions/CategoryIntersection/CategoryIntersection.php
@@ -6,22 +6,17 @@
77 * @copyright (c) 2008 by Magnus Manske
88 * @license Released under GPL
99
10 - // FIXME: creation of table should be done through hook.
11 - SQL for creating categoryintersections table:
1210
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 -
1911 **/
2012
2113 # Alert the user that this is not a valid entry point to MediaWiki if they try to access the skin file directly.
2214 if ( !defined( 'MEDIAWIKI' ) ) {
2315 echo <<<EOT
2416 To install my extension, put the following line in LocalSettings.php:
 17+<br/>
2518 require_once("\$IP/extensions/CategoryIntersection/CategoryIntersection.php");
 19+<br/>
 20+Then run the update.php maintenance script, followed by the refreshLinks.php maintenance script.
2621 EOT;
2722 exit( 1 );
2823 }
@@ -95,3 +90,16 @@
9691 $dbw->delete ( 'categoryintersections' , array ( "ci_page" => $article->getID() ) ) ;
9792 return true ;
9893 }
 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+

Status & tagging log