r107767 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107766‎ | r107767 | r107768 >
Date:08:54, 1 January 2012
Author:nikerabbit
Status:deferred
Tags:
Comment:
Stuff older than 1.16 not supported anymore
Modified paths:
  • /trunk/extensions/ReplaceText/SpecialReplaceText.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ReplaceText/SpecialReplaceText.php
@@ -2,31 +2,21 @@
33
44 class ReplaceText extends SpecialPage {
55
6 - /**
7 - * Constructor
8 - */
96 public function __construct() {
10 - global $wgVersion;
117 parent::__construct( 'ReplaceText', 'replacetext' );
12 - if ( version_compare( $wgVersion, '1.16', '<' ) ) {
13 - wfLoadExtensionMessages( 'ReplaceText' );
14 - }
158 }
169
1710 function execute( $query ) {
1811 global $wgUser, $wgOut;
1912
20 - if ( ! $wgUser->isAllowed( 'replacetext' ) ) {
 13+ if ( !$wgUser->isAllowed( 'replacetext' ) ) {
2114 $wgOut->permissionRequired( 'replacetext' );
2215 return;
2316 }
2417
2518 $this->user = $wgUser;
2619 $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' );
3121 $this->doSpecialReplaceText();
3222 }
3323
@@ -43,18 +33,6 @@
4434 }
4535
4636 /**
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 - /**
5937 * Helper function to display a hidden field for different versions
6038 * of MediaWiki.
6139 */
@@ -67,7 +45,8 @@
6846 }
6947
7048 function doSpecialReplaceText() {
71 - global $wgUser, $wgOut, $wgRequest, $wgLang;
 49+ global $wgOut, $wgRequest, $wgLang;
 50+ $linker = class_exists( 'DummyLinker' ) ? new DummyLinker : new Linker;
7251
7352 $this->target = $wgRequest->getText( 'target' );
7453 $this->replacement = $wgRequest->getText( 'replacement' );
@@ -87,7 +66,7 @@
8867
8968 if ( $wgRequest->getCheck( 'replace' ) ) {
9069 $replacement_params = array();
91 - $replacement_params['user_id'] = $wgUser->getId();
 70+ $replacement_params['user_id'] = $this->user->getId();
9271 $replacement_params['target_str'] = $this->target;
9372 $replacement_params['replacement_str'] = $this->replacement;
9473 $replacement_params['use_regex'] = $this->use_regex;
@@ -120,8 +99,7 @@
121100 $wgOut->addWikiMsg( 'replacetext_success', "<tt><nowiki>{$this->target}</nowiki></tt>", "<tt><nowiki>{$this->replacement}</nowiki></tt>", $count );
122101
123102 // 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' ) ) );
126104 return;
127105 } elseif ( $wgRequest->getCheck( 'target' ) ) { // very long elseif, look for "end elseif"
128106 // first, check that at least one namespace has been
@@ -173,15 +151,14 @@
174152 // if no results were found, check to see if a bad
175153 // category name was entered
176154 if ( count( $titles_for_edit ) == 0 && count( $titles_for_move ) == 0 ) {
177 - $sk = $this->user->getSkin();
178155 $bad_cat_name = false;
179156 if ( ! empty( $this->category ) ) {
180157 $category_title = Title::makeTitleSafe( NS_CATEGORY, $this->category );
181158 if ( ! $category_title->exists() ) $bad_cat_name = true;
182159 }
183160 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 ) );
186163 } else {
187164 if ( $this->edit_pages )
188165 $wgOut->addWikiMsg( 'replacetext_noreplacement', "<tt><nowiki>{$this->target}</nowiki></tt>" );
@@ -190,7 +167,7 @@
191168 }
192169 // link back to starting form
193170 //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>' );
195172 } else {
196173 // Show a warning message if the replacement
197174 // string is either blank or found elsewhere on
@@ -373,10 +350,9 @@
374351 }
375352
376353 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;
378356
379 - $skin = $this->user->getSkin();
380 -
381357 $formOpts = array( 'id' => 'choose_pages', 'method' => 'post', 'action' => $this->getTitle()->getFullUrl() );
382358 $wgOut->addHTML(
383359 Xml::openElement( 'form', $formOpts ) . "\n" .
@@ -386,9 +362,7 @@
387363 self::hiddenField( 'use_regex', $this->use_regex )
388364 );
389365
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" );
393367
394368 if ( count( $titles_for_edit ) > 0 ) {
395369 $wgOut->addWikiMsg( 'replacetext_choosepagesforedit', "<tt><nowiki>{$this->target}</nowiki></tt>", "<tt><nowiki>{$this->replacement}</nowiki></tt>",
@@ -398,7 +372,7 @@
399373 list( $title, $context ) = $title_and_context;
400374 $wgOut->addHTML(
401375 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"
403377 );
404378 }
405379 $wgOut->addHTML( '<br />' );
@@ -409,7 +383,7 @@
410384 foreach ( $titles_for_move as $title ) {
411385 $wgOut->addHTML(
412386 Xml::check( 'move-' . $title->getArticleID(), true ) .
413 - $skin->makeLinkObj( $title, htmlspecialchars( $title->getPrefixedText() ) ) . "<br />\n"
 387+ $linker->link( $title ) . "<br />\n"
414388 );
415389 }
416390 $wgOut->addHTML( '<br />' );
@@ -447,7 +421,7 @@
448422 $wgOut->addWikiMsg( 'replacetext_cannotmove', $wgLang->formatNum( count( $unmoveable_titles ) ) );
449423 $text = "<ul>\n";
450424 foreach ( $unmoveable_titles as $title ) {
451 - $text .= "<li>{$this->linkToTitle( $skin, $title, $title->getPrefixedText() )}<br />\n";
 425+ $text .= "<li>{$linker->link( $title )}<br />\n";
452426 }
453427 $text .= "</ul>\n";
454428 $wgOut->addHTML( $text );
@@ -535,13 +509,8 @@
536510 if ( $use_regex ) {
537511 $comparisonCond = 'page_title REGEXP ' . $dbr->addQuotes( $str );
538512 } 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 );
546515 }
547516 $conds = array(
548517 $comparisonCond,
@@ -562,13 +531,8 @@
563532 if ( $use_regex ) {
564533 $comparisonCond = 'old_text REGEXP ' . $dbr->addQuotes( $search );
565534 } 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 );
573537 }
574538 $conds = array(
575539 $comparisonCond,
@@ -585,7 +549,7 @@
586550 }
587551
588552 protected function categoryCondition( $category, &$tables, &$conds ) {
589 - if ( !empty( $category ) ) {
 553+ if ( strval( $category ) !== '' ) {
590554 $category = Title::newFromText( $category )->getDbKey();
591555 $tables[] = 'categorylinks';
592556 $conds[] = 'page_id = cl_from';
@@ -594,17 +558,14 @@
595559 }
596560
597561 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;
608564 }
 565+
 566+ $dbr = wfGetDB( DB_SLAVE );
 567+ $prefix = Title::newFromText( $prefix )->getDbKey();
 568+ $any = $dbr->anyString();
 569+ $conds[] = 'page_title ' . $dbr->buildLike( $prefix, $any );
609570 }
610571
611572 }

Sign-offs

UserFlagDate
Santhosh.thottingalinspected07:16, 3 January 2012

Follow-up revisions

RevisionCommit summaryAuthorDate
r107884Follow-up to r107766 and r107767 - those two revisions accidentally removed c...yaron13:36, 3 January 2012

Status & tagging log