r108902 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108901‎ | r108902 | r108903 >
Date:14:27, 14 January 2012
Author:ialex
Status:ok
Tags:
Comment:
Per Aaron, fix for r108274: added canUseWikiPage() to context objects to know whether getWikiPage() can be safely called
Modified paths:
  • /trunk/phase3/includes/context/ContextSource.php (modified) (history)
  • /trunk/phase3/includes/context/DerivativeContext.php (modified) (history)
  • /trunk/phase3/includes/context/IContextSource.php (modified) (history)
  • /trunk/phase3/includes/context/RequestContext.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/context/RequestContext.php
@@ -109,6 +109,29 @@
110110 }
111111
112112 /**
 113+ * Check whether a WikiPage object can be get with getWikiPage().
 114+ * Callers should expect that an exception is thrown from getWikiPage()
 115+ * if this method returns false.
 116+ *
 117+ * @since 1.19
 118+ * @return bool
 119+ */
 120+ public function canUseWikiPage() {
 121+ if ( $this->wikipage !== null ) {
 122+ # If there's a WikiPage object set, we can for sure get it
 123+ return true;
 124+ }
 125+ $title = $this->getTitle();
 126+ if ( $title === null ) {
 127+ # No Title, no WikiPage
 128+ return false;
 129+ } else {
 130+ # Only namespaces whose pages are stored in the database can have WikiPage
 131+ return $title->canExist();
 132+ }
 133+ }
 134+
 135+ /**
113136 * Set the WikiPage object
114137 *
115138 * @since 1.19
@@ -119,7 +142,10 @@
120143 }
121144
122145 /**
123 - * Get the WikiPage object
 146+ * Get the WikiPage object.
 147+ * May throw an exception if there's no Title object set or the Title object
 148+ * belongs to a special namespace that doesn't have WikiPage, so use first
 149+ * canUseWikiPage() to check whether this method can be called safely.
124150 *
125151 * @since 1.19
126152 * @return WikiPage
Index: trunk/phase3/includes/context/IContextSource.php
@@ -43,9 +43,22 @@
4444 public function getTitle();
4545
4646 /**
47 - * Get the WikiPage object
 47+ * Check whether a WikiPage object can be get with getWikiPage().
 48+ * Callers should expect that an exception is thrown from getWikiPage()
 49+ * if this method returns false.
4850 *
4951 * @since 1.19
 52+ * @return bool
 53+ */
 54+ public function canUseWikiPage();
 55+
 56+ /**
 57+ * Get the WikiPage object.
 58+ * May throw an exception if there's no Title object set or the Title object
 59+ * belongs to a special namespace that doesn't have WikiPage, so use first
 60+ * canUseWikiPage() to check whether this method can be called safely.
 61+ *
 62+ * @since 1.19
5063 * @return WikiPage
5164 */
5265 public function getWikiPage();
Index: trunk/phase3/includes/context/ContextSource.php
@@ -79,9 +79,24 @@
8080 }
8181
8282 /**
83 - * Get the WikiPage object
 83+ * Check whether a WikiPage object can be get with getWikiPage().
 84+ * Callers should expect that an exception is thrown from getWikiPage()
 85+ * if this method returns false.
8486 *
8587 * @since 1.19
 88+ * @return bool
 89+ */
 90+ public function canUseWikiPage() {
 91+ return $this->getContext()->canUseWikiPage();
 92+ }
 93+
 94+ /**
 95+ * Get the WikiPage object.
 96+ * May throw an exception if there's no Title object set or the Title object
 97+ * belongs to a special namespace that doesn't have WikiPage, so use first
 98+ * canUseWikiPage() to check whether this method can be called safely.
 99+ *
 100+ * @since 1.19
86101 * @return WikiPage
87102 */
88103 public function getWikiPage() {
Index: trunk/phase3/includes/context/DerivativeContext.php
@@ -119,6 +119,24 @@
120120 }
121121
122122 /**
 123+ * Check whether a WikiPage object can be get with getWikiPage().
 124+ * Callers should expect that an exception is thrown from getWikiPage()
 125+ * if this method returns false.
 126+ *
 127+ * @since 1.19
 128+ * @return bool
 129+ */
 130+ public function canUseWikiPage() {
 131+ if ( $this->wikipage !== null ) {
 132+ return true;
 133+ } elseif ( $this->title !== null ) {
 134+ return $this->title->canExist();
 135+ } else {
 136+ return $this->getContext()->canUseWikiPage();
 137+ }
 138+ }
 139+
 140+ /**
123141 * Set the WikiPage object
124142 *
125143 * @since 1.19
@@ -129,7 +147,10 @@
130148 }
131149
132150 /**
133 - * Get the WikiPage object
 151+ * Get the WikiPage object.
 152+ * May throw an exception if there's no Title object set or the Title object
 153+ * belongs to a special namespace that doesn't have WikiPage, so use first
 154+ * canUseWikiPage() to check whether this method can be called safely.
134155 *
135156 * @since 1.19
136157 * @return WikiPage

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r108274* Added WikiPage to RequestContext and related so that it can be shared to av...ialex20:00, 6 January 2012

Status & tagging log