r62740 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62739‎ | r62740 | r62741 >
Date:17:05, 20 February 2010
Author:ialex
Status:ok
Tags:
Comment:
(bug 8790) Metadata edition ($wgUseMetadataEdit) has been moved to a separate extension "MetadataEdit":
* Removed $wgUseMetadataEdit and related code in EditPage from and created a new extension "MetadataEdit"
* Added 3 new hooks EditFormInitialText, EditFormGetDiffText and EditFormGetPreviewText
* Moved 'metadata_help' message to the extension
Modified paths:
  • /trunk/extensions/MetadataEdit (added) (history)
  • /trunk/extensions/MetadataEdit/MetadataEdit.i18n.php (added) (history)
  • /trunk/extensions/MetadataEdit/MetadataEdit.php (added) (history)
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/docs/hooks.txt (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/EditPage.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/maintenance/language/messages.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/language/messages.inc
@@ -201,9 +201,6 @@
202202 'namespaces',
203203 'variants',
204204 ),
205 - 'metadata_help' => array(
206 - 'metadata_help',
207 - ),
208205 'miscellaneous2' => array(
209206 'errorpagetitle',
210207 'returnto',
@@ -3156,7 +3153,6 @@
31573154 'miscellaneous1' => '',
31583155 'cologneblue' => 'Cologne Blue skin',
31593156 'vector' => 'Vector skin',
3160 - 'metadata_help' => 'Metadata in edit box',
31613157 'miscellaneous2' => '',
31623158 'links' => 'All link text and link target definitions of links into project namespace that get used by other message strings, with the exception of user group pages (see grouppage) and the disambiguation template definition (see disambiguations).',
31633159 'badaccess' => '',
Index: trunk/phase3/docs/hooks.txt
@@ -638,6 +638,10 @@
639639 &$text: Text to preload with
640640 &$title: Title object representing the page being created
641641
 642+'EditFormInitialText': Allows modifying the edit form when editing existing
 643+pages
 644+$editPage: EditPage object
 645+
642646 'EditPage::attemptSave': called before an article is
643647 saved, that is before insertNewArticle() is called
644648 $editpage_Obj: the current EditPage object
@@ -689,6 +693,15 @@
690694 $title: title of page being edited
691695 &$msg: localization message name, overridable. Default is either 'copyrightwarning' or 'copyrightwarning2'
692696
 697+'EditPageGetDiffText': Allow modifying the wikitext that will be used in
 698+"Show changes"
 699+$editPage: EditPage object
 700+&$newtext: wikitext that will be used as "your version"
 701+
 702+'EditPageGetPreviewText': Allow modifying the wikitext that will be previewed
 703+$editPage: EditPage object
 704+&$toparse: wikitext that will be parsed
 705+
693706 'EditPageNoSuchSection': When a section edit request is given for an non-existent section
694707 &$editpage: The current EditPage object
695708 &$res: the HTML of the error text
Index: trunk/phase3/includes/EditPage.php
@@ -45,7 +45,6 @@
4646 var $mArticle;
4747 var $mTitle;
4848 var $action;
49 - var $mMetaData = '';
5049 var $isConflict = false;
5150 var $isCssJsSubpage = false;
5251 var $isCssSubpage = false;
@@ -247,95 +246,6 @@
248247 }
249248 }
250249
251 - /**
252 - * This is the function that extracts metadata from the article body on the first view.
253 - * To turn the feature on, set $wgUseMetadataEdit = true ; in LocalSettings
254 - * and set $wgMetadataWhitelist to the *full* title of the template whitelist
255 - */
256 - function extractMetaDataFromArticle () {
257 - global $wgUseMetadataEdit, $wgMetadataWhitelist, $wgContLang;
258 - $this->mMetaData = '';
259 - if ( !$wgUseMetadataEdit ) return;
260 - if ( $wgMetadataWhitelist == '' ) return;
261 - $s = '';
262 - $t = $this->getContent();
263 -
264 - # MISSING : <nowiki> filtering
265 -
266 - # Categories and language links
267 - $t = explode( "\n" , $t );
268 - $catlow = strtolower( $wgContLang->getNsText( NS_CATEGORY ) );
269 - $cat = $ll = array();
270 - foreach ( $t as $key => $x ) {
271 - $y = trim( strtolower ( $x ) );
272 - while ( substr( $y , 0 , 2 ) == '[[' ) {
273 - $y = explode( ']]' , trim ( $x ) );
274 - $first = array_shift( $y );
275 - $first = explode( ':' , $first );
276 - $ns = array_shift( $first );
277 - $ns = trim( str_replace( '[' , '' , $ns ) );
278 - if ( $wgContLang->getLanguageName( $ns ) || strtolower( $ns ) == $catlow ) {
279 - $add = '[[' . $ns . ':' . implode( ':' , $first ) . ']]';
280 - if ( strtolower( $ns ) == $catlow ) $cat[] = $add;
281 - else $ll[] = $add;
282 - $x = implode( ']]', $y );
283 - $t[$key] = $x;
284 - $y = trim( strtolower( $x ) );
285 - } else {
286 - $x = implode( ']]' , $y );
287 - $y = trim( strtolower( $x ) );
288 - }
289 - }
290 - }
291 - if ( count( $cat ) ) $s .= implode( ' ' , $cat ) . "\n";
292 - if ( count( $ll ) ) $s .= implode( ' ' , $ll ) . "\n";
293 - $t = implode( "\n" , $t );
294 -
295 - # Load whitelist
296 - $sat = array () ; # stand-alone-templates; must be lowercase
297 - $wl_title = Title::newFromText( $wgMetadataWhitelist );
298 - $wl_article = new Article ( $wl_title );
299 - $wl = explode ( "\n" , $wl_article->getContent() );
300 - foreach ( $wl AS $x ) {
301 - $isentry = false;
302 - $x = trim ( $x );
303 - while ( substr ( $x , 0 , 1 ) == '*' ) {
304 - $isentry = true;
305 - $x = trim ( substr ( $x , 1 ) );
306 - }
307 - if ( $isentry ) {
308 - $sat[] = strtolower ( $x );
309 - }
310 -
311 - }
312 -
313 - # Templates, but only some
314 - $t = explode( '{{' , $t );
315 - $tl = array() ;
316 - foreach ( $t as $key => $x ) {
317 - $y = explode( '}}' , $x , 2 );
318 - if ( count( $y ) == 2 ) {
319 - $z = $y[0];
320 - $z = explode( '|' , $z );
321 - $tn = array_shift( $z );
322 - if ( in_array( strtolower( $tn ) , $sat ) ) {
323 - $tl[] = '{{' . $y[0] . '}}';
324 - $t[$key] = $y[1];
325 - $y = explode( '}}' , $y[1] , 2 );
326 - }
327 - else $t[$key] = '{{' . $x;
328 - }
329 - else if ( $key != 0 ) $t[$key] = '{{' . $x;
330 - else $t[$key] = $x;
331 - }
332 - if ( count( $tl ) ) $s .= implode( ' ' , $tl );
333 - $t = implode( '' , $t );
334 -
335 - $t = str_replace( "\n\n\n", "\n", $t );
336 - $this->mArticle->mContent = $t;
337 - $this->mMetaData = $s;
338 - }
339 -
340250 /*
341251 * Check if a page was deleted while the user was editing it, before submit.
342252 * Note that we rely on the logging table, which hasn't been always there,
@@ -427,7 +337,6 @@
428338 if ( $this->previewOnOpen() ) {
429339 $this->formtype = 'preview';
430340 } else {
431 - $this->extractMetaDataFromArticle () ;
432341 $this->formtype = 'initial';
433342 }
434343 }
@@ -495,6 +404,8 @@
496405 }
497406 if ( !$this->mTitle->getArticleId() )
498407 wfRunHooks( 'EditFormPreloadText', array( &$this->textbox1, &$this->mTitle ) );
 408+ else
 409+ wfRunHooks( 'EditFormInitialText', array( $this ) );
499410 }
500411
501412 $this->showEditForm();
@@ -620,7 +531,7 @@
621532 $this->textbox1 = $textbox1;
622533 wfProfileOut( get_class($this)."::importContentFormData" );
623534 }
624 - $this->mMetaData = rtrim( $request->getText( 'metadata' ) );
 535+
625536 # Truncate for whole multibyte characters. +5 bytes for ellipsis
626537 $this->summary = $wgLang->truncate( $request->getText( 'wpSummary' ), 250, '' );
627538
@@ -690,7 +601,6 @@
691602 # Not a posted form? Start with nothing.
692603 wfDebug( __METHOD__ . ": Not a posted form.\n" );
693604 $this->textbox1 = '';
694 - $this->mMetaData = '';
695605 $this->summary = '';
696606 $this->edittime = '';
697607 $this->starttime = wfTimestampNow();
@@ -852,8 +762,7 @@
853763 wfProfileIn( __METHOD__ );
854764 wfProfileIn( __METHOD__ . '-checks' );
855765
856 - if ( !wfRunHooks( 'EditPage::attemptSave', array( $this ) ) )
857 - {
 766+ if ( !wfRunHooks( 'EditPage::attemptSave', array( $this ) ) ) {
858767 wfDebug( "Hook 'EditPage::attemptSave' aborted article saving\n" );
859768 return self::AS_HOOK_ERROR;
860769 }
@@ -869,10 +778,6 @@
870779 }
871780 }
872781
873 - # Reintegrate metadata
874 - if ( $this->mMetaData != '' ) $this->textbox1 .= "\n" . $this->mMetaData ;
875 - $this->mMetaData = '' ;
876 -
877782 # Check for spam
878783 $match = self::matchSummarySpamRegex( $this->summary );
879784 if ( $match === false ) {
@@ -1392,10 +1297,6 @@
13931298 if ( isset($this->editFormTextAfterWarn) && $this->editFormTextAfterWarn !== '' )
13941299 $wgOut->addHTML( $this->editFormTextAfterWarn );
13951300
1396 - global $wgUseMetadataEdit;
1397 - if ( $wgUseMetadataEdit )
1398 - $this->showMetaData();
1399 -
14001301 $this->showStandardInputs();
14011302
14021303 $this->showFormAfterText();
@@ -1749,15 +1650,6 @@
17501651
17511652 $wgOut->addHTML( Html::textarea( $name, $wikitext, $attribs ) );
17521653 }
1753 -
1754 - protected function showMetaData() {
1755 - global $wgOut, $wgContLang, $wgUser;
1756 - $metadata = htmlspecialchars( $wgContLang->recodeForEdit( $this->mMetaData ) );
1757 - $ew = $wgUser->getOption( 'editwidth' ) ? ' style="width:100%"' : '';
1758 - $cols = $wgUser->getIntOption( 'cols' );
1759 - $metadata = wfMsgWikiHtml( 'metadata_help' ) . "<textarea name='metadata' rows='3' cols='{$cols}'{$ew}>{$metadata}</textarea>" ;
1760 - $wgOut->addHTML( $metadata );
1761 - }
17621654
17631655 protected function displayPreviewArea( $previewOutput, $isOnTop = false ) {
17641656 global $wgOut;
@@ -1969,10 +1861,10 @@
19701862 # If we're adding a comment, we need to show the
19711863 # summary as the headline
19721864 if ( $this->section == "new" && $this->summary != "" ) {
1973 - $toparse="== {$this->summary} ==\n\n" . $toparse;
 1865+ $toparse = "== {$this->summary} ==\n\n" . $toparse;
19741866 }
19751867
1976 - if ( $this->mMetaData != "" ) $toparse .= "\n" . $this->mMetaData;
 1868+ wfRunHooks( 'EditPageGetPreviewText', array( $this, &$toparse ) );
19771869
19781870 // Parse mediawiki messages with correct target language
19791871 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
@@ -2496,6 +2388,9 @@
24972389 $oldtext = $this->mArticle->fetchContent();
24982390 $newtext = $this->mArticle->replaceSection(
24992391 $this->section, $this->textbox1, $this->summary, $this->edittime );
 2392+
 2393+ wfRunHooks( 'EditPageGetDiffText', array( $this, &$newtext ) );
 2394+
25002395 $newtext = $this->mArticle->preSaveTransform( $newtext );
25012396 $oldtitle = wfMsgExt( 'currentrev', array( 'parseinline' ) );
25022397 $newtitle = wfMsgExt( 'yourtext', array( 'parseinline' ) );
Index: trunk/phase3/includes/DefaultSettings.php
@@ -2486,16 +2486,6 @@
24872487 */
24882488 $wgEnableNewpagesUserFilter = true;
24892489
2490 -/**
2491 - * Whether to use metadata edition
2492 - * This will put categories, language links and allowed templates in a separate text box
2493 - * while editing pages
2494 - * EXPERIMENTAL
2495 - */
2496 -$wgUseMetadataEdit = false;
2497 -/** Full name (including namespace) of the page containing templates names that will be allowed as metadata */
2498 -$wgMetadataWhitelist = '';
2499 -
25002490 #
25012491 # Copyright and credits settings
25022492 #
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -800,9 +800,6 @@
801801 'namespaces' => 'Namespaces',
802802 'variants' => 'Variants',
803803
804 -# Metadata in edit box
805 -'metadata_help' => 'Metadata:',
806 -
807804 'errorpagetitle' => 'Error',
808805 'returnto' => 'Return to $1.',
809806 'tagline' => 'From {{SITENAME}}',
Index: trunk/phase3/RELEASE-NOTES
@@ -101,6 +101,8 @@
102102 for controlling debug output.
103103 * New $wgBlockDisablesLogin when set to true disallows blocked users from
104104 logging in.
 105+* (bug 8790) Metadata edition ($wgUseMetadataEdit) has been moved to a separate
 106+ extension "MetadataEdit".
105107
106108 === New features in 1.16 ===
107109
Index: trunk/extensions/MetadataEdit/MetadataEdit.i18n.php
@@ -0,0 +1,14 @@
 2+<?php
 3+/**
 4+ * Internationalisation file for MetadataEdit extension.
 5+ *
 6+ * @file
 7+ * @ingroup Extensions
 8+ */
 9+
 10+$messages = array();
 11+
 12+$messages['en'] = array(
 13+ 'metadataedit-desc' => 'Put categories, language links and allowed templates in a separate text box while editing pages',
 14+ 'metadata_help' => 'Metadata:',
 15+);
\ No newline at end of file
Property changes on: trunk/extensions/MetadataEdit/MetadataEdit.i18n.php
___________________________________________________________________
Name: svn:eol-style
116 + native
Index: trunk/extensions/MetadataEdit/MetadataEdit.php
@@ -0,0 +1,165 @@
 2+<?php
 3+
 4+/**
 5+ * Put categories, language links and allowed templates in a separate text box
 6+ * while editing pages.
 7+ *
 8+ * @file
 9+ * @ingroup Extensions
 10+ * @author Magnus Manske and Alexandre Emsenhuber
 11+ */
 12+
 13+$wgExtensionCredits['other'][] = array(
 14+ 'path' => __FILE__,
 15+ 'name' => 'MetadataEdit',
 16+ 'author' => array( 'Magnus Manske', 'Alexandre Emsenhuber' ),
 17+ 'url' => 'http://www.mediawiki.org/wiki/Extension:MetadataEdit',
 18+ 'description' => 'Put categories, language links and allowed templates in a separate text box while editing pages',
 19+ 'descriptionmsg' => 'metadataedit-desc',
 20+ 'version' => '0.1',
 21+);
 22+
 23+/**
 24+ * Full name (including namespace) of the page containing templates names that
 25+ * will be allowed as metadata
 26+ */
 27+$wgMetadataWhitelist = '';
 28+
 29+$wgExtensionMessagesFiles['MetadataEdit'] = dirname( __FILE__ ) . '/MetadataEdit.i18n.php';
 30+
 31+$wgHooks['EditFormInitialText'][] = 'wfMetadataEditExtractFromArticle';
 32+$wgHooks['EditPage::importFormData'][] = 'wfMetadataEditOnImportData';
 33+$wgHooks['EditPage::attemptSave'][] = 'wfMetadataEditOnAttemptSave';
 34+$wgHooks['EditPage::showEditForm:fields'][] = 'wfMetadataEditOnShowFields';
 35+$wgHooks['EditPageGetPreviewText'][] = 'wfMetadataEditOnGetPreviewText';
 36+$wgHooks['EditPageGetDiffText'][] = 'wfMetadataEditOnGetDiffText';
 37+
 38+function wfMetadataEditExtractFromArticle( $editPage ) {
 39+ global $wgMetadataWhitelist, $wgContLang;
 40+
 41+ $editPage->mMetaData = '';
 42+ if ( $wgMetadataWhitelist == '' ) return true;
 43+ $s = '';
 44+ $t = $editPage->textbox1;
 45+
 46+ # MISSING : <nowiki> filtering
 47+
 48+ # Categories and language links
 49+ $t = explode( "\n" , $t );
 50+ $catlow = strtolower( $wgContLang->getNsText( NS_CATEGORY ) );
 51+ $cat = $ll = array();
 52+ foreach ( $t as $key => $x ) {
 53+ $y = trim( strtolower ( $x ) );
 54+ while ( substr( $y , 0 , 2 ) == '[[' ) {
 55+ $y = explode( ']]' , trim ( $x ) );
 56+ $first = array_shift( $y );
 57+ $first = explode( ':' , $first );
 58+ $ns = array_shift( $first );
 59+ $ns = trim( str_replace( '[' , '' , $ns ) );
 60+ if ( $wgContLang->getLanguageName( $ns ) || strtolower( $ns ) == $catlow ) {
 61+ $add = '[[' . $ns . ':' . implode( ':' , $first ) . ']]';
 62+ if ( strtolower( $ns ) == $catlow ) $cat[] = $add;
 63+ else $ll[] = $add;
 64+ $x = implode( ']]', $y );
 65+ $t[$key] = $x;
 66+ $y = trim( strtolower( $x ) );
 67+ } else {
 68+ $x = implode( ']]' , $y );
 69+ $y = trim( strtolower( $x ) );
 70+ }
 71+ }
 72+ }
 73+ if ( count( $cat ) ) $s .= implode( ' ' , $cat ) . "\n";
 74+ if ( count( $ll ) ) $s .= implode( ' ' , $ll ) . "\n";
 75+ $t = implode( "\n" , $t );
 76+
 77+ # Load whitelist
 78+ $sat = array () ; # stand-alone-templates; must be lowercase
 79+ $wl_title = Title::newFromText( $wgMetadataWhitelist );
 80+ if ( !$wl_title ) {
 81+ throw new MWException( '$wgMetadataWhitelist is not set to a valid page title.' );
 82+ }
 83+ $wl_article = new Article ( $wl_title );
 84+ $wl = array();//explode ( "\n" , $wl_article->getContent() );
 85+ foreach ( $wl AS $x ) {
 86+ $isentry = false;
 87+ $x = trim ( $x );
 88+ while ( substr ( $x , 0 , 1 ) == '*' ) {
 89+ $isentry = true;
 90+ $x = trim ( substr ( $x , 1 ) );
 91+ }
 92+ if ( $isentry ) {
 93+ $sat[] = strtolower ( $x );
 94+ }
 95+
 96+ }
 97+
 98+ # Templates, but only some
 99+ $t = explode( '{{' , $t );
 100+ $tl = array() ;
 101+ foreach ( $t as $key => $x ) {
 102+ $y = explode( '}}' , $x , 2 );
 103+ if ( count( $y ) == 2 ) {
 104+ $z = $y[0];
 105+ $z = explode( '|' , $z );
 106+ $tn = array_shift( $z );
 107+ if ( in_array( strtolower( $tn ) , $sat ) ) {
 108+ $tl[] = '{{' . $y[0] . '}}';
 109+ $t[$key] = $y[1];
 110+ $y = explode( '}}' , $y[1] , 2 );
 111+ }
 112+ else $t[$key] = '{{' . $x;
 113+ }
 114+ else if ( $key != 0 ) $t[$key] = '{{' . $x;
 115+ else $t[$key] = $x;
 116+ }
 117+ if ( count( $tl ) ) $s .= implode( ' ' , $tl );
 118+ $t = implode( '' , $t );
 119+
 120+ $t = str_replace( "\n\n\n", "\n", $t );
 121+ $editPage->textbox1 = $t;
 122+ $editPage->mMetaData = $s;
 123+
 124+ return true;
 125+}
 126+
 127+function wfMetadataEditOnImportData( $editPage, $request ) {
 128+ if ( $request->wasPosted() ) {
 129+ $editPage->mMetaData = rtrim( $request->getText( 'metadata' ) );
 130+ } else {
 131+ $editPage->mMetaData = '';
 132+ }
 133+
 134+ return true;
 135+}
 136+
 137+function wfMetadataEditOnAttemptSave( $editPage ) {
 138+ # Reintegrate metadata
 139+ if ( $editPage->mMetaData != '' ) $editPage->textbox1 .= "\n" . $editPage->mMetaData;
 140+ $editPage->mMetaData = '';
 141+
 142+ return true;
 143+}
 144+
 145+function wfMetadataEditOnShowFields( $editPage ) {
 146+ global $wgContLang, $wgUser;
 147+ $metadata = htmlspecialchars( $wgContLang->recodeForEdit( $editPage->mMetaData ) );
 148+ $ew = $wgUser->getOption( 'editwidth' ) ? ' style="width:100%"' : '';
 149+ $cols = $wgUser->getIntOption( 'cols' );
 150+ $metadata = wfMsgWikiHtml( 'metadata_help' ) . "<textarea name='metadata' rows='3' cols='{$cols}'{$ew}>{$metadata}</textarea>" ;
 151+ $editPage->editFormTextAfterContent .= $metadata;
 152+
 153+ return true;
 154+}
 155+
 156+function wfMetadataEditOnGetPreviewText( $editPage, &$toparse ) {
 157+ if ( $editPage->mMetaData != '' ) $toparse .= "\n" . $editPage->mMetaData;
 158+
 159+ return true;
 160+}
 161+
 162+function wfMetadataEditOnGetDiffText( $editPage, &$newText ) {
 163+ if ( $editPage->mMetaData != '' ) $newText .= "\n" . $editPage->mMetaData;
 164+
 165+ return true;
 166+}
Property changes on: trunk/extensions/MetadataEdit/MetadataEdit.php
___________________________________________________________________
Name: svn:eol-style
1167 + native

Follow-up revisions

RevisionCommit summaryAuthorDate
r62743Follow-up r62740: add the extension to Translateialex17:53, 20 February 2010

Status & tagging log