https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114148
Revision: 114148
Author: jeroendedauw
Date: 2012-03-19 16:25:51 +0000 (Mon, 19 Mar 2012)
Log Message:
-----------
allow setting default course descriptions via wiki pages
Modified Paths:
--------------
trunk/extensions/EducationProgram/EducationProgram.settings.php
trunk/extensions/EducationProgram/actions/EditCourseAction.php
trunk/extensions/EducationProgram/compat/SpecialCachedPage.php
trunk/extensions/EducationProgram/includes/EPUtils.php
Modified: trunk/extensions/EducationProgram/EducationProgram.settings.php
===================================================================
--- trunk/extensions/EducationProgram/EducationProgram.settings.php
2012-03-19 16:14:05 UTC (rev 114147)
+++ trunk/extensions/EducationProgram/EducationProgram.settings.php
2012-03-19 16:25:51 UTC (rev 114148)
@@ -50,6 +50,8 @@
'US' => 'Flag_of_the_United_States.svg',
),
'fallbackFlag' => 'Nuvola unknown flag.svg',
+ 'courseDescPage' => 'Course description',
+ 'courseOrgDescPage' => '$2/$1', // $1 = org name, $2 =
courseDescPage setting
);
}
Modified: trunk/extensions/EducationProgram/actions/EditCourseAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EditCourseAction.php
2012-03-19 16:14:05 UTC (rev 114147)
+++ trunk/extensions/EducationProgram/actions/EditCourseAction.php
2012-03-19 16:25:51 UTC (rev 114148)
@@ -252,6 +252,13 @@
);
$data['term'] = $this->getRequest()->getVal( 'newterm'
);
+
+ $data['description'] = $this->getDefaultDescription(
array(
+ 'institutionid' => $data['org_id'],
+ 'name' => $data['mc'],
+ 'title' => $data['name'],
+ 'term' => $data['term'],
+ ) );
}
return $data;
@@ -268,5 +275,57 @@
return $value;
}
+
+ /**
+ * Returns the description to use as default, based
+ * on the courseDescPage and courseOrgDescPage settings.
+ *
+ * @since 0.1
+ *
+ * @param array $data
+ *
+ * @return string
+ */
+ protected function getDefaultDescription( array $data ) {
+ $primaryPage = EPSettings::get( 'courseDescPage' );
+ $orgPage = EPSettings::get( 'courseOrgDescPage' );
+
+ $orgTitle = EPOrgs::singleton()->selectFieldsRow( 'name',
array( 'id' => $data['institutionid'] ) );
+
+ $content = false;
+
+ if ( $orgTitle !== false ) {
+ $orgPage = str_replace(
+ array( '$1', '$2' ),
+ array( $orgTitle, $primaryPage ),
+ $orgPage
+ );
+
+ $content = EPUtils::getArticleContent( $orgPage );
+ }
+
+ if ( $content === false ) {
+ $content = EPUtils::getArticleContent( $primaryPage );
+ }
+
+ if ( $content === false ) {
+ $content = '';
+ }
+ else {
+ if ( $orgTitle !== false ) {
+ $data['institution'] = $orgTitle;
+ }
+
+ $content = str_replace(
+ array_map( function( $name ) {
+ return '{{{' . $name . '}}}';
+ }, array_keys( $data ) ),
+ $data,
+ $content
+ );
+ }
+
+ return $content;
+ }
}
\ No newline at end of file
Modified: trunk/extensions/EducationProgram/compat/SpecialCachedPage.php
===================================================================
--- trunk/extensions/EducationProgram/compat/SpecialCachedPage.php
2012-03-19 16:14:05 UTC (rev 114147)
+++ trunk/extensions/EducationProgram/compat/SpecialCachedPage.php
2012-03-19 16:25:51 UTC (rev 114148)
@@ -80,7 +80,7 @@
* @return string
*/
protected function getCachedNotice( $subPage ) {
- $refreshArgs = $_GET;
+ $refreshArgs = $this->getRequest()->getQueryValues();
unset( $refreshArgs['title'] );
$refreshArgs['action'] = 'purge';
@@ -91,7 +91,7 @@
$refreshArgs
);
- if ( $this->cacheExpiry < 1000000000 ) {
+ if ( $this->cacheExpiry < 86400 * 3650 ) {
$message = $this->msg(
'cachedspecial-viewing-cached-ttl',
$this->getDurationText( $this->cacheExpiry )
Modified: trunk/extensions/EducationProgram/includes/EPUtils.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPUtils.php 2012-03-19
16:14:05 UTC (rev 114147)
+++ trunk/extensions/EducationProgram/includes/EPUtils.php 2012-03-19
16:25:51 UTC (rev 114148)
@@ -249,5 +249,25 @@
$req->setSessionData( 'epfail', false );
}
}
+ /**
+ * Gets the content of the article with the provided page name,
+ * or an empty string when there is no such article.
+ *
+ * @since 0.1
+ *
+ * @param string $pageName
+ *
+ * @return string|false
+ */
+ public static function getArticleContent( $pageName ) {
+ $title = Title::newFromText( $pageName );
+ if ( is_null( $title ) ) {
+ return '';
+ }
+
+ $article = new Article( $title, 0 );
+ return $article->fetchContent();
+ }
+
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs