Index: ACCP/AutoCreateCategoryPages.php =================================================================== --- ACCP/AutoCreateCategoryPages.php (revision 51662) +++ ACCP/AutoCreateCategoryPages.php (working copy) @@ -22,5 +22,5 @@ $wgAutoCreateCategoryPagesObject = new UniwikiAutoCreateCategoryPages(); /* ---- HOOKS ---- */ -$wgHooks['ArticleSaveComplete'][] = array($wgAutoCreateCategoryPagesObject,"UW_AutoCreateCategoryPages_Save"); +$wgHooks['ArticleAfterFetchContent'][] = array($wgAutoCreateCategoryPagesObject,"UW_AutoCreateCategoryPages_Save"); $wgHooks['UserGetReservedNames'][] = array($wgAutoCreateCategoryPagesObject,'UW_OnUserGetReservedNames'); Index: ACCP/AutoCreateCategoryPages.body.php =================================================================== --- ACCP/AutoCreateCategoryPages.body.php (revision 51662) +++ ACCP/AutoCreateCategoryPages.body.php (working copy) @@ -1,50 +1,35 @@ getDBkey(); - - $regex = "/\[\[category:(.+?)(?:\|.*)?\]\]/i"; - preg_match_all ( $regex, $text, $matches ); - - foreach ( $matches[1] as $cat ) - $on_page[] = Title::newFromText ( $cat )->getDBkey(); - - // array of the categories in the db - $db = wfGetDB ( DB_MASTER ); - $results = $db->resultObject ( $db->query( - "select distinct page_title from {$wgDBprefix}page " . - "where page_namespace = '" . NS_CATEGORY . "'" ) - ); - - $in_db = array(); - while ( $r = $results->next() ) - $in_db[] = $r->page_title; - + /* As of 29 March 2009: The original category link extraction + algorithm (as of r45982) was completely changed from Wikitext + manipulation to a query to categorylinks. This fixes the fixme + (Limitation to en) mentioned in that version and allows categories + encapsulated in templates to be created correctly. This also + addresses MinuteElectron's comment on testing. + + FIXME: Exception Catching at doEdit, and probable security hazard of + implementation.*/ + + // Get a list of the catlinks the page has by querying categorylinks + $art_id=$article->getID(); + + $art_cat_list=array(); + $dbr= wfGetDB (DB_SLAVE); + $art_cat_db=$dbr->select('categorylinks','cl_to', array('cl_from'=>$art_id), __METHOD__ ); + while (($row = $dbr->fetchObject($art_cat_db))) + { + array_push($art_cat_list, $row->cl_to); + } + /* loop through the categories in the page and * see if they already exist as a category page */ - foreach ( $on_page as $db_key ) { - if ( !in_array( $db_key, $in_db ) ) { - + foreach ( $art_cat_list as $db_key ) { + $title_object=Title::newFromText ($db_key,NS_CATEGORY); + if ( !($title_object->IsKnown()) ) { wfLoadExtensionMessages( 'AutoCreateCategoryPages' ); - // Create a user object for the editing user and add it to the database // if it is not there already $editor = User::newFromName( wfMsgForContent( 'autocreatecategorypages-editor' ) ); @@ -53,7 +38,7 @@ } // if it does not exist, then create it here - $page_title = Title::newFromDBkey ( $db_key )->getText(); + $page_title = $title_object->getText(); $stub = wfMsgForContent ( 'autocreatecategorypages-stub', $page_title ); $summary = wfMsgForContent ( 'autocreatecategorypages-createdby' ); $article = new Article ( Title::newFromDBkey( "Category:$db_key" ) );