https://www.mediawiki.org/wiki/Special:Code/MediaWiki/112123

Revision: 112123
Author:   maxsem
Date:     2012-02-22 17:54:47 +0000 (Wed, 22 Feb 2012)
Log Message:
-----------
Use tidy and other stuff

Modified Paths:
--------------
    trunk/extensions/MobileFrontend/ApiQueryExcerpt.php

Modified: trunk/extensions/MobileFrontend/ApiQueryExcerpt.php
===================================================================
--- trunk/extensions/MobileFrontend/ApiQueryExcerpt.php 2012-02-22 17:41:56 UTC 
(rev 112122)
+++ trunk/extensions/MobileFrontend/ApiQueryExcerpt.php 2012-02-22 17:54:47 UTC 
(rev 112123)
@@ -22,6 +22,11 @@
                }
        }
 
+       /**
+        * Returns a processed, but not trimmed excerpt
+        * @param Title $title
+        * @return string 
+        */
        private function getExcerpt( Title $title ) {
                global $wgMemc;
 
@@ -40,6 +45,12 @@
                return $text;
        }
 
+       /**
+        * Converts page HTML into an excerpt
+        * @param string $text
+        * @param Title $title
+        * @return string 
+        */
        private function processText( $text, Title $title ) {
                $text = preg_replace( '/<h[1-6].*$/s', '', $text );
                $mf = new MobileFormatter( $text, $title, 'XHTML' );
@@ -53,14 +64,20 @@
        }
 
        private function trimText( $text, $requestedLength ) {
+               global $wgUseTidy;
+
                $length = mb_strlen( $text );
                if ( $length <= $requestedLength ) {
                        return $text;
                }
                $pattern = "#^.{{$requestedLength}}[\\w/]*>?#su";
                preg_match( $pattern, $text, $m );
-               var_dump($pattern);var_dump($m);die;
-               $text = $m[1];
+               $text = $m[0];
+               // Fix possibly unclosed tags
+               if ( $wgUseTidy ) {
+                       $text = trim ( MWTidy::tidy( $text ) );
+               }
+               $text .= wfMessage( 'ellipsis' )->text();
                return $text;
        }
 
@@ -85,13 +102,14 @@
 
        public function getParamDescription() {
                return array(
+                       'length' => 'How many characters to return, actual text 
returned might be slightly longer.',
                        'limit' => 'How many excerpts to return',
                        'continue' => 'When more results are available, use 
this to continue',
                );
        }
 
        public function getDescription() {
-               return 'Returns plain-text excerpts of the given page(s)';
+               return 'Returns excerpts of the given page(s)';
        }
 
        public function getPossibleErrors() {
@@ -101,7 +119,9 @@
        }
 
        public function getExamples() {
-               return false;//@todo:
+               return array(
+                       
'api.php?action=query&prop=excerpt&length=175&titles=Therion' => 'Get a 
175-character excerpt',
+               );
        }
 
 


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to