r50080 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r50079‎ | r50080 | r50081 >
Date:18:55, 30 April 2009
Author:yaron
Status:deferred
Tags:
Comment:
Inputs for strings now textarea, to allow multi-line values; various bug fixes
and improvements
Modified paths:
  • /trunk/extensions/ReplaceText/SpecialReplaceText.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ReplaceText/SpecialReplaceText.php
@@ -25,7 +25,7 @@
2626 $this->doSpecialReplaceText();
2727 }
2828
29 - function displayConfirmForm( $message, $target, $replacement, $edit_pages, $move_pages ) {
 29+ function displayConfirmForm( $message ) {
3030 global $wgOut;
3131
3232 $formOpts = array( 'method' => 'post', 'action' => $this->getTitle()->getFullUrl() );
@@ -33,10 +33,10 @@
3434 $wgOut->addHTML(
3535 Xml::openElement( 'form', $formOpts ) .
3636 Xml::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
37 - Xml::hidden( 'target', $target ) .
38 - Xml::hidden( 'replacement', $replacement ) .
39 - Xml::hidden( 'edit_pages', $edit_pages ) .
40 - Xml::hidden( 'move_pages', $move_pages ) .
 37+ Xml::hidden( 'target', $this->target ) .
 38+ Xml::hidden( 'replacement', $this->replacement ) .
 39+ Xml::hidden( 'edit_pages', $this->edit_pages ) .
 40+ Xml::hidden( 'move_pages', $this->move_pages ) .
4141 Xml::hidden( 'confirm', 1 )
4242 );
4343 $wgOut->wrapWikiMsg( '$1', $message );
@@ -51,22 +51,24 @@
5252 function doSpecialReplaceText() {
5353 global $wgUser, $wgOut, $wgRequest, $wgLang;
5454
55 - $target = $wgRequest->getText( 'target' );
56 - $replacement = $wgRequest->getText( 'replacement' );
 55+ $this->target = $wgRequest->getText( 'target' );
 56+ $this->replacement = $wgRequest->getText( 'replacement' );
 57+ $this->edit_pages = $wgRequest->getCheck( 'edit_pages' );
 58+ $this->move_pages = $wgRequest->getCheck( 'move_pages' );
5759
58 - if ( $target === '' ) {
59 - if ( !$wgRequest->wasPosted() ) $this->showForm( 'replacetext_docu' );
60 - else $this->showForm( 'replacetext_givetarget' );
61 - return;
 60+ if ( $wgRequest->getCheck( 'continue' ) ) {
 61+ if ( $this->target === '' ) {
 62+ $this->showForm( 'replacetext_givetarget' );
 63+ return;
 64+ }
6265 }
6366
64 -
6567 if ( $wgRequest->getCheck( 'replace' ) ) {
6668 $replacement_params = array();
6769 $replacement_params['user_id'] = $wgUser->getId();
68 - $replacement_params['target_str'] = $target;
69 - $replacement_params['replacement_str'] = $replacement;
70 - $replacement_params['edit_summary'] = wfMsgForContent( 'replacetext_editsummary', $target, $replacement );
 70+ $replacement_params['target_str'] = $this->target;
 71+ $replacement_params['replacement_str'] = $this->replacement;
 72+ $replacement_params['edit_summary'] = wfMsgForContent( 'replacetext_editsummary', $this->target, $this->replacement );
7173 $replacement_params['create_redirect'] = false;
7274 $replacement_params['watch_page'] = false;
7375 foreach ( $wgRequest->getValues() as $key => $value ) {
@@ -92,7 +94,7 @@
9395 Job::batchInsert( $jobs );
9496
9597 $count = $wgLang->formatNum( count( $jobs ) );
96 - $wgOut->addWikiMsg( 'replacetext_success', $target, $replacement, $count );
 98+ $wgOut->addWikiMsg( 'replacetext_success', $this->target, $this->replacement, $count );
9799
98100 // Link back
99101 $sk = $this->user->getSkin();
@@ -101,9 +103,7 @@
102104
103105 // first, check that either editing or moving pages
104106 // has been selected
105 - $edit_pages = $wgRequest->getCheck( 'edit_pages' );
106 - $move_pages = $wgRequest->getCheck( 'move_pages' );
107 - if ( ! $edit_pages && ! $move_pages ) {
 107+ if ( ! $this->edit_pages && ! $this->move_pages ) {
108108 $this->showForm( 'replacetext_editormove' );
109109 return;
110110 }
@@ -122,43 +122,43 @@
123123
124124 $message = false;
125125
126 - if ( $replacement === '' ) {
 126+ if ( $this->replacement === '' ) {
127127 $message = 'replacetext_blankwarning';
128 - } elseif ( $edit_pages ) {
129 - $res = $this->doSearchQuery( $replacement );
 128+ } elseif ( $this->edit_pages ) {
 129+ $res = $this->doSearchQuery( $this->replacement );
130130 $count = $res->numRows();
131131 if ( $count > 0 ) {
132 - $message = array( 'replacetext_warning', $wgLang->formatNum( $count ), $replacement );
 132+ $message = array( 'replacetext_warning', $wgLang->formatNum( $count ), $this->replacement );
133133 }
134 - } elseif ( $move_pages ) {
135 - $res = $this->getMoveTitles( $target );
 134+ } elseif ( $this->move_pages ) {
 135+ $res = $this->getMatchingTitles( $this->replacement );
136136 $count = $res->numRows();
137137 if ( $count > 0 ) {
138 - $message = array( 'replacetext_warning', $wgLang->formatNum( $count ), $replacement );
 138+ $message = array( 'replacetext_warning', $wgLang->formatNum( $count ), $this->replacement );
139139 }
140140 }
141141
142142 if ( $message ) {
143 - $this->displayConfirmForm( $message, $target, $replacement, $edit_pages, $move_pages );
 143+ $this->displayConfirmForm( $message );
144144 return;
145145 }
146146 }
147147
148148 // if user is replacing text within pages...
149 - if ( $edit_pages ) {
150 - $res = $this->doSearchQuery( $target );
 149+ if ( $this->edit_pages ) {
 150+ $res = $this->doSearchQuery( $this->target );
151151 foreach ( $res as $row ) {
152152 $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
153 - $context = $this->extractContext( $row->old_text, $target );
 153+ $context = $this->extractContext( $row->old_text, $this->target );
154154 $titles_for_edit[] = array( $title, $context );
155155 }
156156 }
157 - if ( $move_pages ) {
158 - $res = $this->getMoveTitles( $target );
 157+ if ( $this->move_pages ) {
 158+ $res = $this->getMatchingTitles( $this->target );
159159 foreach ( $res as $row ) {
160160 $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
161161 // see if this move can happen
162 - $new_title = Title::makeTitleSafe( $row->page_namespace, str_replace( $target, $replacement, $row->page_title ) );
 162+ $new_title = Title::makeTitleSafe( $row->page_namespace, str_replace( $this->target, $this->replacement, $row->page_title ) );
163163 $err = $title->isValidMoveOperation( $new_title );
164164 if ( $title->userCanMove( true ) && !is_array( $err ) ) {
165165 $titles_for_move[] = $title;
@@ -168,35 +168,42 @@
169169 }
170170 }
171171 if ( count($titles_for_edit) == 0 && count($titles_for_move) == 0 ) {
172 - if ( $edit_pages )
173 - $wgOut->addWikiMsg( 'replacetext_noreplacement', $target );
174 - if ( $move_pages )
175 - $wgOut->addWikiMsg( 'replacetext_nomove', $target );
 172+ if ( $this->edit_pages )
 173+ $wgOut->addWikiMsg( 'replacetext_noreplacement', $this->target );
 174+ if ( $this->move_pages )
 175+ $wgOut->addWikiMsg( 'replacetext_nomove', $this->target );
176176 // link back to starting form
177177 $sk = $this->user->getSkin();
178178 $wgOut->addHTML( '<p>' . $sk->makeKnownLinkObj( $this->getTitle(), wfMsg( 'replacetext_return' ) ) . '</p>' );
179179 } else {
180 - $this->pageListForm( $target, $replacement, $titles_for_edit, $titles_for_move, $unmoveable_titles );
 180+ $this->pageListForm( $titles_for_edit, $titles_for_move, $unmoveable_titles );
181181 }
 182+ return;
182183 }
 184+
 185+ // if we're still here, show the starting form
 186+ $this->showForm( 'replacetext_docu' );
183187 }
184188
185189 function showForm( $message ) {
186190 global $wgOut;
187191 $wgOut->addHTML(
188192 Xml::openElement( 'form', array( 'action' => $this->getTitle()->getFullUrl(), 'method' => 'post' ) ) .
189 - Xml::hidden( 'title', $this->getTitle()->getPrefixedText() )
 193+ Xml::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
 194+ Xml::hidden( 'continue', 1 )
190195 );
191196 $wgOut->addWikiMsg( $message );
192197 $wgOut->addWikiMsg( 'replacetext_note' );
193 - $wgOut->addHTML( '<table><tr><td>' );
 198+ $wgOut->addHTML( '<table><tr><td style="vertical-align: top;">' );
194199 $wgOut->addWikiMsg( 'replacetext_originaltext' );
195200 $wgOut->addHTML( '</td><td>' );
196 - $wgOut->addHTML( Xml::input( 'target', 10 ) );
197 - $wgOut->addHTML( '</td></tr><tr><td>' );
 201+ $wgOut->addHTML( Xml::textarea( 'target', $this->target, 50, 2 ) );
 202+ $wgOut->addHTML( Xml::closeElement( 'textarea' ) );
 203+ $wgOut->addHTML( '</td></tr><tr><td style="vertical-align: top;">' );
198204 $wgOut->addWikiMsg( 'replacetext_replacementtext' );
199205 $wgOut->addHTML( '</td><td>' );
200 - $wgOut->addHTML( Xml::input( 'replacement', 10 ) );
 206+ $wgOut->addHTML( Xml::textarea( 'replacement', $this->replacement, 50, 2 ) );
 207+ $wgOut->addHTML( Xml::closeElement( 'textarea' ) );
201208 $wgOut->addHTML( '</td></tr></table>' );
202209 $wgOut->addHTML(
203210 Xml::checkLabel( wfMsg( 'replacetext_editpages' ), 'edit_pages', 'edit_pages', true ) . '<br />' .
@@ -206,7 +213,7 @@
207214 );
208215 }
209216
210 - function pageListForm( $target, $replacement, $titles_for_edit, $titles_for_move, $unmoveable_titles ) {
 217+ function pageListForm( $titles_for_edit, $titles_for_move, $unmoveable_titles ) {
211218 global $wgOut, $wgLang, $wgScript;
212219
213220 $skin = $this->user->getSkin();
@@ -215,16 +222,16 @@
216223 $wgOut->addHTML(
217224 Xml::openElement( 'form', $formOpts ) .
218225 Xml::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
219 - Xml::hidden( 'target', $target ) .
220 - Xml::hidden( 'replacement', $replacement )
 226+ Xml::hidden( 'target', $this->target ) .
 227+ Xml::hidden( 'replacement', $this->replacement )
221228 );
222229
 230+ $js = file_get_contents( dirname( __FILE__ ) . '/ReplaceText.js' );
 231+ $js = '<script type="text/javascript">' . $js . '</script>';
 232+ $wgOut->addScript( $js );
 233+
223234 if ( count( $titles_for_edit ) > 0 ) {
224 - $js = file_get_contents( dirname( __FILE__ ) . '/ReplaceText.js' );
225 - $js = '<script type="text/javascript">' . $js . '</script>';
226 - $wgOut->addScript( $js );
227 -
228 - $wgOut->addWikiMsg( 'replacetext_choosepagesforedit', $target, $replacement,
 235+ $wgOut->addWikiMsg( 'replacetext_choosepagesforedit', $this->target, $this->replacement,
229236 $wgLang->formatNum( count( $titles_for_edit ) ) );
230237
231238 foreach ( $titles_for_edit as $title_and_context ) {
@@ -238,7 +245,7 @@
239246 }
240247
241248 if ( count( $titles_for_move ) > 0 ) {
242 - $wgOut->addWikiMsg( 'replacetext_choosepagesformove', $target, $replacement, $wgLang->formatNum( count( $titles_for_move ) ) );
 249+ $wgOut->addWikiMsg( 'replacetext_choosepagesformove', $this->target, $this->replacement, $wgLang->formatNum( count( $titles_for_move ) ) );
243250 foreach ( $titles_for_move as $title ) {
244251 $wgOut->addHTML(
245252 Xml::check( 'move-' . $title->getArticleID(), true ) .
@@ -342,17 +349,17 @@
343350 return $msg;
344351 }
345352
346 - function getMoveTitles( $target ) {
347 - $title = Title::newFromText( $target );
 353+ function getMatchingTitles( $str) {
 354+ $title = Title::newFromText( $str );
348355 if ( !$title ) return array();
349356
350357 $dbr = wfGetDB( DB_SLAVE );
351 - $target = $dbr->escapeLike( $title->getDbKey() );
 358+ $sql_str = $dbr->escapeLike( $title->getDbKey() );
352359
353360 return $dbr->select(
354361 'page',
355362 array( 'page_title', 'page_namespace' ),
356 - "page_title like '%$target%'",
 363+ "page_title like '%$sql_str%'",
357364 __METHOD__,
358365 array( 'ORDER BY' => 'page_namespace, page_title' )
359366 );

Status & tagging log