r110287 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110286‎ | r110287 | r110288 >
Date:13:13, 30 January 2012
Author:jeroendedauw
Status:deferred
Tags:educationprogram 
Comment:
added docs, comment out currently dead code and fixed some messages
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.hooks.php (modified) (history)
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.php (modified) (history)
  • /trunk/extensions/EducationProgram/EducationProgram.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EPEditAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EPHistoryAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/pages/EPPage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/EducationProgram.php
@@ -165,6 +165,7 @@
166166 $wgHooks['SkinTemplateNavigation::SpecialPage'][] = 'EPHooks::onSpecialPageTabs';
167167 $wgHooks['ArticleFromTitle'][] = 'EPHooks::onArticleFromTitle';
168168 $wgHooks['CanonicalNamespaces'][] = 'EPHooks::onCanonicalNamespaces';
 169+$wgHooks['TitleIsKnown'][] = 'EPHooks::onTitleIsKnown';
169170
170171 // Logging
171172 $wgLogTypes[] = 'institution';
Index: trunk/extensions/EducationProgram/pages/EPPage.php
@@ -14,7 +14,26 @@
1515 */
1616 abstract class EPPage extends Page implements IContextSource {
1717
 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+ */
1832 protected $context;
 33+
 34+ /**
 35+ * @since 0.1
 36+ * @var WikiPage
 37+ */
1938 protected $page;
2039
2140 public function __construct( Title $title ) {
@@ -78,8 +97,6 @@
7998 return call_user_func_array( array( $this->getContext(), 'msg' ), $args );
8099 }
81100
82 - protected abstract function getActions();
83 -
84101 public function getActionOverrides() {
85102 $actions = $this->getActions();
86103
@@ -95,7 +112,11 @@
96113 public function getTouched() {
97114 return '19700101000000';
98115 }
99 -
 116+
 117+ /**
 118+ * @deprecated
 119+ * @return Language
 120+ */
100121 public function getLang() {
101122 wfDeprecated( __METHOD__, '1.19' );
102123 return $this->getLanguage();
Index: trunk/extensions/EducationProgram/actions/EPHistoryAction.php
@@ -13,7 +13,14 @@
1414 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1515 */
1616 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+ */
1825 protected abstract function getItemClass();
1926
2027 public function onView() {
Index: trunk/extensions/EducationProgram/actions/EPEditAction.php
@@ -29,7 +29,14 @@
3030 * @var boolean|null
3131 */
3232 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+ */
3441 protected abstract function getItemClass();
3542
3643 public function onView() {
@@ -78,7 +85,7 @@
7986 $object = new $c( $data, true );
8087 }
8188 elseif ( $this->isNewPost() ) {
82 - $this->showWarning( wfMessage( 'educationprogram-' . strtolower( $this->getName() ) . '-exists-already' ) );
 89+ $this->showWarning( wfMessage( 'ep-' . strtolower( $this->getName() ) . '-exists-already' ) );
8390 }
8491
8592 $this->getOutput()->setSubtitle( $this->getDescription() );
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
@@ -240,6 +240,7 @@
241241 'educationprogram-org-submit' => 'Submit',
242242 'ep-addorg' => 'There is no institution with this name yet, but you can add it.',
243243 'ep-editorg' => 'You are editing an existing institution.',
 244+ 'ep-editorg-exists-already' => 'This institution already exists. You are editing it.',
244245
245246 // Course editing
246247 'editcourse-add-legend' => 'Add course',
@@ -259,6 +260,7 @@
260261 'ep-course-edit-lang' => 'Course language',
261262 'ep-addcourse' => 'There is no course with this name yet, but you can add it.',
262263 'ep-editcourse' => 'You are editing an existing course.',
 264+ 'ep-editcourse-exists-already' => 'This course already exists. You are editing it.',
263265
264266 'ep-course-invalid-org' => 'This institution does not exist.',
265267 '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 @@
226226
227227 return true;
228228 }
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+ */
230239 protected static function displayTabs( SkinTemplate &$sktemplate, array &$links, Title $title ) {
231240 $classes = array(
232241 EP_NS_INSTITUTION => 'EPOrg',
233242 EP_NS_COURSE => 'EPCourse',
234243 );
235244
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+// );
242251
243252 $exists = null;
244253
@@ -290,44 +299,68 @@
291300 }
292301 }
293302
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+// }
306315 }
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() );
314362 }
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;
332365 }
333366
334367 }

Status & tagging log