r111779 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111778‎ | r111779 | r111780 >
Date:19:49, 17 February 2012
Author:yaron
Status:deferred
Tags:
Comment:
Added support for regexps with PostgreSQL - patch from Thomas Werner
Modified paths:
  • /trunk/extensions/ReplaceText/SpecialReplaceText.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ReplaceText/SpecialReplaceText.php
@@ -16,7 +16,7 @@
1717
1818 $this->user = $wgUser;
1919 $this->setHeaders();
20 - if ( method_exists( $wgOut, 'addModuleStyles' ) &&
 20+ if ( method_exists( $wgOut, 'addModuleStyles' ) &&
2121 !is_null( $wgOut->getResourceLoader()->getModule( 'mediawiki.special' ) ) ) {
2222 $wgOut->addModuleStyles( 'mediawiki.special' );
2323 }
@@ -85,7 +85,7 @@
8686 }
8787 $jobs = array();
8888 foreach ( $wgRequest->getValues() as $key => $value ) {
89 - if ( $value == '1' && $key !== 'replace' ) {
 89+ if ( $value == '1' && $key !== 'replace' && $key !== 'use_regex' ) {
9090 if ( strpos( $key, 'move-' ) !== false ) {
9191 $title = Title::newFromID( substr( $key, 5 ) );
9292 $replacement_params['move_page'] = true;
@@ -516,7 +516,7 @@
517517
518518 $str = str_replace( ' ', '_', $str );
519519 if ( $use_regex ) {
520 - $comparisonCond = 'page_title REGEXP ' . $dbr->addQuotes( $str );
 520+ $comparisonCond = $this->regexCond( $dbr, 'page_title', $str );
521521 } else {
522522 $any = $dbr->anyString();
523523 $comparisonCond = 'page_title ' . $dbr->buildLike( $any, $str, $any );
@@ -538,7 +538,7 @@
539539 $tables = array( 'page', 'revision', 'text' );
540540 $vars = array( 'page_id', 'page_namespace', 'page_title', 'old_text' );
541541 if ( $use_regex ) {
542 - $comparisonCond = 'old_text REGEXP ' . $dbr->addQuotes( $search );
 542+ $comparisonCond = $this->regexCond( $dbr, 'old_text', $search );
543543 } else {
544544 $any = $dbr->anyString();
545545 $comparisonCond = 'old_text ' . $dbr->buildLike( $any, $search, $any );
@@ -580,4 +580,12 @@
581581 $conds[] = 'page_title ' . $dbr->buildLike( $prefix, $any );
582582 }
583583
 584+ private function regexCond( $dbr, $column, $regex ) {
 585+ if ( $dbr instanceof DatabasePostgres ) {
 586+ $op = '~';
 587+ } else {
 588+ $op = 'REGEXP';
 589+ }
 590+ return "$column $op " . $dbr->addQuotes( $regex );
 591+ }
584592 }

Sign-offs

UserFlagDate
Nikerabbitinspected21:19, 17 February 2012
Awjrichardsinspected21:46, 17 February 2012

Status & tagging log