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:
Siebrand Mazeland 2015-10-02 09:48:42 +02:00 committed by Paladox
parent f3e0f76864
commit afb4e332a9
11 changed files with 114 additions and 66 deletions

6
.gitignore vendored
View file

@ -2,8 +2,6 @@
*~ *~
*.kate-swp *.kate-swp
.*.swp .*.swp
!.gitignore
!.gitreview
!.jshintrc
node_modules/ node_modules/
/composer.lock
/vendor/

View file

@ -2,7 +2,6 @@
"predef": [ "predef": [
"jQuery" "jQuery"
], ],
/* Common */ /* Common */
// Enforcing // Enforcing
@ -19,7 +18,6 @@
"trailing": true, "trailing": true,
"undef": true, "undef": true,
"unused": true, "unused": true,
// Environment // Environment
"browser": true "browser": true
} }

View file

@ -1,10 +1,19 @@
/*jshint node:true */ /*jshint node:true */
module.exports = function ( grunt ) { module.exports = function ( grunt ) {
grunt.loadNpmTasks( 'grunt-contrib-jshint' );
grunt.loadNpmTasks( 'grunt-banana-checker' ); grunt.loadNpmTasks( 'grunt-banana-checker' );
grunt.loadNpmTasks( 'grunt-jsonlint' ); grunt.loadNpmTasks( 'grunt-jsonlint' );
var conf = grunt.file.readJSON( 'extension.json' ); var conf = grunt.file.readJSON( 'extension.json' );
grunt.initConfig( { grunt.initConfig( {
jshint: {
options: {
jshintrc: true
},
all: [
'*.js'
]
},
banana: conf.MessagesDirs, banana: conf.MessagesDirs,
jsonlint: { jsonlint: {
all: [ all: [
@ -14,6 +23,6 @@ module.exports = function ( grunt ) {
} }
} ); } );
grunt.registerTask( 'test', [ 'jsonlint', 'banana' ] ); grunt.registerTask( 'test', [ 'jshint', 'jsonlint', 'banana' ] );
grunt.registerTask( 'default', 'test' ); grunt.registerTask( 'default', 'test' );
}; };

View file

@ -22,6 +22,7 @@ class NukeHooks {
array( 'target' => $userPageTitle->getText() ) array( 'target' => $userPageTitle->getText() )
); );
} }
return true; return true;
} }
} }

View file

@ -5,10 +5,12 @@ if ( function_exists( 'wfLoadExtension' ) ) {
// Keep i18n globals so mergeMessageFileList.php doesn't break // Keep i18n globals so mergeMessageFileList.php doesn't break
$wgMessagesDirs['Nuke'] = __DIR__ . '/i18n'; $wgMessagesDirs['Nuke'] = __DIR__ . '/i18n';
$wgExtensionMessagesFiles['NukeAlias'] = __DIR__ . '/Nuke.alias.php'; $wgExtensionMessagesFiles['NukeAlias'] = __DIR__ . '/Nuke.alias.php';
/* wfWarn( /* wfWarn(
'Deprecated PHP entry point used for Nuke extension. Please use wfLoadExtension instead, ' . 'Deprecated PHP entry point used for Nuke extension. Please use wfLoadExtension instead, ' .
'see https://www.mediawiki.org/wiki/Extension_registration for more details.' 'see https://www.mediawiki.org/wiki/Extension_registration for more details.'
); */ ); */
return true; return true;
} else { } else {
die( 'This version of the Nuke extension requires MediaWiki 1.25+' ); die( 'This version of the Nuke extension requires MediaWiki 1.25+' );

View file

@ -38,7 +38,7 @@ class SpecialNuke extends SpecialPage {
$msg = $target === '' ? $msg = $target === '' ?
$this->msg( 'nuke-multiplepeople' )->inContentLanguage()->text() : $this->msg( 'nuke-multiplepeople' )->inContentLanguage()->text() :
$this->msg( 'nuke-defaultreason', $target )-> $this->msg( 'nuke-defaultreason', $target )->
inContentLanguage()->text(); inContentLanguage()->text();
$reason = $req->getText( 'wpReason', $msg ); $reason = $req->getText( 'wpReason', $msg );
$limit = $req->getInt( 'limit', 500 ); $limit = $req->getInt( 'limit', 500 );
@ -46,16 +46,18 @@ class SpecialNuke extends SpecialPage {
$namespace = ctype_digit( $namespace ) ? (int)$namespace : null; $namespace = ctype_digit( $namespace ) ? (int)$namespace : null;
if ( $req->wasPosted() 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' ); $pages = $req->getArray( 'pages' );
if ( $pages ) { if ( $pages ) {
$this->doDelete( $pages, $reason ); $this->doDelete( $pages, $reason );
return; return;
} }
} elseif ( $req->getVal( 'action' ) == 'submit' ) { } elseif ( $req->getVal( 'action' ) === 'submit' ) {
$this->listForm( $target, $reason, $limit, $namespace ); $this->listForm( $target, $reason, $limit, $namespace );
} else { } else {
$this->promptForm(); $this->promptForm();
@ -82,25 +84,37 @@ class SpecialNuke extends SpecialPage {
Xml::openElement( Xml::openElement(
'form', 'form',
array( array(
'action' => $this->getTitle()->getLocalURL( 'action=submit' ), 'action' => $this->getPageTitle()->getLocalURL( 'action=submit' ),
'method' => 'post' 'method' => 'post'
) )
) )
. '<table><tr>' . '<table><tr>'
. '<td>' . Xml::label( $this->msg( 'nuke-userorip' )->text(), 'nuke-target' ) . '</td>' . '<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>' . '</tr><tr>'
. '<td>' . Xml::label( $this->msg( 'nuke-pattern' )->text(), 'nuke-pattern' ) . '</td>' . '<td>' . Xml::label( $this->msg( 'nuke-pattern' )->text(), 'nuke-pattern' ) . '</td>'
. '<td>' . Xml::input( 'pattern', 40, '', array( 'id' => '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>'
. '</tr><tr>' . '</tr><tr>'
. '<td>' . Xml::label( $this->msg( 'nuke-maxpages' )->text(), 'nuke-limit' ) . '</td>' . '<td>' . Xml::label( $this->msg( 'nuke-namespace' )->text(), 'nuke-namespace' ) . '</td>'
. '<td>' . Xml::input( 'limit', 7, '500', array( 'id' => 'nuke-limit' ) ) . '</td>' . '<td>' . Html::namespaceSelector(
array( 'all' => 'all' ),
array( 'name' => 'namespace' )
) . '</td>'
. '</tr><tr>' . '</tr><tr>'
. '<td></td>' . '<td>' . Xml::label( $this->msg( 'nuke-maxpages' )->text(), 'nuke-limit' ) . '</td>'
. '<td>' . Xml::submitButton( $this->msg( 'nuke-submit-user' )->text() ) . '</td>' . '<td>' . Xml::input( 'limit', 7, '500', array( 'id' => 'nuke-limit' ) ) . '</td>'
. '</tr><tr>'
. '<td></td>'
. '<td>' . Xml::submitButton( $this->msg( 'nuke-submit-user' )->text() ) . '</td>'
. '</tr></table>' . '</tr></table>'
. Html::hidden( 'wpEditToken', $this->getUser()->getEditToken() ) . Html::hidden( 'wpEditToken', $this->getUser()->getEditToken() )
. Xml::closeElement( 'form' ) . Xml::closeElement( 'form' )
@ -120,7 +134,7 @@ class SpecialNuke extends SpecialPage {
$pages = $this->getNewPages( $username, $limit, $namespace ); $pages = $this->getNewPages( $username, $limit, $namespace );
if ( count( $pages ) == 0 ) { if ( count( $pages ) === 0 ) {
if ( $username === '' ) { if ( $username === '' ) {
$out->addWikiMsg( 'nuke-nopages-global' ); $out->addWikiMsg( 'nuke-nopages-global' );
} else { } else {
@ -128,6 +142,7 @@ class SpecialNuke extends SpecialPage {
} }
$this->promptForm( $username ); $this->promptForm( $username );
return; return;
} }
@ -137,15 +152,15 @@ class SpecialNuke extends SpecialPage {
$out->addWikiMsg( 'nuke-list', $username ); $out->addWikiMsg( 'nuke-list', $username );
} }
$nuke = $this->getTitle(); $nuke = $this->getPageTitle();
$out->addModules( 'ext.nuke' ); $out->addModules( 'ext.nuke' );
$out->addHTML( $out->addHTML(
Xml::openElement( 'form', array( Xml::openElement( 'form', array(
'action' => $nuke->getLocalURL( 'action=delete' ), 'action' => $nuke->getLocalURL( 'action=delete' ),
'method' => 'post', 'method' => 'post',
'name' => 'nukelist' ) 'name' => 'nukelist' )
) . ) .
Html::hidden( 'wpEditToken', $this->getUser()->getEditToken() ) . Html::hidden( 'wpEditToken', $this->getUser()->getEditToken() ) .
Xml::tags( 'p', Xml::tags( 'p',
@ -188,10 +203,14 @@ class SpecialNuke extends SpecialPage {
*/ */
list( $title, $userName ) = $info; list( $title, $userName ) = $info;
$image = $title->getNamespace() == NS_IMAGE ? wfLocalFile( $title ) : false; $image = $title->getNamespace() === NS_IMAGE ? wfLocalFile( $title ) : false;
$thumb = $image && $image->exists() ? $image->transform( array( 'width' => 120, 'height' => 120 ), 0 ) : 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( $changesLink = Linker::linkKnown(
$title, $title,
$this->msg( 'nuke-viewchanges' )->escaped(), $this->msg( 'nuke-viewchanges' )->escaped(),
@ -202,7 +221,7 @@ class SpecialNuke extends SpecialPage {
Xml::check( Xml::check(
'pages[]', 'pages[]',
true, true,
array( 'value' => $title->getPrefixedDbKey() ) array( 'value' => $title->getPrefixedDBKey() )
) . '&#160;' . ) . '&#160;' .
( $thumb ? $thumb->toHtml( array( 'desc-link' => true ) ) : '' ) . ( $thumb ? $thumb->toHtml( array( 'desc-link' => true ) ) : '' ) .
Linker::linkKnown( $title ) . $wordSeparator . Linker::linkKnown( $title ) . $wordSeparator .
@ -288,7 +307,7 @@ class SpecialNuke extends SpecialPage {
foreach ( $pages as $page ) { foreach ( $pages as $page ) {
$title = Title::newFromURL( $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() ); $permission_errors = $title->getUserPermissionsErrors( 'delete', $this->getUser() );

View file

@ -1,2 +1,2 @@
<?php <?php
require_once( __DIR__ . '/Nuke.php' ); require_once __DIR__ . '/Nuke.php';

12
composer.json Normal file
View 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"
]
}
}

View file

@ -1,34 +1,34 @@
{ {
"@metadata": { "@metadata": {
"authors": [ "authors": [
"Brion Vibber", "Brion Vibber",
"Jeroen De Dauw" "Jeroen De Dauw"
] ]
}, },
"nuke": "Mass delete", "nuke": "Mass delete",
"action-nuke": "nuke pages", "action-nuke": "nuke pages",
"nuke-desc": "Gives administrators the ability to [[Special:Nuke|mass delete]] pages", "nuke-desc": "Gives administrators the ability to [[Special:Nuke|mass delete]] pages",
"nuke-nopages": "No new pages by [[Special:Contributions/$1|{{GENDER:$1|$1}}]] in recent changes.", "nuke-nopages": "No new pages by [[Special:Contributions/$1|{{GENDER:$1|$1}}]] in recent changes.",
"nuke-list": "The following pages were recently created by [[Special:Contributions/$1|{{GENDER:$1|$1}}]];\nput in a comment and hit the button to delete them.", "nuke-list": "The following pages were recently created by [[Special:Contributions/$1|{{GENDER:$1|$1}}]];\nput in a comment and hit the button to delete them.",
"nuke-list-multiple": "The following pages were recently created;\nput in a comment and hit the button to delete them.", "nuke-list-multiple": "The following pages were recently created;\nput in a comment and hit the button to delete them.",
"nuke-defaultreason": "Mass deletion of pages added by [[Special:Contributions/$1|{{GENDER:$1|$1}}]]", "nuke-defaultreason": "Mass deletion of pages added by [[Special:Contributions/$1|{{GENDER:$1|$1}}]]",
"nuke-multiplepeople": "Mass deletion of recently added pages", "nuke-multiplepeople": "Mass deletion of recently added pages",
"nuke-tools": "This tool allows for mass deletions of pages recently added by a given user or an IP address.\nInput the username or IP address to get a list of pages to delete, or leave blank for all users.", "nuke-tools": "This tool allows for mass deletions of pages recently added by a given user or an IP address.\nInput the username or IP address to get a list of pages to delete, or leave blank for all users.",
"nuke-submit-user": "Go", "nuke-submit-user": "Go",
"nuke-toggleinvert": "Invert", "nuke-toggleinvert": "Invert",
"nuke-submit-delete": "Delete selected", "nuke-submit-delete": "Delete selected",
"right-nuke": "Mass delete pages", "right-nuke": "Mass delete pages",
"nuke-select": "Select: $1", "nuke-select": "Select: $1",
"nuke-userorip": "Username, IP address or blank:", "nuke-userorip": "Username, IP address or blank:",
"nuke-maxpages": "Maximum number of pages:", "nuke-maxpages": "Maximum number of pages:",
"nuke-editby": "Created by [[Special:Contributions/$1|{{GENDER:$1|$1}}]]", "nuke-editby": "Created by [[Special:Contributions/$1|{{GENDER:$1|$1}}]]",
"nuke-deleted": "Page '''$1''' has been deleted.", "nuke-deleted": "Page '''$1''' has been deleted.",
"nuke-not-deleted": "Page [[:$1]] '''could not''' be deleted.", "nuke-not-deleted": "Page [[:$1]] '''could not''' be deleted.",
"nuke-delete-more": "[[Special:Nuke|Delete more pages]]", "nuke-delete-more": "[[Special:Nuke|Delete more pages]]",
"nuke-pattern": "Pattern for the page name:", "nuke-pattern": "Pattern for the page name:",
"nuke-nopages-global": "There are no new pages in [[Special:RecentChanges|recent changes]].", "nuke-nopages-global": "There are no new pages in [[Special:RecentChanges|recent changes]].",
"nuke-viewchanges": "view changes", "nuke-viewchanges": "view changes",
"nuke-namespace": "Limit to namespace:", "nuke-namespace": "Limit to namespace:",
"nuke-linkoncontribs": "mass delete", "nuke-linkoncontribs": "mass delete",
"nuke-linkoncontribs-text": "Mass delete pages where this user is the only author" "nuke-linkoncontribs-text": "Mass delete pages where this user is the only author"
} }

View file

@ -6,6 +6,7 @@
"devDependencies": { "devDependencies": {
"grunt": "0.4.5", "grunt": "0.4.5",
"grunt-cli": "0.1.13", "grunt-cli": "0.1.13",
"grunt-contrib-jshint": "0.11.3",
"grunt-banana-checker": "0.2.2", "grunt-banana-checker": "0.2.2",
"grunt-jsonlint": "1.0.4" "grunt-jsonlint": "1.0.4"
} }

8
phpcs.xml Normal file
View file

@ -0,0 +1,8 @@
<?xml version="1.0"?>
<ruleset>
<rule ref="vendor/mediawiki/mediawiki-codesniffer/MediaWiki"/>
<file>.</file>
<arg name="extensions" value="php,php5,inc"/>
<arg name="encoding" value="utf8"/>
<exclude-pattern>vendor</exclude-pattern>
</ruleset>