r40024 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r40023‎ | r40024 | r40025 >
Date:15:10, 26 August 2008
Author:demon
Status:old
Tags:
Comment:
Revert 40016, 40021, 40022. Breaks ability to save and has html entities problems.
Modified paths:
  • /trunk/phase3/includes/EditPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/EditPage.php
@@ -44,7 +44,6 @@
4545
4646 var $mArticle;
4747 var $mTitle;
48 - var $action;
4948 var $mMetaData = '';
5049 var $isConflict = false;
5150 var $isCssJsSubpage = false;
@@ -62,8 +61,7 @@
6362 var $allowBlankSummary = false;
6463 var $autoSumm = '';
6564 var $hookError = '';
66 - #var $mPreviewTemplates;
67 - var $mParserOutput;
 65+ var $mPreviewTemplates;
6866 var $mBaseRevision = false;
6967
7068 # Form values
@@ -94,7 +92,6 @@
9593 function EditPage( $article ) {
9694 $this->mArticle =& $article;
9795 $this->mTitle = $article->getTitle();
98 - $this->action = 'submit';
9996
10097 # Placeholders for text injection by hooks (empty per default)
10198 $this->editFormPageTop =
@@ -1062,29 +1059,6 @@
10631060 return true;
10641061 }
10651062
1066 - function setHeaders() {
1067 - global $wgOut, $wgTitle;
1068 - $wgOut->setRobotPolicy( 'noindex,nofollow' );
1069 - if ( $this->formtype == 'preview' ) {
1070 - $wgOut->setPageTitleActionText( wfMsg( 'preview' ) );
1071 - }
1072 - if ( $this->isConflict ) {
1073 - $wgOut->setPageTitle( wfMsg( 'editconflict', $wgTitle->getPrefixedText() ) );
1074 - } elseif( $this->section != '' ) {
1075 - $msg = $this->section == 'new' ? 'editingcomment' : 'editingsection';
1076 - $wgOut->setPageTitle( wfMsg( $msg, $wgTitle->getPrefixedText() ) );
1077 - } else {
1078 - # Use the title defined by DISPLAYTITLE magic word when present
1079 - if( isset($this->mParserOutput)
1080 - && ( $dt = $this->mParserOutput->getDisplayTitle() ) !== false ) {
1081 - $title = $dt;
1082 - } else {
1083 - $title = $wgTitle->getPrefixedText();
1084 - }
1085 - $wgOut->setPageTitle( wfMsg( 'editing', $title ) );
1086 - }
1087 - }
1088 -
10891063 /**
10901064 * Send the edit form and related headers to $wgOut
10911065 * @param $formCallback Optional callable that takes an OutputPage
@@ -1108,41 +1082,46 @@
11091083
11101084 wfRunHooks( 'EditPage::showEditForm:initial', array( &$this ) ) ;
11111085
1112 - #need to parse the preview early so that we know which templates are used,
1113 - #otherwise users with "show preview after edit box" will get a blank list
1114 - #we parse this near the beginning so that setHeaders can do the title
1115 - #setting work instead of leaving it in getPreviewText
1116 - $previewOutput = '';
1117 - if ( $this->formtype == 'preview' ) {
1118 - $previewOutput = $this->getPreviewText();
1119 - }
 1086+ $wgOut->setRobotPolicy( 'noindex,nofollow' );
11201087
1121 - $this->setHeaders();
1122 -
11231088 # Enabled article-related sidebar, toplinks, etc.
11241089 $wgOut->setArticleRelated( true );
11251090
 1091+ if ( $this->formtype == 'preview' ) {
 1092+ $wgOut->setPageTitleActionText( wfMsg( 'preview' ) );
 1093+ }
 1094+
11261095 if ( $this->isConflict ) {
 1096+ $s = wfMsg( 'editconflict', $wgTitle->getPrefixedText() );
 1097+ $wgOut->setPageTitle( $s );
11271098 $wgOut->addWikiMsg( 'explainconflict' );
11281099
11291100 $this->textbox2 = $this->textbox1;
11301101 $this->textbox1 = $this->getContent();
11311102 $this->edittime = $this->mArticle->getTimestamp();
11321103 } else {
1133 - if( $this->section != '' && $this->section != 'new' ) {
1134 - $matches = array();
1135 - if( !$this->summary && !$this->preview && !$this->diff ) {
1136 - preg_match( "/^(=+)(.+)\\1/mi",
1137 - $this->textbox1,
1138 - $matches );
1139 - if( !empty( $matches[2] ) ) {
1140 - global $wgParser;
1141 - $this->summary = "/* " .
1142 - $wgParser->stripSectionName(trim($matches[2])) .
1143 - " */ ";
 1104+ if( $this->section != '' ) {
 1105+ if( $this->section == 'new' ) {
 1106+ $s = wfMsg('editingcomment', $wgTitle->getPrefixedText() );
 1107+ } else {
 1108+ $s = wfMsg('editingsection', $wgTitle->getPrefixedText() );
 1109+ $matches = array();
 1110+ if( !$this->summary && !$this->preview && !$this->diff ) {
 1111+ preg_match( "/^(=+)(.+)\\1/mi",
 1112+ $this->textbox1,
 1113+ $matches );
 1114+ if( !empty( $matches[2] ) ) {
 1115+ global $wgParser;
 1116+ $this->summary = "/* " .
 1117+ $wgParser->stripSectionName(trim($matches[2])) .
 1118+ " */ ";
 1119+ }
11441120 }
11451121 }
 1122+ } else {
 1123+ $s = wfMsg( 'editing', $wgTitle->getPrefixedText() );
11461124 }
 1125+ $wgOut->setPageTitle( $s );
11471126
11481127 if ( $this->missingComment ) {
11491128 $wgOut->wrapWikiMsg( '<div id="mw-missingcommenttext">$1</div>', 'missingcommenttext' );
@@ -1238,7 +1217,20 @@
12391218 $wgOut->addHTML( "</div>\n" );
12401219 }
12411220
1242 - $q = 'action='.$this->action;
 1221+ #need to parse the preview early so that we know which templates are used,
 1222+ #otherwise users with "show preview after edit box" will get a blank list
 1223+ if ( $this->formtype == 'preview' ) {
 1224+ $previewOutput = $this->getPreviewText();
 1225+ }
 1226+
 1227+ $rows = $wgUser->getIntOption( 'rows' );
 1228+ $cols = $wgUser->getIntOption( 'cols' );
 1229+
 1230+ $ew = $wgUser->getOption( 'editwidth' );
 1231+ if ( $ew ) $ew = " style=\"width:100%\"";
 1232+ else $ew = '';
 1233+
 1234+ $q = 'action=submit';
12431235 #if ( "no" == $redirect ) { $q .= "&redirect=no"; }
12441236 $action = $wgTitle->escapeLocalURL( $q );
12451237
@@ -1290,9 +1282,16 @@
12911283 $wgOut->addHTML( $this->editFormPageTop );
12921284
12931285 if ( $wgUser->getOption( 'previewontop' ) ) {
1294 - $this->displayPreviewArea( $previewOutput );
1295 - // Spacer for the edit toolbar
1296 - $wgOut->addHTML( '<p><br /></p>' );
 1286+
 1287+ if ( 'preview' == $this->formtype ) {
 1288+ $this->showPreview( $previewOutput );
 1289+ } else {
 1290+ $wgOut->addHTML( '<div id="wikiPreview"></div>' );
 1291+ }
 1292+
 1293+ if ( 'diff' == $this->formtype ) {
 1294+ $this->showDiff();
 1295+ }
12971296 }
12981297
12991298
@@ -1331,7 +1330,7 @@
13321331 if( !$this->preview && !$this->diff ) {
13331332 $wgOut->setOnloadHandler( 'document.editform.wpTextbox1.focus()' );
13341333 }
1335 - $templates = $this->getTemplates();
 1334+ $templates = ($this->preview || $this->section != '') ? $this->mPreviewTemplates : $this->mArticle->getUsedTemplates();
13361335 $formattedtemplates = $sk->formatTemplates( $templates, $this->preview, $this->section != '');
13371336
13381337 $hiddencats = $this->mArticle->getHiddenCategories();
@@ -1342,15 +1341,11 @@
13431342 $metadata = $this->mMetaData ;
13441343 $metadata = htmlspecialchars( $wgContLang->recodeForEdit( $metadata ) ) ;
13451344 $top = wfMsgWikiHtml( 'metadata_help' );
1346 - /* ToDo: Replace with clean code */
1347 - $ew = $wgUser->getOption( 'editwidth' );
1348 - if ( $ew ) $ew = " style=\"width:100%\"";
1349 - else $ew = '';
1350 - /* /ToDo */
13511345 $metadata = $top . "<textarea name='metadata' rows='3' cols='{$cols}'{$ew}>{$metadata}</textarea>" ;
13521346 }
13531347 else $metadata = "" ;
13541348
 1349+ $hidden = '';
13551350 $recreate = '';
13561351 if ($this->wasDeletedSinceLastEdit()) {
13571352 if ( 'save' != $this->formtype ) {
@@ -1359,6 +1354,7 @@
13601355 // Hide the toolbar and edit area, use can click preview to get it back
13611356 // Add an confirmation checkbox and explanation.
13621357 $toolbar = '';
 1358+ $hidden = 'type="hidden" style="display:none;"';
13631359 $recreate = $wgOut->parse( wfMsg( 'confirmrecreate', $this->lastDelete->user_name , $this->lastDelete->log_comment ));
13641360 $recreate .=
13651361 "<br /><input tabindex='1' type='checkbox' value='1' name='wpRecreate' id='wpRecreate' />".
@@ -1392,27 +1388,40 @@
13931389 wfRunHooks( 'EditPage::showEditForm:fields', array( &$this, &$wgOut ) );
13941390
13951391 // Put these up at the top to ensure they aren't lost on early form submission
1396 - $this->showFormBeforeText();
 1392+ $wgOut->addHTML( "
 1393+<input type='hidden' value=\"" . htmlspecialchars( $this->section ) . "\" name=\"wpSection\" />
 1394+<input type='hidden' value=\"{$this->starttime}\" name=\"wpStarttime\" />\n
 1395+<input type='hidden' value=\"{$this->edittime}\" name=\"wpEdittime\" />\n
 1396+<input type='hidden' value=\"{$this->scrolltop}\" name=\"wpScrolltop\" id=\"wpScrolltop\" />\n" );
13971397
 1398+ $encodedtext = htmlspecialchars( $this->safeUnicodeOutput( $this->textbox1 ) );
 1399+ if( $encodedtext !== '' ) {
 1400+ // Ensure there's a newline at the end, otherwise adding lines
 1401+ // is awkward.
 1402+ // But don't add a newline if the ext is empty, or Firefox in XHTML
 1403+ // mode will show an extra newline. A bit annoying.
 1404+ $encodedtext .= "\n";
 1405+ }
 1406+
13981407 $wgOut->addHTML( <<<END
1399 -{$recreate}
 1408+$recreate
14001409 {$commentsubject}
14011410 {$subjectpreview}
14021411 {$this->editFormTextBeforeContent}
 1412+<textarea tabindex='1' accesskey="," name="wpTextbox1" id="wpTextbox1" rows='{$rows}'
 1413+cols='{$cols}'{$ew} $hidden>{$encodedtext}</textarea>
14031414 END
14041415 );
1405 - $this->showTextbox1();
14061416
14071417 $wgOut->wrapWikiMsg( "<div id=\"editpage-copywarn\">\n$1\n</div>", $copywarnMsg );
1408 - $wgOut->addHTML( <<<END
1409 -{$this->editFormTextAfterWarn}
 1418+ $wgOut->addHTML( $this->editFormTextAfterWarn );
 1419+ $wgOut->addHTML( "
14101420 {$metadata}
14111421 {$editsummary}
14121422 {$summarypreview}
14131423 {$checkboxhtml}
14141424 {$safemodehtml}
1415 -END
1416 -);
 1425+");
14171426
14181427 $wgOut->addHTML(
14191428 "<div class='editButtons'>
@@ -1436,18 +1445,20 @@
14371446 $token = htmlspecialchars( $wgUser->editToken() );
14381447 $wgOut->addHTML( "\n<input type='hidden' value=\"$token\" name=\"wpEditToken\" />\n" );
14391448
1440 - $this->showEditTools();
 1449+ $wgOut->addHtml( '<div class="mw-editTools">' );
 1450+ $wgOut->addWikiMsgArray( 'edittools', array(), array( 'content' ) );
 1451+ $wgOut->addHtml( '</div>' );
14411452
1442 - $wgOut->addHTML( <<<END
1443 -{$this->editFormTextAfterTools}
 1453+ $wgOut->addHTML( $this->editFormTextAfterTools );
 1454+
 1455+ $wgOut->addHTML( "
14441456 <div class='templatesUsed'>
14451457 {$formattedtemplates}
14461458 </div>
14471459 <div class='hiddencats'>
14481460 {$formattedhiddencats}
14491461 </div>
1450 -END
1451 -);
 1462+");
14521463
14531464 if ( $this->isConflict && wfRunHooks( 'EditPageBeforeConflictDiff', array( &$this, &$wgOut ) ) ) {
14541465 $wgOut->wrapWikiMsg( '==$1==', "yourdiff" );
@@ -1457,76 +1468,26 @@
14581469 $de->showDiff( wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
14591470
14601471 $wgOut->wrapWikiMsg( '==$1==', "yourtext" );
1461 - $this->showTextbox2();
 1472+ $wgOut->addHTML( "<textarea tabindex='6' id='wpTextbox2' name=\"wpTextbox2\" rows='{$rows}' cols='{$cols}'>"
 1473+ . htmlspecialchars( $this->safeUnicodeOutput( $this->textbox2 ) ) . "\n</textarea>" );
14621474 }
14631475 $wgOut->addHTML( $this->editFormTextBottom );
14641476 $wgOut->addHTML( "</form>\n" );
14651477 if ( !$wgUser->getOption( 'previewontop' ) ) {
1466 - $this->displayPreviewArea( $previewOutput );
1467 - }
14681478
1469 - wfProfileOut( $fname );
1470 - }
 1479+ if ( $this->formtype == 'preview') {
 1480+ $this->showPreview( $previewOutput );
 1481+ } else {
 1482+ $wgOut->addHTML( '<div id="wikiPreview"></div>' );
 1483+ }
14711484
1472 - protected function showFormBeforeText() {
1473 - return "
1474 -<input type='hidden' value=\"" . htmlspecialchars( $this->section ) . "\" name=\"wpSection\" />
1475 -<input type='hidden' value=\"{$this->starttime}\" name=\"wpStarttime\" />\n
1476 -<input type='hidden' value=\"{$this->edittime}\" name=\"wpEdittime\" />\n
1477 -<input type='hidden' value=\"{$this->scrolltop}\" name=\"wpScrolltop\" id=\"wpScrolltop\" />\n";
1478 - }
1479 -
1480 - protected function showTextbox1() {
1481 - $attribs = array( 'tabindex' => 1 );
1482 -
1483 - if( $this->wasDeletedSinceLastEdit() )
1484 - $attribs['type'] = 'hidden';
1485 -
1486 - $this->showTextbox( $this->textbox1, 'wpTextbox1', $attribs );
1487 - }
1488 -
1489 - protected function showTextbox2() {
1490 - $this->showTextbox( $encodedtext, 'wpTextbox2', array( 'tabindex' => 6 ) );
1491 - }
1492 -
1493 - protected function showTextbox( $content, $name, $attribs = array() ) {
1494 - global $wgOut, $wgUser;
1495 -
1496 - $encodedtext = htmlspecialchars( $this->safeUnicodeOutput( $content ) );
1497 - if( $encodedtext !== '' ) {
1498 - // Ensure there's a newline at the end, otherwise adding lines
1499 - // is awkward.
1500 - // But don't add a newline if the ext is empty, or Firefox in XHTML
1501 - // mode will show an extra newline. A bit annoying.
1502 - $encodedtext .= "\n";
1503 - }
1504 -
1505 - $attribs = array(
1506 - 'accesskey' => ',',
1507 - 'id' => $name,
1508 - );
1509 -
1510 - if( $wgUser->getOption( 'editwidth' ) )
1511 - $attribs['style'] = 'width: 100%';
1512 -
1513 - $wgOut->addHTML( Xml::textarea(
1514 - $name,
1515 - $encodedtext,
1516 - $wgUser->getIntOption( 'cols' ), $wgUser->getIntOption( 'rows' ),
1517 - $attribs ) );
1518 - }
 1485+ if ( $this->formtype == 'diff') {
 1486+ $this->showDiff();
 1487+ }
15191488
1520 - protected function displayPreviewArea( $previewOutput ) {
1521 - global $wgOut;
1522 - if ( $this->formtype == 'preview') {
1523 - $this->showPreview( $previewOutput );
1524 - } else {
1525 - $wgOut->addHTML( '<div id="wikiPreview"></div>' );
15261489 }
15271490
1528 - if ( $this->formtype == 'diff') {
1529 - $this->showDiff();
1530 - }
 1491+ wfProfileOut( $fname );
15311492 }
15321493
15331494 /**
@@ -1563,19 +1524,12 @@
15641525 function doLivePreviewScript() {
15651526 global $wgOut, $wgTitle;
15661527 $wgOut->addScriptFile( 'preview.js' );
1567 - $liveAction = $wgTitle->getLocalUrl( "action={$this->action}&wpPreview=true&live=true" );
 1528+ $liveAction = $wgTitle->getLocalUrl( 'action=submit&wpPreview=true&live=true' );
15681529 return "return !lpDoPreview(" .
15691530 "editform.wpTextbox1.value," .
15701531 '"' . $liveAction . '"' . ")";
15711532 }
15721533
1573 - protected function showEditTools() {
1574 - global $wgOut;
1575 - $wgOut->addHtml( '<div class="mw-editTools">' );
1576 - $wgOut->addWikiMsgArray( 'edittools', array(), array( 'content' ) );
1577 - $wgOut->addHtml( '</div>' );
1578 - }
1579 -
15801534 function getLastDelete() {
15811535 $dbr = wfGetDB( DB_SLAVE );
15821536 $fname = 'EditPage::getLastDelete';
@@ -1615,7 +1569,8 @@
16161570 function getPreviewText() {
16171571 global $wgOut, $wgUser, $wgTitle, $wgParser, $wgLang, $wgContLang;
16181572
1619 - wfProfileIn( __METHOD__ );
 1573+ $fname = 'EditPage::getPreviewText';
 1574+ wfProfileIn( $fname );
16201575
16211576 if ( $this->mTriedSave && !$this->mTokenOk ) {
16221577 if ( $this->mTokenOkExceptSuffix ) {
@@ -1649,9 +1604,9 @@
16501605 }
16511606 $parserOptions->setTidy(true);
16521607 $parserOutput = $wgParser->parse( $previewtext , $this->mTitle, $parserOptions );
1653 - //$wgOut->addHTML( $parserOutput->mText );
 1608+ $wgOut->addHTML( $parserOutput->mText );
16541609 $previewHTML = '';
1655 - } elseif( $rt = Title::newFromRedirect( $this->textbox1 ) ) {
 1610+ } else if( $rt = Title::newFromRedirect( $this->textbox1 ) ) {
16561611 $previewHTML = $this->mArticle->viewRedirect( $rt, false );
16571612 } else {
16581613 $toparse = $this->textbox1;
@@ -1688,9 +1643,20 @@
16891644 $this->mTitle, $parserOptions );
16901645
16911646 $previewHTML = $parserOutput->getText();
1692 - $this->mParserOutput = $parserOutput;
16931647 $wgOut->addParserOutputNoText( $parserOutput );
16941648
 1649+ # ParserOutput might have altered the page title, so reset it
 1650+ # Also, use the title defined by DISPLAYTITLE magic word when present
 1651+ if( ( $dt = $parserOutput->getDisplayTitle() ) !== false ) {
 1652+ $wgOut->setPageTitle( wfMsg( 'editing', $dt ) );
 1653+ } else {
 1654+ $wgOut->setPageTitle( wfMsg( 'editing', $wgTitle->getPrefixedText() ) );
 1655+ }
 1656+
 1657+ foreach ( $parserOutput->getTemplates() as $ns => $template)
 1658+ foreach ( array_keys( $template ) as $dbk)
 1659+ $this->mPreviewTemplates[] = Title::makeTitle($ns, $dbk);
 1660+
16951661 if ( count( $parserOutput->getWarnings() ) ) {
16961662 $note .= "\n\n" . implode( "\n\n", $parserOutput->getWarnings() );
16971663 }
@@ -1699,26 +1665,18 @@
17001666 $previewhead = '<h2>' . htmlspecialchars( wfMsg( 'preview' ) ) . "</h2>\n" .
17011667 "<div class='previewnote'>" . $wgOut->parse( $note ) . "</div>\n";
17021668 if ( $this->isConflict ) {
1703 - $previewhead .='<h2>' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "</h2>\n";
 1669+ $previewhead.='<h2>' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "</h2>\n";
17041670 }
17051671
1706 - wfProfileOut( __METHOD__ );
1707 - return $previewhead . $previewHTML;
1708 - }
1709 -
1710 - function getTemplates() {
1711 - if( $this->preview || $this->section != '' ) {
1712 - $templates = array();
1713 - if( !isset($this->mParserOutput) ) return $templates;
1714 - foreach( $this->mParserOutput->getTemplates() as $ns => $template) {
1715 - foreach( array_keys( $template ) as $dbk ) {
1716 - $templates[] = Title::makeTitle($ns, $dbk);
1717 - }
1718 - }
1719 - return $templates;
 1672+ if( $wgUser->getOption( 'previewontop' ) ) {
 1673+ // Spacer for the edit toolbar
 1674+ $previewfoot = '<p><br /></p>';
17201675 } else {
1721 - return $this->mArticle->getUsedTemplates();
 1676+ $previewfoot = '';
17221677 }
 1678+
 1679+ wfProfileOut( $fname );
 1680+ return $previewhead . $previewHTML . $previewfoot;
17231681 }
17241682
17251683 /**
@@ -1739,8 +1697,8 @@
17401698
17411699 # Spit out the source or the user's modified version
17421700 if( $source !== false ) {
1743 - $rows = $wgUser->getIntOption( 'rows' );
1744 - $cols = $wgUser->getIntOption( 'cols' );
 1701+ $rows = $wgUser->getOption( 'rows' );
 1702+ $cols = $wgUser->getOption( 'cols' );
17451703 $attribs = array( 'id' => 'wpTextbox1', 'name' => 'wpTextbox1', 'cols' => $cols, 'rows' => $rows, 'readonly' => 'readonly' );
17461704 $wgOut->addHtml( '<hr />' );
17471705 $wgOut->addWikiMsg( $first ? 'blockedoriginalsource' : 'blockededitsource', $this->mTitle->getPrefixedText() );

Status & tagging log