Malvineous has uploaded a new change for review.
https://gerrit.wikimedia.org/r/189179
Change subject: Fix formatting and restore some behaviour lost
......................................................................
Fix formatting and restore some behaviour lost
Change-Id: I269af2bf243a1f196b77b719f237db714f6cf41c
---
M MassEditRegex.api.php
M MassEditRegex.class.php
M MassEditRegex.i18n.php
M MassEditRegex.js
M MassEditRegex.php
M MassEditRegex.special.php
6 files changed, 345 insertions(+), 329 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MassEditRegex
refs/changes/79/189179/1
diff --git a/MassEditRegex.api.php b/MassEditRegex.api.php
index cf10f9e..a57507a 100644
--- a/MassEditRegex.api.php
+++ b/MassEditRegex.api.php
@@ -1,33 +1,33 @@
<?php
class MassEditRegexAPI {
- public static function edit($pageid,$search,$replace,$summary){
- $massEditRegex = new MassEditRegex($search,$replace,$summary);
+ public static function edit( $pageid, $search, $replace, $summary ) {
+ $massEditRegex = new MassEditRegex( $search, $replace, $summary
);
$user = User::newFromSession();
// Check permissions
if ( !$user->isAllowed( 'masseditregex' ) ) {
- return json_encode(array(
+ return json_encode( array(
'error' =>
mfMessage('masseditregex-noaccess')->text()
- ));
+ ) );
}
// Show a message if the database is in read-only mode
if ( wfReadOnly() ) {
- return json_encode(array(
+ return json_encode( array(
'error' =>
mfMessage('masseditregex-readonlydb')->text()
- ));
+ ) );
}
// If user is blocked, s/he doesn't need to access this page
if ( $user->isBlocked() ) {
- return json_encode(array(
+ return json_encode( array(
'error' =>
mfMessage('masseditregex-blocked')->text()
- ));
+ ) );
}
return json_encode(array(
'changes' =>
$massEditRegex->editPage(Title::newFromID($pageid))
- ));
+ ) );
}
}
\ No newline at end of file
diff --git a/MassEditRegex.class.php b/MassEditRegex.class.php
index b58b776..2e2d4a4 100644
--- a/MassEditRegex.class.php
+++ b/MassEditRegex.class.php
@@ -33,10 +33,10 @@
* @param User $user
*/
function __construct( $search, $replace, $summary, \User $user = null )
{
- $this->setReplace($replace);
- $this->setSearch($search);
- $this->setSummary($summary);
- $this->setUser($user);
+ $this->setReplace( $replace );
+ $this->setSearch( $search );
+ $this->setSummary( $summary );
+ $this->setUser( $user );
$this->diffEngine = new DifferenceEngine();
}
@@ -49,12 +49,12 @@
*
* @return number of changes performed on given title
*/
- public function editPage(\Title $title) {
- $article = new Article($title);
- $rev = $this->getRevision($title);
- $content = $this->getContent($rev);
+ public function editPage( \Title $title ) {
+ $article = new Article( $title );
+ $rev = $this->getRevision( $title );
+ $content = $this->getContent( $rev );
$curText = $content->getNativeData();
- list($newText,$changes) = $this->replaceText($curText);
+ list( $newText, $changes ) = $this->replaceText( $curText );
if ( strcmp( $curText, $newText ) != 0 ) {
$newContent = new WikitextContent( $newText );
@@ -74,11 +74,11 @@
*
* @return string html diff
*/
- public function previewPage(\Title $title) {
- $rev = $this->getRevision($title);
- $content = $this->getContent($rev);
+ public function previewPage( \Title $title ) {
+ $rev = $this->getRevision( $title );
+ $content = $this->getContent( $rev );
$curText = $content->getNativeData();
- list($newText) = $this->replaceText($curText);
+ list( $newText ) = $this->replaceText( $curText );
$this->diffEngine->setText( $curText, $newText );
@@ -89,6 +89,8 @@
}
/**
+ * Main regex transform function.
+ *
* @param $input
* @return mixed
* @throws UsageException
@@ -97,21 +99,24 @@
$changes = $iCount = 0;
foreach ( $this->search as $i => $strMatch ) {
$strNextReplace = $this->replace[ $i ];
- $result = @preg_replace_callback($strMatch, function (
$aMatches ) use ( $strNextReplace ) {
+ $result = @preg_replace_callback($strMatch,
+ function ( $aMatches ) use ( $strNextReplace ) {
foreach ( $aMatches as $i => $strMatch
) {
$aFind[ ] = '$' . $i;
$aReplace[ ] = $strMatch;
}
- return str_replace($aFind, $aReplace,
$strNextReplace);
- }, $input, -1, $iCount);
+ return str_replace( $aFind, $aReplace,
$strNextReplace );
+ }, $input, -1, $iCount );
$changes += $iCount;
- if( $result !== null ) {
+ if ( $result !== null ) {
$input = $result;
} else {
- throw new UsageException( wfMessage(
'masseditregex-badregex' )->text() . ' <b>' . htmlspecialchars($strMatch) .
'</b>', 'masseditregex-badregex' );
+ throw new UsageException( wfMessage(
'masseditregex-badregex' )->text()
+ . ' <b>' . htmlspecialchars( $strMatch
) . '</b>',
+ 'masseditregex-badregex' );
}
}
- return array($input,$changes);
+ return array( $input, $changes );
}
/**
@@ -120,8 +125,8 @@
* @throws BadTitleError
*/
private function getRevision( \Title $title ) {
- $rev = Revision::newFromTitle($title, 0, Revision::READ_LATEST);
- if( !$rev ) {
+ $rev = Revision::newFromTitle( $title, 0, Revision::READ_LATEST
);
+ if ( !$rev ) {
throw new \BadTitleError(
wfMessage('masseditregex-norevisions') );
}
return $rev;
@@ -134,9 +139,9 @@
*/
private function getContent( $rev ) {
- $content = $rev->getContent(Revision::FOR_THIS_USER,
$this->user);
- if( !$content ) {
- throw new
\PermissionsError(wfMessage('masseditregex-noaccess')->text());
+ $content = $rev->getContent( Revision::FOR_THIS_USER,
$this->user );
+ if ( !$content ) {
+ throw new \PermissionsError(
wfMessage('masseditregex-noaccess' )->text());
}
return $content;
}
@@ -187,18 +192,17 @@
* @param \User $user
*/
public function setUser( $user = null ) {
- if(is_null($user)){
+ if ( is_null( $user ) ){
$user = User::newFromSession();
}
$this->user = $user;
}
-
/**
* @param string $replace
*/
public function setReplace( $replace ) {
- $replace = explode("\n",$replace);
+ $replace = explode( "\n", $replace );
foreach ( $replace as &$str ) {
// Convert \n into a newline, \\n into \n, \\\n into
\<newline>, etc.
@@ -219,7 +223,7 @@
* @param string $search
*/
public function setSearch( $search ) {
- $this->search = explode("\n",trim($search));
+ $this->search = explode( "\n", trim( $search ) );
}
/**
@@ -228,5 +232,4 @@
public function setSummary( $summary ) {
$this->summary = $summary;
}
-
}
diff --git a/MassEditRegex.i18n.php b/MassEditRegex.i18n.php
index 9165892..244fdc2 100644
--- a/MassEditRegex.i18n.php
+++ b/MassEditRegex.i18n.php
@@ -57,6 +57,7 @@
'masseditregex-norevisions' => 'No revisions found',
'masseditregex-blocked' => 'User is blocked',
'masseditregex-readonlydb' => 'Database is read-only',
+ 'masseditregex-js-clientside' => 'Execute in browser',
'masseditregex-js-execution' => 'Check this to do execution on client
side, used when many pages causes php max execution time.',
'masseditregex-js-jobdone' => 'Job finished',
'masseditregex-js-editpage' => 'Replaced $1 occurence(s) on $2, $3
left.',
@@ -170,6 +171,7 @@
'masseditregex-norevisions' => 'error message displayed when no
revisions could be found for a given title',
'masseditregex-blocked' => 'error message displayed when a user account
is blocked',
'masseditregex-readonlydb' => 'error message displayed when database is
set to read only',
+ 'masseditregex-js-clientside' => 'Tickbox that when ticked will perform
the page iteration in the browser, sending a request to the server for each
page.',
'masseditregex-js-execution' => 'message title of a html checkbox which
describes that checking this, would enable client side execution',
'masseditregex-js-jobdone
See also:
diff --git a/MassEditRegex.js b/MassEditRegex.js
index 0784bb8..3a9732b 100644
--- a/MassEditRegex.js
+++ b/MassEditRegex.js
@@ -1,271 +1,276 @@
-function executeMassEdit(){
+function executeMassEdit() {
- function getDataFromPath(data,path){
- path = path.split('.');
- for(var x = 0; x < path.length; x++){
- var dataKeys = [];
- for(var k in data) dataKeys.push(k);
- if($.inArray(path[x], dataKeys) == -1){
- return false
- }
- data = data[path[x]];
- }
- return data;
- }
+ function getDataFromPath( data, path ) {
+ path = path.split( '.' );
+ for ( var x = 0; x < path.length; x++ ) {
+ var dataKeys = [];
+ for (var k in data) dataKeys.push( k );
+ if ( $.inArray( path[x], dataKeys ) == -1 ) {
+ return false
+ }
+ data = data[path[x]];
+ }
+ return data;
+ }
- function makeAPICall(data,callback,c){
- var waitForCallback = false;
+ function makeAPICall( data, callback, c ) {
+ var waitForCallback = false;
- if(c !== undefined){
- data.params[data.continueKey] = c;
- }
+ if ( c !== undefined ) {
+ data.params[data.continueKey] = c;
+ }
- $.ajax({
- url: mw.util.wikiScript( 'api' ),
- data: data.params,
- dataType: 'json',
- type: 'POST',
- success: function( response ) {
- var result = getDataFromPath(response,data.resultPath);
- if ( result ) {
- if(data.continuePath){
- var continueData =
getDataFromPath(response,data.continuePath);
- if(continueData){
- waitForCallback = true;
- makeAPICall(data,function(r){
- waitForCallback = false;
- result = result.concat(r);
- },continueData);
- }
- var timerId = setInterval(function(){
- if(!waitForCallback){
- callback(result);
- clearInterval(timerId);
- }
- },10);
- }else{
- callback(result);
- }
- } else if ( response && response.error ) {
- alert(
mw.message('masseditregex-js-mwapi-api-error',response.error.code,
response.error.info).text());
- } else {
- alert(
mw.message('masseditregex-js-mwapi-general-error').text() );
- }
- },
- error: function( xhr ) {
-
alert(mw.message('masseditregex-js-mwapi-unknown-error').text());
- }
- });
- }
+ $.ajax( {
+ url: mw.util.wikiScript( 'api' ),
+ data: data.params,
+ dataType: 'json',
+ type: 'POST',
+ success: function( response ) {
+ var result = getDataFromPath( response,
data.resultPath );
+ if ( result ) {
+ if ( data.continuePath ) {
+ var continueData =
getDataFromPath( response, data.continuePath );
+ if ( continueData ) {
+ waitForCallback = true;
+ makeAPICall( data,
function( r ) {
+ waitForCallback
= false;
+ result =
result.concat( r );
+ }, continueData );
+ }
+ var timerId = setInterval(
function() {
+ if ( !waitForCallback )
{
+ callback(
result );
+ clearInterval(
timerId );
+ }
+ }, 10 );
+ } else {
+ callback( result );
+ }
+ } else if ( response && response.error ) {
+ alert( mw.message(
'masseditregex-js-mwapi-api-error',
+ response.error.code,
response.error.info ).text() );
+ } else {
+ alert( mw.message(
'masseditregex-js-mwapi-general-error' ).text() );
+ }
+ },
+ error: function( xhr ) {
+ alert( mw.message(
'masseditregex-js-mwapi-unknown-error' ).text() );
+ }
+ } );
+ }
- function getCategoryPages(page,callback){
- var data = {
- resultPath: 'query.categorymembers',
- continuePath:'query-continue.categorymembers.cmcontinue',
- continueKey:'cmcontinue',
- params:{
- format: 'json',
- action: 'query',
- list: 'categorymembers',
- cmtitle: 'Category:' + page,
- cmlimit: 100
- }
- };
- makeAPICall(data,callback);
- }
+ function getCategoryPages( page, callback ) {
+ var data = {
+ resultPath: 'query.categorymembers',
+ continuePath:
'query-continue.categorymembers.cmcontinue',
+ continueKey: 'cmcontinue',
+ params:{
+ format: 'json',
+ action: 'query',
+ list: 'categorymembers',
+ cmtitle: 'Category:' + page,
+ cmlimit: 100
+ }
+ };
+ makeAPICall( data, callback );
+ }
- function getBackLinkPages(page,callback){
- var data = {
- resultPath: 'query.backlinks',
- continuePath:'query-continue.backlinks.blcontinue',
- continueKey:'cmcontinue',
- params:{
- format: 'json',
- action: 'query',
- list: 'backlinks',
- bltitle: page,
- bllimit: 100
- }
- };
- makeAPICall(data,callback);
- }
+ function getBackLinkPages( page, callback ) {
+ var data = {
+ resultPath: 'query.backlinks',
+ continuePath: 'query-continue.backlinks.blcontinue',
+ continueKey: 'cmcontinue',
+ params:{
+ format: 'json',
+ action: 'query',
+ list: 'backlinks',
+ bltitle: page,
+ bllimit: 100
+ }
+ };
+ makeAPICall( data, callback );
+ }
- function getAllPrefixPages(page,callback){
- var data = {
- resultPath: 'query.namespaces',
- params:{
- format: 'json',
- action: 'query',
- meta: 'siteinfo',
- siprop: 'namespaces'
- }
- };
- makeAPICall(data,function(namespaces){
- var data;
- var nsId;
- var result = {
- pages:[]
- };
- var size = 0;
- var count = 0;
+ function getAllPrefixPages( page, callback ) {
+ var data = {
+ resultPath: 'query.namespaces',
+ params:{
+ format: 'json',
+ action: 'query',
+ meta: 'siteinfo',
+ siprop: 'namespaces'
+ }
+ };
+ makeAPICall( data, function( namespaces ) {
+ var data;
+ var nsId;
+ var result = {
+ pages: []
+ };
+ var size = 0;
+ var count = 0;
- //count number of elements
- for(var key in namespaces){
- if(namespaces[key].id > 0){
- size++;
- }
- }
+ // Count number of elements
+ for ( var key in namespaces ) {
+ if ( namespaces[key].id > 0 ) {
+ size++;
+ }
+ }
- //iterate through the namespaces
- for(var key in namespaces){
- nsId = namespaces[key].id;
- if(nsId >= 0){
- data = {
- resultPath: 'query.allpages',
- continuePath:'query-continue.allpages.apcontinue',
- continueKey:'apcontinue',
- params:{
- format: 'json',
- action: 'query',
- list: 'allpages',
- apnamespace:nsId,
- apprefix:page,
- aplimit: 100
- }
- };
- (function(data,result,callback){
- makeAPICall(data,function(pages){
- result.pages = result.pages.concat(pages);
- if(callback !== null){
- callback(result.pages);
- }
- });
+ // Iterate through the namespaces
+ for ( var key in namespaces ) {
+ nsId = namespaces[key].id;
+ if ( nsId >= 0 ) {
+ data = {
+ resultPath: 'query.allpages',
+ continuePath:
'query-continue.allpages.apcontinue',
+ continueKey: 'apcontinue',
+ params:{
+ format: 'json',
+ action: 'query',
+ list: 'allpages',
+ apnamespace: nsId,
+ apprefix: page,
+ aplimit: 100
+ }
+ };
- }(data,result,count++ === size ? callback : null));
- }
- }
- });
- }
+ ( function ( data, result, callback ) {
+ makeAPICall(data, function
(pages) {
+ result.pages =
result.pages.concat( pages );
+ if ( callback !== null
) {
+ callback(
result.pages );
+ }
+ });
+ }( data, result, count++ === size ?
callback : null ) );
- function getPages(pages,callback){
+ }
+ }
+ } );
+ }
- var data = {
- resultPath: 'query.pages',
- params:{
- format: 'json',
- action: 'query',
- titles: pages.join('|')
- }
- };
- makeAPICall(data,function(data){
- //convert from object to array
- pages = [];
- for (key in data){
- pages.push(data[key]);
- }
- callback(pages);
- });
- }
+ function getPages( pages, callback ) {
+ var data = {
+ resultPath: 'query.pages',
+ params: {
+ format: 'json',
+ action: 'query',
+ titles: pages.join( '|' )
+ }
+ };
+ makeAPICall( data, function ( data ) {
+ // Convert from object to array
+ pages = [];
+ for ( key in data ) {
+ pages.push( data[key] );
+ }
+ callback( pages );
+ } );
+ }
- function editPages(pages,search,replace,summary,cb){
- var rObj = {remaining: pages.length};
- if(pages.length === 0){
- cb({error:'No pages found!'});
- return;
- }
+ function editPages( pages, search, replace, summary, cb ) {
+ var rObj = { remaining: pages.length };
+ if ( pages.length === 0 ) {
+ cb( { error: 'No pages found!' } );
+ return;
+ }
- for(var x = 0; x < pages.length; x++){
- (function(page,search,replace,cb,rObj){
- var pageId = page.pageid;
+ for ( var x = 0; x < pages.length; x++ ) {
+ ( function ( page, search, replace, cb, rObj ) {
+ var pageId = page.pageid;
- if(pageId === undefined){
-
cb({error:mw.message('masseditregex-js-pagenotexist',page.title).text()});
- }else{
- $.ajax({
- url: mw.util.wikiScript(),
- data: {
- action: 'ajax',
- rs: 'MassEditRegexAPI::edit',
- rsargs: [pageId,search,replace,summary]
- },
- dataType: 'json',
- type: 'POST'
- }).done(function (response) {
- rObj.remaining--;
- cb(page,response,rObj.remaining);
- });
- }
- }(pages[x],search,replace,cb,rObj));
- }
- }
+ if ( pageId === undefined ) {
+ cb( { error: mw.message(
'masseditregex-js-pagenotexist', page.title ).text() } );
+ } else {
+ $.ajax({
+ url: mw.util.wikiScript(),
+ data: {
+ action: 'ajax',
+ rs:
'MassEditRegexAPI::edit',
+ rsargs: [pageId,
search, replace, summary]
+ },
+ dataType: 'json',
+ type: 'POST'
+ }).done( function ( response ) {
+ rObj.remaining--;
+ cb( page, response,
rObj.remaining );
+ });
+ }
+ }( pages[x], search, replace, cb, rObj ) );
+ }
+ }
- function doEdit(pages){
- var search = $('#wpMatch').val();
- var replace = $('#wpReplace').val();
- var summary = $('#wpSummary').val();
- var content = $('<div></div>');
- var heading = $('<h1></h1>');
- content.append(heading);
- heading.text(mw.message('masseditregex-js-working').text());
- var list = $('<ul></ul>');
- content.append(list);
+ function doEdit( pages ) {
+ var search = $( '#wpMatch' ).val();
+ var replace = $( '#wpReplace' ).val();
+ var summary = $( '#wpSummary' ).val();
+ var content = $( '<div></div>' );
+ var heading = $( '<h1></h1>' );
+ content.append( heading );
+ heading.text( mw.message( 'masseditregex-js-working' ).text() );
+ var list = $( '<ul></ul>' );
+ content.append( list );
- content.dialog({
- height: $(window).height() * 0.8,
- width: $(window).width() * 0.8,
- modal: true
- });
+ content.dialog( {
+ height: $(window).height() * 0.8,
+ width: $(window).width() * 0.8,
+ modal: true
+ } );
+ editPages( pages, search, replace, summary,
+ function( page, response, remaining ) {
+ var li = $('<li></li>');
-
editPages(pages,search,replace,summary,function(page,response,remaining){
- var li = $('<li></li>');
+ if ( page.error || response.error ) {
+ li.text(page.title + ': ' + page.error
? page.error : response.error);
+ } else {
+ li.text( mw.message(
'masseditregex-js-editpage', response.changes,
+ page.title, remaining ).text()
);
+ }
- if(page.error || response.error){
- li.text(page.title+': '+page.error ? page.error :
response.error);
- }else{
-
li.text(mw.message('masseditregex-js-editpage',response.changes,page.title,remaining).text());
- }
+ list.prepend(li);
- list.prepend(li);
+ if ( remaining === 0 ) {
+ var li = $('<li></li>');
+ li.text( mw.message(
'masseditregex-js-jobdone' ).text() );
+ list.prepend(li);
+ heading.text( mw.message(
'masseditregex-js-jobdone' ).text() );
+ }
+ }
+ );
+ }
- if(remaining === 0){
- heading.text(mw.message('masseditregex-js-jobdone').text());
- }
- });
+ var pages = $( '#wpPageList' ).val().split( '\n' );
+ var type = $( 'input[name="wpPageListType"]:checked' ).val();
- }
-
- var pages = $('#wpPageList').val().split('\n');
- var type = $('input[name="wpPageListType"]:checked').val();
-
- switch (type) {
- case 'pagenames':
- getPages(pages,doEdit);
- break;
- case 'pagename-prefixes':
- for(var x = 0; x < pages.length; x++){
- getAllPrefixPages(pages[x],doEdit);
- }
- break;
- case 'backlinks':
- for(var x = 0; x < pages.length; x++){
- getBackLinkPages(pages[x],doEdit);
- }
- break;
- case 'categories':
- for(var x = 0; x < pages.length; x++){
- getCategoryPages(pages[x],doEdit);
- }
- break;
- }
+ switch ( type ) {
+ case 'pagenames':
+ getPages( pages, doEdit );
+ break;
+ case 'pagename-prefixes':
+ for ( var x = 0; x < pages.length; x++ ) {
+ getAllPrefixPages( pages[x], doEdit );
+ }
+ break;
+ case 'backlinks':
+ for ( var x = 0; x < pages.length; x++ ) {
+ getBackLinkPages( pages[x], doEdit );
+ }
+ break;
+ case 'categories':
+ for ( var x = 0; x < pages.length; x++ ) {
+ getCategoryPages( pages[x], doEdit );
+ }
+ break;
+ }
}
-$(document).ready(function(){
- $('#wpSave').click(function(){
- if($('#wpClientSide').is(':checked')){
- executeMassEdit();
- return false;
- }
- return true;
- });
-});
\ No newline at end of file
+$( document ).ready( function () {
+ $( '#wpSave' ).click( function () {
+ if ( $( '#wpClientSide' ).is( ':checked' ) ) {
+ executeMassEdit();
+ return false;
+ }
+ return true;
+ } );
+} );
diff --git a/MassEditRegex.php b/MassEditRegex.php
index c44958c..aaf011f 100644
--- a/MassEditRegex.php
+++ b/MassEditRegex.php
@@ -11,14 +11,15 @@
* @link http://www.mediawiki.org/wiki/Extension:MassEditRegex Documentation
*
* @author Adam Nielsen <[email protected]>
- * @copyright Copyright © 2009,2013 Adam Nielsen
+ * @author Kim Eik <[email protected]>
+ * @copyright Copyright © 2009-2015 Adam Nielsen
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
2.0 or later
*/
$wgExtensionCredits['specialpage'][] = array(
'path' => __FILE__,
'name' => 'Mass Edit via Regular Expressions',
- 'version' => 'r6',
+ 'version' => 'r7',
'author' => 'Adam Nielsen',
'url' => 'https://www.mediawiki.org/wiki/Extension:MassEditRegex',
'descriptionmsg' => 'masseditregex-desc'
@@ -61,5 +62,5 @@
)
);
-//ajax
-$wgAjaxExportList[] = 'MassEditRegexAPI::edit';
\ No newline at end of file
+// AJAX
+$wgAjaxExportList[] = 'MassEditRegexAPI::edit';
diff --git a/MassEditRegex.special.php b/MassEditRegex.special.php
index 8c5b0da..92d4729 100644
--- a/MassEditRegex.special.php
+++ b/MassEditRegex.special.php
@@ -27,6 +27,7 @@
private $strPageListType; ///< Type of titles (categories, backlinks,
etc.)
private $strMatch; ///< Match regex from form
private $strReplace; ///< Substitution regex from form
+ private $isClientSide; ///< Is the client-side checkbox ticked?
private $sk; ///< Skin instance
/**
@@ -173,6 +174,7 @@
$this->showForm();
// Show the diffs now (after any errors)
+ $wgOut->addHTML( '<hr style="margin: 1em;"/>' );
$wgOut->addHTML( $htmlDiff );
} else {
$wgOut->addWikiMsg(
'masseditregex-num-articles-changed', $iArticleCount );
@@ -185,11 +187,12 @@
}
}
- /// Run the regexes.
+ /// Display the special page, and run the regexes if a form is being
submitted
public function execute( $par ) {
global $wgUser;
$wgOut = $this->getOutput();
+ $wgOut->addModules('MassEditRegex');
$this->setHeaders();
@@ -215,7 +218,7 @@
$wgRequest = $this->getRequest();
$strPageList = $wgRequest->getText( 'wpPageList', 'Sandbox' );
- $this->aPageList = explode("\n", trim($strPageList));
+ $this->aPageList = explode( "\n", trim( $strPageList ) );
$this->strPageListType = $wgRequest->getText( 'wpPageListType',
'pagenames' );
$this->sk = $wgUser->getSkin();
@@ -225,8 +228,11 @@
$this->strReplace = $wgRequest->getText( 'wpReplace', 'goodbye
$1' );
$summary = $wgRequest->getText( 'wpSummary', '' );
+ $this->isClientSide = $wgRequest->getVal( 'wpClientSide', false
) == 1;
- $this->massEditRegex = new
MassEditRegex($this->strMatch,$this->strReplace,$summary,$wgUser);
+ $this->massEditRegex = new MassEditRegex(
+ $this->strMatch, $this->strReplace, $summary, $wgUser
+ );
if ( $wgRequest->wasPosted() ) {
$this->perform( !$wgRequest->getCheck('wpSave') );
@@ -317,7 +323,10 @@
Xml::closeElement('tr') .
Xml::closeElement('table') .
- Xml::openElement( 'div', array( 'class' =>
'editOptions' ) ) .
+ Xml::openElement( 'div', array(
+ 'class' => 'editOptions',
+ 'style' => 'margin: 1ex;'
+ ) ) .
// Display the edit summary and preview
@@ -348,26 +357,6 @@
) .
Xml::closeElement( 'div' ) . // class=editOptions
-
- // Display client side checkbox option
- Xml::openElement( 'div',array('style' => 'margin-top:
10px; margin-bottom: 10px;')) .
-
- Xml::tags( 'span',
- array(),
- Xml::tags( 'label', array(
- 'for' => 'wpClientSide'
- ), 'Client sided execution:' )
- ) . ' ' .
-
- Xml::element('input', array(
- 'id' => 'wpClientSide',
- 'name' => 'wpClientSide',
- 'type' => 'checkbox',
- 'title' =>
wfMessage('masseditregex-js-execution'),
- )) .
-
- Xml::closeElement( 'div' ) .
-
// Display the preview + execute buttons
Xml::element('input', array(
'id' => 'wpSave',
@@ -385,8 +374,22 @@
'value' => wfMessage( 'showpreview'
)->text(),
'accesskey' => wfMessage( 'accesskey-preview'
)->text(),
'title' => wfMessage( 'tooltip-preview'
)->text().' ['.wfMessage( 'accesskey-preview' )->text().']',
- ))
+ )) .
+ Xml::tags( 'span',
+ array(
+ 'style' => 'margin-left: 1em;'
+ ),
+ Xml::checkLabel(
+
wfMessage('masseditregex-js-clientside'),
+ 'wpClientSide',
+ 'wpClientSide',
+ $this->isClientSide,
+ array(
+ 'title' =>
wfMessage('masseditregex-js-execution'),
+ )
+ )
+ )
);
$wgOut->addHTML( Xml::closeElement('form') );
@@ -451,22 +454,21 @@
public static function efSkinTemplateNavigationUniversal( &$sktemplate,
&$links )
{
- global $wgTitle;
- if ( !is_object( $wgTitle ) ) return;
+ $title = $sktemplate->getTitle();
+ $ns = $title->getNamespace();
- $ns = $wgTitle->getNamespace();
if ( $ns == NS_CATEGORY ) {
$url = SpecialPage::getTitleFor( 'MassEditRegex'
)->getLocalURL(
array(
- 'wpPageList' => $wgTitle->getText(),
+ 'wpPageList' => $title->getText(),
'wpPageListType' => 'categories',
)
);
} elseif (
( $ns == NS_SPECIAL )
- && ( $wgTitle->isSpecial( 'Whatlinkshere' ) )
+ && ( $title->isSpecial( 'Whatlinkshere' ) )
) {
- $titleParts =
SpecialPageFactory::resolveAlias($wgTitle->getText());
+ $titleParts =
SpecialPageFactory::resolveAlias($title->getText());
$url = SpecialPage::getTitleFor( 'MassEditRegex'
)->getLocalURL(
array(
@@ -499,25 +501,28 @@
}
/**
- * Wrapper for new function
+ * Call MassEditRegex::editPage() or MassEditRegex::previewPage()
* @param $title
* @param $isPreview
* @param $htmlDiff
- * @deprecated this is just a wrapper function for legacy code, do not
use. instead use editPage or previewPage in MassEditRegex
+ * @deprecated this is just a wrapper function for legacy code, do not
use.
+ * Instead use editPage or previewPage in MassEditRegex
* @return bool
*/
private function editPage( $title, $isPreview, &$htmlDiff ) {
- try{
- if($isPreview){
- $htmlDiff .=
$this->massEditRegex->previewPage($title);
- }else{
- $this->massEditRegex->editPage($title);
+ global $wgOut;
+ try {
+ if ( $isPreview ) {
+ $htmlDiff .= $this->massEditRegex->previewPage(
$title );
+ } else {
+ $changeCount = $this->massEditRegex->editPage(
$title );
+ $wgOut->addHTML( '<li>' . $this->msg(
'masseditregex-num-changes',
+ $title->getPrefixedText(), $changeCount
)->escaped() . '</li>' );
}
return true;
- }catch(Exception $e){
- wfDebug($e->getMessage());
+ } catch ( Exception $e ) {
+ wfDebug( $e->getMessage() );
return false;
}
}
-
}
--
To view, visit https://gerrit.wikimedia.org/r/189179
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I269af2bf243a1f196b77b719f237db714f6cf41c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MassEditRegex
Gerrit-Branch: master
Gerrit-Owner: Malvineous <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits