Index: trunk/phase3/includes/search/SearchEngine.php |
— | — | @@ -101,21 +101,21 @@ |
102 | 102 | private static function getNearMatchInternal( $searchterm ) { |
103 | 103 | global $wgContLang; |
104 | 104 | |
105 | | - $allSearchTerms = array($searchterm); |
| 105 | + $allSearchTerms = array( $searchterm ); |
106 | 106 | |
107 | 107 | if ( $wgContLang->hasVariants() ) { |
108 | | - $allSearchTerms = array_merge($allSearchTerms,$wgContLang->convertLinkToAllVariants($searchterm)); |
| 108 | + $allSearchTerms = array_merge( $allSearchTerms, $wgContLang->convertLinkToAllVariants( $searchterm ) ); |
109 | 109 | } |
110 | 110 | |
111 | | - if( !wfRunHooks( 'SearchGetNearMatchBefore', array( $allSearchTerms, &$titleResult ) ) ) { |
| 111 | + if ( !wfRunHooks( 'SearchGetNearMatchBefore', array( $allSearchTerms, &$titleResult ) ) ) { |
112 | 112 | return $titleResult; |
113 | 113 | } |
114 | 114 | |
115 | | - foreach($allSearchTerms as $term) { |
| 115 | + foreach ( $allSearchTerms as $term ) { |
116 | 116 | |
117 | 117 | # Exact match? No need to look further. |
118 | 118 | $title = Title::newFromText( $term ); |
119 | | - if (is_null($title)) |
| 119 | + if ( is_null( $title ) ) |
120 | 120 | return null; |
121 | 121 | |
122 | 122 | if ( $title->getNamespace() == NS_SPECIAL || $title->isExternal() || $title->exists() ) { |
— | — | @@ -124,7 +124,7 @@ |
125 | 125 | |
126 | 126 | # See if it still otherwise has content is some sane sense |
127 | 127 | $article = MediaWiki::articleFromTitle( $title ); |
128 | | - if( $article->hasViewableContent() ) { |
| 128 | + if ( $article->hasViewableContent() ) { |
129 | 129 | return $title; |
130 | 130 | } |
131 | 131 | |
— | — | @@ -150,14 +150,14 @@ |
151 | 151 | } |
152 | 152 | |
153 | 153 | # Now try Word-Caps-Breaking-At-Word-Breaks, for hyphenated names etc |
154 | | - $title = Title::newFromText( $wgContLang->ucwordbreaks($term) ); |
| 154 | + $title = Title::newFromText( $wgContLang->ucwordbreaks( $term ) ); |
155 | 155 | if ( $title && $title->exists() ) { |
156 | 156 | return $title; |
157 | 157 | } |
158 | 158 | |
159 | 159 | // Give hooks a chance at better match variants |
160 | 160 | $title = null; |
161 | | - if( !wfRunHooks( 'SearchGetNearMatch', array( $term, &$title ) ) ) { |
| 161 | + if ( !wfRunHooks( 'SearchGetNearMatch', array( $term, &$title ) ) ) { |
162 | 162 | return $title; |
163 | 163 | } |
164 | 164 | } |
— | — | @@ -165,7 +165,7 @@ |
166 | 166 | $title = Title::newFromText( $searchterm ); |
167 | 167 | |
168 | 168 | # Entering an IP address goes to the contributions page |
169 | | - if ( ( $title->getNamespace() == NS_USER && User::isIP($title->getText() ) ) |
| 169 | + if ( ( $title->getNamespace() == NS_USER && User::isIP( $title->getText() ) ) |
170 | 170 | || User::isIP( trim( $searchterm ) ) ) { |
171 | 171 | return SpecialPage::getTitleFor( 'Contributions', $title->getDBkey() ); |
172 | 172 | } |
— | — | @@ -179,22 +179,22 @@ |
180 | 180 | # Go to images that exist even if there's no local page. |
181 | 181 | # There may have been a funny upload, or it may be on a shared |
182 | 182 | # file repository such as Wikimedia Commons. |
183 | | - if( $title->getNamespace() == NS_FILE ) { |
| 183 | + if ( $title->getNamespace() == NS_FILE ) { |
184 | 184 | $image = wfFindFile( $title ); |
185 | | - if( $image ) { |
| 185 | + if ( $image ) { |
186 | 186 | return $title; |
187 | 187 | } |
188 | 188 | } |
189 | 189 | |
190 | 190 | # MediaWiki namespace? Page may be "implied" if not customized. |
191 | 191 | # Just return it, with caps forced as the message system likes it. |
192 | | - if( $title->getNamespace() == NS_MEDIAWIKI ) { |
| 192 | + if ( $title->getNamespace() == NS_MEDIAWIKI ) { |
193 | 193 | return Title::makeTitle( NS_MEDIAWIKI, $wgContLang->ucfirst( $title->getText() ) ); |
194 | 194 | } |
195 | 195 | |
196 | 196 | # Quoted term? Try without the quotes... |
197 | 197 | $matches = array(); |
198 | | - if( preg_match( '/^"([^"]+)"$/', $searchterm, $matches ) ) { |
| 198 | + if ( preg_match( '/^"([^"]+)"$/', $searchterm, $matches ) ) { |
199 | 199 | return SearchEngine::getNearMatch( $matches[1] ); |
200 | 200 | } |
201 | 201 | |
— | — | @@ -233,28 +233,28 @@ |
234 | 234 | * |
235 | 235 | * @param $query String |
236 | 236 | */ |
237 | | - function replacePrefixes( $query ){ |
| 237 | + function replacePrefixes( $query ) { |
238 | 238 | global $wgContLang; |
239 | 239 | |
240 | 240 | $parsed = $query; |
241 | | - if( strpos($query,':') === false ) { // nothing to do |
| 241 | + if ( strpos( $query, ':' ) === false ) { // nothing to do |
242 | 242 | wfRunHooks( 'SearchEngineReplacePrefixesComplete', array( $this, $query, &$parsed ) ); |
243 | 243 | return $parsed; |
244 | 244 | } |
245 | 245 | |
246 | | - $allkeyword = wfMsgForContent('searchall').":"; |
247 | | - if( strncmp($query, $allkeyword, strlen($allkeyword)) == 0 ){ |
| 246 | + $allkeyword = wfMsgForContent( 'searchall' ) . ":"; |
| 247 | + if ( strncmp( $query, $allkeyword, strlen( $allkeyword ) ) == 0 ) { |
248 | 248 | $this->namespaces = null; |
249 | | - $parsed = substr($query,strlen($allkeyword)); |
250 | | - } else if( strpos($query,':') !== false ) { |
251 | | - $prefix = substr($query,0,strpos($query,':')); |
252 | | - $index = $wgContLang->getNsIndex($prefix); |
253 | | - if($index !== false){ |
254 | | - $this->namespaces = array($index); |
255 | | - $parsed = substr($query,strlen($prefix)+1); |
| 249 | + $parsed = substr( $query, strlen( $allkeyword ) ); |
| 250 | + } else if ( strpos( $query, ':' ) !== false ) { |
| 251 | + $prefix = substr( $query, 0, strpos( $query, ':' ) ); |
| 252 | + $index = $wgContLang->getNsIndex( $prefix ); |
| 253 | + if ( $index !== false ) { |
| 254 | + $this->namespaces = array( $index ); |
| 255 | + $parsed = substr( $query, strlen( $prefix ) + 1 ); |
256 | 256 | } |
257 | 257 | } |
258 | | - if(trim($parsed) == '') |
| 258 | + if ( trim( $parsed ) == '' ) |
259 | 259 | $parsed = $query; // prefix was the whole query |
260 | 260 | |
261 | 261 | wfRunHooks( 'SearchEngineReplacePrefixesComplete', array( $this, $query, &$parsed ) ); |
— | — | @@ -269,8 +269,8 @@ |
270 | 270 | public static function searchableNamespaces() { |
271 | 271 | global $wgContLang; |
272 | 272 | $arr = array(); |
273 | | - foreach( $wgContLang->getNamespaces() as $ns => $name ) { |
274 | | - if( $ns >= NS_MAIN ) { |
| 273 | + foreach ( $wgContLang->getNamespaces() as $ns => $name ) { |
| 274 | + if ( $ns >= NS_MAIN ) { |
275 | 275 | $arr[$ns] = $name; |
276 | 276 | } |
277 | 277 | } |
— | — | @@ -291,18 +291,18 @@ |
292 | 292 | |
293 | 293 | // get search everything preference, that can be set to be read for logged-in users |
294 | 294 | $searcheverything = false; |
295 | | - if( ( $wgSearchEverythingOnlyLoggedIn && $user->isLoggedIn() ) |
| 295 | + if ( ( $wgSearchEverythingOnlyLoggedIn && $user->isLoggedIn() ) |
296 | 296 | || !$wgSearchEverythingOnlyLoggedIn ) |
297 | | - $searcheverything = $user->getOption('searcheverything'); |
| 297 | + $searcheverything = $user->getOption( 'searcheverything' ); |
298 | 298 | |
299 | 299 | // searcheverything overrides other options |
300 | | - if( $searcheverything ) |
301 | | - return array_keys(SearchEngine::searchableNamespaces()); |
| 300 | + if ( $searcheverything ) |
| 301 | + return array_keys( SearchEngine::searchableNamespaces() ); |
302 | 302 | |
303 | 303 | $arr = Preferences::loadOldSearchNs( $user ); |
304 | 304 | $searchableNamespaces = SearchEngine::searchableNamespaces(); |
305 | 305 | |
306 | | - $arr = array_intersect( $arr, array_keys($searchableNamespaces) ); // Filter |
| 306 | + $arr = array_intersect( $arr, array_keys( $searchableNamespaces ) ); // Filter |
307 | 307 | |
308 | 308 | return $arr; |
309 | 309 | } |
— | — | @@ -313,12 +313,12 @@ |
314 | 314 | * @param $user User |
315 | 315 | * @return Array contextlines, contextchars |
316 | 316 | */ |
317 | | - public static function userHighlightPrefs( &$user ){ |
318 | | - //$contextlines = $user->getOption( 'contextlines', 5 ); |
319 | | - //$contextchars = $user->getOption( 'contextchars', 50 ); |
| 317 | + public static function userHighlightPrefs( &$user ) { |
| 318 | + // $contextlines = $user->getOption( 'contextlines', 5 ); |
| 319 | + // $contextchars = $user->getOption( 'contextchars', 50 ); |
320 | 320 | $contextlines = 2; // Hardcode this. Old defaults sucked. :) |
321 | 321 | $contextchars = 75; // same as above.... :P |
322 | | - return array($contextlines, $contextchars); |
| 322 | + return array( $contextlines, $contextchars ); |
323 | 323 | } |
324 | 324 | |
325 | 325 | /** |
— | — | @@ -326,10 +326,10 @@ |
327 | 327 | * |
328 | 328 | * @return Array |
329 | 329 | */ |
330 | | - public static function defaultNamespaces(){ |
| 330 | + public static function defaultNamespaces() { |
331 | 331 | global $wgNamespacesToBeSearchedDefault; |
332 | 332 | |
333 | | - return array_keys($wgNamespacesToBeSearchedDefault, true); |
| 333 | + return array_keys( $wgNamespacesToBeSearchedDefault, true ); |
334 | 334 | } |
335 | 335 | |
336 | 336 | /** |
— | — | @@ -338,12 +338,12 @@ |
339 | 339 | * |
340 | 340 | * @param $namespaces Array |
341 | 341 | */ |
342 | | - public static function namespacesAsText( $namespaces ){ |
| 342 | + public static function namespacesAsText( $namespaces ) { |
343 | 343 | global $wgContLang; |
344 | 344 | |
345 | | - $formatted = array_map( array($wgContLang,'getFormattedNsText'), $namespaces ); |
346 | | - foreach( $formatted as $key => $ns ){ |
347 | | - if ( empty($ns) ) |
| 345 | + $formatted = array_map( array( $wgContLang, 'getFormattedNsText' ), $namespaces ); |
| 346 | + foreach ( $formatted as $key => $ns ) { |
| 347 | + if ( empty( $ns ) ) |
348 | 348 | $formatted[$key] = wfMsg( 'blanknamespace' ); |
349 | 349 | } |
350 | 350 | return $formatted; |
— | — | @@ -379,13 +379,13 @@ |
380 | 380 | public static function create() { |
381 | 381 | global $wgSearchType; |
382 | 382 | $dbr = wfGetDB( DB_SLAVE ); |
383 | | - if( $wgSearchType ) { |
| 383 | + if ( $wgSearchType ) { |
384 | 384 | $class = $wgSearchType; |
385 | 385 | } else { |
386 | 386 | $class = $dbr->getSearchEngine(); |
387 | 387 | } |
388 | 388 | $search = new $class( $dbr ); |
389 | | - $search->setLimitOffset(0,0); |
| 389 | + $search->setLimitOffset( 0, 0 ); |
390 | 390 | return $search; |
391 | 391 | } |
392 | 392 | |
— | — | @@ -421,12 +421,12 @@ |
422 | 422 | */ |
423 | 423 | public static function getOpenSearchTemplate() { |
424 | 424 | global $wgOpenSearchTemplate, $wgServer, $wgScriptPath; |
425 | | - if( $wgOpenSearchTemplate ) { |
| 425 | + if ( $wgOpenSearchTemplate ) { |
426 | 426 | return $wgOpenSearchTemplate; |
427 | 427 | } else { |
428 | 428 | $ns = implode( '|', SearchEngine::defaultNamespaces() ); |
429 | | - if( !$ns ) $ns = "0"; |
430 | | - return $wgServer . $wgScriptPath . '/api.php?action=opensearch&search={searchTerms}&namespace='.$ns; |
| 429 | + if ( !$ns ) $ns = "0"; |
| 430 | + return $wgServer . $wgScriptPath . '/api.php?action=opensearch&search={searchTerms}&namespace=' . $ns; |
431 | 431 | } |
432 | 432 | } |
433 | 433 | |
— | — | @@ -437,7 +437,7 @@ |
438 | 438 | */ |
439 | 439 | public static function getMWSuggestTemplate() { |
440 | 440 | global $wgMWSuggestTemplate, $wgServer, $wgScriptPath; |
441 | | - if($wgMWSuggestTemplate) |
| 441 | + if ( $wgMWSuggestTemplate ) |
442 | 442 | return $wgMWSuggestTemplate; |
443 | 443 | else |
444 | 444 | return $wgServer . $wgScriptPath . '/api.php?action=opensearch&search={searchTerms}&namespace={namespaces}&suggest'; |
— | — | @@ -500,14 +500,14 @@ |
501 | 501 | /** |
502 | 502 | * @return String: suggested query, null if none |
503 | 503 | */ |
504 | | - function getSuggestionQuery(){ |
| 504 | + function getSuggestionQuery() { |
505 | 505 | return null; |
506 | 506 | } |
507 | 507 | |
508 | 508 | /** |
509 | 509 | * @return String: HTML highlighted suggested query, '' if none |
510 | 510 | */ |
511 | | - function getSuggestionSnippet(){ |
| 511 | + function getSuggestionSnippet() { |
512 | 512 | return ''; |
513 | 513 | } |
514 | 514 | |
— | — | @@ -571,25 +571,25 @@ |
572 | 572 | } |
573 | 573 | |
574 | 574 | function numRows() { |
575 | | - if ($this->mResultSet === false ) |
| 575 | + if ( $this->mResultSet === false ) |
576 | 576 | return false; |
577 | 577 | |
578 | 578 | return $this->mResultSet->numRows(); |
579 | 579 | } |
580 | 580 | |
581 | 581 | function next() { |
582 | | - if ($this->mResultSet === false ) |
| 582 | + if ( $this->mResultSet === false ) |
583 | 583 | return false; |
584 | 584 | |
585 | 585 | $row = $this->mResultSet->fetchObject(); |
586 | | - if ($row === false) |
| 586 | + if ( $row === false ) |
587 | 587 | return false; |
588 | 588 | |
589 | 589 | return SearchResult::newFromRow( $row ); |
590 | 590 | } |
591 | 591 | |
592 | 592 | function free() { |
593 | | - if ($this->mResultSet === false ) |
| 593 | + if ( $this->mResultSet === false ) |
594 | 594 | return false; |
595 | 595 | |
596 | 596 | $this->mResultSet->free(); |
— | — | @@ -600,7 +600,7 @@ |
601 | 601 | * @ingroup Search |
602 | 602 | */ |
603 | 603 | class SearchResultTooMany { |
604 | | - ## Some search engines may bail out if too many matches are found |
| 604 | + # # Some search engines may bail out if too many matches are found |
605 | 605 | } |
606 | 606 | |
607 | 607 | |
— | — | @@ -662,11 +662,11 @@ |
663 | 663 | */ |
664 | 664 | protected function initFromTitle( $title ) { |
665 | 665 | $this->mTitle = $title; |
666 | | - if( !is_null( $this->mTitle ) ){ |
| 666 | + if ( !is_null( $this->mTitle ) ) { |
667 | 667 | $this->mRevision = Revision::newFromTitle( $this->mTitle ); |
668 | | - if( $this->mTitle->getNamespace() === NS_FILE ) |
| 668 | + if ( $this->mTitle->getNamespace() === NS_FILE ) |
669 | 669 | $this->mImage = wfFindFile( $this->mTitle ); |
670 | | - } |
| 670 | + } |
671 | 671 | } |
672 | 672 | |
673 | 673 | /** |
— | — | @@ -674,8 +674,8 @@ |
675 | 675 | * |
676 | 676 | * @return Boolean |
677 | 677 | */ |
678 | | - function isBrokenTitle(){ |
679 | | - if( is_null($this->mTitle) ) |
| 678 | + function isBrokenTitle() { |
| 679 | + if ( is_null( $this->mTitle ) ) |
680 | 680 | return true; |
681 | 681 | return false; |
682 | 682 | } |
— | — | @@ -685,7 +685,7 @@ |
686 | 686 | * |
687 | 687 | * @return Boolean |
688 | 688 | */ |
689 | | - function isMissingRevision(){ |
| 689 | + function isMissingRevision() { |
690 | 690 | return !$this->mRevision && !$this->mImage; |
691 | 691 | } |
692 | 692 | |
— | — | @@ -706,9 +706,9 @@ |
707 | 707 | /** |
708 | 708 | * Lazy initialization of article text from DB |
709 | 709 | */ |
710 | | - protected function initText(){ |
711 | | - if( !isset($this->mText) ){ |
712 | | - if($this->mRevision != null) |
| 710 | + protected function initText() { |
| 711 | + if ( !isset( $this->mText ) ) { |
| 712 | + if ( $this->mRevision != null ) |
713 | 713 | $this->mText = $this->mRevision->getText(); |
714 | 714 | else // TODO: can we fetch raw wikitext for commons images? |
715 | 715 | $this->mText = ''; |
— | — | @@ -720,12 +720,12 @@ |
721 | 721 | * @param $terms Array: terms to highlight |
722 | 722 | * @return String: highlighted text snippet, null (and not '') if not supported |
723 | 723 | */ |
724 | | - function getTextSnippet($terms){ |
| 724 | + function getTextSnippet( $terms ) { |
725 | 725 | global $wgUser, $wgAdvancedSearchHighlighting; |
726 | 726 | $this->initText(); |
727 | | - list($contextlines,$contextchars) = SearchEngine::userHighlightPrefs($wgUser); |
| 727 | + list( $contextlines, $contextchars ) = SearchEngine::userHighlightPrefs( $wgUser ); |
728 | 728 | $h = new SearchHighlighter(); |
729 | | - if( $wgAdvancedSearchHighlighting ) |
| 729 | + if ( $wgAdvancedSearchHighlighting ) |
730 | 730 | return $h->highlightText( $this->mText, $terms, $contextlines, $contextchars ); |
731 | 731 | else |
732 | 732 | return $h->highlightSimple( $this->mText, $terms, $contextlines, $contextchars ); |
— | — | @@ -735,7 +735,7 @@ |
736 | 736 | * @param $terms Array: terms to highlight |
737 | 737 | * @return String: highlighted title, '' if not supported |
738 | 738 | */ |
739 | | - function getTitleSnippet($terms){ |
| 739 | + function getTitleSnippet( $terms ) { |
740 | 740 | return ''; |
741 | 741 | } |
742 | 742 | |
— | — | @@ -743,38 +743,38 @@ |
744 | 744 | * @param $terms Array: terms to highlight |
745 | 745 | * @return String: highlighted redirect name (redirect to this page), '' if none or not supported |
746 | 746 | */ |
747 | | - function getRedirectSnippet($terms){ |
| 747 | + function getRedirectSnippet( $terms ) { |
748 | 748 | return ''; |
749 | 749 | } |
750 | 750 | |
751 | 751 | /** |
752 | 752 | * @return Title object for the redirect to this page, null if none or not supported |
753 | 753 | */ |
754 | | - function getRedirectTitle(){ |
| 754 | + function getRedirectTitle() { |
755 | 755 | return null; |
756 | 756 | } |
757 | 757 | |
758 | 758 | /** |
759 | 759 | * @return string highlighted relevant section name, null if none or not supported |
760 | 760 | */ |
761 | | - function getSectionSnippet(){ |
| 761 | + function getSectionSnippet() { |
762 | 762 | return ''; |
763 | 763 | } |
764 | 764 | |
765 | 765 | /** |
766 | 766 | * @return Title object (pagename+fragment) for the section, null if none or not supported |
767 | 767 | */ |
768 | | - function getSectionTitle(){ |
| 768 | + function getSectionTitle() { |
769 | 769 | return null; |
770 | 770 | } |
771 | 771 | |
772 | 772 | /** |
773 | 773 | * @return String: timestamp |
774 | 774 | */ |
775 | | - function getTimestamp(){ |
776 | | - if( $this->mRevision ) |
| 775 | + function getTimestamp() { |
| 776 | + if ( $this->mRevision ) |
777 | 777 | return $this->mRevision->getTimestamp(); |
778 | | - else if( $this->mImage ) |
| 778 | + else if ( $this->mImage ) |
779 | 779 | return $this->mImage->getTimestamp(); |
780 | 780 | return ''; |
781 | 781 | } |
— | — | @@ -782,7 +782,7 @@ |
783 | 783 | /** |
784 | 784 | * @return Integer: number of words |
785 | 785 | */ |
786 | | - function getWordCount(){ |
| 786 | + function getWordCount() { |
787 | 787 | $this->initText(); |
788 | 788 | return str_word_count( $this->mText ); |
789 | 789 | } |
— | — | @@ -790,7 +790,7 @@ |
791 | 791 | /** |
792 | 792 | * @return Integer: size in bytes |
793 | 793 | */ |
794 | | - function getByteSize(){ |
| 794 | + function getByteSize() { |
795 | 795 | $this->initText(); |
796 | 796 | return strlen( $this->mText ); |
797 | 797 | } |
— | — | @@ -798,14 +798,14 @@ |
799 | 799 | /** |
800 | 800 | * @return Boolean if hit has related articles |
801 | 801 | */ |
802 | | - function hasRelated(){ |
| 802 | + function hasRelated() { |
803 | 803 | return false; |
804 | 804 | } |
805 | 805 | |
806 | 806 | /** |
807 | 807 | * @return String: interwiki prefix of the title (return iw even if title is broken) |
808 | 808 | */ |
809 | | - function getInterwikiPrefix(){ |
| 809 | + function getInterwikiPrefix() { |
810 | 810 | return ''; |
811 | 811 | } |
812 | 812 | } |
— | — | @@ -843,7 +843,7 @@ |
844 | 844 | class SearchHighlighter { |
845 | 845 | var $mCleanWikitext = true; |
846 | 846 | |
847 | | - function SearchHighlighter($cleanupWikitext = true){ |
| 847 | + function SearchHighlighter( $cleanupWikitext = true ) { |
848 | 848 | $this->mCleanWikitext = $cleanupWikitext; |
849 | 849 | } |
850 | 850 | |
— | — | @@ -861,7 +861,7 @@ |
862 | 862 | global $wgSearchHighlightBoundaries; |
863 | 863 | $fname = __METHOD__; |
864 | 864 | |
865 | | - if($text == '') |
| 865 | + if ( $text == '' ) |
866 | 866 | return ''; |
867 | 867 | |
868 | 868 | // spli text into text + templates/links/tables |
— | — | @@ -870,10 +870,10 @@ |
871 | 871 | $endPatterns = array( |
872 | 872 | 1 => '/(\{\{)|(\}\})/', // template |
873 | 873 | 2 => '/(\[\[)|(\]\])/', // image |
874 | | - 3 => "/(\n\\{\\|)|(\n\\|\\})/"); // table |
| 874 | + 3 => "/(\n\\{\\|)|(\n\\|\\})/" ); // table |
875 | 875 | |
876 | 876 | // FIXME: this should prolly be a hook or something |
877 | | - if(function_exists('wfCite')){ |
| 877 | + if ( function_exists( 'wfCite' ) ) { |
878 | 878 | $spat .= '|(<ref>)'; // references via cite extension |
879 | 879 | $endPatterns[4] = '/(<ref>)|(<\/ref>)/'; |
880 | 880 | } |
— | — | @@ -882,18 +882,18 @@ |
883 | 883 | $otherExt = array(); // other extracts |
884 | 884 | wfProfileIn( "$fname-split" ); |
885 | 885 | $start = 0; |
886 | | - $textLen = strlen($text); |
| 886 | + $textLen = strlen( $text ); |
887 | 887 | $count = 0; // sequence number to maintain ordering |
888 | | - while( $start < $textLen ){ |
| 888 | + while ( $start < $textLen ) { |
889 | 889 | // find start of template/image/table |
890 | | - if( preg_match( $spat, $text, $matches, PREG_OFFSET_CAPTURE, $start ) ){ |
| 890 | + if ( preg_match( $spat, $text, $matches, PREG_OFFSET_CAPTURE, $start ) ) { |
891 | 891 | $epat = ''; |
892 | | - foreach($matches as $key => $val){ |
893 | | - if($key > 0 && $val[1] != -1){ |
894 | | - if($key == 2){ |
| 892 | + foreach ( $matches as $key => $val ) { |
| 893 | + if ( $key > 0 && $val[1] != - 1 ) { |
| 894 | + if ( $key == 2 ) { |
895 | 895 | // see if this is an image link |
896 | | - $ns = substr($val[0],2,-1); |
897 | | - if( $wgContLang->getNsIndex($ns) != NS_FILE ) |
| 896 | + $ns = substr( $val[0], 2, - 1 ); |
| 897 | + if ( $wgContLang->getNsIndex( $ns ) != NS_FILE ) |
898 | 898 | break; |
899 | 899 | |
900 | 900 | } |
— | — | @@ -903,42 +903,42 @@ |
904 | 904 | break; |
905 | 905 | } |
906 | 906 | } |
907 | | - if( $epat ){ |
| 907 | + if ( $epat ) { |
908 | 908 | // find end (and detect any nested elements) |
909 | 909 | $level = 0; |
910 | 910 | $offset = $start + 1; |
911 | 911 | $found = false; |
912 | | - while( preg_match( $epat, $text, $endMatches, PREG_OFFSET_CAPTURE, $offset ) ){ |
913 | | - if( array_key_exists(2,$endMatches) ){ |
| 912 | + while ( preg_match( $epat, $text, $endMatches, PREG_OFFSET_CAPTURE, $offset ) ) { |
| 913 | + if ( array_key_exists( 2, $endMatches ) ) { |
914 | 914 | // found end |
915 | | - if($level == 0){ |
916 | | - $len = strlen($endMatches[2][0]); |
| 915 | + if ( $level == 0 ) { |
| 916 | + $len = strlen( $endMatches[2][0] ); |
917 | 917 | $off = $endMatches[2][1]; |
918 | 918 | $this->splitAndAdd( $otherExt, $count, |
919 | 919 | substr( $text, $start, $off + $len - $start ) ); |
920 | 920 | $start = $off + $len; |
921 | 921 | $found = true; |
922 | 922 | break; |
923 | | - } else{ |
| 923 | + } else { |
924 | 924 | // end of nested element |
925 | 925 | $level -= 1; |
926 | 926 | } |
927 | | - } else{ |
| 927 | + } else { |
928 | 928 | // nested |
929 | 929 | $level += 1; |
930 | 930 | } |
931 | | - $offset = $endMatches[0][1] + strlen($endMatches[0][0]); |
| 931 | + $offset = $endMatches[0][1] + strlen( $endMatches[0][0] ); |
932 | 932 | } |
933 | | - if( ! $found ){ |
| 933 | + if ( ! $found ) { |
934 | 934 | // couldn't find appropriate closing tag, skip |
935 | | - $this->splitAndAdd( $textExt, $count, substr( $text, $start, strlen($matches[0][0]) ) ); |
936 | | - $start += strlen($matches[0][0]); |
| 935 | + $this->splitAndAdd( $textExt, $count, substr( $text, $start, strlen( $matches[0][0] ) ) ); |
| 936 | + $start += strlen( $matches[0][0] ); |
937 | 937 | } |
938 | 938 | continue; |
939 | 939 | } |
940 | 940 | } |
941 | 941 | // else: add as text extract |
942 | | - $this->splitAndAdd( $textExt, $count, substr($text,$start) ); |
| 942 | + $this->splitAndAdd( $textExt, $count, substr( $text, $start ) ); |
943 | 943 | break; |
944 | 944 | } |
945 | 945 | |
— | — | @@ -947,29 +947,29 @@ |
948 | 948 | wfProfileOut( "$fname-split" ); |
949 | 949 | |
950 | 950 | // prepare regexps |
951 | | - foreach( $terms as $index => $term ) { |
| 951 | + foreach ( $terms as $index => $term ) { |
952 | 952 | // manually do upper/lowercase stuff for utf-8 since PHP won't do it |
953 | | - if(preg_match('/[\x80-\xff]/', $term) ){ |
954 | | - $terms[$index] = preg_replace_callback('/./us',array($this,'caseCallback'),$terms[$index]); |
| 953 | + if ( preg_match( '/[\x80-\xff]/', $term ) ) { |
| 954 | + $terms[$index] = preg_replace_callback( '/./us', array( $this, 'caseCallback' ), $terms[$index] ); |
955 | 955 | } else { |
956 | 956 | $terms[$index] = $term; |
957 | 957 | } |
958 | 958 | } |
959 | 959 | $anyterm = implode( '|', $terms ); |
960 | | - $phrase = implode("$wgSearchHighlightBoundaries+", $terms ); |
| 960 | + $phrase = implode( "$wgSearchHighlightBoundaries+", $terms ); |
961 | 961 | |
962 | 962 | // FIXME: a hack to scale contextchars, a correct solution |
963 | 963 | // would be to have contextchars actually be char and not byte |
964 | 964 | // length, and do proper utf-8 substrings and lengths everywhere, |
965 | 965 | // but PHP is making that very hard and unclean to implement :( |
966 | | - $scale = strlen($anyterm) / mb_strlen($anyterm); |
| 966 | + $scale = strlen( $anyterm ) / mb_strlen( $anyterm ); |
967 | 967 | $contextchars = intval( $contextchars * $scale ); |
968 | 968 | |
969 | 969 | $patPre = "(^|$wgSearchHighlightBoundaries)"; |
970 | 970 | $patPost = "($wgSearchHighlightBoundaries|$)"; |
971 | 971 | |
972 | | - $pat1 = "/(".$phrase.")/ui"; |
973 | | - $pat2 = "/$patPre(".$anyterm.")$patPost/ui"; |
| 972 | + $pat1 = "/(" . $phrase . ")/ui"; |
| 973 | + $pat2 = "/$patPre(" . $anyterm . ")$patPost/ui"; |
974 | 974 | |
975 | 975 | wfProfileIn( "$fname-extract" ); |
976 | 976 | |
— | — | @@ -981,43 +981,43 @@ |
982 | 982 | // show beginning only if it contains all words |
983 | 983 | $first = 0; |
984 | 984 | $firstText = ''; |
985 | | - foreach($textExt as $index => $line){ |
986 | | - if(strlen($line)>0 && $line[0] != ';' && $line[0] != ':'){ |
| 985 | + foreach ( $textExt as $index => $line ) { |
| 986 | + if ( strlen( $line ) > 0 && $line[0] != ';' && $line[0] != ':' ) { |
987 | 987 | $firstText = $this->extract( $line, 0, $contextchars * $contextlines ); |
988 | 988 | $first = $index; |
989 | 989 | break; |
990 | 990 | } |
991 | 991 | } |
992 | | - if( $firstText ){ |
| 992 | + if ( $firstText ) { |
993 | 993 | $succ = true; |
994 | 994 | // check if first text contains all terms |
995 | | - foreach($terms as $term){ |
996 | | - if( ! preg_match("/$patPre".$term."$patPost/ui", $firstText) ){ |
| 995 | + foreach ( $terms as $term ) { |
| 996 | + if ( ! preg_match( "/$patPre" . $term . "$patPost/ui", $firstText ) ) { |
997 | 997 | $succ = false; |
998 | 998 | break; |
999 | 999 | } |
1000 | 1000 | } |
1001 | | - if( $succ ){ |
| 1001 | + if ( $succ ) { |
1002 | 1002 | $snippets[$first] = $firstText; |
1003 | 1003 | $offsets[$first] = 0; |
1004 | 1004 | } |
1005 | 1005 | } |
1006 | | - if( ! $snippets ) { |
| 1006 | + if ( ! $snippets ) { |
1007 | 1007 | // match whole query on text |
1008 | | - $this->process($pat1, $textExt, $left, $contextchars, $snippets, $offsets); |
| 1008 | + $this->process( $pat1, $textExt, $left, $contextchars, $snippets, $offsets ); |
1009 | 1009 | // match whole query on templates/tables/images |
1010 | | - $this->process($pat1, $otherExt, $left, $contextchars, $snippets, $offsets); |
| 1010 | + $this->process( $pat1, $otherExt, $left, $contextchars, $snippets, $offsets ); |
1011 | 1011 | // match any words on text |
1012 | | - $this->process($pat2, $textExt, $left, $contextchars, $snippets, $offsets); |
| 1012 | + $this->process( $pat2, $textExt, $left, $contextchars, $snippets, $offsets ); |
1013 | 1013 | // match any words on templates/tables/images |
1014 | | - $this->process($pat2, $otherExt, $left, $contextchars, $snippets, $offsets); |
| 1014 | + $this->process( $pat2, $otherExt, $left, $contextchars, $snippets, $offsets ); |
1015 | 1015 | |
1016 | | - ksort($snippets); |
| 1016 | + ksort( $snippets ); |
1017 | 1017 | } |
1018 | 1018 | |
1019 | 1019 | // add extra chars to each snippet to make snippets constant size |
1020 | 1020 | $extended = array(); |
1021 | | - if( count( $snippets ) == 0 ){ |
| 1021 | + if ( count( $snippets ) == 0 ) { |
1022 | 1022 | // couldn't find the target words, just show beginning of article |
1023 | 1023 | if ( array_key_exists( $first, $all ) ) { |
1024 | 1024 | $targetchars = $contextchars * $contextlines; |
— | — | @@ -1026,32 +1026,32 @@ |
1027 | 1027 | } |
1028 | 1028 | } else { |
1029 | 1029 | // if begin of the article contains the whole phrase, show only that !! |
1030 | | - if( array_key_exists($first,$snippets) && preg_match($pat1,$snippets[$first]) |
1031 | | - && $offsets[$first] < $contextchars * 2 ){ |
1032 | | - $snippets = array ($first => $snippets[$first]); |
| 1030 | + if ( array_key_exists( $first, $snippets ) && preg_match( $pat1, $snippets[$first] ) |
| 1031 | + && $offsets[$first] < $contextchars * 2 ) { |
| 1032 | + $snippets = array ( $first => $snippets[$first] ); |
1033 | 1033 | } |
1034 | 1034 | |
1035 | 1035 | // calc by how much to extend existing snippets |
1036 | | - $targetchars = intval( ($contextchars * $contextlines) / count ( $snippets ) ); |
| 1036 | + $targetchars = intval( ( $contextchars * $contextlines ) / count ( $snippets ) ); |
1037 | 1037 | } |
1038 | 1038 | |
1039 | | - foreach($snippets as $index => $line){ |
| 1039 | + foreach ( $snippets as $index => $line ) { |
1040 | 1040 | $extended[$index] = $line; |
1041 | | - $len = strlen($line); |
1042 | | - if( $len < $targetchars - 20 ){ |
| 1041 | + $len = strlen( $line ); |
| 1042 | + if ( $len < $targetchars - 20 ) { |
1043 | 1043 | // complete this line |
1044 | | - if($len < strlen( $all[$index] )){ |
1045 | | - $extended[$index] = $this->extract( $all[$index], $offsets[$index], $offsets[$index]+$targetchars, $offsets[$index]); |
| 1044 | + if ( $len < strlen( $all[$index] ) ) { |
| 1045 | + $extended[$index] = $this->extract( $all[$index], $offsets[$index], $offsets[$index] + $targetchars, $offsets[$index] ); |
1046 | 1046 | $len = strlen( $extended[$index] ); |
1047 | 1047 | } |
1048 | 1048 | |
1049 | 1049 | // add more lines |
1050 | 1050 | $add = $index + 1; |
1051 | | - while( $len < $targetchars - 20 |
1052 | | - && array_key_exists($add,$all) |
1053 | | - && !array_key_exists($add,$snippets) ){ |
| 1051 | + while ( $len < $targetchars - 20 |
| 1052 | + && array_key_exists( $add, $all ) |
| 1053 | + && !array_key_exists( $add, $snippets ) ) { |
1054 | 1054 | $offsets[$add] = 0; |
1055 | | - $tt = "\n".$this->extract( $all[$add], 0, $targetchars - $len, $offsets[$add] ); |
| 1055 | + $tt = "\n" . $this->extract( $all[$add], 0, $targetchars - $len, $offsets[$add] ); |
1056 | 1056 | $extended[$add] = $tt; |
1057 | 1057 | $len += strlen( $tt ); |
1058 | 1058 | $add++; |
— | — | @@ -1059,27 +1059,27 @@ |
1060 | 1060 | } |
1061 | 1061 | } |
1062 | 1062 | |
1063 | | - //$snippets = array_map('htmlspecialchars', $extended); |
| 1063 | + // $snippets = array_map('htmlspecialchars', $extended); |
1064 | 1064 | $snippets = $extended; |
1065 | | - $last = -1; |
| 1065 | + $last = - 1; |
1066 | 1066 | $extract = ''; |
1067 | | - foreach($snippets as $index => $line){ |
1068 | | - if($last == -1) |
| 1067 | + foreach ( $snippets as $index => $line ) { |
| 1068 | + if ( $last == - 1 ) |
1069 | 1069 | $extract .= $line; // first line |
1070 | | - elseif($last+1 == $index && $offsets[$last]+strlen($snippets[$last]) >= strlen($all[$last])) |
1071 | | - $extract .= " ".$line; // continous lines |
| 1070 | + elseif ( $last + 1 == $index && $offsets[$last] + strlen( $snippets[$last] ) >= strlen( $all[$last] ) ) |
| 1071 | + $extract .= " " . $line; // continous lines |
1072 | 1072 | else |
1073 | 1073 | $extract .= '<b> ... </b>' . $line; |
1074 | 1074 | |
1075 | 1075 | $last = $index; |
1076 | 1076 | } |
1077 | | - if( $extract ) |
| 1077 | + if ( $extract ) |
1078 | 1078 | $extract .= '<b> ... </b>'; |
1079 | 1079 | |
1080 | 1080 | $processed = array(); |
1081 | | - foreach($terms as $term){ |
1082 | | - if( ! isset($processed[$term]) ){ |
1083 | | - $pat3 = "/$patPre(".$term.")$patPost/ui"; // highlight word |
| 1081 | + foreach ( $terms as $term ) { |
| 1082 | + if ( ! isset( $processed[$term] ) ) { |
| 1083 | + $pat3 = "/$patPre(" . $term . ")$patPost/ui"; // highlight word |
1084 | 1084 | $extract = preg_replace( $pat3, |
1085 | 1085 | "\\1<span class='searchmatch'>\\2</span>\\3", $extract ); |
1086 | 1086 | $processed[$term] = true; |
— | — | @@ -1098,11 +1098,11 @@ |
1099 | 1099 | * @param $count Integer |
1100 | 1100 | * @param $text String |
1101 | 1101 | */ |
1102 | | - function splitAndAdd(&$extracts, &$count, $text){ |
1103 | | - $split = explode( "\n", $this->mCleanWikitext? $this->removeWiki($text) : $text ); |
1104 | | - foreach($split as $line){ |
1105 | | - $tt = trim($line); |
1106 | | - if( $tt ) |
| 1102 | + function splitAndAdd( &$extracts, &$count, $text ) { |
| 1103 | + $split = explode( "\n", $this->mCleanWikitext ? $this->removeWiki( $text ) : $text ); |
| 1104 | + foreach ( $split as $line ) { |
| 1105 | + $tt = trim( $line ); |
| 1106 | + if ( $tt ) |
1107 | 1107 | $extracts[$count++] = $tt; |
1108 | 1108 | } |
1109 | 1109 | } |
— | — | @@ -1112,10 +1112,10 @@ |
1113 | 1113 | * |
1114 | 1114 | * @param $matches Array |
1115 | 1115 | */ |
1116 | | - function caseCallback($matches){ |
| 1116 | + function caseCallback( $matches ) { |
1117 | 1117 | global $wgContLang; |
1118 | | - if( strlen($matches[0]) > 1 ){ |
1119 | | - return '['.$wgContLang->lc($matches[0]).$wgContLang->uc($matches[0]).']'; |
| 1118 | + if ( strlen( $matches[0] ) > 1 ) { |
| 1119 | + return '[' . $wgContLang->lc( $matches[0] ) . $wgContLang->uc( $matches[0] ) . ']'; |
1120 | 1120 | } else |
1121 | 1121 | return $matches[0]; |
1122 | 1122 | } |
— | — | @@ -1130,23 +1130,23 @@ |
1131 | 1131 | * @param $posEnd Integer: (out) actual end position |
1132 | 1132 | * @return String |
1133 | 1133 | */ |
1134 | | - function extract($text, $start, $end, &$posStart = null, &$posEnd = null ){ |
| 1134 | + function extract( $text, $start, $end, &$posStart = null, &$posEnd = null ) { |
1135 | 1135 | global $wgContLang; |
1136 | 1136 | |
1137 | | - if( $start != 0) |
| 1137 | + if ( $start != 0 ) |
1138 | 1138 | $start = $this->position( $text, $start, 1 ); |
1139 | | - if( $end >= strlen($text) ) |
1140 | | - $end = strlen($text); |
| 1139 | + if ( $end >= strlen( $text ) ) |
| 1140 | + $end = strlen( $text ); |
1141 | 1141 | else |
1142 | 1142 | $end = $this->position( $text, $end ); |
1143 | 1143 | |
1144 | | - if(!is_null($posStart)) |
| 1144 | + if ( !is_null( $posStart ) ) |
1145 | 1145 | $posStart = $start; |
1146 | | - if(!is_null($posEnd)) |
| 1146 | + if ( !is_null( $posEnd ) ) |
1147 | 1147 | $posEnd = $end; |
1148 | 1148 | |
1149 | | - if($end > $start) |
1150 | | - return substr($text, $start, $end-$start); |
| 1149 | + if ( $end > $start ) |
| 1150 | + return substr( $text, $start, $end - $start ); |
1151 | 1151 | else |
1152 | 1152 | return ''; |
1153 | 1153 | } |
— | — | @@ -1159,21 +1159,21 @@ |
1160 | 1160 | * @param $offset Integer: offset to found index |
1161 | 1161 | * @return Integer: nearest nonletter index, or beginning of utf8 char if none |
1162 | 1162 | */ |
1163 | | - function position($text, $point, $offset=0 ){ |
| 1163 | + function position( $text, $point, $offset = 0 ) { |
1164 | 1164 | $tolerance = 10; |
1165 | 1165 | $s = max( 0, $point - $tolerance ); |
1166 | | - $l = min( strlen($text), $point + $tolerance ) - $s; |
| 1166 | + $l = min( strlen( $text ), $point + $tolerance ) - $s; |
1167 | 1167 | $m = array(); |
1168 | | - if( preg_match('/[ ,.!?~!@#$%^&*\(\)+=\-\\\|\[\]"\'<>]/', substr($text,$s,$l), $m, PREG_OFFSET_CAPTURE ) ){ |
| 1168 | + if ( preg_match( '/[ ,.!?~!@#$%^&*\(\)+=\-\\\|\[\]"\'<>]/', substr( $text, $s, $l ), $m, PREG_OFFSET_CAPTURE ) ) { |
1169 | 1169 | return $m[0][1] + $s + $offset; |
1170 | | - } else{ |
| 1170 | + } else { |
1171 | 1171 | // check if point is on a valid first UTF8 char |
1172 | 1172 | $char = ord( $text[$point] ); |
1173 | | - while( $char >= 0x80 && $char < 0xc0 ) { |
| 1173 | + while ( $char >= 0x80 && $char < 0xc0 ) { |
1174 | 1174 | // skip trailing bytes |
1175 | 1175 | $point++; |
1176 | | - if($point >= strlen($text)) |
1177 | | - return strlen($text); |
| 1176 | + if ( $point >= strlen( $text ) ) |
| 1177 | + return strlen( $text ); |
1178 | 1178 | $char = ord( $text[$point] ); |
1179 | 1179 | } |
1180 | 1180 | return $point; |
— | — | @@ -1192,11 +1192,11 @@ |
1193 | 1193 | * @param $offsets Array: map of starting points of snippets |
1194 | 1194 | * @protected |
1195 | 1195 | */ |
1196 | | - function process( $pattern, $extracts, &$linesleft, &$contextchars, &$out, &$offsets ){ |
1197 | | - if($linesleft == 0) |
| 1196 | + function process( $pattern, $extracts, &$linesleft, &$contextchars, &$out, &$offsets ) { |
| 1197 | + if ( $linesleft == 0 ) |
1198 | 1198 | return; // nothing to do |
1199 | | - foreach($extracts as $index => $line){ |
1200 | | - if( array_key_exists($index,$out) ) |
| 1199 | + foreach ( $extracts as $index => $line ) { |
| 1200 | + if ( array_key_exists( $index, $out ) ) |
1201 | 1201 | continue; // this line already highlighted |
1202 | 1202 | |
1203 | 1203 | $m = array(); |
— | — | @@ -1204,22 +1204,22 @@ |
1205 | 1205 | continue; |
1206 | 1206 | |
1207 | 1207 | $offset = $m[0][1]; |
1208 | | - $len = strlen($m[0][0]); |
1209 | | - if($offset + $len < $contextchars) |
| 1208 | + $len = strlen( $m[0][0] ); |
| 1209 | + if ( $offset + $len < $contextchars ) |
1210 | 1210 | $begin = 0; |
1211 | | - elseif( $len > $contextchars) |
| 1211 | + elseif ( $len > $contextchars ) |
1212 | 1212 | $begin = $offset; |
1213 | 1213 | else |
1214 | | - $begin = $offset + intval( ($len - $contextchars) / 2 ); |
| 1214 | + $begin = $offset + intval( ( $len - $contextchars ) / 2 ); |
1215 | 1215 | |
1216 | 1216 | $end = $begin + $contextchars; |
1217 | 1217 | |
1218 | 1218 | $posBegin = $begin; |
1219 | 1219 | // basic snippet from this line |
1220 | | - $out[$index] = $this->extract($line,$begin,$end,$posBegin); |
| 1220 | + $out[$index] = $this->extract( $line, $begin, $end, $posBegin ); |
1221 | 1221 | $offsets[$index] = $posBegin; |
1222 | 1222 | $linesleft--; |
1223 | | - if($linesleft == 0) |
| 1223 | + if ( $linesleft == 0 ) |
1224 | 1224 | return; |
1225 | 1225 | } |
1226 | 1226 | } |
— | — | @@ -1228,25 +1228,25 @@ |
1229 | 1229 | * Basic wikitext removal |
1230 | 1230 | * @protected |
1231 | 1231 | */ |
1232 | | - function removeWiki($text) { |
| 1232 | + function removeWiki( $text ) { |
1233 | 1233 | $fname = __METHOD__; |
1234 | 1234 | wfProfileIn( $fname ); |
1235 | 1235 | |
1236 | | - //$text = preg_replace("/'{2,5}/", "", $text); |
1237 | | - //$text = preg_replace("/\[[a-z]+:\/\/[^ ]+ ([^]]+)\]/", "\\2", $text); |
1238 | | - //$text = preg_replace("/\[\[([^]|]+)\]\]/", "\\1", $text); |
1239 | | - //$text = preg_replace("/\[\[([^]]+\|)?([^|]]+)\]\]/", "\\2", $text); |
1240 | | - //$text = preg_replace("/\\{\\|(.*?)\\|\\}/", "", $text); |
1241 | | - //$text = preg_replace("/\\[\\[[A-Za-z_-]+:([^|]+?)\\]\\]/", "", $text); |
1242 | | - $text = preg_replace("/\\{\\{([^|]+?)\\}\\}/", "", $text); |
1243 | | - $text = preg_replace("/\\{\\{([^|]+\\|)(.*?)\\}\\}/", "\\2", $text); |
1244 | | - $text = preg_replace("/\\[\\[([^|]+?)\\]\\]/", "\\1", $text); |
1245 | | - $text = preg_replace_callback("/\\[\\[([^|]+\\|)(.*?)\\]\\]/", array($this,'linkReplace'), $text); |
1246 | | - //$text = preg_replace("/\\[\\[([^|]+\\|)(.*?)\\]\\]/", "\\2", $text); |
1247 | | - $text = preg_replace("/<\/?[^>]+>/", "", $text); |
1248 | | - $text = preg_replace("/'''''/", "", $text); |
1249 | | - $text = preg_replace("/('''|<\/?[iIuUbB]>)/", "", $text); |
1250 | | - $text = preg_replace("/''/", "", $text); |
| 1236 | + // $text = preg_replace("/'{2,5}/", "", $text); |
| 1237 | + // $text = preg_replace("/\[[a-z]+:\/\/[^ ]+ ([^]]+)\]/", "\\2", $text); |
| 1238 | + // $text = preg_replace("/\[\[([^]|]+)\]\]/", "\\1", $text); |
| 1239 | + // $text = preg_replace("/\[\[([^]]+\|)?([^|]]+)\]\]/", "\\2", $text); |
| 1240 | + // $text = preg_replace("/\\{\\|(.*?)\\|\\}/", "", $text); |
| 1241 | + // $text = preg_replace("/\\[\\[[A-Za-z_-]+:([^|]+?)\\]\\]/", "", $text); |
| 1242 | + $text = preg_replace( "/\\{\\{([^|]+?)\\}\\}/", "", $text ); |
| 1243 | + $text = preg_replace( "/\\{\\{([^|]+\\|)(.*?)\\}\\}/", "\\2", $text ); |
| 1244 | + $text = preg_replace( "/\\[\\[([^|]+?)\\]\\]/", "\\1", $text ); |
| 1245 | + $text = preg_replace_callback( "/\\[\\[([^|]+\\|)(.*?)\\]\\]/", array( $this, 'linkReplace' ), $text ); |
| 1246 | + // $text = preg_replace("/\\[\\[([^|]+\\|)(.*?)\\]\\]/", "\\2", $text); |
| 1247 | + $text = preg_replace( "/<\/?[^>]+>/", "", $text ); |
| 1248 | + $text = preg_replace( "/'''''/", "", $text ); |
| 1249 | + $text = preg_replace( "/('''|<\/?[iIuUbB]>)/", "", $text ); |
| 1250 | + $text = preg_replace( "/''/", "", $text ); |
1251 | 1251 | |
1252 | 1252 | wfProfileOut( $fname ); |
1253 | 1253 | return $text; |
— | — | @@ -1258,14 +1258,14 @@ |
1259 | 1259 | * |
1260 | 1260 | * @param $matches Array |
1261 | 1261 | */ |
1262 | | - function linkReplace($matches){ |
| 1262 | + function linkReplace( $matches ) { |
1263 | 1263 | $colon = strpos( $matches[1], ':' ); |
1264 | | - if( $colon === false ) |
| 1264 | + if ( $colon === false ) |
1265 | 1265 | return $matches[2]; // replace with caption |
1266 | 1266 | global $wgContLang; |
1267 | 1267 | $ns = substr( $matches[1], 0, $colon ); |
1268 | | - $index = $wgContLang->getNsIndex($ns); |
1269 | | - if( $index !== false && ($index == NS_FILE || $index == NS_CATEGORY) ) |
| 1268 | + $index = $wgContLang->getNsIndex( $ns ); |
| 1269 | + if ( $index !== false && ( $index == NS_FILE || $index == NS_CATEGORY ) ) |
1270 | 1270 | return $matches[0]; // return the whole thing |
1271 | 1271 | else |
1272 | 1272 | return $matches[2]; |
— | — | @@ -1306,7 +1306,7 @@ |
1307 | 1307 | continue; |
1308 | 1308 | } |
1309 | 1309 | --$contextlines; |
1310 | | - $pre = $wgContLang->truncate( $m[1], -$contextchars ); |
| 1310 | + $pre = $wgContLang->truncate( $m[1], - $contextchars ); |
1311 | 1311 | |
1312 | 1312 | if ( count( $m ) < 3 ) { |
1313 | 1313 | $post = ''; |