r91969 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91968‎ | r91969 | r91970 >
Date:15:38, 12 July 2011
Author:ialex
Status:ok
Tags:
Comment:
* In EditPage.php: don't add the separator if getCancelLink() returns an empty string
* In TalkHere extension: override getCancelLink() instead of having mangleEditForm() hack
Modified paths:
  • /trunk/extensions/TalkHere/TalkHere.php (modified) (history)
  • /trunk/extensions/TalkHere/TalkHereHooks.php (modified) (history)
  • /trunk/phase3/includes/EditPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/EditPage.php
@@ -1924,12 +1924,14 @@
19251925 $wgOut->addHTML( implode( $this->getEditButtons( $tabindex ), "\n" ) . "\n" );
19261926
19271927 $cancel = $this->getCancelLink();
1928 - $separator = wfMsgExt( 'pipe-separator' , 'escapenoentities' );
 1928+ if ( $cancel !== '' ) {
 1929+ $cancel .= wfMsgExt( 'pipe-separator' , 'escapenoentities' );
 1930+ }
19291931 $edithelpurl = Skin::makeInternalOrExternalUrl( wfMsgForContent( 'edithelppage' ) );
19301932 $edithelp = '<a target="helpwindow" href="'.$edithelpurl.'">'.
19311933 htmlspecialchars( wfMsg( 'edithelp' ) ).'</a> '.
19321934 htmlspecialchars( wfMsg( 'newwindow' ) );
1933 - $wgOut->addHTML( " <span class='editHelp'>{$cancel}{$separator}{$edithelp}</span>\n" );
 1935+ $wgOut->addHTML( " <span class='editHelp'>{$cancel}{$edithelp}</span>\n" );
19341936 $wgOut->addHTML( "</div><!-- editButtons -->\n</div><!-- editOptions -->\n" );
19351937 }
19361938
Index: trunk/extensions/TalkHere/TalkHere.php
@@ -32,6 +32,7 @@
3333
3434 ///// hook it up /////////////////////////////////////////////////////
3535 $wgAutoloadClasses['TalkHereHooks'] = $dir . 'TalkHereHooks.php';
 36+$wgAutoloadClasses['TalkHereEditPage'] = $dir . 'TalkHereHooks.php';
3637
3738 $wgHooks['BeforePageDisplay'][] = 'TalkHereHooks::onBeforePageDisplay';
3839 $wgHooks['CustomEditor'][] = 'TalkHereHooks::onCustomEditor';
@@ -40,29 +41,11 @@
4142
4243 $wgAjaxExportList[] = 'wfTalkHereAjaxEditor';
4344
44 -function mangleEditForm( &$out, $returnto = false, $ajax = false ) { //HACK! too bad we need this :(
45 - global $wgUser;
46 - $sk = $wgUser->getSkin();
47 -
48 - $html = $out->getHTML();
49 -
50 - if ( $returnto ) { //re-target cancel link
51 - $cancel = $sk->makeLinkObj( Title::newFromText( $returnto ), wfMsgExt('cancel', array( 'parseinline' ) ) );
52 - $html = preg_replace( '!<a[^<>]+>[^<>]+</a>( *\| *<a target=["\']helpwindow["\'])!smi', $cancel . '\1', $html );
53 - }
54 - else {
55 - $html = preg_replace( '!<a[^<>]+>[^<>]+</a> *\| *(<a target=["\']helpwindow["\'])!smi', '\1', $html );
56 - }
57 -
58 - $out->clearHTML();
59 - $out->addHTML($html);
60 -}
61 -
6245 function wfTalkHereAjaxEditor( $page, $section, $returnto ) {
6346 global $wgRequest, $wgTitle, $wgOut;
6447
65 - $wgTitle = Title::newFromText( $page );
66 - if ( !$wgTitle ) {
 48+ $title = Title::newFromText( $page );
 49+ if ( !$title ) {
6750 return false;
6851 }
6952
@@ -75,15 +58,15 @@
7659 );
7760
7861 $wgRequest = new FauxRequest( $args );
79 - $article = MediaWiki::articleFromTitle( $wgTitle, RequestContext::getMain() );
80 - $editor = new EditPage( $article );
 62+ $wgTitle = $title;
8163
 64+ $article = MediaWiki::articleFromTitle( $title, RequestContext::getMain() );
 65+ $editor = new TalkHereEditPage( $article );
 66+
8267 //generate form
8368 $editor->importFormData( $wgRequest );
8469 $editor->showEditForm();
8570
86 - mangleEditForm( $wgOut, false, true ); //HACK. This sucks.
87 -
8871 $response = new AjaxResponse();
8972 $response->addText( $wgOut->getHTML() );
9073 $response->setCacheDuration( false ); //don't cache, because of tokens etc
Index: trunk/extensions/TalkHere/TalkHereHooks.php
@@ -279,6 +279,7 @@
280280
281281 //use a wrapper to override redirection target
282282 $editor = new TalkHereEditPage( $article );
 283+ $editor->setReturnTo( $to );
283284 $editor->submit();
284285 $code = $editor->getCode();
285286
@@ -288,7 +289,6 @@
289290 $wgOut->redirect( $to->getFullURL() . $editor->getAnchor() );
290291 }
291292
292 - mangleEditForm( $wgOut, $returnto ); //HACK. This sucks.
293293 return false;
294294 }
295295
@@ -315,7 +315,22 @@
316316 class TalkHereEditPage extends EditPage {
317317 private $code = 0;
318318 private $sectionanchor = '';
 319+ private $returnto;
319320
 321+ public function setReturnTo( $returnto ) {
 322+ $this->returnto = $returnto;
 323+ }
 324+
 325+ public function getCancelLink() {
 326+ global $wgUser;
 327+
 328+ if ( $this->returnto ) {
 329+ return $wgUser->getSkin()->link( $this->returnto, wfMsgExt('cancel', array( 'parseinline' ) ) );
 330+ } else {
 331+ return '';
 332+ }
 333+ }
 334+
320335 public function internalAttemptSave( &$result, $bot = false ) {
321336 $res = parent::internalAttemptSave( $result, $bot );
322337 $this->code = $res;

Status & tagging log