Last modified: 2009-03-13 20:01:38 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T19956, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 17956 - Uniwiki Layouts: Edge case with assigning Category
Uniwiki Layouts: Edge case with assigning Category
Status: RESOLVED FIXED
Product: MediaWiki extensions
Classification: Unclassified
Uniwiki (Other open bugs)
unspecified
All All
: Normal minor (vote)
: ---
Assigned To: Robert Leverington
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2009-03-12 19:18 UTC by Mikel Maron
Modified: 2009-03-13 20:01 UTC (History)
1 user (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Mikel Maron 2009-03-12 19:18:18 UTC
If Categories are listed in an @optional section (typically the last section), they won't be assigned to the article.

This patch strips the categories and applies to the new page, before applying layout directives.


@@ -252,11 +252,15 @@
 	// fetch the layout object
 	$layout_title = Title::newFromURL ( "Layout:" . $layout_slug );
 	$layout_article = new Article ( $layout_title );
-
+	$layout_cats = '';
+	
 	/* if the layout article exists, pre-fill the textarea with its
 	 * wiki text. if it doesn't exist, do nothing (no error) */
 	if ( ( $layout_text = $layout_article->fetchContent() ) !== false ) {
 
+		$layout_text = UW_Layouts_stripCats($layout_text, $layout_cats);
+		$text .= $layout_cats;
+		
 		/* break the layout text into sections by splitting
 		 * at header level =one= or ==two==, and iterate */
 		$nodes = preg_split ( "/^(==?[^=].*)$/mi", $layout_text, - 1, PREG_SPLIT_DELIM_CAPTURE );
@@ -282,3 +286,39 @@
 
 	return true;
 }
+
+
+function UW_Layouts_stripCats($texttostrip,&$catsintext){
+	global $wgContLang, $wgOut;
+
+	# Get localised namespace string:
+	$m_catString = strtolower( $wgContLang->getNsText( NS_CATEGORY ) );
+	# The regular expression to find the category links:
+	$m_pattern = "\[\[({$m_catString}|category):(.*?)\]\]";
+	
+	$m_replace = "$2";
+	# The container to store the processed text:
+	$m_cleanText = '';
+
+	# Check linewise for category links:
+	foreach( explode( "\n", $texttostrip ) as $m_textLine ) {
+		# Filter line through pattern and store the result:
+        $m_cleanText .= trim( preg_replace( "/{$m_pattern}/i", "", $m_textLine ) ) . "\n";
+
+		# Check if we have found a category, else proceed with next line:
+        if( preg_match_all( "/{$m_pattern}/i", $m_textLine,$catsintext2,PREG_SET_ORDER) ){        
+			 foreach( $catsintext2 as $local_cat => $m_prefix ) {
+				//Set first letter to upper case to match MediaWiki standard
+				$strFirstLetter = substr($m_prefix[2], 0,1);
+				strtoupper($strFirstLetter);
+				$newString = strtoupper($strFirstLetter) . substr($m_prefix[2], 1);
+				$catsintext .= "[[" . $m_catString . ":" . $newString . "]]\n";					 
+	 		}
+			# Get the category link from the original text and store it in our list:
+			preg_replace( "/.*{$m_pattern}/i", $m_replace, $m_textLine,-1,$intNumber );
+		}
+		
+	}
+	
+	return $m_cleanText;	
+}
Comment 1 Robert Leverington 2009-03-12 21:40:00 UTC
Thank you for the patch, but is there a reason why categories in optional sections should be applied if that section is not included - this behaviour could even be seen as a feature (optional categories tied to sections), and any categories that you want to be applied no-matter-what sections are included can simply be put at the top of the page.

I would lean towards closing this as INVALID/WONTFIX, but I'm sure you can provide a good reason for doing it the way you have proposed!
Comment 2 Mikel Maron 2009-03-12 21:49:39 UTC
In combination with the SelectCategoryTagCloud extension, this is a problem. SelectCategoryTagCloud always places the Category tags in the last section, so it's not possible to make the last section optional.

And actually, I think categories in @optional sections will _never_ be applied .. later adding that section in GenericEditPage will not add the section-text, only the section-title.

Still I could see how this might be confusing. Perhaps make this an optional behavior, which is turned off by default?
Comment 3 Robert Leverington 2009-03-12 21:52:48 UTC
That is true, if there aren't any further comments by tomorrow I will apply the patch at the weekend.
Comment 4 Robert Leverington 2009-03-13 20:01:38 UTC
Patch applied in r48378, in future please can you supply patches as an attachment including the full header - so that they can be automatically applied. Thank you.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links