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

Revision: 114401
Author:   catrope
Date:     2012-03-21 20:27:59 +0000 (Wed, 21 Mar 2012)
Log Message:
-----------
Revert r113365, r113372, r113395, r113474, r113475: unreviewed revisions in 
OpenSearchXml.

All of these revisions are tagged with 'gerritmigration' and will be 
resubmitted into Gerrit after the Gerrit switchover. See also 
http://lists.wikimedia.org/pipermail/wikitech-l/2012-March/059124.html

Modified Paths:
--------------
    trunk/extensions/OpenSearchXml/ApiOpenSearchXml.php
    trunk/extensions/OpenSearchXml/OpenSearchXml.php

Modified: trunk/extensions/OpenSearchXml/ApiOpenSearchXml.php
===================================================================
--- trunk/extensions/OpenSearchXml/ApiOpenSearchXml.php 2012-03-21 20:21:34 UTC 
(rev 114400)
+++ trunk/extensions/OpenSearchXml/ApiOpenSearchXml.php 2012-03-21 20:27:59 UTC 
(rev 114401)
@@ -85,10 +85,9 @@
                // Open search results may be stored for a very long time
                $this->getMain()->setCacheMaxAge( 1200 );
 
-               $data = $this->search( $search, $limit, $namespaces );
-               wfRunHooks( 'OpenSearchXml', array( &$data ) );
+               $srchres = PrefixSearch::titleSearch( $search, $limit, 
$namespaces );
 
-               $items = array_map( array( $this, 'formatItem' ), $data );
+               $items = array_filter( array_map( array( $this, 'formatItem' ), 
$srchres ) );
 
                $result = $this->getResult();
                $result->addValue( null, 'version', '2.0' );
@@ -98,28 +97,6 @@
                $result->addValue( null, 'Section', $items );
        }
 
-       private function search( $search, $limit, $namespaces ) {
-               $srchres = PrefixSearch::titleSearch( $search, $limit, 
$namespaces );
-               $titles = array_filter( array_map( 'Title::newFromText', 
$srchres ) );
-               $lb = new LinkBatch( $titles );
-               $lb->setCaller( __METHOD__ );
-               $lb->execute();
-
-               $results = array();
-               foreach ( $titles as $title ) {
-                       $title = $this->checkRedirect( $title );
-                       if( $this->seen( $title ) ) {
-                               continue;
-                       }
-                       $results[$title->getArticleID()] = array(
-                               'title' => $title,
-                               'extract' => false,
-                               'image' => false,
-                       );
-               }
-               return $results;
-       }
-
        public function getAllowedParams() {
                $params = parent::getAllowedParams();
                $params['format'] = array(
@@ -141,54 +118,47 @@
        }
 
        /**
-        * @param $result array
+        * @param $name string
         * @return array|bool
         */
-       protected function formatItem( $result ) {
-               $title = $result['title'];
+       protected function formatItem( $name ) {
+               $title = Title::newFromText( $name );
+               if( $title ) {
+                       $title = $this->_checkRedirect( $title );
+                       if( $this->_seen( $title ) ) {
+                               return false;
+                       }
 
-               $item = array();
-               if ( $result['extract'] === false || $result['image'] === false 
) {
                        list( $extract, $badge ) = $this->getExtract( $title );
-                       if ( $result['image'] === false ) {
-                               $image = $this->getBadge( $title, $badge );
-                               if( $image ) {
-                                       $thumb = $image->transform( array( 
'width' => 50, 'height' => 50 ), 0 );
-                                       if( $thumb ) {
-                                               $item['Image'] = array(
-                                                       'source' => 
wfExpandUrl( $thumb->getUrl(), PROTO_CURRENT ),
-                                                       //alt
-                                                       'width' => 
$thumb->getWidth(),
-                                                       'height' => 
$thumb->getHeight()
-                                               );
-                                       }
+                       $image = $this->getBadge( $title, $badge );
+
+                       $item = array();
+                       $item['Text']['*'] = $title->getPrefixedText();
+                       $item['Description']['*'] = $extract;
+                       $item['Url']['*'] = wfExpandUrl( $title->getFullUrl(), 
PROTO_CURRENT );
+                       if( $image ) {
+                               $thumb = $image->transform( array( 'width' => 
50, 'height' => 50 ), 0 );
+                               if( $thumb ) {
+                                       $item['Image'] = array(
+                                               'source' => wfExpandUrl( 
$thumb->getUrl(), PROTO_CURRENT ),
+                                               //alt
+                                               'width' => $thumb->getWidth(),
+                                               'height' => $thumb->getHeight()
+                                       );
                                }
                        }
+               } else {
+                       $item = array( 'Text' => array( '*' => $name ) );
                }
-
-               if ( is_string( $result['extract'] ) ) {
-                       $extract = $result['extract'];
-                       if ( !isset( $result['extract trimmed'] ) || 
!$result['extract trimmed'] ) {
-                               $extract = $this->extractStart( $extract );
-                       }
-               }
-               if ( is_array( $result['image'] ) ) {
-                       $item['Image'] = $result['image'];
-               }
-
-               $item['Text']['*'] = $title->getPrefixedText();
-               $item['Description']['*'] = $extract;
-               $item['Url']['*'] = wfExpandUrl( $title->getFullUrl(), 
PROTO_CURRENT );
-
                return $item;
        }
 
        /**
         * @param $title Title
         *
-        * @return Title
+        * @return
         */
-       protected function checkRedirect( $title ) {
+       protected function _checkRedirect( $title ) {
                $art = new Article( $title );
                $target = $art->getRedirectTarget();
                if( $target ) {
@@ -202,7 +172,7 @@
         * @param  $title Title
         * @return bool
         */
-       protected function seen( $title ) {
+       protected function _seen( $title ) {
                $name = $title->getPrefixedText();
                if( isset( $this->mSeen[$name] ) ) {
                        return true;
@@ -216,7 +186,7 @@
         * @param string $text
         * @return string
         */
-       function stripMarkup( $text ) {
+       function _stripMarkup( $text ) {
                $text = substr( $text, 0, 4096 ); // don't bother with long 
text...
 
                $text = str_replace( "'''", "", $text );
@@ -233,7 +203,7 @@
                                (?:\|($pipeContents))?
                                (?:\|$pipeContents)*
                        \]\]
-                       #six", array( $this, 'stripLink' ), $text );
+                       #six", array( $this, '_stripLink' ), $text );
 
                $text = preg_replace( '#\\[(?:$protocols).*? (.*?)\\]#s', '$1', 
$text ); // URL links
                $text = preg_replace( '#</?[a-z0-9]+.*?>#s', '', $text ); // 
HTML-style tags
@@ -248,7 +218,7 @@
         * @param $matches array
         * @return string
         */
-       function stripLink( $matches ) {
+       function _stripLink( $matches ) {
                $target = trim( $matches[1] );
                if( isset( $matches[2] ) ) {
                        $text = trim( $matches[2] );
@@ -274,8 +244,7 @@
         * @return string
         * @access private
         */
-       function extractStart( $text ) {
-               global $wgOpenSearchDescriptionLength;
+       function _extractStart( $text ) {
                $endchars = array(
                        '([^\d])\.\s', '\!\s', '\?\s', // regular ASCII
                        '。', // full-width ideographic full-stop
@@ -285,7 +254,7 @@
 
                $endgroup = implode( '|', $endchars );
                $end = "(?:$endgroup)";
-               $sentence = ".{{$wgOpenSearchDescriptionLength},}?$end+";
+               $sentence = ".*?$end+";
                $firstone = "/^($sentence)/u";
                $matches = array();
                if( preg_match( $firstone, $text, $matches ) ) {
@@ -303,7 +272,7 @@
         * @param $text string
         * @return string|bool
         */
-       function extractBadge( $text ) {
+       function _extractBadge( $text ) {
                global $wgContLang;
                $image = preg_quote( $wgContLang->getNsText( NS_IMAGE ), '#' );
                $matches = array();
@@ -318,10 +287,10 @@
         * @param $arg string
         * @return bool|String
         */
-       function validateBadge( $arg ) {
+       function _validateBadge( $arg ) {
                // Some templates want an entire [[Image:Foo.jpg|250px]]
                if( substr( $arg, 0, 2 ) == '[[' ) {
-                       return $this->extractBadge( $arg );
+                       return $this->_extractBadge( $arg );
                }
 
                // Others will take Image:Foo.jpg or Foo.jpg
@@ -376,7 +345,7 @@
                                                        //var_dump( $arg );
                                                        $argName = trim( 
$frame->expand( $arg["name"], PPFrame::RECOVER_ORIG ) );
                                                        if( in_array( $argName, 
$imageArgs ) ) {
-                                                               $badge = 
$this->validateBadge(
+                                                               $badge = 
$this->_validateBadge(
                                                                        trim(
                                                                                
$frame->expand( $arg["value"], PPFrame::RECOVER_ORIG ) ) );
                                                                if( $badge ) {
@@ -393,18 +362,18 @@
                        if( !$badge ) {
                                // Look for the first image in the body text if 
there wasn't
                                // one in an infobox.
-                               $badge = $this->extractBadge( $out );
+                               $badge = $this->_extractBadge( $out );
                        }
 
                        // The remaining text may still contain wiki and HTML 
markup.
                        // We'll use our shitty hand parser to strip most of 
those from
                        // the beginning of the text.
-                       $stripped = $this->stripMarkup( $out );
+                       $stripped = $this->_stripMarkup( $out );
 
                        // And now, we'll grab just the first sentence as text, 
and
                        // also try to rip out a badge image.
                        return array(
-                               $this->extractStart( $stripped ),
+                               $this->_extractStart( $stripped ),
                                $badge );
                }
                return '';

Modified: trunk/extensions/OpenSearchXml/OpenSearchXml.php
===================================================================
--- trunk/extensions/OpenSearchXml/OpenSearchXml.php    2012-03-21 20:21:34 UTC 
(rev 114400)
+++ trunk/extensions/OpenSearchXml/OpenSearchXml.php    2012-03-21 20:27:59 UTC 
(rev 114401)
@@ -40,11 +40,6 @@
 $wgOpenSearchAdvertiseXml = true;
 
 /**
- * Minimum length of extract in <Description>. Actual extracts will last until 
the end of sentence.
- */
-$wgOpenSearchDescriptionLength = 100;
-
-/**
  * @param $urls array
  * @return bool
  */


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

Reply via email to