Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F5670
svnpatch
Public
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
•
bzimport
Nov 21 2014, 10:36 PM
2014-11-21 22:36:25 (UTC+0)
Size
4 KB
Referenced Files
None
Subscribers
None
svnpatch
View Options
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 @@
<?php
class UniwikiAutoCreateCategoryPages {
- public function UW_AutoCreateCategoryPages_Save ( &$article, &$user, &$text, &$summary, &$minoredit, &$watchthis, &$sectionanchor, &$flags, $revision ) {
+ public function UW_AutoCreateCategoryPages_Save ( &$article, &$content) {
global $wgDBprefix;
-
- /* after the page is saved, get all the categories
- * and see if they exists as "proper" pages; if not
- * then create a simple page for them automatically */
-
- // Extract the categories on this page
- //
- // FIXME: this obviously only works for the English namespaces
- //
- $category = wfMsg("nstab-category");
- $regex = "/\[\[{$category}:(.+?)(?:\|.*)?\]\]/i";
- preg_match_all ( $regex, $text, $matches );
-
- // array of the categories on the page (in db form)
- $on_page = array();
- foreach ( $matches[1] as $cat )
- $on_page[] = Title::newFromText ( $cat )->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" ) );
File Metadata
Details
Attached
Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5220
Default Alt Text
svnpatch (4 KB)
Attached To
Mode
T20245: AutoCreateCategoryPages unable to detect category links embedded in templates that depends on template parameters
Attached
Detach File
Event Timeline
Log In to Comment