Index: trunk/extensions/EducationProgram/EducationProgram.php |
— | — | @@ -165,6 +165,7 @@ |
166 | 166 | $wgHooks['SkinTemplateNavigation::SpecialPage'][] = 'EPHooks::onSpecialPageTabs'; |
167 | 167 | $wgHooks['ArticleFromTitle'][] = 'EPHooks::onArticleFromTitle'; |
168 | 168 | $wgHooks['CanonicalNamespaces'][] = 'EPHooks::onCanonicalNamespaces'; |
| 169 | +$wgHooks['TitleIsKnown'][] = 'EPHooks::onTitleIsKnown'; |
169 | 170 | |
170 | 171 | // Logging |
171 | 172 | $wgLogTypes[] = 'institution'; |
Index: trunk/extensions/EducationProgram/pages/EPPage.php |
— | — | @@ -14,7 +14,26 @@ |
15 | 15 | */ |
16 | 16 | abstract class EPPage extends Page implements IContextSource { |
17 | 17 | |
| 18 | + /** |
| 19 | + * Returns a list of actions this page can handle. |
| 20 | + * Array keys are action names, their values are the names of the handling Action classes. |
| 21 | + * |
| 22 | + * @since 0.1 |
| 23 | + * |
| 24 | + * @return array |
| 25 | + */ |
| 26 | + protected abstract function getActions(); |
| 27 | + |
| 28 | + /** |
| 29 | + * @since 0.1 |
| 30 | + * @var IContextSource |
| 31 | + */ |
18 | 32 | protected $context; |
| 33 | + |
| 34 | + /** |
| 35 | + * @since 0.1 |
| 36 | + * @var WikiPage |
| 37 | + */ |
19 | 38 | protected $page; |
20 | 39 | |
21 | 40 | public function __construct( Title $title ) { |
— | — | @@ -78,8 +97,6 @@ |
79 | 98 | return call_user_func_array( array( $this->getContext(), 'msg' ), $args ); |
80 | 99 | } |
81 | 100 | |
82 | | - protected abstract function getActions(); |
83 | | - |
84 | 101 | public function getActionOverrides() { |
85 | 102 | $actions = $this->getActions(); |
86 | 103 | |
— | — | @@ -95,7 +112,11 @@ |
96 | 113 | public function getTouched() { |
97 | 114 | return '19700101000000'; |
98 | 115 | } |
99 | | - |
| 116 | + |
| 117 | + /** |
| 118 | + * @deprecated |
| 119 | + * @return Language |
| 120 | + */ |
100 | 121 | public function getLang() { |
101 | 122 | wfDeprecated( __METHOD__, '1.19' ); |
102 | 123 | return $this->getLanguage(); |
Index: trunk/extensions/EducationProgram/actions/EPHistoryAction.php |
— | — | @@ -13,7 +13,14 @@ |
14 | 14 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
15 | 15 | */ |
16 | 16 | abstract class EPHistoryAction extends FormlessAction { |
17 | | - |
| 17 | + |
| 18 | + /** |
| 19 | + * Returns the class name of the EPDBObject this action handles. |
| 20 | + * |
| 21 | + * @since 0.1 |
| 22 | + * |
| 23 | + * @return string |
| 24 | + */ |
18 | 25 | protected abstract function getItemClass(); |
19 | 26 | |
20 | 27 | public function onView() { |
Index: trunk/extensions/EducationProgram/actions/EPEditAction.php |
— | — | @@ -29,7 +29,14 @@ |
30 | 30 | * @var boolean|null |
31 | 31 | */ |
32 | 32 | protected $isNew = null; |
33 | | - |
| 33 | + |
| 34 | + /** |
| 35 | + * Returns the class name of the EPDBObject this action handles. |
| 36 | + * |
| 37 | + * @since 0.1 |
| 38 | + * |
| 39 | + * @return string |
| 40 | + */ |
34 | 41 | protected abstract function getItemClass(); |
35 | 42 | |
36 | 43 | public function onView() { |
— | — | @@ -78,7 +85,7 @@ |
79 | 86 | $object = new $c( $data, true ); |
80 | 87 | } |
81 | 88 | elseif ( $this->isNewPost() ) { |
82 | | - $this->showWarning( wfMessage( 'educationprogram-' . strtolower( $this->getName() ) . '-exists-already' ) ); |
| 89 | + $this->showWarning( wfMessage( 'ep-' . strtolower( $this->getName() ) . '-exists-already' ) ); |
83 | 90 | } |
84 | 91 | |
85 | 92 | $this->getOutput()->setSubtitle( $this->getDescription() ); |
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php |
— | — | @@ -240,6 +240,7 @@ |
241 | 241 | 'educationprogram-org-submit' => 'Submit', |
242 | 242 | 'ep-addorg' => 'There is no institution with this name yet, but you can add it.', |
243 | 243 | 'ep-editorg' => 'You are editing an existing institution.', |
| 244 | + 'ep-editorg-exists-already' => 'This institution already exists. You are editing it.', |
244 | 245 | |
245 | 246 | // Course editing |
246 | 247 | 'editcourse-add-legend' => 'Add course', |
— | — | @@ -259,6 +260,7 @@ |
260 | 261 | 'ep-course-edit-lang' => 'Course language', |
261 | 262 | 'ep-addcourse' => 'There is no course with this name yet, but you can add it.', |
262 | 263 | 'ep-editcourse' => 'You are editing an existing course.', |
| 264 | + 'ep-editcourse-exists-already' => 'This course already exists. You are editing it.', |
263 | 265 | |
264 | 266 | 'ep-course-invalid-org' => 'This institution does not exist.', |
265 | 267 | 'ep-course-invalid-token' => 'The token needs to be at least contain $1 {{PLURAL:$1|character|characters}}.', |
Index: trunk/extensions/EducationProgram/EducationProgram.hooks.php |
— | — | @@ -225,19 +225,28 @@ |
226 | 226 | |
227 | 227 | return true; |
228 | 228 | } |
229 | | - |
| 229 | + |
| 230 | + /** |
| 231 | + * Display the tabs for a course or institution. |
| 232 | + * |
| 233 | + * @since 0.1 |
| 234 | + * |
| 235 | + * @param SkinTemplate $sktemplate |
| 236 | + * @param array $links |
| 237 | + * @param Title $title |
| 238 | + */ |
230 | 239 | protected static function displayTabs( SkinTemplate &$sktemplate, array &$links, Title $title ) { |
231 | 240 | $classes = array( |
232 | 241 | EP_NS_INSTITUTION => 'EPOrg', |
233 | 242 | EP_NS_COURSE => 'EPCourse', |
234 | 243 | ); |
235 | 244 | |
236 | | - $ns = array( |
237 | | - EP_NS_COURSE, |
238 | | - EP_NS_COURSE_TALK, |
239 | | - EP_NS_INSTITUTION, |
240 | | - EP_NS_INSTITUTION_TALK, |
241 | | - ); |
| 245 | +// $ns = array( |
| 246 | +// EP_NS_COURSE, |
| 247 | +// EP_NS_COURSE_TALK, |
| 248 | +// EP_NS_INSTITUTION, |
| 249 | +// EP_NS_INSTITUTION_TALK, |
| 250 | +// ); |
242 | 251 | |
243 | 252 | $exists = null; |
244 | 253 | |
— | — | @@ -290,44 +299,68 @@ |
291 | 300 | } |
292 | 301 | } |
293 | 302 | |
294 | | - if ( in_array( $title->getNamespace(), $ns ) ) { |
295 | | - $subjectTitle = $title->getSubjectPage(); |
296 | | - |
297 | | - if ( is_null( $exists ) ) { |
298 | | - $class = $classes[$subjectTitle->getNamespace()]; |
299 | | - $exists = $class::hasIdentifier( $title->getText() ); |
300 | | - } |
301 | | - |
302 | | - $tab = array_shift( $links['namespaces'] ); |
303 | | - self::fixRedlinking( $tab, $exists, $subjectTitle ); |
304 | | - array_unshift( $links['namespaces'], $tab ); |
305 | | - } |
| 303 | +// if ( in_array( $title->getNamespace(), $ns ) ) { |
| 304 | +// $subjectTitle = $title->getSubjectPage(); |
| 305 | +// |
| 306 | +// if ( is_null( $exists ) ) { |
| 307 | +// $class = $classes[$subjectTitle->getNamespace()]; |
| 308 | +// $exists = $class::hasIdentifier( $title->getText() ); |
| 309 | +// } |
| 310 | +// |
| 311 | +// $tab = array_shift( $links['namespaces'] ); |
| 312 | +// self::fixRedlinking( $tab, $exists, $subjectTitle ); |
| 313 | +// array_unshift( $links['namespaces'], $tab ); |
| 314 | +// } |
306 | 315 | } |
307 | | - |
308 | | - protected static function fixRedlinking( array &$tab, $exists, Title $title ) { |
309 | | - $classes = explode( ' ', $tab['class'] ); |
310 | | - $classes = array_flip( $classes ); |
311 | | - |
312 | | - if ( array_key_exists( 'new', $classes ) && $exists ) { |
313 | | - unset( $classes['new'] ); |
| 316 | + |
| 317 | +// protected static function fixRedlinking( array &$tab, $exists, Title $title ) { |
| 318 | +// $classes = explode( ' ', $tab['class'] ); |
| 319 | +// $classes = array_flip( $classes ); |
| 320 | +// |
| 321 | +// if ( array_key_exists( 'new', $classes ) && $exists ) { |
| 322 | +// unset( $classes['new'] ); |
| 323 | +// } |
| 324 | +// |
| 325 | +// $classes = array_flip( $classes ); |
| 326 | +// |
| 327 | +// if ( !$exists && !in_array( 'new', $classes ) ) { |
| 328 | +// $classes[] = 'new'; |
| 329 | +// } |
| 330 | +// |
| 331 | +// $tab['class'] = implode( ' ', $classes ); |
| 332 | +// |
| 333 | +// $query = array(); |
| 334 | +// |
| 335 | +// if ( !$exists ) { |
| 336 | +// $query['action'] = 'edit'; |
| 337 | +// $query['redlink'] = '1'; |
| 338 | +// } |
| 339 | +// |
| 340 | +// $tab['href'] = $title->getLocalURL( $query ); |
| 341 | +// } |
| 342 | + |
| 343 | + /** |
| 344 | + * Override the isKnown check for course and institution pages, so they don't all show up as redlinks. |
| 345 | + * @see https://www.mediawiki.org/wiki/Manual:Hooks/TitleIsKnown |
| 346 | + * |
| 347 | + * @since 0.1 |
| 348 | + * |
| 349 | + * @param Title $title |
| 350 | + * @param boolean|null $isKnown |
| 351 | + * |
| 352 | + * @return true |
| 353 | + */ |
| 354 | + public static function onTitleIsKnown( Title $title, &$isKnown ) { |
| 355 | + if ( in_array( $title->getNamespace(), array( EP_NS_COURSE, EP_NS_INSTITUTION ) ) ) { |
| 356 | + $classes = array( |
| 357 | + EP_NS_COURSE => 'EPCourse', |
| 358 | + EP_NS_INSTITUTION => 'EPOrg', |
| 359 | + ); |
| 360 | + |
| 361 | + $isKnown = $classes[$title->getNamespace()]::hasIdentifier( $title->getText() ); |
314 | 362 | } |
315 | | - |
316 | | - $classes = array_flip( $classes ); |
317 | | - |
318 | | - if ( !$exists && !in_array( 'new', $classes ) ) { |
319 | | - $classes[] = 'new'; |
320 | | - } |
321 | | - |
322 | | - $tab['class'] = implode( ' ', $classes ); |
323 | | - |
324 | | - $query = array(); |
325 | | - |
326 | | - if ( !$exists ) { |
327 | | - $query['action'] = 'edit'; |
328 | | - $query['redlink'] = '1'; |
329 | | - } |
330 | | - |
331 | | - $tab['href'] = $title->getLocalURL( $query ); |
| 363 | + |
| 364 | + return true; |
332 | 365 | } |
333 | 366 | |
334 | 367 | } |