Index: trunk/extensions/ReplaceText/SpecialReplaceText.php |
— | — | @@ -2,31 +2,21 @@ |
3 | 3 | |
4 | 4 | class ReplaceText extends SpecialPage { |
5 | 5 | |
6 | | - /** |
7 | | - * Constructor |
8 | | - */ |
9 | 6 | public function __construct() { |
10 | | - global $wgVersion; |
11 | 7 | parent::__construct( 'ReplaceText', 'replacetext' ); |
12 | | - if ( version_compare( $wgVersion, '1.16', '<' ) ) { |
13 | | - wfLoadExtensionMessages( 'ReplaceText' ); |
14 | | - } |
15 | 8 | } |
16 | 9 | |
17 | 10 | function execute( $query ) { |
18 | 11 | global $wgUser, $wgOut; |
19 | 12 | |
20 | | - if ( ! $wgUser->isAllowed( 'replacetext' ) ) { |
| 13 | + if ( !$wgUser->isAllowed( 'replacetext' ) ) { |
21 | 14 | $wgOut->permissionRequired( 'replacetext' ); |
22 | 15 | return; |
23 | 16 | } |
24 | 17 | |
25 | 18 | $this->user = $wgUser; |
26 | 19 | $this->setHeaders(); |
27 | | - if ( method_exists( $wgOut, 'addModuleStyles' ) && |
28 | | - !is_null( $wgOut->getResourceLoader()->getModule( 'mediawiki.special' ) ) ) { |
29 | | - $wgOut->addModuleStyles( 'mediawiki.special' ); |
30 | | - } |
| 20 | + $wgOut->addModuleStyles( 'mediawiki.special' ); |
31 | 21 | $this->doSpecialReplaceText(); |
32 | 22 | } |
33 | 23 | |
— | — | @@ -43,18 +33,6 @@ |
44 | 34 | } |
45 | 35 | |
46 | 36 | /** |
47 | | - * Helper function to generate a link. |
48 | | - */ |
49 | | - static function linkToTitle( $skin, $title, $linkText ) { |
50 | | - // link() method was added in MW 1.16 |
51 | | - if ( method_exists( $skin, 'link' ) ) { |
52 | | - return $skin->link( $title, $linkText ); |
53 | | - } else { |
54 | | - return $skin->makeKnownLinkObj( $title, $linkText ); |
55 | | - } |
56 | | - } |
57 | | - |
58 | | - /** |
59 | 37 | * Helper function to display a hidden field for different versions |
60 | 38 | * of MediaWiki. |
61 | 39 | */ |
— | — | @@ -67,7 +45,8 @@ |
68 | 46 | } |
69 | 47 | |
70 | 48 | function doSpecialReplaceText() { |
71 | | - global $wgUser, $wgOut, $wgRequest, $wgLang; |
| 49 | + global $wgOut, $wgRequest, $wgLang; |
| 50 | + $linker = class_exists( 'DummyLinker' ) ? new DummyLinker : new Linker; |
72 | 51 | |
73 | 52 | $this->target = $wgRequest->getText( 'target' ); |
74 | 53 | $this->replacement = $wgRequest->getText( 'replacement' ); |
— | — | @@ -87,7 +66,7 @@ |
88 | 67 | |
89 | 68 | if ( $wgRequest->getCheck( 'replace' ) ) { |
90 | 69 | $replacement_params = array(); |
91 | | - $replacement_params['user_id'] = $wgUser->getId(); |
| 70 | + $replacement_params['user_id'] = $this->user->getId(); |
92 | 71 | $replacement_params['target_str'] = $this->target; |
93 | 72 | $replacement_params['replacement_str'] = $this->replacement; |
94 | 73 | $replacement_params['use_regex'] = $this->use_regex; |
— | — | @@ -120,8 +99,7 @@ |
121 | 100 | $wgOut->addWikiMsg( 'replacetext_success', "<tt><nowiki>{$this->target}</nowiki></tt>", "<tt><nowiki>{$this->replacement}</nowiki></tt>", $count ); |
122 | 101 | |
123 | 102 | // Link back |
124 | | - $sk = $this->user->getSkin(); |
125 | | - $wgOut->addHTML( $this->linkToTitle( $sk, $this->getTitle(), wfMsgHtml( 'replacetext_return' ) ) ); |
| 103 | + $wgOut->addHTML( $linker->link( $this->getTitle(), wfMsgHtml( 'replacetext_return' ) ) ); |
126 | 104 | return; |
127 | 105 | } elseif ( $wgRequest->getCheck( 'target' ) ) { // very long elseif, look for "end elseif" |
128 | 106 | // first, check that at least one namespace has been |
— | — | @@ -173,15 +151,14 @@ |
174 | 152 | // if no results were found, check to see if a bad |
175 | 153 | // category name was entered |
176 | 154 | if ( count( $titles_for_edit ) == 0 && count( $titles_for_move ) == 0 ) { |
177 | | - $sk = $this->user->getSkin(); |
178 | 155 | $bad_cat_name = false; |
179 | 156 | if ( ! empty( $this->category ) ) { |
180 | 157 | $category_title = Title::makeTitleSafe( NS_CATEGORY, $this->category ); |
181 | 158 | if ( ! $category_title->exists() ) $bad_cat_name = true; |
182 | 159 | } |
183 | 160 | if ( $bad_cat_name ) { |
184 | | - //FIXME: raw html message |
185 | | - $wgOut->addHTML( wfMsg( 'replacetext_nosuchcategory', $this->linkToTitle( $sk, $category_title, ucfirst( $this->category ) ) ) ); |
| 161 | + $link = $linker->link( $category_title, htmlspecialchars( ucfirst( $this->category ) ) ); |
| 162 | + $wgOut->addHTML( wfMsgHtml( 'replacetext_nosuchcategory', $link ) ); |
186 | 163 | } else { |
187 | 164 | if ( $this->edit_pages ) |
188 | 165 | $wgOut->addWikiMsg( 'replacetext_noreplacement', "<tt><nowiki>{$this->target}</nowiki></tt>" ); |
— | — | @@ -190,7 +167,7 @@ |
191 | 168 | } |
192 | 169 | // link back to starting form |
193 | 170 | //FIXME: raw html message |
194 | | - $wgOut->addHTML( '<p>' . $this->linkToTitle( $sk, $this->getTitle(), wfMsg( 'replacetext_return' ) ) . '</p>' ); |
| 171 | + $wgOut->addHTML( '<p>' . $linker->link( $this->getTitle(), wfMsgHtml( 'replacetext_return' ) ) . '</p>' ); |
195 | 172 | } else { |
196 | 173 | // Show a warning message if the replacement |
197 | 174 | // string is either blank or found elsewhere on |
— | — | @@ -373,10 +350,9 @@ |
374 | 351 | } |
375 | 352 | |
376 | 353 | function pageListForm( $titles_for_edit, $titles_for_move, $unmoveable_titles ) { |
377 | | - global $wgOut, $wgLang, $wgScript; |
| 354 | + global $wgOut, $wgLang, $wgScriptPath; |
| 355 | + $linker = class_exists( 'DummyLinker' ) ? new DummyLinker : new Linker; |
378 | 356 | |
379 | | - $skin = $this->user->getSkin(); |
380 | | - |
381 | 357 | $formOpts = array( 'id' => 'choose_pages', 'method' => 'post', 'action' => $this->getTitle()->getFullUrl() ); |
382 | 358 | $wgOut->addHTML( |
383 | 359 | Xml::openElement( 'form', $formOpts ) . "\n" . |
— | — | @@ -386,9 +362,7 @@ |
387 | 363 | self::hiddenField( 'use_regex', $this->use_regex ) |
388 | 364 | ); |
389 | 365 | |
390 | | - $js = file_get_contents( dirname( __FILE__ ) . '/ReplaceText.js' ); |
391 | | - $js = '<script type="text/javascript">' . $js . '</script>'; |
392 | | - $wgOut->addScript( $js ); |
| 366 | + $wgOut->addScriptFile( "$wgScriptPath/extensions/ReplaceText/ReplaceText.js" ); |
393 | 367 | |
394 | 368 | if ( count( $titles_for_edit ) > 0 ) { |
395 | 369 | $wgOut->addWikiMsg( 'replacetext_choosepagesforedit', "<tt><nowiki>{$this->target}</nowiki></tt>", "<tt><nowiki>{$this->replacement}</nowiki></tt>", |
— | — | @@ -398,7 +372,7 @@ |
399 | 373 | list( $title, $context ) = $title_and_context; |
400 | 374 | $wgOut->addHTML( |
401 | 375 | Xml::check( $title->getArticleID(), true ) . |
402 | | - $this->linkToTitle( $skin, $title, $title->getPrefixedText() ) . " - <small>$context</small><br />\n" |
| 376 | + $linker->link( $title ) . " - <small>$context</small><br />\n" |
403 | 377 | ); |
404 | 378 | } |
405 | 379 | $wgOut->addHTML( '<br />' ); |
— | — | @@ -409,7 +383,7 @@ |
410 | 384 | foreach ( $titles_for_move as $title ) { |
411 | 385 | $wgOut->addHTML( |
412 | 386 | Xml::check( 'move-' . $title->getArticleID(), true ) . |
413 | | - $skin->makeLinkObj( $title, htmlspecialchars( $title->getPrefixedText() ) ) . "<br />\n" |
| 387 | + $linker->link( $title ) . "<br />\n" |
414 | 388 | ); |
415 | 389 | } |
416 | 390 | $wgOut->addHTML( '<br />' ); |
— | — | @@ -447,7 +421,7 @@ |
448 | 422 | $wgOut->addWikiMsg( 'replacetext_cannotmove', $wgLang->formatNum( count( $unmoveable_titles ) ) ); |
449 | 423 | $text = "<ul>\n"; |
450 | 424 | foreach ( $unmoveable_titles as $title ) { |
451 | | - $text .= "<li>{$this->linkToTitle( $skin, $title, $title->getPrefixedText() )}<br />\n"; |
| 425 | + $text .= "<li>{$linker->link( $title )}<br />\n"; |
452 | 426 | } |
453 | 427 | $text .= "</ul>\n"; |
454 | 428 | $wgOut->addHTML( $text ); |
— | — | @@ -535,13 +509,8 @@ |
536 | 510 | if ( $use_regex ) { |
537 | 511 | $comparisonCond = 'page_title REGEXP ' . $dbr->addQuotes( $str ); |
538 | 512 | } else { |
539 | | - // anyString() method was added in MW 1.16 |
540 | | - if ( method_exists( $dbr, 'anyString' ) ) { |
541 | | - $any = $dbr->anyString(); |
542 | | - $comparisonCond = 'page_title ' . $dbr->buildLike( $any, $str, $any ); |
543 | | - } else { |
544 | | - $comparisonCond = 'page_title LIKE ' . $dbr->addQuotes( "%$str%" ); |
545 | | - } |
| 513 | + $any = $dbr->anyString(); |
| 514 | + $comparisonCond = 'page_title ' . $dbr->buildLike( $any, $str, $any ); |
546 | 515 | } |
547 | 516 | $conds = array( |
548 | 517 | $comparisonCond, |
— | — | @@ -562,13 +531,8 @@ |
563 | 532 | if ( $use_regex ) { |
564 | 533 | $comparisonCond = 'old_text REGEXP ' . $dbr->addQuotes( $search ); |
565 | 534 | } else { |
566 | | - // anyString() method was added in MW 1.16 |
567 | | - if ( method_exists( $dbr, 'anyString' ) ) { |
568 | | - $any = $dbr->anyString(); |
569 | | - $comparisonCond = 'old_text ' . $dbr->buildLike( $any, $search, $any ); |
570 | | - } else { |
571 | | - $comparisonCond = 'old_text LIKE ' . $dbr->addQuotes( "%$search%" ); |
572 | | - } |
| 535 | + $any = $dbr->anyString(); |
| 536 | + $comparisonCond = 'old_text ' . $dbr->buildLike( $any, $search, $any ); |
573 | 537 | } |
574 | 538 | $conds = array( |
575 | 539 | $comparisonCond, |
— | — | @@ -585,7 +549,7 @@ |
586 | 550 | } |
587 | 551 | |
588 | 552 | protected function categoryCondition( $category, &$tables, &$conds ) { |
589 | | - if ( !empty( $category ) ) { |
| 553 | + if ( strval( $category ) !== '' ) { |
590 | 554 | $category = Title::newFromText( $category )->getDbKey(); |
591 | 555 | $tables[] = 'categorylinks'; |
592 | 556 | $conds[] = 'page_id = cl_from'; |
— | — | @@ -594,17 +558,14 @@ |
595 | 559 | } |
596 | 560 | |
597 | 561 | protected function prefixCondition( $prefix, &$conds ) { |
598 | | - if ( !empty( $prefix ) ) { |
599 | | - $dbr = wfGetDB( DB_SLAVE ); |
600 | | - $prefix = Title::newFromText( $prefix )->getDbKey(); |
601 | | - // anyString() function was added in MW 1.16 |
602 | | - if ( method_exists( $dbr, 'anyString' ) ) { |
603 | | - $any = $dbr->anyString(); |
604 | | - $conds[] = 'page_title ' . $dbr->buildLike( $prefix, $any ); |
605 | | - } else { |
606 | | - $conds[] = "page_title LIKE '$prefix%'"; |
607 | | - } |
| 562 | + if ( strval( $prefix ) === '' ) { |
| 563 | + return; |
608 | 564 | } |
| 565 | + |
| 566 | + $dbr = wfGetDB( DB_SLAVE ); |
| 567 | + $prefix = Title::newFromText( $prefix )->getDbKey(); |
| 568 | + $any = $dbr->anyString(); |
| 569 | + $conds[] = 'page_title ' . $dbr->buildLike( $prefix, $any ); |
609 | 570 | } |
610 | 571 | |
611 | 572 | } |