r81903 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81902‎ | r81903 | r81904 >
Date:17:08, 10 February 2011
Author:ialex
Status:ok
Tags:
Comment:
Added "context title" to replace $wgTitle, current behavior unchanges, but added a comment that this might change in the future to completely remove $wgTitle usage in EditPage

Also removed null check on showEditForm() since $wgTitle is set on ApiEditPage.php, so it won't catch anything
Modified paths:
  • /trunk/phase3/includes/EditPage.php (modified) (history)
  • /trunk/phase3/includes/api/ApiEditPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/EditPage.php
@@ -11,7 +11,7 @@
1212 * interfaces.
1313 *
1414 * EditPage cares about two distinct titles:
15 - * $wgTitle is the page that forms submit to, links point to,
 15+ * $this->mContextTitle is the page that forms submit to, links point to,
1616 * redirects go to, etc. $this->mTitle (as well as $mArticle) is the
1717 * page in the database that is actually being edited. These are
1818 * usually the same, but they are now allowed to be different.
@@ -44,6 +44,7 @@
4545
4646 var $mArticle;
4747 var $mTitle;
 48+ private $mContextTitle = null;
4849 var $action;
4950 var $isConflict = false;
5051 var $isCssJsSubpage = false;
@@ -117,8 +118,32 @@
118119 return $this->mArticle;
119120 }
120121
 122+ /**
 123+ * Set the context Title object
 124+ *
 125+ * @param $title Title object or null
 126+ */
 127+ public function setContextTitle( $title ) {
 128+ $this->mContextTitle = $title;
 129+ }
121130
122131 /**
 132+ * Get the context title object.
 133+ * If not set, $wgTitle will be returned. This behavior might changed in
 134+ * the future to return $this->mTitle instead.
 135+ *
 136+ * @return Title object
 137+ */
 138+ public function getContextTitle() {
 139+ if ( is_null( $this->mContextTitle ) ) {
 140+ global $wgTitle;
 141+ return $wgTitle;
 142+ } else {
 143+ return $this->mContextTitle;
 144+ }
 145+ }
 146+
 147+ /**
123148 * Fetch initial editing page content.
124149 * @returns mixed string on success, $def_text for invalid sections
125150 * @private
@@ -1200,23 +1225,23 @@
12011226 }
12021227
12031228 function setHeaders() {
1204 - global $wgOut, $wgTitle;
 1229+ global $wgOut;
12051230 $wgOut->setRobotPolicy( 'noindex,nofollow' );
12061231 if ( $this->formtype == 'preview' ) {
12071232 $wgOut->setPageTitleActionText( wfMsg( 'preview' ) );
12081233 }
12091234 if ( $this->isConflict ) {
1210 - $wgOut->setPageTitle( wfMsg( 'editconflict', $wgTitle->getPrefixedText() ) );
 1235+ $wgOut->setPageTitle( wfMsg( 'editconflict', $this->getContextTitle()->getPrefixedText() ) );
12111236 } elseif ( $this->section != '' ) {
12121237 $msg = $this->section == 'new' ? 'editingcomment' : 'editingsection';
1213 - $wgOut->setPageTitle( wfMsg( $msg, $wgTitle->getPrefixedText() ) );
 1238+ $wgOut->setPageTitle( wfMsg( $msg, $this->getContextTitle()->getPrefixedText() ) );
12141239 } else {
12151240 # Use the title defined by DISPLAYTITLE magic word when present
12161241 if ( isset( $this->mParserOutput )
12171242 && ( $dt = $this->mParserOutput->getDisplayTitle() ) !== false ) {
12181243 $title = $dt;
12191244 } else {
1220 - $title = $wgTitle->getPrefixedText();
 1245+ $title = $this->getContextTitle()->getPrefixedText();
12211246 }
12221247 $wgOut->setPageTitle( wfMsg( 'editing', $title ) );
12231248 }
@@ -1229,15 +1254,8 @@
12301255 * near the top, for captchas and the like.
12311256 */
12321257 function showEditForm( $formCallback = null ) {
1233 - global $wgOut, $wgUser, $wgTitle;
 1258+ global $wgOut, $wgUser;
12341259
1235 - # If $wgTitle is null, that means we're in API mode.
1236 - # Some hook probably called this function without checking
1237 - # for is_null($wgTitle) first. Bail out right here so we don't
1238 - # do lots of work just to discard it right after.
1239 - if ( is_null( $wgTitle ) )
1240 - return;
1241 -
12421260 wfProfileIn( __METHOD__ );
12431261
12441262 $sk = $wgUser->getSkin();
@@ -1263,7 +1281,7 @@
12641282 return;
12651283 }
12661284
1267 - $action = htmlspecialchars( $this->getActionURL( $wgTitle ) );
 1285+ $action = htmlspecialchars( $this->getActionURL( $this->getContextTitle() ) );
12681286
12691287 if ( $wgUser->getOption( 'showtoolbar' ) and !$this->isCssJsSubpage ) {
12701288 # prepare toolbar for edit buttons
@@ -1397,7 +1415,7 @@
13981416 }
13991417
14001418 protected function showHeader() {
1401 - global $wgOut, $wgUser, $wgTitle, $wgMaxArticleSize, $wgLang;
 1419+ global $wgOut, $wgUser, $wgMaxArticleSize, $wgLang;
14021420 if ( $this->isConflict ) {
14031421 $wgOut->wrapWikiMsg( "<div class='mw-explainconflict'>\n$1\n</div>", 'explainconflict' );
14041422 $this->edittime = $this->mArticle->getTimestamp();
@@ -1471,7 +1489,7 @@
14721490 if ( $this->isCssJsSubpage ) {
14731491 # Check the skin exists
14741492 if ( $this->isWrongCaseCssJsPage ) {
1475 - $wgOut->wrapWikiMsg( "<div class='error' id='mw-userinvalidcssjstitle'>\n$1\n</div>", array( 'userinvalidcssjstitle', $wgTitle->getSkinFromCssJsSubpage() ) );
 1493+ $wgOut->wrapWikiMsg( "<div class='error' id='mw-userinvalidcssjstitle'>\n$1\n</div>", array( 'userinvalidcssjstitle', $this->getContextTitle()->getSkinFromCssJsSubpage() ) );
14761494 }
14771495 if ( $this->formtype !== 'preview' ) {
14781496 if ( $this->isCssSubpage )
@@ -1922,7 +1940,7 @@
19231941 }
19241942
19251943 # don't parse user css/js, show message about preview
1926 - # XXX: stupid php bug won't let us use $wgTitle->isCssJsSubpage() here -- This note has been there since r3530. Sure the bug was fixed time ago?
 1944+ # XXX: stupid php bug won't let us use $this->getContextTitle()->isCssJsSubpage() here -- This note has been there since r3530. Sure the bug was fixed time ago?
19271945
19281946 if ( $this->isCssJsSubpage || $this->mTitle->isCssOrJsPage() ) {
19291947 $level = 'user';
@@ -2040,7 +2058,7 @@
20412059 * Produce the stock "please login to edit pages" page
20422060 */
20432061 function userNotLoggedInPage() {
2044 - global $wgUser, $wgOut, $wgTitle;
 2062+ global $wgUser, $wgOut;
20452063 $skin = $wgUser->getSkin();
20462064
20472065 $loginTitle = SpecialPage::getTitleFor( 'Userlogin' );
@@ -2048,7 +2066,7 @@
20492067 $loginTitle,
20502068 wfMsgHtml( 'loginreqlink' ),
20512069 array(),
2052 - array( 'returnto' => $wgTitle->getPrefixedText() ),
 2070+ array( 'returnto' => $this->getContextTitle()->getPrefixedText() ),
20532071 array( 'known', 'noclasses' )
20542072 );
20552073
@@ -2057,7 +2075,7 @@
20582076 $wgOut->setArticleRelated( false );
20592077
20602078 $wgOut->addWikiMsgArray( 'whitelistedittext', array( $loginLink ), array( 'replaceafter' ) );
2061 - $wgOut->returnToMain( false, $wgTitle );
 2079+ $wgOut->returnToMain( false, $this->getContextTitle() );
20622080 }
20632081
20642082 /**
@@ -2107,7 +2125,7 @@
21082126 * @param $match Text which triggered one or more filters
21092127 */
21102128 public function spamPageWithContent( $match = false ) {
2111 - global $wgOut, $wgTitle;
 2129+ global $wgOut;
21122130 $this->textbox2 = $this->textbox1;
21132131
21142132 $wgOut->setPageTitle( wfMsg( 'spamprotectiontitle' ) );
@@ -2129,7 +2147,7 @@
21302148 $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourtext" );
21312149 $this->showTextbox2();
21322150
2133 - $wgOut->addReturnTo( $wgTitle, array( 'action' => 'edit' ) );
 2151+ $wgOut->addReturnTo( $this->getContextTitle(), array( 'action' => 'edit' ) );
21342152 }
21352153
21362154
@@ -2504,7 +2522,7 @@
25052523
25062524
25072525 public function getCancelLink() {
2508 - global $wgUser, $wgTitle;
 2526+ global $wgUser;
25092527
25102528 $cancelParams = array();
25112529 if ( !$this->isConflict && $this->mArticle->getOldID() > 0 ) {
@@ -2512,7 +2530,7 @@
25132531 }
25142532
25152533 return $wgUser->getSkin()->link(
2516 - $wgTitle,
 2534+ $this->getContextTitle(),
25172535 wfMsgExt( 'cancel', array( 'parseinline' ) ),
25182536 array( 'id' => 'mw-editform-cancel' ),
25192537 $cancelParams,
@@ -2683,7 +2701,7 @@
26842702 * @return bool false if output is done, true if the rest of the form should be displayed
26852703 */
26862704 function attemptSave() {
2687 - global $wgUser, $wgOut, $wgTitle;
 2705+ global $wgUser, $wgOut;
26882706
26892707 $resultDetails = false;
26902708 # Allow bots to exempt some edits from bot flagging
@@ -2761,7 +2779,7 @@
27622780 return;
27632781
27642782 case self::AS_BLANK_ARTICLE:
2765 - $wgOut->redirect( $wgTitle->getFullURL() );
 2783+ $wgOut->redirect( $this->getContextTitle()->getFullURL() );
27662784 return false;
27672785
27682786 case self::AS_IMAGE_REDIRECT_LOGGED:
Index: trunk/phase3/includes/api/ApiEditPage.php
@@ -181,6 +181,8 @@
182182 }
183183
184184 $ep = new EditPage( $articleObj );
 185+ $ep->setContextTitle( $titleObj );
 186+
185187 // EditPage wants to parse its stuff from a WebRequest
186188 // That interface kind of sucks, but it's workable
187189 $reqArr = array(

Status & tagging log