9f53fd4f2f11c9cba4d5a051f20a845ed10a9c7b
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 * http://www.gnu.org/copyleft/gpl.html
21 * implements Special:ComparePages
22 * @ingroup SpecialPage
24 class SpecialComparePages
extends SpecialPage
{
27 protected $opts, $skin;
29 // Some internal settings
30 protected $showNavigation = false;
32 public function __construct() {
33 parent
::__construct( 'ComparePages' );
34 $this->includable( false );
37 protected function setup( $par ) {
38 global $wgRequest, $wgUser, $wgEnableNewpagesUserFilter;
41 $opts = new FormOptions();
42 $this->opts
= $opts; // bind
43 $opts->add( 'page1', '' );
44 $opts->add( 'page2', '' );
45 $opts->add( 'rev1', '' );
46 $opts->add( 'rev2', '' );
47 $opts->add( 'action', '' );
48 $opts->add( 'diffonly', '' );
51 $opts->fetchValuesFromRequest( $wgRequest );
53 $title1 = Title
::newFromText( $opts->getValue( 'page1' ) );
54 $title2 = Title
::newFromText( $opts->getValue( 'page2' ) );
56 if( $title1 && $title1->exists() && $opts->getValue( 'rev1' ) == '' ) {
57 $pda = new Article( $title1 );
59 $pdLastRevision = Revision
::loadFromPageId( wfGetDB( DB_SLAVE
), $pdi );
60 $opts->setValue('rev1', $pdLastRevision->getId() );
61 } elseif ( $opts->getValue( 'rev1' ) != '' ) {
62 $pdrev = Revision
::newFromId( $opts->getValue( 'rev1' ) );
63 if( $pdrev ) $opts->setValue( 'page1', $pdrev->getTitle()->getPrefixedDBkey() );
65 if( $title2 && $title2->exists() && $opts->getValue( 'rev2' ) == '' ) {
66 $pda = new Article( $title2 );
68 $pdLastRevision = Revision
::loadFromPageId( wfGetDB( DB_SLAVE
), $pdi );
69 $opts->setValue('rev2', $pdLastRevision->getId() );
70 } elseif ( $opts->getValue( 'rev2' ) != '' ) {
71 $pdrev = Revision
::newFromId( $opts->getValue( 'rev2' ) );
72 if( $pdrev ) $opts->setValue( 'page2', $pdrev->getTitle()->getPrefixedDBkey() );
76 $this->skin
= $wgUser->getSkin();
80 * Show a form for filtering namespace and username
85 public function execute( $par ) {
86 global $wgLang, $wgOut;
89 $this->outputHeader();
96 if( $this->opts
->getValue( 'rev1' ) && $this->opts
->getValue( 'rev2' ) ) {
97 $de = new DifferenceEngine( null,
98 $this->opts
->getValue( 'rev1' ),
99 $this->opts
->getValue( 'rev2' ),
101 ($this->opts
->getValue( 'action') == "purge" ?
true : false ),
103 $de->showDiffPage( (bool)$this->opts
->getValue( 'diffonly' ) );
107 protected function form() {
108 global $wgOut, $wgScript;
111 $page1 = $this->opts
->consumeValue( 'page1' );
112 $page2 = $this->opts
->consumeValue( 'page2' );
113 $rev1 = $this->opts
->consumeValue( 'rev1' );
114 $rev2 = $this->opts
->consumeValue( 'rev2' );
116 // Store query values in hidden fields so that form submission doesn't lose them
118 foreach ( $this->opts
->getUnconsumedValues() as $key => $value ) {
119 $hidden[] = Xml
::hidden( $key, $value );
121 $hidden = implode( "\n", $hidden );
123 $form = Xml
::openElement( 'form', array( 'action' => $wgScript ) ) .
124 Xml
::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) .
125 Xml
::fieldset( wfMsg( 'compare-selector') ) .
126 Xml
::openElement( 'table', array( 'id' => 'mw-diff-table', 'width' => '100%' ) ) .
128 <td class='mw-label' width='10%'>" .
129 Xml
::label( wfMsg( 'compare-page1' ), 'page1' ) .
131 <td class='mw-input' width='40%'>" .
132 Xml
::input( 'page1', 40, $page1, array( 'type' => 'text' ) ) .
134 <td class='mw-label' width='10%'>" .
135 Xml
::label( wfMsg( 'compare-page2' ), 'page2' ) .
137 <td class='mw-input' width='40%'>" .
138 Xml
::input( 'page2', 40, $page2, array( 'type' => 'text' ) ) .
142 <td class='mw-label'>" .
143 Xml
::label( wfMsg( 'compare-rev1' ), 'rev1' ) .
145 <td class='mw-input'>" .
146 Xml
::input( 'rev1', 8, $rev1, array( 'type' => 'text' ) ) .
148 <td class='mw-label'>" .
149 Xml
::label( wfMsg( 'compare-rev2' ), 'rev2' ) .
151 <td class='mw-input'>" .
152 Xml
::input( 'rev2', 8, $rev2, array( 'type' => 'text' ) ) .
156 <td class='mw-submit' colspan='3'>" .
157 Xml
::submitButton( wfMsg( 'compare-submit') ) .
160 Xml
::closeElement( 'table' ) .
161 Xml
::closeElement( 'fieldset' ) .
163 Xml
::closeElement( 'form' );
165 $wgOut->addHTML( $form );