Index: trunk/extensions/ReplaceText/SpecialReplaceText.php |
— | — | @@ -25,7 +25,7 @@ |
26 | 26 | $this->doSpecialReplaceText(); |
27 | 27 | } |
28 | 28 | |
29 | | - function displayConfirmForm( $message, $target, $replacement, $edit_pages, $move_pages ) { |
| 29 | + function displayConfirmForm( $message ) { |
30 | 30 | global $wgOut; |
31 | 31 | |
32 | 32 | $formOpts = array( 'method' => 'post', 'action' => $this->getTitle()->getFullUrl() ); |
— | — | @@ -33,10 +33,10 @@ |
34 | 34 | $wgOut->addHTML( |
35 | 35 | Xml::openElement( 'form', $formOpts ) . |
36 | 36 | 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 ) . |
41 | 41 | Xml::hidden( 'confirm', 1 ) |
42 | 42 | ); |
43 | 43 | $wgOut->wrapWikiMsg( '$1', $message ); |
— | — | @@ -51,22 +51,24 @@ |
52 | 52 | function doSpecialReplaceText() { |
53 | 53 | global $wgUser, $wgOut, $wgRequest, $wgLang; |
54 | 54 | |
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' ); |
57 | 59 | |
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 | + } |
62 | 65 | } |
63 | 66 | |
64 | | - |
65 | 67 | if ( $wgRequest->getCheck( 'replace' ) ) { |
66 | 68 | $replacement_params = array(); |
67 | 69 | $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 ); |
71 | 73 | $replacement_params['create_redirect'] = false; |
72 | 74 | $replacement_params['watch_page'] = false; |
73 | 75 | foreach ( $wgRequest->getValues() as $key => $value ) { |
— | — | @@ -92,7 +94,7 @@ |
93 | 95 | Job::batchInsert( $jobs ); |
94 | 96 | |
95 | 97 | $count = $wgLang->formatNum( count( $jobs ) ); |
96 | | - $wgOut->addWikiMsg( 'replacetext_success', $target, $replacement, $count ); |
| 98 | + $wgOut->addWikiMsg( 'replacetext_success', $this->target, $this->replacement, $count ); |
97 | 99 | |
98 | 100 | // Link back |
99 | 101 | $sk = $this->user->getSkin(); |
— | — | @@ -101,9 +103,7 @@ |
102 | 104 | |
103 | 105 | // first, check that either editing or moving pages |
104 | 106 | // 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 ) { |
108 | 108 | $this->showForm( 'replacetext_editormove' ); |
109 | 109 | return; |
110 | 110 | } |
— | — | @@ -122,43 +122,43 @@ |
123 | 123 | |
124 | 124 | $message = false; |
125 | 125 | |
126 | | - if ( $replacement === '' ) { |
| 126 | + if ( $this->replacement === '' ) { |
127 | 127 | $message = 'replacetext_blankwarning'; |
128 | | - } elseif ( $edit_pages ) { |
129 | | - $res = $this->doSearchQuery( $replacement ); |
| 128 | + } elseif ( $this->edit_pages ) { |
| 129 | + $res = $this->doSearchQuery( $this->replacement ); |
130 | 130 | $count = $res->numRows(); |
131 | 131 | if ( $count > 0 ) { |
132 | | - $message = array( 'replacetext_warning', $wgLang->formatNum( $count ), $replacement ); |
| 132 | + $message = array( 'replacetext_warning', $wgLang->formatNum( $count ), $this->replacement ); |
133 | 133 | } |
134 | | - } elseif ( $move_pages ) { |
135 | | - $res = $this->getMoveTitles( $target ); |
| 134 | + } elseif ( $this->move_pages ) { |
| 135 | + $res = $this->getMatchingTitles( $this->replacement ); |
136 | 136 | $count = $res->numRows(); |
137 | 137 | if ( $count > 0 ) { |
138 | | - $message = array( 'replacetext_warning', $wgLang->formatNum( $count ), $replacement ); |
| 138 | + $message = array( 'replacetext_warning', $wgLang->formatNum( $count ), $this->replacement ); |
139 | 139 | } |
140 | 140 | } |
141 | 141 | |
142 | 142 | if ( $message ) { |
143 | | - $this->displayConfirmForm( $message, $target, $replacement, $edit_pages, $move_pages ); |
| 143 | + $this->displayConfirmForm( $message ); |
144 | 144 | return; |
145 | 145 | } |
146 | 146 | } |
147 | 147 | |
148 | 148 | // 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 ); |
151 | 151 | foreach ( $res as $row ) { |
152 | 152 | $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 ); |
154 | 154 | $titles_for_edit[] = array( $title, $context ); |
155 | 155 | } |
156 | 156 | } |
157 | | - if ( $move_pages ) { |
158 | | - $res = $this->getMoveTitles( $target ); |
| 157 | + if ( $this->move_pages ) { |
| 158 | + $res = $this->getMatchingTitles( $this->target ); |
159 | 159 | foreach ( $res as $row ) { |
160 | 160 | $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title ); |
161 | 161 | // 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 ) ); |
163 | 163 | $err = $title->isValidMoveOperation( $new_title ); |
164 | 164 | if ( $title->userCanMove( true ) && !is_array( $err ) ) { |
165 | 165 | $titles_for_move[] = $title; |
— | — | @@ -168,35 +168,42 @@ |
169 | 169 | } |
170 | 170 | } |
171 | 171 | 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 ); |
176 | 176 | // link back to starting form |
177 | 177 | $sk = $this->user->getSkin(); |
178 | 178 | $wgOut->addHTML( '<p>' . $sk->makeKnownLinkObj( $this->getTitle(), wfMsg( 'replacetext_return' ) ) . '</p>' ); |
179 | 179 | } 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 ); |
181 | 181 | } |
| 182 | + return; |
182 | 183 | } |
| 184 | + |
| 185 | + // if we're still here, show the starting form |
| 186 | + $this->showForm( 'replacetext_docu' ); |
183 | 187 | } |
184 | 188 | |
185 | 189 | function showForm( $message ) { |
186 | 190 | global $wgOut; |
187 | 191 | $wgOut->addHTML( |
188 | 192 | 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 ) |
190 | 195 | ); |
191 | 196 | $wgOut->addWikiMsg( $message ); |
192 | 197 | $wgOut->addWikiMsg( 'replacetext_note' ); |
193 | | - $wgOut->addHTML( '<table><tr><td>' ); |
| 198 | + $wgOut->addHTML( '<table><tr><td style="vertical-align: top;">' ); |
194 | 199 | $wgOut->addWikiMsg( 'replacetext_originaltext' ); |
195 | 200 | $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;">' ); |
198 | 204 | $wgOut->addWikiMsg( 'replacetext_replacementtext' ); |
199 | 205 | $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' ) ); |
201 | 208 | $wgOut->addHTML( '</td></tr></table>' ); |
202 | 209 | $wgOut->addHTML( |
203 | 210 | Xml::checkLabel( wfMsg( 'replacetext_editpages' ), 'edit_pages', 'edit_pages', true ) . '<br />' . |
— | — | @@ -206,7 +213,7 @@ |
207 | 214 | ); |
208 | 215 | } |
209 | 216 | |
210 | | - function pageListForm( $target, $replacement, $titles_for_edit, $titles_for_move, $unmoveable_titles ) { |
| 217 | + function pageListForm( $titles_for_edit, $titles_for_move, $unmoveable_titles ) { |
211 | 218 | global $wgOut, $wgLang, $wgScript; |
212 | 219 | |
213 | 220 | $skin = $this->user->getSkin(); |
— | — | @@ -215,16 +222,16 @@ |
216 | 223 | $wgOut->addHTML( |
217 | 224 | Xml::openElement( 'form', $formOpts ) . |
218 | 225 | 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 ) |
221 | 228 | ); |
222 | 229 | |
| 230 | + $js = file_get_contents( dirname( __FILE__ ) . '/ReplaceText.js' ); |
| 231 | + $js = '<script type="text/javascript">' . $js . '</script>'; |
| 232 | + $wgOut->addScript( $js ); |
| 233 | + |
223 | 234 | 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, |
229 | 236 | $wgLang->formatNum( count( $titles_for_edit ) ) ); |
230 | 237 | |
231 | 238 | foreach ( $titles_for_edit as $title_and_context ) { |
— | — | @@ -238,7 +245,7 @@ |
239 | 246 | } |
240 | 247 | |
241 | 248 | 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 ) ) ); |
243 | 250 | foreach ( $titles_for_move as $title ) { |
244 | 251 | $wgOut->addHTML( |
245 | 252 | Xml::check( 'move-' . $title->getArticleID(), true ) . |
— | — | @@ -342,17 +349,17 @@ |
343 | 350 | return $msg; |
344 | 351 | } |
345 | 352 | |
346 | | - function getMoveTitles( $target ) { |
347 | | - $title = Title::newFromText( $target ); |
| 353 | + function getMatchingTitles( $str) { |
| 354 | + $title = Title::newFromText( $str ); |
348 | 355 | if ( !$title ) return array(); |
349 | 356 | |
350 | 357 | $dbr = wfGetDB( DB_SLAVE ); |
351 | | - $target = $dbr->escapeLike( $title->getDbKey() ); |
| 358 | + $sql_str = $dbr->escapeLike( $title->getDbKey() ); |
352 | 359 | |
353 | 360 | return $dbr->select( |
354 | 361 | 'page', |
355 | 362 | array( 'page_title', 'page_namespace' ), |
356 | | - "page_title like '%$target%'", |
| 363 | + "page_title like '%$sql_str%'", |
357 | 364 | __METHOD__, |
358 | 365 | array( 'ORDER BY' => 'page_namespace, page_title' ) |
359 | 366 | ); |