/**
* Show a form for filtering namespace and username
*
- * @param $par String
- * @return String
+ * @param string $par
+ * @return string
*/
public function execute( $par ) {
$this->setHeaders();
$this->outputHeader();
+ $this->getOutput()->addModuleStyles( 'mediawiki.special.comparepages.styles' );
- $form = new HTMLForm( array(
- 'Page1' => array(
- 'type' => 'text',
+ $form = HTMLForm::factory( 'ooui', [
+ 'Page1' => [
+ 'type' => 'title',
'name' => 'page1',
'label-message' => 'compare-page1',
'size' => '40',
'section' => 'page1',
- 'validation-callback' => array( $this, 'checkExistingTitle' ),
- ),
- 'Revision1' => array(
+ 'validation-callback' => [ $this, 'checkExistingTitle' ],
+ ],
+ 'Revision1' => [
'type' => 'int',
'name' => 'rev1',
'label-message' => 'compare-rev1',
'size' => '8',
'section' => 'page1',
- 'validation-callback' => array( $this, 'checkExistingRevision' ),
- ),
- 'Page2' => array(
- 'type' => 'text',
+ 'validation-callback' => [ $this, 'checkExistingRevision' ],
+ ],
+ 'Page2' => [
+ 'type' => 'title',
'name' => 'page2',
'label-message' => 'compare-page2',
'size' => '40',
'section' => 'page2',
- 'validation-callback' => array( $this, 'checkExistingTitle' ),
- ),
- 'Revision2' => array(
+ 'validation-callback' => [ $this, 'checkExistingTitle' ],
+ ],
+ 'Revision2' => [
'type' => 'int',
'name' => 'rev2',
'label-message' => 'compare-rev2',
'size' => '8',
'section' => 'page2',
- 'validation-callback' => array( $this, 'checkExistingRevision' ),
- ),
- 'Action' => array(
+ 'validation-callback' => [ $this, 'checkExistingRevision' ],
+ ],
+ 'Action' => [
'type' => 'hidden',
'name' => 'action',
- ),
- 'Diffonly' => array(
+ ],
+ 'Diffonly' => [
'type' => 'hidden',
'name' => 'diffonly',
- ),
- 'Unhide' => array(
+ ],
+ 'Unhide' => [
'type' => 'hidden',
'name' => 'unhide',
- ),
- ), $this->getContext(), 'compare' );
+ ],
+ ], $this->getContext(), 'compare' );
$form->setSubmitTextMsg( 'compare-submit' );
$form->suppressReset();
$form->setMethod( 'get' );
- $form->setSubmitCallback( array( __CLASS__, 'showDiff' ) );
+ $form->setSubmitCallback( [ __CLASS__, 'showDiff' ] );
$form->loadData();
$form->displayForm( '' );
$form->trySubmit();
}
- public static function showDiff( $data, HTMLForm $form ){
+ public static function showDiff( $data, HTMLForm $form ) {
$rev1 = self::revOrTitle( $data['Revision1'], $data['Page1'] );
$rev2 = self::revOrTitle( $data['Revision2'], $data['Page2'] );
- if( $rev1 && $rev2 ) {
- $contentHandler = ContentHandler::getForModelID( $rev1->getContentModel() );
- $de = $contentHandler->createDifferenceEngine( $form->getContext(),
- $rev1,
- $rev2,
- null, // rcid
- ( $data['Action'] == 'purge' ),
- ( $data['Unhide'] == '1' )
- );
- $de->showDiffPage( true );
+ if ( $rev1 && $rev2 ) {
+ $revision = Revision::newFromId( $rev1 );
+
+ if ( $revision ) { // NOTE: $rev1 was already checked, should exist.
+ $contentHandler = $revision->getContentHandler();
+ $de = $contentHandler->createDifferenceEngine( $form->getContext(),
+ $rev1,
+ $rev2,
+ null, // rcid
+ ( $data['Action'] == 'purge' ),
+ ( $data['Unhide'] == '1' )
+ );
+ $de->showDiffPage( true );
+ }
}
}
public static function revOrTitle( $revision, $title ) {
- if( $revision ){
+ if ( $revision ) {
return $revision;
- } elseif( $title ) {
+ } elseif ( $title ) {
$title = Title::newFromText( $title );
- if( $title instanceof Title ){
+ if ( $title instanceof Title ) {
return $title->getLatestRevID();
}
}
+
return null;
}
if ( !$title->exists() ) {
return $this->msg( 'compare-title-not-exists' )->parseAsBlock();
}
+
return true;
}
if ( $revision === null ) {
return $this->msg( 'compare-revision-not-exists' )->parseAsBlock();
}
+
return true;
}
+
+ protected function getGroupName() {
+ return 'pagetools';
+ }
}