Jump to content

פרסום

From mediawiki.org
This page is a translated version of the page Advertising and the translation is 100% complete.

הצבת פרסומות או באנרים אחרים יכולה להיות שימושית עבור אתרי ויקי, במיוחד אתרי ויקי קטנים הדורשים פרסומות כדי לייצר כסף ולקזז את עלויות השרת. הצבת פרסומות יכולה להיות מאתגרת למשתמשים שאין להם הבנה מעמיקה של מדיה-ויקי. חלק מהאתגרים עשויים לכלול:

  • צורך למצוא דרך להכניס את הפרסומת לכל דף באתר ויקי. – הוספת הקוד ידנית לכל דף, דבר שניתן לעשות בעזרת תבנית, לא תהיה יעילה במיוחד.
  • שיקולי אבטחה – לא ניתן להוסיף תגי HTML רבים ו-JavaScript לדפים, מה שמונע את הדבקת הקוד בדפים בודדים או ב-sitenotice . הפעלת פונקציונליות כזו מסוכנת ביותר ותגרום לפריצה לאתר האינטרנט שלך.
  • שמירת הקוד במקום הנכון – מישהו עם ידע ב-HTML של מדיה-ויקי יכול להוסיף באנר לקובץ ה-PHP הרלוונטי של הערכת עיצוב, אך באנר זה יושמד במהלך כל שדרוג. ייתכן גם שיהיה קשה למישהו לדעת היכן למקם את הקוד.

סקריפטים ותוספים להצבת פרסומות

הוספת באנרים לערכות עיצוב במקומות שאינם בהודעת האתר

כל הערכות עיצוב המודרניים תומכים בהוספת באנרים בסרגל צד ובתחתית הערכת עיצוב באמצעות SkinAfterPortlet (מאזMW 1.35) וקריאות־וו של SkinAfterContent . לא אמורים להיות צורך בתוספים או בעיצובים מיוחדים.

	public function onSkinAfterPortlet( $skin, $portletName, &$html ) {
		$key1 = 'AD1'; // <== Place this key in the MediaWiki:Sidebar
		$key2 = 'AD2'; // <== Place this key in the MediaWiki:Sidebar
		$html_snippet1 = '<div style="">Potential banner location.</div>';
		$html_snippet2 = '<div style="">Potential banner location.</div>';
		$sidebar_elements = [];
		$sidebar_elements[$key1] = $html_snippet1;
		$sidebar_elements[$key2] = $html_snippet2;

		if ( array_key_exists( $portletName, $sidebar_elements ) ) {
			$element = $sidebar_elements[$portletName];
			if ( !empty( $element ) ) {
				$html = $element;
				return true;
			}
		}
	}

	public function onSkinAfterContent( &$data, $skin ) {
		$data .= '<div style="">Potential banner location on the bottom.</div>';
	}

The following information is outdated. The collapsible feature has been removed from the Vector skin. The collapsible navigation portals are now provided by the CollapsibleVector extension which will have to be installed additionally.[1]

  • https://gist.github.com/Inquisitor-Sasha/6759008
    One of the problems with placing advertising in the Vector sidebar is that the sections are collapsible, meaning that many visitors will not see advertisements if they are not properly put it. The problem is that locking a sidebar section open requires technical server side scripting that some users might not want to do. This script places the code of the banner above the title of the section, and displays whether or not the section is expanded.
    To use this script, add it to the MediaWiki:Vector.js page and change the referenced ID of the sidebar section to the ID of the section where you want to add the banner.

Howto

There are a number of existing advertisement extensions for MediaWiki that may serve as examples of how it can be done.

There are a few different ways to inject ad banners into a MediaWiki skin:

  • Edit the skin template itself (e.g. skins/Vector.php for the Vector skin) and add the banner code in a suitable location. This is a fairly quick and easy solution, but suffers from the problem that you'll need to redo it every time you upgrade MediaWiki (or upgrade your skin, if you're using a non-standard one).
  • Find a suitable hook to inject the banner code into the skin. If you're just doing this for your own wiki, you can simply write the hook code directly into your LocalSettings.php (or into a separate PHP file that you include from there, if you prefer), but you could also turn it into a full MediaWiki extension (which basically just means, at a minimum, putting it in a separate file and adding a bit of boilerplate code).
  • Alas, finding the right hook for the job may not always be trivial. For injecting ads into the sidebar, the SkinBuildSidebar hook may be convenient; SkinAfterContent might work for footer ads, and for top ads, you could maybe (ab)use the SiteNoticeAfter hook.
  • Create a parser tag extension that allows you to add a custom tag like ‎<adshere /> to your pages to inject the ad banner code at that location. Straightforward, but requires you put the tag on any page that you want ads on (or in an interface message, if you can find a suitable one; tip: try appending the parameter uselang=qqx to URLs to see which messages are used where).
  • Find a suitably located interface message which is treated as raw HTML, and put your ad code there directly. Alas, there aren't many such messages, and the trend is towards getting rid of the few that are left.
  • For ads that can be injected with JavaScript only, you can simply put the code in MediaWiki:Common.js (or in the appropriate skin-specific JS page).[2]
  1. Skin:Vector - section "Collapsible navigation"
  2. From the Answer on stackoverflow.com on August 16, 2012 to the question "Using ads and banners on MediaWiki".