MediaWiki  REL1_19
SpecialComparePages.php
Go to the documentation of this file.
00001 <?php
00031 class SpecialComparePages extends SpecialPage {
00032 
00033         // Stored objects
00034         protected $opts, $skin;
00035 
00036         // Some internal settings
00037         protected $showNavigation = false;
00038 
00039         public function __construct() {
00040                 parent::__construct( 'ComparePages' );
00041         }
00042 
00049         public function execute( $par ) {
00050                 $this->setHeaders();
00051                 $this->outputHeader();
00052 
00053                 $form = new HTMLForm( array(
00054                         'Page1' => array(
00055                                 'type' => 'text',
00056                                 'name' => 'page1',
00057                                 'label-message' => 'compare-page1',
00058                                 'size' => '40',
00059                                 'section' => 'page1',
00060                                 'validation-callback' => array( $this, 'checkExistingTitle' ),
00061                         ),
00062                         'Revision1' => array(
00063                                 'type' => 'int',
00064                                 'name' => 'rev1',
00065                                 'label-message' => 'compare-rev1',
00066                                 'size' => '8',
00067                                 'section' => 'page1',
00068                                 'validation-callback' => array( $this, 'checkExistingRevision' ),
00069                         ),
00070                         'Page2' => array(
00071                                 'type' => 'text',
00072                                 'name' => 'page2',
00073                                 'label-message' => 'compare-page2',
00074                                 'size' => '40',
00075                                 'section' => 'page2',
00076                                 'validation-callback' => array( $this, 'checkExistingTitle' ),
00077                         ),
00078                         'Revision2' => array(
00079                                 'type' => 'int',
00080                                 'name' => 'rev2',
00081                                 'label-message' => 'compare-rev2',
00082                                 'size' => '8',
00083                                 'section' => 'page2',
00084                                 'validation-callback' => array( $this, 'checkExistingRevision' ),
00085                         ),
00086                         'Action' => array(
00087                                 'type' => 'hidden',
00088                                 'name' => 'action',
00089                         ),
00090                         'Diffonly' => array(
00091                                 'type' => 'hidden',
00092                                 'name' => 'diffonly',
00093                         ),
00094                         'Unhide' => array(
00095                                 'type' => 'hidden',
00096                                 'name' => 'unhide',
00097                         ),
00098                 ), $this->getContext(), 'compare' );
00099                 $form->setSubmitTextMsg( 'compare-submit' );
00100                 $form->suppressReset();
00101                 $form->setMethod( 'get' );
00102                 $form->setSubmitCallback( array( __CLASS__, 'showDiff' ) );
00103 
00104                 $form->loadData();
00105                 $form->displayForm( '' );
00106                 $form->trySubmit();
00107         }
00108 
00109         public static function showDiff( $data, HTMLForm $form ){
00110                 $rev1 = self::revOrTitle( $data['Revision1'], $data['Page1'] );
00111                 $rev2 = self::revOrTitle( $data['Revision2'], $data['Page2'] );
00112 
00113                 if( $rev1 && $rev2 ) {
00114                         $de = new DifferenceEngine( $form->getContext(),
00115                                 $rev1,
00116                                 $rev2,
00117                                 null, // rcid
00118                                 ( $data['Action'] == 'purge' ),
00119                                 ( $data['Unhide'] == '1' )
00120                         );
00121                         $de->showDiffPage( true );
00122                 }
00123         }
00124 
00125         public static function revOrTitle( $revision, $title ) {
00126                 if( $revision ){
00127                         return $revision;
00128                 } elseif( $title ) {
00129                         $title = Title::newFromText( $title );
00130                         if( $title instanceof Title ){
00131                                 return $title->getLatestRevID();
00132                         }
00133                 }
00134                 return null;
00135         }
00136 
00137         public function checkExistingTitle( $value, $alldata ) {
00138                 if ( $value === '' || $value === null ) {
00139                         return true;
00140                 }
00141                 $title = Title::newFromText( $value );
00142                 if ( !$title instanceof Title ) {
00143                         return $this->msg( 'compare-invalid-title' )->parseAsBlock();
00144                 }
00145                 if ( !$title->exists() ) {
00146                         return $this->msg( 'compare-title-not-exists' )->parseAsBlock();
00147                 }
00148                 return true;
00149         }
00150 
00151         public function checkExistingRevision( $value, $alldata ) {
00152                 if ( $value === '' || $value === null ) {
00153                         return true;
00154                 }
00155                 $revision = Revision::newFromId( $value );
00156                 if ( $revision === null ) {
00157                         return $this->msg( 'compare-revision-not-exists' )->parseAsBlock();
00158                 }
00159                 return true;
00160         }
00161 }