r52015 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r52014‎ | r52015 | r52016 >
Date:23:57, 16 June 2009
Author:dale
Status:deferred (Comments)
Tags:
Comment:
fixed user login link
Modified paths:
  • /trunk/extensions/MetavidWiki/includes/MV_MetavidInterface/MV_EditPageAjax.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MetavidWiki/includes/MV_MetavidInterface/MV_EditPageAjax.php
@@ -4,28 +4,28 @@
55 *
66 * All Metavid Wiki code is Released Under the GPL2
77 * for more info visit http://metavid.org/wiki/Code
8 - *
9 - *
 8+ *
 9+ *
1010 * The metavid interface class
1111 * provides the metavid interface for Metavid: requests
1212 * provides the base metadata
13 - *
 13+ *
1414 */
1515 if ( !defined( 'MEDIAWIKI' ) ) die( 1 );
1616 /* very similar to showEditForm in EditPage
1717 * differences include:
18 - * ajax type display request and processing
19 - * display type based on mvTitle info
 18+ * ajax type display request and processing
 19+ * display type based on mvTitle info
2020 */
21 -
 21+
2222 class MV_EditPageAjax extends EditPage {
2323 var $adj_html = '';
2424 var $basic_html = '';
25 -
 25+
2626 function __construct( $article ) {
2727 $this->mArticle =& $article;
2828 $this->mTitle =& $article->mTitle;
29 -
 29+
3030 // print "article content: " . $this->mArticle->getContent();
3131 # Placeholders for text injection by hooks (empty per default)
3232 $this->editFormPageTop =
@@ -35,22 +35,22 @@
3636 $this->editFormTextBottom = "";
3737 }
3838 function do_pre_annoEdit() {
39 -
 39+
4040 }
4141 function getAjaxForm() {
4242 global $wgUser;
43 - return '<form id="mvd_form_' . $this->mvd_id . '" name="mvd_form_' . $this->mvd_id . '" method="GET" action=""
 43+ return '<form id="mvd_form_' . $this->mvd_id . '" name="mvd_form_' . $this->mvd_id . '" method="GET" action=""
4444 onSubmit="mv_do_ajax_form_submit(\'' . $this->mvd_id . '\', \'save\'); return false;" ' .
4545 'enctype="multipart/form-data" >' .
4646 '<input type="hidden" name="fname" value="mv_edit_submit">' .
47 - // do the normal edit hidden fields:
 47+ // do the normal edit hidden fields:
4848 "\n" . '<input type="hidden" value="' . htmlspecialchars( $wgUser->editToken() ) .
4949 '" name="wpEditToken" />' . "\n" .
5050 '<input type="hidden" name="title" value="' . $this->mTitle->getDBkey() . '">' . "\n" .
5151 '<input type="hidden" name="mvd_id" value="' . $this->mvd_id . '">' . "\n";
5252 }
5353 function loadEditText() {
54 - // get the article text if it exists
 54+ // get the article text if it exists
5555 if ( $this->mArticle->mTitle->exists() ) {
5656 $this->stripped_edit_text = $this->mArticle->getContent();
5757 } else {
@@ -61,31 +61,31 @@
6262 function do_pre_htEdit() {
6363 global $wgOut, $wgUser;
6464 $this->loadEditText();
65 -
 65+
6666 $MvOverlay = new MV_Overlay();
6767 // strip semantic tags which are managed by the interface:
6868 $semantic_data = $MvOverlay->get_and_strip_semantic_tags( $this->stripped_edit_text );
6969 $out = $js_eval = '';
70 - // add a div for previews:
 70+ // add a div for previews:
7171 $wgOut->addHTML( '<div id="wikiPreview_' . $this->mvd_id . '"></div>' );
72 -
73 - // set the default action so save page:
 72+
 73+ // set the default action so save page:
7474 $wgOut->addHTML( $this->getAjaxForm() );
75 -
76 - // add in adjust html if present:
 75+
 76+ // add in adjust html if present:
7777 $wgOut->addHTML( $this->adj_html );
78 -
79 - // structure layout via tables (@@todo switch to class based css layout)
 78+
 79+ // structure layout via tables (@@todo switch to class based css layout)
8080 $wgOut->addHTML( '<table style="background: transparent;" width="100%"><tr><td valign="top" width="90">' );
8181 // output the person selector:
8282 if ( !isset ( $semantic_data['spoken_by'] ) )$semantic_data['spoken_by'] = '';
8383 $img = mv_get_person_img( $semantic_data['spoken_by'] );
8484 $wgOut->addHTML( '<img id="mv_edit_im_' . htmlspecialchars( $this->mvd_id ) . '" style="display: block;margin-left: auto;margin-right: auto;" src="' . htmlspecialchars( $img->getURL() ) . '" width="44">' );
85 - $wgOut->addHTML( '<input style="font-size:x-small"
86 - value="' . htmlspecialchars( $semantic_data['spoken_by'] ) . '"
 85+ $wgOut->addHTML( '<input style="font-size:x-small"
 86+ value="' . htmlspecialchars( $semantic_data['spoken_by'] ) . '"
8787 name="smw_Spoken_By"
88 - onClick="this.value=\'\';"
89 - type="text" id="auto_comp_' . htmlspecialchars( $this->mvd_id ) . '" size="12"
 88+ onClick="this.value=\'\';"
 89+ type="text" id="auto_comp_' . htmlspecialchars( $this->mvd_id ) . '" size="12"
9090 maxlength="125" autocomplete="off"/>' );
9191 // only add one auto_comp_choices_ per object/request pass
9292 if ( !isset( $this->auto_comp_choices ) ) {
@@ -149,19 +149,19 @@
150150 // limt rows for ajax:
151151 $non_ajax_rows = $wgUser->getIntOption( 'rows' );
152152 $wgUser->setOption( 'rows', 5 );
153 -
 153+
154154 $sk = $wgUser->getSkin();
155155 $cancel = '<a href="javascript:mv_disp_mvd(\'' . $this->mTitle->getDBkey() . '\',\'' .
156156 $this->mvd_id . '\');">' . wfMsgExt( 'cancel', array( 'parseinline' ) ) . '</a>';
157 -
 157+
158158 // get the stream parent:
159159 $mvd = MV_Index::getMVDbyId( $this->mvd_id );
160160 $stream_name = MV_Stream::getStreamNameFromId( $mvd->stream_id );
161 -
 161+
162162 $lTitle = Title::makeTitle( NS_SPECIAL, 'Userlogin' );
163 - $loginLink = $lTitle->getFullURL('returnto=' . MWNamespace::getCanonicalName( MV_NS_STREAM ) . ':' . $stream_name );
164 -
165 - $wgOut->addHTML( wfMsg( 'mv_user_cant_edit', $loginLink, $cancel ) );
 163+ $loginLink = $lTitle->getFullURL('returnto=' . MWNamespace::getCanonicalName( MV_NS_STREAM ) . ':' . $stream_name );
 164+
 165+ $wgOut->addWikiText( wfMsg( 'mv_user_cant_edit', $loginLink, $cancel ) );
166166 $wgOut->readOnlyPage( $this->mArticle->getContent(), true, $permErrors );
167167 $wgUser->setOption( 'rows', $non_ajax_rows );
168168 wfProfileOut( $fname );
@@ -215,7 +215,7 @@
216216 # Show applicable editing introductions
217217 if ( $this->formtype == 'initial' || $this->firsttime )
218218 $this->showIntro();
219 -
 219+
220220 if ( $this->mTitle->isTalkPage() ) {
221221 $wgOut->addWikiText( wfMsg( 'talkpagetext' ) );
222222 }
@@ -225,9 +225,9 @@
226226 # that edit() already checked just in case someone tries to sneak
227227 # in the back door with a hand-edited submission URL.
228228
229 - // set up commit transaction
 229+ // set up commit transaction
230230 // $dbw = wfGetDB( DB_MASTER );
231 - // $dbw->begin();
 231+ // $dbw->begin();
232232
233233 if ( 'save' == $this->formtype ) {
234234 if ( !$this->attemptSave() ) {
@@ -236,7 +236,7 @@
237237 return;
238238 }
239239 }
240 -
 240+
241241 // $dbw->immediateCommit();
242242
243243 # First time through: get contents, set time for conflict
@@ -256,7 +256,7 @@
257257 wfProfileOut( "$fname-business-end" );
258258 wfProfileOut( $fname );
259259 }
260 - /********would not have to override if they where not "private" functions
 260+ /********would not have to override if they where not "private" functions
261261 /**
262262 * Should we show a preview when the edit form is first shown?
263263 *
@@ -323,7 +323,7 @@
324324 }
325325 function do_post_HtEdit() {
326326 global $wgOut;
327 - /*"<textarea name=\"wpTextbox{$mvd_id}\"
 327+ /*"<textarea name=\"wpTextbox{$mvd_id}\"
328328 id=\"wpTextbox{$this->mvd_id}\" rows='3'
329329 cols=\"50\" >$text
330330 </textarea>"*/
@@ -348,7 +348,7 @@
349349 }
350350 function internalAttemptSave( &$result, $bot = false ) {
351351 global $wgHooks;
352 - // clear confirmEdit for ajax edits:
 352+ // clear confirmEdit for ajax edits:
353353 if ( isset( $wgHooks['EditFilter'] ) ) {
354354 foreach ( $wgHooks['EditFilter'] as $k => $hook ) {
355355 unset( $wgHooks['EditFilter'][$k] );
@@ -358,13 +358,13 @@
359359 }
360360 function showEditForm( $formCallback = null ) {
361361 global $wgOut, $wgUser, $wgLang, $wgContLang, $wgMaxArticleSize;
362 -
 362+
363363 // print "call SHOW EDIT FORM";
364364 if ( !isset( $this->stripped_edit_text ) )$this->stripped_edit_text = '';
365 -
 365+
366366 $fname = 'EditPageAjax::showEditForm';
367367 wfProfileIn( $fname );
368 -
 368+
369369 $closeFormHtml = '';
370370 // check if we are in the MVD namespace (and need to use templates for edits:)
371371 if ( $this->mTitle->getNamespace() == MV_NS_MVD ) {
@@ -374,7 +374,7 @@
375375 }
376376 $editFormType = strtolower( $this->mvTitle->getMvdTypeKey() );
377377 } else {
378 - // check if its seq type:
 378+ // check if its seq type:
379379 if ( $this->mvd_id == 'seq' ) {
380380 $editFormType = 'seq';
381381 } else {
@@ -388,9 +388,9 @@
389389 break;
390390 case 'anno_en':
391391 $this->loadEditText();
392 - // set the default action so save page:
 392+ // set the default action so save page:
393393 $wgOut->addHTML( $this->getAjaxForm() );
394 - // add in adjust html if present:
 394+ // add in adjust html if present:
395395 $wgOut->addHTML( $this->adj_html );
396396 break;
397397 case 'seq':
@@ -404,7 +404,7 @@
405405 break;
406406 default:
407407 $this->loadEditText();
408 - // set the default action so save page:
 408+ // set the default action so save page:
409409 $wgOut->addHTML( $this->getAjaxForm() );
410410 break;
411411 }
@@ -535,7 +535,7 @@
536536 if ( $this->formtype == 'preview' ) {
537537 $previewOutput = $this->getPreviewText();
538538 }
539 -
 539+
540540 if ( $wgUser->getOption( 'previewontop' ) ) {
541541
542542 if ( 'preview' == $this->formtype ) {
@@ -550,7 +550,7 @@
551551 }
552552 $wgOut->addHTML( $this->basic_html );
553553 $wgOut->addHTML( '<div style="display:inline" class="mv_advanced_edit"><br>' );
554 -
 554+
555555 // $rows = $wgUser->getIntOption( 'rows' );
556556 // $cols = $wgUser->getIntOption( 'cols' );
557557 // for ajax short edit area:
@@ -560,7 +560,7 @@
561561 $ew = $wgUser->getOption( 'editwidth' );
562562 if ( $ew ) $ew = " style=\"width:100%\"";
563563 else $ew = '';
564 -
 564+
565565 // do ajax action:
566566 // $q = 'action=ajax';
567567 # if ( "no" == $redirect ) { $q .= "&redirect=no"; }
@@ -582,7 +582,7 @@
583583 $this->mvd_id . '\');">' . wfMsgExt( 'cancel', array( 'parseinline' ) ) . '</a>';
584584 $edithelpurl = Skin::makeInternalOrExternalUrl( wfMsgForContent( 'edithelppage' ) );
585585 }
586 -
 586+
587587 $edithelp = '<a target="helpwindow" href="' . $edithelpurl . '">' .
588588 htmlspecialchars( wfMsg( 'edithelp' ) ) . '</a> ' .
589589 htmlspecialchars( wfMsg( 'newwindow' ) );
@@ -594,7 +594,7 @@
595595 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]',
596596 $wgRightsText ) . "\n</div>";
597597 */
598 -
 598+
599599 if ( $wgUser->getOption( 'showtoolbar' ) and !$this->isCssJsSubpage ) {
600600 # prepare toolbar for edit buttons
601601 $toolbar = EditPage::getEditToolbar();
@@ -641,7 +641,7 @@
642642 /*if( !$this->preview && !$this->diff ) {
643643 $wgOut->setOnloadHandler( 'document.editform.wpTextbox1.focus()' );
644644 }*/
645 -
 645+
646646 $templates = ( $this->preview || $this->section != '' ) ? $this->mPreviewTemplates : $this->mArticle->getUsedTemplates();
647647 $formattedtemplates = $sk->formatTemplates( $templates, $this->preview, $this->section != '' );
648648
@@ -677,9 +677,9 @@
678678 array( 'minor' => $this->minoredit, 'watch' => $this->watchthis ) );
679679
680680 $checkboxhtml = implode( $checkboxes, "\n" );
681 -
 681+
682682 $button_action = 'mv_do_ajax_form_submit(\'' . $this->mvd_id . '\', \'%s\');';
683 -
 683+
684684 $buttons = $this->getEditButtons( $tabindex , $button_action );
685685 $buttonshtml = implode( $buttons, "\n" );
686686
@@ -717,7 +717,7 @@
718718 "
719719 </textarea>
720720 " );
721 -
 721+
722722 // close advanced display_edit div
723723 $wgOut->addHTML( "</div>" );
724724
@@ -836,10 +836,10 @@
837837 );
838838 if ( $this->mvd_id == 'seq' )
839839 $temp['value'] = wfMsg( 'mv_save_sequence' );
840 -
 840+
841841 if ( $button_action != '' )
842842 $temp['onMouseUp'] = sprintf( $button_action, 'save' );
843 -
 843+
844844 $buttons['save'] = Xml::element( 'input', $temp, '' );
845845
846846 ++$tabindex; // use the same for preview and live preview
@@ -883,7 +883,7 @@
884884 );
885885 if ( $button_action != '' )
886886 $temp['onMouseUp'] = sprintf( $button_action, 'preview' );
887 -
 887+
888888 $buttons['preview'] = Xml::element( 'input', $temp, '' );
889889 $buttons['live'] = '';
890890 }

Comments

#Comment by Nikerabbit (talk | contribs)   05:46, 17 June 2009
'<input type="hidden" name="title" value="' . $this->mTitle->getDBkey() . '">' . "\n" .

Looks like many kinds of titles will create invalid html.

+ $wgOut->addWikiText( wfMsg( 'mv_user_cant_edit', $loginLink, $cancel ) );

addWikiText + wfMsg is not a good combination - OutputPage::addWikiMsg is better

Shouldn't you fix up all the whitespace in separate commit... lots of only whitespace differences with other changes makes the diff hard to read.

#Comment by Mdale (talk | contribs)   06:16, 17 June 2009

true ... not sure how/why the whitespace issue creep in there..

there is a lot of $wgOut->addWikiText( wfMsg( out in the wild but makes sense to use addWikiMsg instead

the title can / should only be in the MVD namespace that has a "valid and not valid" format checker since it includes temporal time data.

~~ most of this code will be replaced with api calls and javascript based interface (so won't have time to make it perfect) ~

Status & tagging log