r66817 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66816‎ | r66817 | r66818 >
Date:09:49, 24 May 2010
Author:tisane
Status:deferred
Tags:
Comment:
New extension for wikis with mirrored pages updated frequently by bot
Modified paths:
  • /trunk/extensions/FrontBackMatterForcedWikilinks (added) (history)
  • /trunk/extensions/FrontBackMatterForcedWikilinks/FrontBackMatterForcedWikilinks.i18n.php (added) (history)
  • /trunk/extensions/FrontBackMatterForcedWikilinks/FrontBackMatterForcedWikilinks.php (added) (history)

Diff [purge]

Index: trunk/extensions/FrontBackMatterForcedWikilinks/FrontBackMatterForcedWikilinks.i18n.php
@@ -0,0 +1,9 @@
 2+<?php
 3+$messages = array();
 4+
 5+$messages['en'] = array(
 6+ 'frontbackforced-desc' => 'Prepends front matter and appends back matter to pages and implements forced wikilinks',
 7+ 'frontbackforced-front' => '_(front_matter)',
 8+ 'frontbackforced-back' => '_(back_matter)',
 9+ 'frontbackforced-forced' => '_(forced_wikilinks)'
 10+);
\ No newline at end of file
Index: trunk/extensions/FrontBackMatterForcedWikilinks/FrontBackMatterForcedWikilinks.php
@@ -0,0 +1,150 @@
 2+<?php
 3+/**
 4+ * Front and Back Matter and Forced Wikilinks extension by Tisane
 5+ * URL: http://www.mediawiki.org/wiki/Extension:FrontBackMatterForcedWikilinks
 6+ *
 7+ * This program is free software. You can redistribute it and/or modify
 8+ * it under the terms of the GNU General Public License as published by
 9+ * the Free Software Foundation; either version 2 of the License, or
 10+ * (at your option) any later version. You can also redistribute it and/or
 11+ * modify it under the terms of the Creative Commons Attribution 3.0 license.
 12+ *
 13+ * This program prepends front matter and appends back matter to pages and
 14+ * implements forced wikilinks.
 15+ */
 16+
 17+# Alert the user that this is not a valid entry point to MediaWiki if they try to access the
 18+# special pages file directly.
 19+if (!defined('MEDIAWIKI')) {
 20+ echo <<<EOT
 21+To install the Front and Back Matter and Forced Wikilinks extension, put the following line in LocalSettings.php:
 22+require_once( "\$IP/extensions/FrontBackMatterForcedWikilinks/FrontBackMatterForcedWikilinks.php" );
 23+EOT;
 24+ exit( 1 );
 25+}
 26+
 27+$wgExtensionCredits['parserhook'][] = array(
 28+ 'name' => 'Front and Back Matter and Forced Wikilinks',
 29+ 'author' => 'Tisane',
 30+ 'url' => 'http://www.mediawiki.org/wiki/Extension:FrontBackMatterForcedWikilinks',
 31+ 'description' => 'Prepends front matter and appends back matter to pages and implements forced wikilinks',
 32+ 'descriptionmsg' => 'FrontBackForced-desc',
 33+ 'version' => '1.0.0',
 34+);
 35+
 36+$dir = dirname(__FILE__) . '/';
 37+$wgExtensionMessagesFiles['FrontBackMatterForcedWikilinks'] = $dir . 'FrontBackMatterForcedWikilinks.i18n.php';
 38+
 39+$wgHooks['ParserBeforeStrip'][] = 'FrontBackForcedParserBeforeStripHook';
 40+$wgHooks['ArticleSaveComplete'][] = 'FrontBackForcedArticleSaveCompleteHook';
 41+
 42+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');
 48+ $dbr = wfGetDB( DB_SLAVE );
 49+ $title=$parser->getTitle();
 50+ if( $title->getNamespace() == NS_SPECIAL
 51+ || $title->getNamespace() == NS_MEDIA
 52+ || $title->getNamespace() == NS_FILE
 53+ || $title->isExternal()) {
 54+ return true;
 55+ }
 56+ $myRevision=Revision::loadFromTitle($dbr,$title);
 57+ if ($myRevision!=null){
 58+ $myText=$myRevision->getRawText ();
 59+ if ($text==$myText){
 60+ $frontMatterTitle=Title::newFromDBkey($title->getPrefixedDBkey().$frontMsg);
 61+ $frontMatterRev=Revision::loadFromTitle($dbr,$frontMatterTitle);
 62+ if ($frontMatterRev!=null){
 63+ $frontMatterText=$frontMatterRev->getRawText();
 64+ $text=$frontMatterText.$text;
 65+ }
 66+ $backMatterTitle=Title::newFromDBkey($title->getPrefixedDBkey().$backMsg);
 67+ $backMatterRev=Revision::loadFromTitle($dbr,$backMatterTitle);
 68+ if ($backMatterRev!=null){
 69+ $backMatterText=$backMatterRev->getRawText();
 70+ $text=$text.$backMatterText;
 71+ }
 72+ $forcedMatterTitle=Title::newFromDBkey($title->getPrefixedDBkey().$forcedMsg);
 73+ $forcedMatterRev=Revision::loadFromTitle($dbr,$forcedMatterTitle);
 74+ if ($forcedMatterRev!=null){
 75+ $forcedMatterText=$forcedMatterRev->getRawText();
 76+ $strPosition=0;
 77+ $endPosition=0;
 78+ $endSubstPosition=0;
 79+ $thisCount=0;
 80+ $keepGoing=0;
 81+ while (1){
 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+ }
 116+ }
 117+ }
 118+ }
 119+
 120+ #$text=$text.$myText.$text.$myText;
 121+ return true;
 122+}
 123+
 124+function FrontBackForcedArticleSaveCompleteHook (&$article, &$user, $text, $summary,
 125+ $minoredit, $watchthis, $sectionanchor, &$flags, $revision, &$status, $baseRevId ){
 126+ global $wgLang;
 127+ wfLoadExtensionMessages('FrontBackMatterForcedWikilinks');
 128+ $frontMsg=wfMsg( 'frontbackforced-front');
 129+ $backMsg=wfMsg( 'frontbackforced-back');
 130+ $forcedMsg=wfMsg( 'frontbackforced-forced');
 131+ $myTitle=$article->getTitle()->getPrefixedDBkey();
 132+ if (substr($myTitle,strlen($myTitle)-strlen($frontMsg),strlen($frontMsg))==$frontMsg){
 133+ $frontBaseTitle=Title::newFromDBkey(substr($myTitle,0,strlen($myTitle)-strlen($frontMsg)));
 134+ $frontBaseTitle->invalidateCache();
 135+ Article::onArticleCreate($frontBaseTitle);
 136+ Article::onArticleEdit($frontBaseTitle);
 137+ }
 138+ if (substr($myTitle,strlen($myTitle)-strlen($backMsg),strlen($backMsg))==$backMsg){
 139+ $backBaseTitle=Title::newFromDBkey(substr($myTitle,0,strlen($myTitle)-strlen($backMsg)));
 140+ $backBaseTitle->invalidateCache();
 141+ Article::onArticleCreate($backBaseTitle);
 142+ Article::onArticleEdit($backBaseTitle);
 143+ }
 144+ if (substr($myTitle,strlen($myTitle)-strlen($forcedMsg),strlen($forcedMsg))==$forcedMsg){
 145+ $forcedBaseTitle=Title::newFromDBkey(substr($myTitle,0,strlen($myTitle)-strlen($forcedMsg)));
 146+ $forcedBaseTitle->invalidateCache();
 147+ Article::onArticleCreate($forcedBaseTitle);
 148+ Article::onArticleEdit($forcedBaseTitle);
 149+ }
 150+ return true;
 151+}
\ No newline at end of file

Status & tagging log