https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114536
Revision: 114536
Author: bsitu
Date: 2012-03-27 18:31:23 +0000 (Tue, 27 Mar 2012)
Log Message:
-----------
Add logic for generating article snippet in pagetriage listview
Modified Paths:
--------------
trunk/extensions/PageTriage/includes/ArticleMetadata.php
Modified: trunk/extensions/PageTriage/includes/ArticleMetadata.php
===================================================================
--- trunk/extensions/PageTriage/includes/ArticleMetadata.php 2012-03-27
18:28:40 UTC (rev 114535)
+++ trunk/extensions/PageTriage/includes/ArticleMetadata.php 2012-03-27
18:31:23 UTC (rev 114536)
@@ -303,8 +303,6 @@
* @param $metaData array
*/
protected function compileArticleBasicData( &$metaData ) {
- global $wgLang;
-
$dbr = wfGetDB( DB_SLAVE );
// Article page length, creation date, number of edit, title,
article triage status
@@ -376,12 +374,45 @@
__METHOD__
);
foreach ( $res as $row ) {
- $metaData[$row->page_id]['snippet'] =
$wgLang->truncate( $row->old_text, 150 );
+ $metaData[$row->page_id]['snippet'] =
self::generateArticleSnippet( $row->old_text );
}
return true;
}
+
+ /**
+ * Generate article snippet for listview from article text
+ * @param $text string - page text
+ * @return string
+ */
+ public static function generateArticleSnippet( $text ) {
+ global $wgLang;
+ $attempt = 1;
+ $openCurPos = strpos($text, '{{');
+ $closeCurPos = strpos($text, '}}');
+
+ while( $openCurPos !== false && $closeCurPos !== false &&
$openCurPos < $closeCurPos ) {
+ // replace all templates with empty string
+ $text = preg_replace( '/\{\{[^\{]((?!\{\{).)*?\}\}/is',
'', $text );
+
+ $openCurPos = strpos($text, '{{');
+ $closeCurPos = strpos($text, '}}');
+
+ $attempt++;
+ // only try 5 nested levels at max
+ if ( $attempt > 5 ) {
+ break;
+ }
+ }
+
+ // stip out non-useful data for snippet
+ $text = str_replace( array('{', '}'), '', $text );
+ $text = trim( strip_tags( MessageCache::singleton()->parse(
$text )->getText() ) );
+
+ return $wgLang->truncate( $text, 150 );
+ }
+
/**
* Compile user basic data like username for the author
* @param $metaData array
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs