r58737 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r58736‎ | r58737 | r58738 >
Date:01:41, 8 November 2009
Author:juliano
Status:deferred
Tags:
Comment:
Added a "sign and publish" checkbox to edit pages when editing wikilog articles.
Small doc fixes.
Modified paths:
  • /trunk/extensions/Wikilog/RELEASE-NOTES (modified) (history)
  • /trunk/extensions/Wikilog/Wikilog.i18n.php (modified) (history)
  • /trunk/extensions/Wikilog/Wikilog.php (modified) (history)
  • /trunk/extensions/Wikilog/WikilogDefaultSettings.php (modified) (history)
  • /trunk/extensions/Wikilog/WikilogHooks.php (modified) (history)
  • /trunk/extensions/Wikilog/WikilogItemPage.php (modified) (history)
  • /trunk/extensions/Wikilog/WikilogUtils.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikilog/WikilogDefaultSettings.php
@@ -69,6 +69,17 @@
7070 $wgWikilogMaxAuthors = 6;
7171
7272 /**
 73+ * Publish new articles by default. When creating new wikilog articles,
 74+ * if this variable is set to true, the default value of the "Sign and
 75+ * publish this article" checkbox will be checked, which means that saving
 76+ * the article will automatically sign and publish it. In order to save
 77+ * the article as draft, the user would have to uncheck the box before
 78+ * saving.
 79+ * @since Wikilog v1.0.1.
 80+ */
 81+$wgWikilogSignAndPublishDefault = false;
 82+
 83+/**
7384 * Enable use of tags. This is disabled by default since MediaWiki category
7485 * system already provides similar functionality, and are the preferred way
7586 * of organizing wikilog posts. Enable this if you want or need an additional
Index: trunk/extensions/Wikilog/Wikilog.php
@@ -102,30 +102,34 @@
103103 $wgExtensionFunctions[] = array( 'Wikilog', 'ExtensionInit' );
104104
105105 // Main Wikilog hooks
106 -$wgHooks['ArticleFromTitle'][] = 'Wikilog::ArticleFromTitle';
107 -$wgHooks['ArticleViewHeader'][] = 'Wikilog::ArticleViewHeader';
108 -$wgHooks['BeforePageDisplay'][] = 'Wikilog::BeforePageDisplay';
109 -$wgHooks['LinkBegin'][] = 'Wikilog::LinkBegin';
110 -$wgHooks['SkinTemplateTabAction'][] = 'Wikilog::SkinTemplateTabAction';
111 -$wgHooks['SkinTemplateTabs'][] = 'Wikilog::SkinTemplateTabs';
 106+$wgHooks['ArticleFromTitle'][] = 'Wikilog::ArticleFromTitle';
 107+$wgHooks['ArticleViewHeader'][] = 'Wikilog::ArticleViewHeader';
 108+$wgHooks['BeforePageDisplay'][] = 'Wikilog::BeforePageDisplay';
 109+$wgHooks['LinkBegin'][] = 'Wikilog::LinkBegin';
 110+$wgHooks['SkinTemplateTabAction'][] = 'Wikilog::SkinTemplateTabAction';
 111+$wgHooks['SkinTemplateTabs'][] = 'Wikilog::SkinTemplateTabs';
112112
113113 // General Wikilog hooks
114 -$wgHooks['ArticleEditUpdates'][] = 'WikilogHooks::ArticleEditUpdates';
115 -$wgHooks['ArticleDeleteComplete'][] = 'WikilogHooks::ArticleDeleteComplete';
116 -$wgHooks['TitleMoveComplete'][] = 'WikilogHooks::TitleMoveComplete';
 114+$wgHooks['ArticleEditUpdates'][] = 'WikilogHooks::ArticleEditUpdates';
 115+$wgHooks['ArticleDeleteComplete'][] = 'WikilogHooks::ArticleDeleteComplete';
 116+$wgHooks['ArticleSave'][] = 'WikilogHooks::ArticleSave';
 117+$wgHooks['TitleMoveComplete'][] = 'WikilogHooks::TitleMoveComplete';
 118+$wgHooks['EditPage::attemptSave'][] = 'WikilogHooks::EditPageAttemptSave';
 119+$wgHooks['EditPage::showEditForm:fields'][] = 'WikilogHooks::EditPageEditFormFields';
 120+$wgHooks['EditPage::importFormData'][] = 'WikilogHooks::EditPageImportFormData';
117121 $wgHooks['LoadExtensionSchemaUpdates'][] = 'WikilogHooks::ExtensionSchemaUpdates';
118 -$wgHooks['UnknownAction'][] = 'WikilogHooks::UnknownAction';
 122+$wgHooks['UnknownAction'][] = 'WikilogHooks::UnknownAction';
119123
120124 // WikilogLinksUpdate hooks
121 -$wgHooks['LinksUpdate'][] = 'WikilogLinksUpdate::LinksUpdate';
 125+$wgHooks['LinksUpdate'][] = 'WikilogLinksUpdate::LinksUpdate';
122126
123127 // WikilogParser hooks
124 -$wgHooks['ParserFirstCallInit'][] = 'WikilogParser::FirstCallInit';
125 -$wgHooks['ParserClearState'][] = 'WikilogParser::ClearState';
126 -$wgHooks['ParserBeforeInternalParse'][] = 'WikilogParser::BeforeInternalParse';
127 -$wgHooks['ParserAfterTidy'][] = 'WikilogParser::AfterTidy';
128 -$wgHooks['GetLocalURL'][] = 'WikilogParser::GetLocalURL';
129 -$wgHooks['GetFullURL'][] = 'WikilogParser::GetFullURL';
 128+$wgHooks['ParserFirstCallInit'][] = 'WikilogParser::FirstCallInit';
 129+$wgHooks['ParserClearState'][] = 'WikilogParser::ClearState';
 130+$wgHooks['ParserBeforeInternalParse'][] = 'WikilogParser::BeforeInternalParse';
 131+$wgHooks['ParserAfterTidy'][] = 'WikilogParser::AfterTidy';
 132+$wgHooks['GetLocalURL'][] = 'WikilogParser::GetLocalURL';
 133+$wgHooks['GetFullURL'][] = 'WikilogParser::GetFullURL';
130134
131135 if ( !defined( 'MW_SUPPORTS_LOCALISATIONCACHE' ) ) {
132136 /* pre Mw1.16 compatibility */
Index: trunk/extensions/Wikilog/WikilogHooks.php
@@ -179,6 +179,24 @@
180180 }
181181
182182 /**
 183+ * ArticleSave hook handler function.
 184+ * Add article signature if user selected "sign and publish" option in
 185+ * EditPage.
 186+ */
 187+ static function ArticleSave( &$article, &$user, &$text, &$summary,
 188+ $minor, $watch, $sectionanchor, &$flags )
 189+ {
 190+ # $article->mExtWikilog piggybacked from WikilogHooks::EditPageAttemptSave().
 191+ if ( isset( $article->mExtWikilog ) && $article->mExtWikilog['signpub'] ) {
 192+ $t = WikilogUtils::getPublishParameters();
 193+ $txtDate = $t['date'];
 194+ $txtUser = $t['user'];
 195+ $text = rtrim( $text ) . "\n{{wl-publish: {$txtDate} | {$txtUser} }}\n";
 196+ }
 197+ return true;
 198+ }
 199+
 200+ /**
183201 * TitleMoveComplete hook handler function.
184202 * Handles moving articles to and from wikilog namespaces.
185203 */
@@ -259,6 +277,82 @@
260278 }
261279
262280 /**
 281+ * EditPage::showEditForm:fields hook handler function.
 282+ * Adds wikilog article options to edit pages.
 283+ */
 284+ static function EditPageEditFormFields( &$editpage, &$output ) {
 285+ $wi = Wikilog::getWikilogInfo( $editpage->mTitle );
 286+ if ( $wi && $wi->isItem() && !$wi->isTalk() ) {
 287+ global $wgUser, $wgWikilogSignAndPublishDefault;
 288+ $fields = array();
 289+ $item = WikilogItem::newFromInfo( $wi );
 290+
 291+ # [x] Sign and publish this wikilog article.
 292+ if ( !$item || !$item->getIsPublished() ) {
 293+ if ( isset( $editpage->wlSignpub ) ) {
 294+ $checked = $editpage->wlSignpub;
 295+ } else {
 296+ $checked = !$item && $wgWikilogSignAndPublishDefault;
 297+ }
 298+ $label = wfMsgExt( 'wikilog-edit-signpub', array( 'parseinline' ) );
 299+ $tooltip = wfMsgExt( 'wikilog-edit-signpub-tooltip', array( 'parseinline' ) );
 300+ $fields['wlSignpub'] =
 301+ Xml::check( 'wlSignpub', $checked, array(
 302+ 'id' => 'wl-signpub',
 303+ 'tabindex' => 1, // after text, before summary
 304+ ) ) . ' ' .
 305+ Xml::element( 'label', array(
 306+ 'for' => 'wl-signpub',
 307+ 'title' => $tooltip,
 308+ ), $label );
 309+ }
 310+
 311+ $fields = implode( $fields, "\n" );
 312+ $html = Xml::fieldset(
 313+ wfMsgExt( 'wikilog-edit-fieldset-legend', array( 'parseinline' ) ),
 314+ $fields
 315+ );
 316+ $editpage->editFormTextAfterWarn .= $html;
 317+ }
 318+ return true;
 319+ }
 320+
 321+ /**
 322+ * EditPage::importFormData hook handler function.
 323+ * Import wikilog article options form data in edit pages.
 324+ * @note Requires MediaWiki 1.16+.
 325+ */
 326+ static function EditPageImportFormData( &$editpage, &$request ) {
 327+ if ( $request->wasPosted() ) {
 328+ $editpage->wlSignpub = $request->getCheck( 'wlSignpub' );
 329+ }
 330+ return true;
 331+ }
 332+
 333+ /**
 334+ * EditPage::attemptSave hook handler function.
 335+ * Check edit page options.
 336+ * @todo Remove $editpage->wlSignpub hack in Wikilog 1.1.0, along with
 337+ * support for Mw < 1.16.
 338+ */
 339+ static function EditPageAttemptSave( $editpage ) {
 340+ # HACK: For Mw < 1.16, due to the lack of 'EditPage::importFormData' hook.
 341+ if ( !isset( $editpage->wlSignpub ) ) {
 342+ global $wgRequest;
 343+ $editpage->wlSignpub = $wgRequest->getCheck( 'wlSignpub' );
 344+ }
 345+
 346+ $options = array(
 347+ 'signpub' => $editpage->wlSignpub
 348+ );
 349+
 350+ # Piggyback options into article object. Will be retrieved later
 351+ # in 'ArticleEditUpdates' hook.
 352+ $editpage->mArticle->mExtWikilog = $options;
 353+ return true;
 354+ }
 355+
 356+ /**
263357 * LoadExtensionSchemaUpdates hook handler function.
264358 * Updates wikilog database tables.
265359 *
Index: trunk/extensions/Wikilog/RELEASE-NOTES
@@ -2,11 +2,19 @@
33
44 == Current development version ==
55
 6+=== New configuration options ===
 7+
 8+* $wgWikilogSignAndPublishDefault: default state for the new "sign and
 9+ publish" checkbox in the edit page for new articles.
 10+
611 === New features ===
712
813 * New parameters 'date', 'time', 'updatedDate', 'updatedTime' and 'hasMore'
914 for the template pager, used when embedding using templates. Old parameters
1015 'pubdate' and 'updated' were deprecated, and should be removed on v1.2.0.
 16+* Wikilog article edit page now features a "sign and publish" checkbox that,
 17+ when selected, automatically signs and publishes the article by adding an
 18+ appropriate {{wl-publish:...}} parser function call at the end of the text.
1119
1220 === Bug fixes ===
1321
Index: trunk/extensions/Wikilog/WikilogItemPage.php
@@ -154,20 +154,13 @@
155155 * that is then saved to the database and causes the post to be published.
156156 */
157157 function preSaveTransform( $text ) {
158 - global $wgParser, $wgUser, $wgLocaltimezone;
 158+ global $wgParser, $wgUser;
159159
160 - $user = $wgUser->getName();
161160 $popt = ParserOptions::newFromUser( $wgUser );
162161
163 - $unixts = wfTimestamp( TS_UNIX, $popt->getTimestamp() );
164 - if ( isset( $wgLocaltimezone ) ) {
165 - $oldtz = getenv( 'TZ' );
166 - putenv( "TZ={$wgLocaltimezone}" );
167 - $date = date( 'Y-m-d H:i:s O', $unixts );
168 - putenv( "TZ={$oldtz}" );
169 - } else {
170 - $date = date( 'Y-m-d H:i:s O', $unixts );
171 - }
 162+ $t = WikilogUtils::getPublishParameters();
 163+ $date = $t['date'];
 164+ $user = $t['user'];
172165
173166 $sigs = array(
174167 '/\n?(--)?~~~~~\n?/m' => "\n{{wl-publish: {$date} }}\n",
Index: trunk/extensions/Wikilog/Wikilog.i18n.php
@@ -81,6 +81,12 @@
8282
8383 'wikilog-author-signature' => '[[{{ns:User}}:$1|$1]] ([[{{ns:User_talk}}:$1|talk]])',
8484
 85+ # Edit page
 86+ 'wikilog-edit-fieldset-legend' => 'Wikilog options:',
 87+ 'wikilog-edit-signpub' => 'Sign and publish this article',
 88+ 'wikilog-edit-signpub-tooltip' => 'Causes this article to be signed and published in its wikilog when saved.
 89+Uncheck this box to keep the article as a draft.',
 90+
8591 # Comments
8692 'wikilog-comment-by-user' => 'Comment by $1 ($2)',
8793 'wikilog-comment-by-anon' => 'Comment by $3 (anonymous)',
@@ -213,7 +219,7 @@
214220 * $1 = Wikilog URL
215221 * $2 = Wikilog Name
216222 * $5 = Authors,
217 -* $6 = Publish date,
 223+* $6 = Publication date,
218224 * $7 = Comments link',
219225 'wikilog-item-more' => 'Parameters:
220226 * $3 = Item URL',
@@ -223,7 +229,7 @@
224230 * $3 is a date
225231 * $4 is a time',
226232 'wikilog-comment-autosumm' => 'Parameters:
227 -* $1 is a user name
 233+* $1 is a user name
228234 * $2 is a summary',
229235 'wikilog-feed-title' => 'Parameters:
230236 * $1 is a title
Index: trunk/extensions/Wikilog/WikilogUtils.php
@@ -293,4 +293,27 @@
294294 implode( "\n", $rows ) );
295295 return $form;
296296 }
 297+
 298+ /**
 299+ * Returns the date and user parameters suitable for substitution in
 300+ * {{wl-publish:...}} parser function.
 301+ */
 302+ public static function getPublishParameters() {
 303+ global $wgUser, $wgLocaltimezone;
 304+
 305+ $user = $wgUser->getName();
 306+ $popt = ParserOptions::newFromUser( $wgUser );
 307+
 308+ $unixts = wfTimestamp( TS_UNIX, $popt->getTimestamp() );
 309+ if ( isset( $wgLocaltimezone ) ) {
 310+ $oldtz = getenv( 'TZ' );
 311+ putenv( "TZ={$wgLocaltimezone}" );
 312+ $date = date( 'Y-m-d H:i:s O', $unixts );
 313+ putenv( "TZ={$oldtz}" );
 314+ } else {
 315+ $date = date( 'Y-m-d H:i:s O', $unixts );
 316+ }
 317+
 318+ return array( 'date' => $date, 'user' => $user );
 319+ }
297320 }

Status & tagging log