r82236 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82235‎ | r82236 | r82237 >
Date:12:39, 16 February 2011
Author:reedy
Status:ok
Tags:
Comment:
Fix trailing whitespace
Modified paths:
  • /trunk/extensions/OpenSearchXml/ApiOpenSearchXml.php (modified) (history)

Diff [purge]

Index: trunk/extensions/OpenSearchXml/ApiOpenSearchXml.php
@@ -41,7 +41,7 @@
4242 }
4343 return $printer;
4444 }
45 -
 45+
4646 protected function validateFormat() {
4747 $params = $this->extractRequestParams();
4848 $format = $params['format'];
@@ -63,19 +63,19 @@
6464 // Pass back to the JSON defaults
6565 return parent::execute();
6666 }
67 -
 67+
6868 $params = $this->extractRequestParams();
6969 $search = $params['search'];
7070 $limit = $params['limit'];
7171 $namespaces = $params['namespace'];
72 -
 72+
7373 // Open search results may be stored for a very long time
7474 $this->getMain()->setCacheMaxAge(1200);
7575
7676 $srchres = PrefixSearch::titleSearch( $search, $limit, $namespaces );
7777
7878 $items = array_filter( array_map( array( $this, 'formatItem' ), $srchres ) );
79 -
 79+
8080 $result = $this->getResult();
8181 $result->addValue( null, 'version', '2.0' );
8282 $result->addValue( null, 'xmlns', 'http://opensearch.org/searchsuggest2' );
@@ -83,13 +83,13 @@
8484 $result->setIndexedTagName( $items, 'Item' );
8585 $result->addValue( null, 'Section', $items );
8686 }
87 -
 87+
8888 public function getAllowedParams() {
8989 $params = parent::getAllowedParams();
9090 $params['format'] = null;
9191 return $params;
9292 }
93 -
 93+
9494 protected function formatItem( $name ) {
9595 $title = Title::newFromText( $name );
9696 if( $title ) {
@@ -97,7 +97,7 @@
9898 if( $this->_seen( $title ) ) {
9999 return false;
100100 }
101 -
 101+
102102 list( $extract, $badge ) = $this->getExtract( $title );
103103 $image = $this->getBadge( $title, $badge );
104104
@@ -118,7 +118,7 @@
119119 }
120120 return $item;
121121 }
122 -
 122+
123123 protected function _checkRedirect( $title ) {
124124 $art = new Article( $title );
125125 $target = $art->getRedirectTarget();
@@ -150,12 +150,12 @@
151151 */
152152 function _stripMarkup( $text ) {
153153 $text = substr( $text, 0, 4096 ); // don't bother with long text...
154 -
 154+
155155 $text = str_replace( "'''", "", $text );
156156 $text = str_replace( "''", "", $text );
157 -
 157+
158158 $text = preg_replace( '#__[a-z0-9_]+__#i', '', $text ); // magic words
159 -
 159+
160160 $cleanChar = "[^|\[\]]";
161161 $subLink = "\[\[$cleanChar*(?:\|$cleanChar*)*\]\]";
162162 $pipeContents = "(?:$cleanChar|$subLink)*";
@@ -175,7 +175,7 @@
176176 $text = Sanitizer::decodeCharReferences( $text );
177177 return trim( $text );
178178 }
179 -
 179+
180180 function _stripLink( $matches ) {
181181 $target = trim( $matches[1] );
182182 if( isset( $matches[2] ) ) {
@@ -183,7 +183,7 @@
184184 } else {
185185 $text = $target;
186186 }
187 -
 187+
188188 $title = Title::newFromText( $target );
189189 if( $title ) {
190190 $ns = $title->getNamespace();
@@ -196,7 +196,7 @@
197197 return $matches[0];
198198 }
199199 }
200 -
 200+
201201 /**
202202 * Extract the first two sentences, if detectable, from the text.
203203 * @param string $text
@@ -210,7 +210,7 @@
211211 '.', '!', '?', // double-width roman forms
212212 '。', // half-width ideographic full stop
213213 );
214 -
 214+
215215 $endgroup = implode( '|', $endchars );
216216 $end = "(?:$endgroup)";
217217 $sentence = ".*?$end+";
@@ -224,7 +224,7 @@
225225 return trim( $lines[0] );
226226 }
227227 }
228 -
 228+
229229 /**
230230 * Grab the first thing that looks like an image link from the body text.
231231 * This will exclude any templates, including infoboxes...
@@ -239,13 +239,13 @@
240240 return false;
241241 }
242242 }
243 -
 243+
244244 function _validateBadge( $arg ) {
245245 // Some templates want an entire [[Image:Foo.jpg|250px]]
246246 if( substr( $arg, 0, 2 ) == '[[' ) {
247247 return $this->_extractBadge( $arg );
248248 }
249 -
 249+
250250 // Others will take Image:Foo.jpg or Foo.jpg
251251 $title = Title::newFromText( $arg, NS_IMAGE );
252252 if( $title && $title->getNamespace() == NS_IMAGE ) {
@@ -253,12 +253,12 @@
254254 }
255255 return false;
256256 }
257 -
 257+
258258 protected function getExtract( $title, $chars=50 ) {
259259 $rev = Revision::newFromTitle( $title );
260260 if( $rev ) {
261261 $text = substr( $rev->getText(), 0, 16384 );
262 -
 262+
263263 // Ok, first note this is a TERRIBLE HACK. :D
264264 //
265265 // First, we use the system preprocessor to break down the text
@@ -268,14 +268,14 @@
269269 $wgParser->clearState();
270270 $frame = $wgParser->getPreprocessor()->newFrame();
271271 $dom = $wgParser->preprocessToDom( $text );
272 -
 272+
273273 $imageArgs = array(
274274 'image',
275275 'image_skyline',
276276 'img',
277277 'Img',
278278 );
279 -
 279+
280280 // Now, we strip out everything that's not text.
281281 // This works with both DOM and Hash parsers, but feels fragile.
282282 $node = $dom->getFirstChild();
@@ -306,7 +306,7 @@
307307 }
308308 $node = $node->getNextSibling();
309309 }
310 -
 310+
311311 if( !$badge ) {
312312 // Look for the first image in the body text if there wasn't
313313 // one in an infobox.
@@ -317,7 +317,7 @@
318318 // We'll use our shitty hand parser to strip most of those from
319319 // the beginning of the text.
320320 $stripped = $this->_stripMarkup( $out );
321 -
 321+
322322 // And now, we'll grab just the first sentence as text, and
323323 // also try to rip out a badge image.
324324 return array(

Status & tagging log