Index: trunk/phase3/includes/context/RequestContext.php |
— | — | @@ -109,6 +109,29 @@ |
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
| 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 | + /** |
113 | 136 | * Set the WikiPage object |
114 | 137 | * |
115 | 138 | * @since 1.19 |
— | — | @@ -119,7 +142,10 @@ |
120 | 143 | } |
121 | 144 | |
122 | 145 | /** |
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. |
124 | 150 | * |
125 | 151 | * @since 1.19 |
126 | 152 | * @return WikiPage |
Index: trunk/phase3/includes/context/IContextSource.php |
— | — | @@ -43,9 +43,22 @@ |
44 | 44 | public function getTitle(); |
45 | 45 | |
46 | 46 | /** |
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. |
48 | 50 | * |
49 | 51 | * @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 |
50 | 63 | * @return WikiPage |
51 | 64 | */ |
52 | 65 | public function getWikiPage(); |
Index: trunk/phase3/includes/context/ContextSource.php |
— | — | @@ -79,9 +79,24 @@ |
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
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. |
84 | 86 | * |
85 | 87 | * @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 |
86 | 101 | * @return WikiPage |
87 | 102 | */ |
88 | 103 | public function getWikiPage() { |
Index: trunk/phase3/includes/context/DerivativeContext.php |
— | — | @@ -119,6 +119,24 @@ |
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
| 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 | + /** |
123 | 141 | * Set the WikiPage object |
124 | 142 | * |
125 | 143 | * @since 1.19 |
— | — | @@ -129,7 +147,10 @@ |
130 | 148 | } |
131 | 149 | |
132 | 150 | /** |
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. |
134 | 155 | * |
135 | 156 | * @since 1.19 |
136 | 157 | * @return WikiPage |