r114148 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114147‎ | r114148 | r114149 >
Date:16:25, 19 March 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
allow setting default course descriptions via wiki pages
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.settings.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EditCourseAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/compat/SpecialCachedPage.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPUtils.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/compat/SpecialCachedPage.php
@@ -80,7 +80,7 @@
8181 * @return string
8282 */
8383 protected function getCachedNotice( $subPage ) {
84 - $refreshArgs = $_GET;
 84+ $refreshArgs = $this->getRequest()->getQueryValues();
8585 unset( $refreshArgs['title'] );
8686 $refreshArgs['action'] = 'purge';
8787
@@ -91,7 +91,7 @@
9292 $refreshArgs
9393 );
9494
95 - if ( $this->cacheExpiry < 1000000000 ) {
 95+ if ( $this->cacheExpiry < 86400 * 3650 ) {
9696 $message = $this->msg(
9797 'cachedspecial-viewing-cached-ttl',
9898 $this->getDurationText( $this->cacheExpiry )
Index: trunk/extensions/EducationProgram/EducationProgram.settings.php
@@ -50,6 +50,8 @@
5151 'US' => 'Flag_of_the_United_States.svg',
5252 ),
5353 'fallbackFlag' => 'Nuvola unknown flag.svg',
 54+ 'courseDescPage' => 'Course description',
 55+ 'courseOrgDescPage' => '$2/$1', // $1 = org name, $2 = courseDescPage setting
5456 );
5557 }
5658
Index: trunk/extensions/EducationProgram/actions/EditCourseAction.php
@@ -252,6 +252,13 @@
253253 );
254254
255255 $data['term'] = $this->getRequest()->getVal( 'newterm' );
 256+
 257+ $data['description'] = $this->getDefaultDescription( array(
 258+ 'institutionid' => $data['org_id'],
 259+ 'name' => $data['mc'],
 260+ 'title' => $data['name'],
 261+ 'term' => $data['term'],
 262+ ) );
256263 }
257264
258265 return $data;
@@ -268,5 +275,57 @@
269276
270277 return $value;
271278 }
 279+
 280+ /**
 281+ * Returns the description to use as default, based
 282+ * on the courseDescPage and courseOrgDescPage settings.
 283+ *
 284+ * @since 0.1
 285+ *
 286+ * @param array $data
 287+ *
 288+ * @return string
 289+ */
 290+ protected function getDefaultDescription( array $data ) {
 291+ $primaryPage = EPSettings::get( 'courseDescPage' );
 292+ $orgPage = EPSettings::get( 'courseOrgDescPage' );
 293+
 294+ $orgTitle = EPOrgs::singleton()->selectFieldsRow( 'name', array( 'id' => $data['institutionid'] ) );
 295+
 296+ $content = false;
 297+
 298+ if ( $orgTitle !== false ) {
 299+ $orgPage = str_replace(
 300+ array( '$1', '$2' ),
 301+ array( $orgTitle, $primaryPage ),
 302+ $orgPage
 303+ );
 304+
 305+ $content = EPUtils::getArticleContent( $orgPage );
 306+ }
 307+
 308+ if ( $content === false ) {
 309+ $content = EPUtils::getArticleContent( $primaryPage );
 310+ }
 311+
 312+ if ( $content === false ) {
 313+ $content = '';
 314+ }
 315+ else {
 316+ if ( $orgTitle !== false ) {
 317+ $data['institution'] = $orgTitle;
 318+ }
 319+
 320+ $content = str_replace(
 321+ array_map( function( $name ) {
 322+ return '{{{' . $name . '}}}';
 323+ }, array_keys( $data ) ),
 324+ $data,
 325+ $content
 326+ );
 327+ }
 328+
 329+ return $content;
 330+ }
272331
273332 }
\ No newline at end of file
Index: trunk/extensions/EducationProgram/includes/EPUtils.php
@@ -249,5 +249,25 @@
250250 $req->setSessionData( 'epfail', false );
251251 }
252252 }
 253+ /**
 254+ * Gets the content of the article with the provided page name,
 255+ * or an empty string when there is no such article.
 256+ *
 257+ * @since 0.1
 258+ *
 259+ * @param string $pageName
 260+ *
 261+ * @return string|false
 262+ */
 263+ public static function getArticleContent( $pageName ) {
 264+ $title = Title::newFromText( $pageName );
253265
 266+ if ( is_null( $title ) ) {
 267+ return '';
 268+ }
 269+
 270+ $article = new Article( $title, 0 );
 271+ return $article->fetchContent();
 272+ }
 273+
254274 }

Status & tagging log