mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Nuke
synced 2024-11-27 17:50:21 +00:00
Add tests
* Fix all issues so tests pass. * Rework deprecated functions. Compatibility is now with MediaWiki 1.23 or later. Change-Id: I08a0be7df48f9a39951cdc4edd4091fd4b89eade
This commit is contained in:
parent
f3e0f76864
commit
afb4e332a9
6
.gitignore
vendored
6
.gitignore
vendored
|
@ -2,8 +2,6 @@
|
|||
*~
|
||||
*.kate-swp
|
||||
.*.swp
|
||||
|
||||
!.gitignore
|
||||
!.gitreview
|
||||
!.jshintrc
|
||||
node_modules/
|
||||
/composer.lock
|
||||
/vendor/
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
"predef": [
|
||||
"jQuery"
|
||||
],
|
||||
|
||||
/* Common */
|
||||
|
||||
// Enforcing
|
||||
|
@ -19,7 +18,6 @@
|
|||
"trailing": true,
|
||||
"undef": true,
|
||||
"unused": true,
|
||||
|
||||
// Environment
|
||||
"browser": true
|
||||
}
|
||||
|
|
11
Gruntfile.js
11
Gruntfile.js
|
@ -1,10 +1,19 @@
|
|||
/*jshint node:true */
|
||||
module.exports = function ( grunt ) {
|
||||
grunt.loadNpmTasks( 'grunt-contrib-jshint' );
|
||||
grunt.loadNpmTasks( 'grunt-banana-checker' );
|
||||
grunt.loadNpmTasks( 'grunt-jsonlint' );
|
||||
|
||||
var conf = grunt.file.readJSON( 'extension.json' );
|
||||
grunt.initConfig( {
|
||||
jshint: {
|
||||
options: {
|
||||
jshintrc: true
|
||||
},
|
||||
all: [
|
||||
'*.js'
|
||||
]
|
||||
},
|
||||
banana: conf.MessagesDirs,
|
||||
jsonlint: {
|
||||
all: [
|
||||
|
@ -14,6 +23,6 @@ module.exports = function ( grunt ) {
|
|||
}
|
||||
} );
|
||||
|
||||
grunt.registerTask( 'test', [ 'jsonlint', 'banana' ] );
|
||||
grunt.registerTask( 'test', [ 'jshint', 'jsonlint', 'banana' ] );
|
||||
grunt.registerTask( 'default', 'test' );
|
||||
};
|
||||
|
|
|
@ -22,6 +22,7 @@ class NukeHooks {
|
|||
array( 'target' => $userPageTitle->getText() )
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
2
Nuke.php
2
Nuke.php
|
@ -5,10 +5,12 @@ if ( function_exists( 'wfLoadExtension' ) ) {
|
|||
// Keep i18n globals so mergeMessageFileList.php doesn't break
|
||||
$wgMessagesDirs['Nuke'] = __DIR__ . '/i18n';
|
||||
$wgExtensionMessagesFiles['NukeAlias'] = __DIR__ . '/Nuke.alias.php';
|
||||
|
||||
/* wfWarn(
|
||||
'Deprecated PHP entry point used for Nuke extension. Please use wfLoadExtension instead, ' .
|
||||
'see https://www.mediawiki.org/wiki/Extension_registration for more details.'
|
||||
); */
|
||||
|
||||
return true;
|
||||
} else {
|
||||
die( 'This version of the Nuke extension requires MediaWiki 1.25+' );
|
||||
|
|
|
@ -46,16 +46,18 @@ class SpecialNuke extends SpecialPage {
|
|||
$namespace = ctype_digit( $namespace ) ? (int)$namespace : null;
|
||||
|
||||
if ( $req->wasPosted()
|
||||
&& $this->getUser()->matchEditToken( $req->getVal( 'wpEditToken' ) ) ) {
|
||||
&& $this->getUser()->matchEditToken( $req->getVal( 'wpEditToken' ) )
|
||||
) {
|
||||
|
||||
if ( $req->getVal( 'action' ) == 'delete' ) {
|
||||
if ( $req->getVal( 'action' ) === 'delete' ) {
|
||||
$pages = $req->getArray( 'pages' );
|
||||
|
||||
if ( $pages ) {
|
||||
$this->doDelete( $pages, $reason );
|
||||
|
||||
return;
|
||||
}
|
||||
} elseif ( $req->getVal( 'action' ) == 'submit' ) {
|
||||
} elseif ( $req->getVal( 'action' ) === 'submit' ) {
|
||||
$this->listForm( $target, $reason, $limit, $namespace );
|
||||
} else {
|
||||
$this->promptForm();
|
||||
|
@ -82,19 +84,31 @@ class SpecialNuke extends SpecialPage {
|
|||
Xml::openElement(
|
||||
'form',
|
||||
array(
|
||||
'action' => $this->getTitle()->getLocalURL( 'action=submit' ),
|
||||
'action' => $this->getPageTitle()->getLocalURL( 'action=submit' ),
|
||||
'method' => 'post'
|
||||
)
|
||||
)
|
||||
. '<table><tr>'
|
||||
. '<td>' . Xml::label( $this->msg( 'nuke-userorip' )->text(), 'nuke-target' ) . '</td>'
|
||||
. '<td>' . Xml::input( 'target', 40, $userName, array( 'id' => 'nuke-target', 'class' => 'mw-autocomplete-user', 'autofocus' => true ) ) . '</td>'
|
||||
. '<td>' . Xml::input(
|
||||
'target',
|
||||
40,
|
||||
$userName,
|
||||
array(
|
||||
'id' => 'nuke-target',
|
||||
'class' => 'mw-autocomplete-user',
|
||||
'autofocus' => true
|
||||
)
|
||||
) . '</td>'
|
||||
. '</tr><tr>'
|
||||
. '<td>' . Xml::label( $this->msg( 'nuke-pattern' )->text(), 'nuke-pattern' ) . '</td>'
|
||||
. '<td>' . Xml::input( 'pattern', 40, '', array( 'id' => 'nuke-pattern' ) ) . '</td>'
|
||||
. '</tr><tr>'
|
||||
. '<td>' . Xml::label( $this->msg( 'nuke-namespace' )->text(), 'nuke-namespace' ) . '</td>'
|
||||
. '<td>' . Html::namespaceSelector( array( 'all' => 'all' ), array( 'name' => 'namespace' ) ) . '</td>'
|
||||
. '<td>' . Html::namespaceSelector(
|
||||
array( 'all' => 'all' ),
|
||||
array( 'name' => 'namespace' )
|
||||
) . '</td>'
|
||||
. '</tr><tr>'
|
||||
. '<td>' . Xml::label( $this->msg( 'nuke-maxpages' )->text(), 'nuke-limit' ) . '</td>'
|
||||
. '<td>' . Xml::input( 'limit', 7, '500', array( 'id' => 'nuke-limit' ) ) . '</td>'
|
||||
|
@ -120,7 +134,7 @@ class SpecialNuke extends SpecialPage {
|
|||
|
||||
$pages = $this->getNewPages( $username, $limit, $namespace );
|
||||
|
||||
if ( count( $pages ) == 0 ) {
|
||||
if ( count( $pages ) === 0 ) {
|
||||
if ( $username === '' ) {
|
||||
$out->addWikiMsg( 'nuke-nopages-global' );
|
||||
} else {
|
||||
|
@ -128,6 +142,7 @@ class SpecialNuke extends SpecialPage {
|
|||
}
|
||||
|
||||
$this->promptForm( $username );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -137,7 +152,7 @@ class SpecialNuke extends SpecialPage {
|
|||
$out->addWikiMsg( 'nuke-list', $username );
|
||||
}
|
||||
|
||||
$nuke = $this->getTitle();
|
||||
$nuke = $this->getPageTitle();
|
||||
|
||||
$out->addModules( 'ext.nuke' );
|
||||
|
||||
|
@ -188,10 +203,14 @@ class SpecialNuke extends SpecialPage {
|
|||
*/
|
||||
list( $title, $userName ) = $info;
|
||||
|
||||
$image = $title->getNamespace() == NS_IMAGE ? wfLocalFile( $title ) : false;
|
||||
$thumb = $image && $image->exists() ? $image->transform( array( 'width' => 120, 'height' => 120 ), 0 ) : false;
|
||||
$image = $title->getNamespace() === NS_IMAGE ? wfLocalFile( $title ) : false;
|
||||
$thumb = $image && $image->exists() ?
|
||||
$image->transform( array( 'width' => 120, 'height' => 120 ), 0 ) :
|
||||
false;
|
||||
|
||||
$userNameText = $userName ? $this->msg( 'nuke-editby', $userName )->parse() . $commaSeparator : '';
|
||||
$userNameText = $userName ?
|
||||
$this->msg( 'nuke-editby', $userName )->parse() . $commaSeparator :
|
||||
'';
|
||||
$changesLink = Linker::linkKnown(
|
||||
$title,
|
||||
$this->msg( 'nuke-viewchanges' )->escaped(),
|
||||
|
@ -202,7 +221,7 @@ class SpecialNuke extends SpecialPage {
|
|||
Xml::check(
|
||||
'pages[]',
|
||||
true,
|
||||
array( 'value' => $title->getPrefixedDbKey() )
|
||||
array( 'value' => $title->getPrefixedDBKey() )
|
||||
) . ' ' .
|
||||
( $thumb ? $thumb->toHtml( array( 'desc-link' => true ) ) : '' ) .
|
||||
Linker::linkKnown( $title ) . $wordSeparator .
|
||||
|
@ -288,7 +307,7 @@ class SpecialNuke extends SpecialPage {
|
|||
|
||||
foreach ( $pages as $page ) {
|
||||
$title = Title::newFromURL( $page );
|
||||
$file = $title->getNamespace() == NS_FILE ? wfLocalFile( $title ) : false;
|
||||
$file = $title->getNamespace() === NS_FILE ? wfLocalFile( $title ) : false;
|
||||
|
||||
$permission_errors = $title->getUserPermissionsErrors( 'delete', $this->getUser() );
|
||||
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
<?php
|
||||
require_once( __DIR__ . '/Nuke.php' );
|
||||
require_once __DIR__ . '/Nuke.php';
|
||||
|
|
12
composer.json
Normal file
12
composer.json
Normal file
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"require-dev": {
|
||||
"jakub-onderka/php-parallel-lint": "0.9",
|
||||
"mediawiki/mediawiki-codesniffer": "0.4.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": [
|
||||
"parallel-lint . --exclude vendor",
|
||||
"phpcs -p -s"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@
|
|||
"devDependencies": {
|
||||
"grunt": "0.4.5",
|
||||
"grunt-cli": "0.1.13",
|
||||
"grunt-contrib-jshint": "0.11.3",
|
||||
"grunt-banana-checker": "0.2.2",
|
||||
"grunt-jsonlint": "1.0.4"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue