r67182 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r67181‎ | r67182 | r67183 >
Date:12:39, 1 June 2010
Author:raymond
Status:ok
Tags:
Comment:
Tweaks to extension credits
Use content language to fetch the front/back/forced strings. Otherwise you will get unexpected results if user language != content languages
Add extension to translatewiki
Modified paths:
  • /trunk/extensions/FrontBackMatterForcedWikilinks/FrontBackMatterForcedWikilinks.i18n.php (modified) (history)
  • /trunk/extensions/FrontBackMatterForcedWikilinks/FrontBackMatterForcedWikilinks.php (modified) (history)
  • /trunk/extensions/Translate/groups/mediawiki-defines.txt (modified) (history)

Diff [purge]

Index: trunk/extensions/FrontBackMatterForcedWikilinks/FrontBackMatterForcedWikilinks.i18n.php
@@ -1,9 +1,17 @@
22 <?php
 3+/**
 4+ * Internationalisation for FrontBackMatterForcedWikilinks extension
 5+ *
 6+ * @file
 7+ * @ingroup Extensions
 8+ */
 9+
310 $messages = array();
411
512 $messages['en'] = array(
613 'frontbackforced-desc' => 'Prepends front matter and appends back matter to pages and implements forced wikilinks',
714 'frontbackforced-front' => '_(front_matter)',
815 'frontbackforced-back' => '_(back_matter)',
9 - 'frontbackforced-forced' => '_(forced_wikilinks)'
10 -);
\ No newline at end of file
 16+ 'frontbackforced-forced' => '_(forced_wikilinks)',
 17+);
 18+
Index: trunk/extensions/FrontBackMatterForcedWikilinks/FrontBackMatterForcedWikilinks.php
@@ -16,19 +16,20 @@
1717 # Alert the user that this is not a valid entry point to MediaWiki if they try to access the
1818 # special pages file directly.
1919 if (!defined('MEDIAWIKI')) {
20 - echo <<<EOT
 20+ echo <<<EOT
2121 To install the Front and Back Matter and Forced Wikilinks extension, put the following line in LocalSettings.php:
2222 require_once( "\$IP/extensions/FrontBackMatterForcedWikilinks/FrontBackMatterForcedWikilinks.php" );
2323 EOT;
24 - exit( 1 );
 24+ exit( 1 );
2525 }
2626
2727 $wgExtensionCredits['parserhook'][] = array(
 28+ 'path' => __FILE__,
2829 'name' => 'Front and Back Matter and Forced Wikilinks',
2930 'author' => 'Tisane',
3031 'url' => 'http://www.mediawiki.org/wiki/Extension:FrontBackMatterForcedWikilinks',
3132 'description' => 'Prepends front matter and appends back matter to pages and implements forced wikilinks',
32 - 'descriptionmsg' => 'FrontBackForced-desc',
 33+ 'descriptionmsg' => 'frontbackforced-desc',
3334 'version' => '1.0.0',
3435 );
3536
@@ -39,18 +40,18 @@
4041 $wgHooks['ArticleSaveComplete'][] = 'FrontBackForcedArticleSaveCompleteHook';
4142
4243 function FrontBackForcedParserBeforeStripHook( &$parser, &$text, &$strip_state ) {
43 - global $wgLang;
44 - $frontMsg=wfMsg( 'frontbackforced-front');
45 - $backMsg=wfMsg( 'frontbackforced-back');
46 - $forcedMsg=wfMsg( 'frontbackforced-forced');
47 - wfLoadExtensionMessages('FrontBackMatterForcedWikilinks');
 44+ global $wgLang;
 45+ wfLoadExtensionMessages('FrontBackMatterForcedWikilinks');
 46+ $frontMsg=wfMsgForContent( 'frontbackforced-front' );
 47+ $backMsg=wfMsgForContent( 'frontbackforced-back' );
 48+ $forcedMsg=wfMsgForContent( 'frontbackforced-forced' );
4849 $dbr = wfGetDB( DB_SLAVE );
4950 $title=$parser->getTitle();
5051 if( $title->getNamespace() == NS_SPECIAL
5152 || $title->getNamespace() == NS_MEDIA
5253 || $title->getNamespace() == NS_FILE
5354 || $title->isExternal()) {
54 - return true;
 55+ return true;
5556 }
5657 $myRevision=Revision::loadFromTitle($dbr,$title);
5758 if ($myRevision!=null){
@@ -68,49 +69,49 @@
6970 $backMatterText=$backMatterRev->getRawText();
7071 $text=$text.$backMatterText;
7172 }
72 - $forcedMatterTitle=Title::newFromDBkey($title->getPrefixedDBkey().$forcedMsg);
 73+ $forcedMatterTitle=Title::newFromDBkey($title->getPrefixedDBkey().$forcedMsg);
7374 $forcedMatterRev=Revision::loadFromTitle($dbr,$forcedMatterTitle);
7475 if ($forcedMatterRev!=null){
7576 $forcedMatterText=$forcedMatterRev->getRawText();
76 - $strPosition=0;
77 - $endPosition=0;
78 - $endSubstPosition=0;
79 - $thisCount=0;
 77+ $strPosition=0;
 78+ $endPosition=0;
 79+ $endSubstPosition=0;
 80+ $thisCount=0;
8081 while (1){
81 - $oldStrPosition=$strPosition;
82 - $strPosition=strpos($forcedMatterText,'>',$strPosition);
83 - if ($strPosition===false || $strPosition<=$oldStrPosition && $thisCount>0){
84 - break;
85 - }
86 - $oldEndPosition=$endPosition;
87 - $endPosition=strpos($forcedMatterText,'<',$strPosition);
88 - if ($endPosition===false || $endPosition<=$oldEndPosition && $thisCount>0){
89 - break;
90 - }
91 - $wfyText=substr($forcedMatterText,$strPosition+1,$endPosition-$strPosition-1);
92 - $oldEndSubstPosition=$endSubstPosition;
93 - $endSubstPosition=strpos($forcedMatterText,'#',$endPosition);
94 - if ($endSubstPosition===false || $endSubstPosition-$endPosition==1 || $endSubstPosition<=$oldEndSubstPosition && $thisCount>0){
95 - $wfyToText=$wfyText;
96 - } else {
97 - $wfyToText=substr($forcedMatterText,$endPosition+1,$endSubstPosition-$endPosition-1);
98 - }
99 - $articleStartPos=strpos($text,$wfyText);
100 - $continueThis=true;
101 - if ($articleStartPos===false){
102 - $continueThis=false;
103 - }
104 - if ($articleStartPos>2){
105 - if (substr($text,$articleStartPos-2,2)=='[['){
106 - $continueThis=false;
107 - }
108 - }
109 - if ($continueThis==true){
110 - $text=substr($text,0,$articleStartPos).'[['.$wfyToText.'|'.$wfyText.']]'.substr($text,$articleStartPos+strlen($wfyText),strlen($text)-$articleStartPos-strlen($wfyText));
111 - }
112 - $thisCount++;
113 - $strPosition++;
114 - }
 82+ $oldStrPosition=$strPosition;
 83+ $strPosition=strpos($forcedMatterText,'>',$strPosition);
 84+ if ($strPosition===false || $strPosition<=$oldStrPosition && $thisCount>0){
 85+ break;
 86+ }
 87+ $oldEndPosition=$endPosition;
 88+ $endPosition=strpos($forcedMatterText,'<',$strPosition);
 89+ if ($endPosition===false || $endPosition<=$oldEndPosition && $thisCount>0){
 90+ break;
 91+ }
 92+ $wfyText=substr($forcedMatterText,$strPosition+1,$endPosition-$strPosition-1);
 93+ $oldEndSubstPosition=$endSubstPosition;
 94+ $endSubstPosition=strpos($forcedMatterText,'#',$endPosition);
 95+ if ($endSubstPosition===false || $endSubstPosition-$endPosition==1 || $endSubstPosition<=$oldEndSubstPosition && $thisCount>0){
 96+ $wfyToText=$wfyText;
 97+ } else {
 98+ $wfyToText=substr($forcedMatterText,$endPosition+1,$endSubstPosition-$endPosition-1);
 99+ }
 100+ $articleStartPos=strpos($text,$wfyText);
 101+ $continueThis=true;
 102+ if ($articleStartPos===false){
 103+ $continueThis=false;
 104+ }
 105+ if ($articleStartPos>2){
 106+ if (substr($text,$articleStartPos-2,2)=='[['){
 107+ $continueThis=false;
 108+ }
 109+ }
 110+ if ($continueThis==true){
 111+ $text=substr($text,0,$articleStartPos).'[['.$wfyToText.'|'.$wfyText.']]'.substr($text,$articleStartPos+strlen($wfyText),strlen($text)-$articleStartPos-strlen($wfyText));
 112+ }
 113+ $thisCount++;
 114+ $strPosition++;
 115+ }
115116 }
116117 }
117118 }
@@ -119,30 +120,30 @@
120121 }
121122
122123 function FrontBackForcedArticleSaveCompleteHook (&$article, &$user, $text, $summary,
123 - $minoredit, $watchthis, $sectionanchor, &$flags, $revision, &$status, $baseRevId ){
124 - global $wgLang;
125 - wfLoadExtensionMessages('FrontBackMatterForcedWikilinks');
126 - $frontMsg=wfMsg( 'frontbackforced-front');
127 - $backMsg=wfMsg( 'frontbackforced-back');
128 - $forcedMsg=wfMsg( 'frontbackforced-forced');
129 - $myTitle=$article->getTitle()->getPrefixedDBkey();
 124+ $minoredit, $watchthis, $sectionanchor, &$flags, $revision, &$status, $baseRevId ){
 125+ global $wgLang;
 126+ wfLoadExtensionMessages('FrontBackMatterForcedWikilinks');
 127+ $frontMsg=wfMsgForContent( 'frontbackforced-front' );
 128+ $backMsg=wfMsgForContent( 'frontbackforced-back' );
 129+ $forcedMsg=wfMsgForContent( 'frontbackforced-forced' );
 130+ $myTitle=$article->getTitle()->getPrefixedDBkey();
130131 if (substr($myTitle,strlen($myTitle)-strlen($frontMsg),strlen($frontMsg))==$frontMsg){
131 - $frontBaseTitle=Title::newFromDBkey(substr($myTitle,0,strlen($myTitle)-strlen($frontMsg)));
132 - $frontBaseTitle->invalidateCache();
133 - Article::onArticleCreate($frontBaseTitle);
134 - Article::onArticleEdit($frontBaseTitle);
 132+ $frontBaseTitle=Title::newFromDBkey(substr($myTitle,0,strlen($myTitle)-strlen($frontMsg)));
 133+ $frontBaseTitle->invalidateCache();
 134+ Article::onArticleCreate($frontBaseTitle);
 135+ Article::onArticleEdit($frontBaseTitle);
135136 }
136 - if (substr($myTitle,strlen($myTitle)-strlen($backMsg),strlen($backMsg))==$backMsg){
137 - $backBaseTitle=Title::newFromDBkey(substr($myTitle,0,strlen($myTitle)-strlen($backMsg)));
138 - $backBaseTitle->invalidateCache();
139 - Article::onArticleCreate($backBaseTitle);
140 - Article::onArticleEdit($backBaseTitle);
 137+ if (substr($myTitle,strlen($myTitle)-strlen($backMsg),strlen($backMsg))==$backMsg){
 138+ $backBaseTitle=Title::newFromDBkey(substr($myTitle,0,strlen($myTitle)-strlen($backMsg)));
 139+ $backBaseTitle->invalidateCache();
 140+ Article::onArticleCreate($backBaseTitle);
 141+ Article::onArticleEdit($backBaseTitle);
141142 }
142 - if (substr($myTitle,strlen($myTitle)-strlen($forcedMsg),strlen($forcedMsg))==$forcedMsg){
143 - $forcedBaseTitle=Title::newFromDBkey(substr($myTitle,0,strlen($myTitle)-strlen($forcedMsg)));
144 - $forcedBaseTitle->invalidateCache();
145 - Article::onArticleCreate($forcedBaseTitle);
146 - Article::onArticleEdit($forcedBaseTitle);
 143+ if (substr($myTitle,strlen($myTitle)-strlen($forcedMsg),strlen($forcedMsg))==$forcedMsg){
 144+ $forcedBaseTitle=Title::newFromDBkey(substr($myTitle,0,strlen($myTitle)-strlen($forcedMsg)));
 145+ $forcedBaseTitle->invalidateCache();
 146+ Article::onArticleCreate($forcedBaseTitle);
 147+ Article::onArticleEdit($forcedBaseTitle);
147148 }
148 - return true;
 149+ return true;
149150 }
\ No newline at end of file
Index: trunk/extensions/Translate/groups/mediawiki-defines.txt
@@ -466,6 +466,9 @@
467467 ignored = framedvideo_max_height, framedvideo_allow_full_screen, framedvideo_force_allow_full_screen, framedvideo_force_frames
468468 ignored = framedvideo_force_position
469469
 470+Front Back Matter Forced Wikilinks
 471+descmsg = frontbackforced-desc
 472+
470473 Fundraiser Portal
471474
472475 Gadgets

Status & tagging log