(bug 23621) New Special:ComparePages to compare (diff) two articles.
authorDerk-Jan Hartman <hartman@users.mediawiki.org>
Sat, 19 Jun 2010 21:17:42 +0000 (21:17 +0000)
committerDerk-Jan Hartman <hartman@users.mediawiki.org>
Sat, 19 Jun 2010 21:17:42 +0000 (21:17 +0000)
RELEASE-NOTES
includes/AutoLoader.php
includes/DefaultSettings.php
includes/SpecialPage.php
includes/specials/SpecialComparePages.php [new file with mode: 0644]
languages/messages/MessagesEn.php
languages/messages/MessagesQqq.php
maintenance/language/messages.inc

index 2b5359c..b7ebb14 100644 (file)
@@ -83,6 +83,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * Show validity period of the login cookie in Special:UserLogin and
   Special:Preferences
 * Interlanguage links display the page title in their tooltip.
+* (bug 23621) New Special:ComparePages to compare (diff) two articles.
 
 === Bug fixes in 1.17 ===
 * (bug 17560) Half-broken deletion moved image files to deletion archive
index 1893cd9..312f20a 100644 (file)
@@ -577,6 +577,7 @@ $wgAutoloadLocalClasses = array(
        'SpecialAllpages' => 'includes/specials/SpecialAllpages.php',
        'SpecialBlankpage' => 'includes/specials/SpecialBlankpage.php',
        'SpecialBookSources' => 'includes/specials/SpecialBooksources.php',
+       'SpecialComparePages' => 'includes/specials/SpecialComparePages.php',
        'SpecialExport' => 'includes/specials/SpecialExport.php',
        'SpecialImport' => 'includes/specials/SpecialImport.php',
        'SpecialListGroupRights' => 'includes/specials/SpecialListgrouprights.php',
index 392191b..2bc8f6a 100644 (file)
@@ -4635,6 +4635,7 @@ $wgSpecialPageGroups = array(
        'Search'                    => 'redirects',
        'LinkSearch'                => 'redirects',
 
+       'ComparePages'              => 'pagetools',
        'Movepage'                  => 'pagetools',
        'MergeHistory'              => 'pagetools',
        'Revisiondelete'            => 'pagetools',
index af12432..1cfbc18 100644 (file)
@@ -169,6 +169,7 @@ class SpecialPage {
                'Mostrevisions'             => array( 'SpecialPage', 'Mostrevisions' ),
 
                # Page tools
+               'ComparePages'              => 'SpecialComparePages',
                'Export'                    => 'SpecialExport',
                'Import'                    => 'SpecialImport',
                'Undelete'                  => 'UndeleteForm',
diff --git a/includes/specials/SpecialComparePages.php b/includes/specials/SpecialComparePages.php
new file mode 100644 (file)
index 0000000..e91f265
--- /dev/null
@@ -0,0 +1,150 @@
+<?php
+
+/**
+ * implements Special:ComparePages
+ * @ingroup SpecialPage
+ */
+class SpecialComparePages extends SpecialPage {
+
+       // Stored objects
+       protected $opts, $skin;
+
+       // Some internal settings
+       protected $showNavigation = false;
+
+       public function __construct() {
+               parent::__construct( 'ComparePages' );
+               $this->includable( false );     
+       }
+
+       protected function setup( $par ) {
+               global $wgRequest, $wgUser, $wgEnableNewpagesUserFilter;
+
+               // Options
+               $opts = new FormOptions();
+               $this->opts = $opts; // bind
+               $opts->add( 'page1', '' );
+               $opts->add( 'page2', '' );
+               $opts->add( 'rev1', '' );
+               $opts->add( 'rev2', '' );
+               $opts->add( 'action', '' );
+               $opts->add( 'diffonly', '' );
+
+               // Set values
+               $opts->fetchValuesFromRequest( $wgRequest );
+
+               $title1 = Title::newFromText( $opts->getValue( 'page1' ) );
+               $title2 = Title::newFromText( $opts->getValue( 'page2' ) );
+
+               if( $title1 && $title1->exists() && $opts->getValue( 'rev1' ) == '' ) {
+                       $pda = new Article( $title1 );
+                       $pdi = $pda->getID();
+                               $pdLastRevision = Revision::loadFromPageId( wfGetDB( DB_SLAVE ), $pdi );
+                       $opts->setValue('rev1', $pdLastRevision->getId() );
+               } elseif ( $opts->getValue( 'rev1' ) != '' ) {
+                       $pdrev = Revision::newFromId( $opts->getValue( 'rev1' ) );
+                       if( $pdrev ) $opts->setValue( 'page1', $pdrev->getTitle()->getPrefixedDBkey() );
+               }
+               if( $title2 && $title2->exists() && $opts->getValue( 'rev2' ) == '' ) {
+                       $pda = new Article( $title2 );
+                       $pdi = $pda->getID();
+                               $pdLastRevision = Revision::loadFromPageId( wfGetDB( DB_SLAVE ), $pdi );
+                       $opts->setValue('rev2', $pdLastRevision->getId() );
+               } elseif ( $opts->getValue( 'rev2' ) != '' ) {
+                       $pdrev = Revision::newFromId( $opts->getValue( 'rev2' ) );
+                       if( $pdrev ) $opts->setValue( 'page2', $pdrev->getTitle()->getPrefixedDBkey() );
+               }
+
+               // Store some objects
+               $this->skin = $wgUser->getSkin();
+       }
+
+       /**
+        * Show a form for filtering namespace and username
+        *
+        * @param $par String
+        * @return String
+        */
+       public function execute( $par ) {
+               global $wgLang, $wgOut;
+
+               $this->setHeaders();
+               $this->outputHeader();
+
+               $this->setup( $par );
+
+               // Settings
+               $this->form();
+
+               if( $this->opts->getValue( 'rev1' ) && $this->opts->getValue( 'rev2' ) ) {
+                       $de = new DifferenceEngine( null, 
+                               $this->opts->getValue( 'rev1' ),
+                               $this->opts->getValue( 'rev2' ),
+                               null, // rcid
+                               ($this->opts->getValue( 'action') == "purge" ? true : false ),
+                               false );
+                       $de->showDiffPage( (bool)$this->opts->getValue( 'diffonly' ) );
+               }
+       }
+
+       protected function form() {
+               global $wgOut, $wgScript;
+
+               // Consume values
+               $page1 = $this->opts->consumeValue( 'page1' );
+               $page2 = $this->opts->consumeValue( 'page2' );
+               $rev1 = $this->opts->consumeValue( 'rev1' );
+               $rev2 = $this->opts->consumeValue( 'rev2' );
+
+               // Store query values in hidden fields so that form submission doesn't lose them
+               $hidden = array();
+               foreach ( $this->opts->getUnconsumedValues() as $key => $value ) {
+                       $hidden[] = Xml::hidden( $key, $value );
+               }
+               $hidden = implode( "\n", $hidden );
+
+               $form = Xml::openElement( 'form', array( 'action' => $wgScript ) ) .
+                       Xml::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) .
+                       Xml::fieldset( wfMsg( 'compare-selector') ) .
+                       Xml::openElement( 'table', array( 'id' => 'mw-diff-table', 'width' => '100%' ) ) .
+                       "<tr>
+                               <td class='mw-label' width='10%'>" .
+                                       Xml::label( wfMsg( 'compare-page1' ), 'page1' ) .
+                               "</td>
+                               <td class='mw-input' width='40%'>" .
+                                       Xml::input( 'page1', 40, $page1, array( 'type' => 'text' ) ) .
+                               "</td>
+                               <td class='mw-label' width='10%'>" .
+                                       Xml::label( wfMsg( 'compare-page2' ), 'page2' ) .
+                               "</td>
+                               <td class='mw-input' width='40%'>" .
+                                       Xml::input( 'page2', 40, $page2, array( 'type' => 'text' ) ) .
+                               "</td>
+                       </tr>" . 
+                       "<tr>
+                               <td class='mw-label'>" .
+                                       Xml::label( wfMsg( 'compare-rev1' ), 'rev1' ) .
+                               "</td>
+                               <td class='mw-input'>" .
+                                       Xml::input( 'rev1', 8, $rev1, array( 'type' => 'text' ) ) .
+                               "</td>
+                               <td class='mw-label'>" .
+                                       Xml::label( wfMsg( 'compare-rev2' ), 'rev2' ) .
+                               "</td>
+                               <td class='mw-input'>" .
+                                       Xml::input( 'rev2', 8, $rev2, array( 'type' => 'text' ) ) .
+                               "</td>
+                       </tr>" . 
+                       "<tr> <td></td>
+                               <td class='mw-submit' colspan='3'>" .
+                                       Xml::submitButton( wfMsg( 'compare-submit') ) .
+                               "</td>
+                       </tr>" .
+                       Xml::closeElement( 'table' ) .
+                       Xml::closeElement( 'fieldset' ) .
+                       $hidden .
+                       Xml::closeElement( 'form' );
+
+               $wgOut->addHTML( $form );
+       }
+}
index 7ed5af8..610736f 100644 (file)
@@ -457,6 +457,7 @@ $specialPageAliases = array(
        'Tags'                      => array( 'Tags' ),
        'Activeusers'               => array( 'ActiveUsers' ),
        'RevisionMove'              => array( 'RevisionMove' ),
+       'ComparePages'              => array( 'ComparePages' ),
 );
 
 /**
@@ -4286,6 +4287,15 @@ Enter the filename without the "{{ns:file}}:" prefix.',
 'tags-edit'               => 'edit',
 'tags-hitcount'           => '$1 {{PLURAL:$1|change|changes}}',
 
+# Special:ComparePAges
+'comparepages'      => 'Compare pages',
+'compare-selector'  => 'Compare page revisions',
+'compare-page1'     => 'Page 1',
+'compare-page2'     => 'Page 2',
+'compare-rev1'      => 'Revision 1',
+'compare-rev2'      => 'Revision 2',
+'compare-submit'    => 'Compare',
+
 # Database error messages
 'dberr-header'      => 'This wiki has a problem',
 'dberr-problems'    => 'Sorry!
index ca57b5c..46d3e98 100644 (file)
@@ -3613,6 +3613,15 @@ Used on [[Special:Tags]]. Verb. Used as display text on a link to create/edit a
 
 * <code>$1</code> is the number of changes marked with the tag',
 
+# Special:ComparePages
+'comparepages'            => 'The title of [[Special:ComparePages]]',
+'compare-selector'        => 'Header of the form on [[Special:ComparePages]]',
+'compare-page1'           => 'Label for the field of the 1st page in the comparison for [[Special:ComparePages]]',
+'compare-page2'           => 'Label for the field of the 2nd page in the comparison for [[Special:ComparePages]]',
+'compare-rev1'            => 'Label for the field of the 1st revision in the comparison for [[Special:ComparePages]]',
+'compare-rev2'            => 'Label for the field of the 2nd revision in the comparison for [[Special:ComparePages]]',
+'compare-submit'          => 'Submit button on [[Special:ComparePages]]',
+
 # Database error messages
 'dberr-header'    => 'This message does not allow any wiki nor html markup.',
 'dberr-problems'  => 'This message does not allow any wiki nor html markup.',
index d32269e..dd0a616 100644 (file)
@@ -3207,6 +3207,15 @@ $wgMessageStructure = array(
                'ajax-error-dismiss',
                'ajax-remove-category-error',
        ),
+       'comparepages' => array(
+               'comparepages'.
+               'compare-selector',
+               'compare-page1',
+               'compare-page2',
+               'compare-rev1',
+               'compare-rev2',
+               'compare-submit',
+       ),
 );
 
 /** Comments for each block */
@@ -3417,4 +3426,5 @@ Variants for Chinese language",
        'db-error-messages'     => 'Database error messages',
        'html-forms'            => 'HTML forms',
        'ajax-category'         => 'Add categories per AJAX',
+       'comparepages'          => 'Special:ComparePages',
 );